Skip to content

Commit

Permalink
ENH include density in the percontigs output
Browse files Browse the repository at this point in the history
  • Loading branch information
celiosantosjr committed Jul 13, 2023
1 parent b7d895e commit 56b1d6d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions macrel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,14 @@ def do_density(args, clen, prediction):
clen = clen.merge(on='contig', right=tpred, how='outer').fillna(0)
clen[clen.columns[1:]] = clen[clen.columns[1:]].astype(int)
ofile = path.join(args.output, args.outtag + '.percontigs.gz')
sample = clen.set_index('contig').sum(axis=0).tolist()
sample_density = sample[-1] * 1e6 / sample[0]
with open_output(ofile, mode='wb') as raw_out:
with gzip.open(raw_out, 'wt') as out:
from .macrel_version import __version__
out.write('# Prediction from macrel v{}\n'.format(__version__))
out.write(f'# Macrel calculated for the sample a density of {sample_density:.3f} AMPs / Mbp.\n')
clen.to_csv(out, sep='\t', index=False, float_format="%.3f")
sample = clen.set_index('contig').sum(axis=0).tolist()
sample_density = sample[-1] * 1e6 / sample[0]
print(f'Macrel processed the sample and verified a density of {sample_density:.3f} AMPs / Mbp.')

def do_get_examples(args):
Expand Down
1 change: 1 addition & 0 deletions tests/contigs.nosmorfs/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Prediction from macrel v1.2.0
# Macrel calculated for the sample a density of 0.000 AMPs / Mbp.
contig length ORFs smORFs AMPs
scaffold2530_2_MH0058 1324 1 0 0
1 change: 1 addition & 0 deletions tests/contigs/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Prediction from macrel v1.2.0
# Macrel calculated for the sample a density of 45.062 AMPs / Mbp.
contig length ORFs smORFs AMPs
scaffold2530_2_MH0058 717 2 2 0
scaffold75334_1_MH0058 3424 1 1 1
Expand Down
1 change: 1 addition & 0 deletions tests/reads.se/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Prediction from macrel v1.2.0
# Macrel calculated for the sample a density of 59.743 AMPs / Mbp.
contig length ORFs smORFs AMPs
k47_0 3379 4 2 0
k47_1 6046 9 4 0
Expand Down
1 change: 1 addition & 0 deletions tests/reads/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Prediction from macrel v1.2.0
# Macrel calculated for the sample a density of 57.627 AMPs / Mbp.
contig length ORFs smORFs AMPs
k77_3 1270 1 0 0
k77_5 5202 6 3 0
Expand Down

0 comments on commit 56b1d6d

Please sign in to comment.