Skip to content

Commit

Permalink
add percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
xinehc committed Oct 11, 2022
1 parent 8e6f4f2 commit 951c16c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions args_oap/argoap_pipeline_stagetwo_version3.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,20 @@

logger.info("Saving output files ...")
for level in levels:
for measure, normalizer, name in zip(['scov', 'scov', 'count', 'rpk'],
['CellNumber', '#of16Sreads', '#ofReads', '#ofReads'],
['normalize_cellnumber', 'normalize_16s', 'ppm', 'fpkm']):
for measure, normalizer, name in zip(['scov', 'scov', 'count', 'rpk', 'rpk'],
['CellNumber', '#of16Sreads', '#ofReads', '#ofReads', '#ofReads'],
['normalize_cellnumber', 'normalize_16s', 'ppm', 'fpkm', 'percentage']):
agg = result.groupby([level, 'Name'])[measure].sum().reset_index()
out = pd.merge(agg, meta, on = 'Name', how ='outer')
out['value'] = out[measure]/out[normalizer]
if measure in {'ppm', 'fpkm'}:

if name in {'ppm', 'fpkm'}:
out['value'] = out['value'] * 1e6

if name in {'percentage'}:
out = pd.merge(out, out.groupby('Name')['value'].sum().reset_index(), on='Name')
out['value'] = out['value_x'] / out['value_y']

out.set_index(level).pivot(columns = 'Name', values = 'value').fillna(0).sort_index().to_csv(
str(args.o) + '.' + name + '.' + level + '.txt', sep ='\t')

Expand Down

0 comments on commit 951c16c

Please sign in to comment.