diff --git a/macrel/main.py b/macrel/main.py index c4180ef..5e2f979 100644 --- a/macrel/main.py +++ b/macrel/main.py @@ -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): diff --git a/tests/contigs.nosmorfs/expected.percontigs b/tests/contigs.nosmorfs/expected.percontigs index a11e9aa..138570d 100644 --- a/tests/contigs.nosmorfs/expected.percontigs +++ b/tests/contigs.nosmorfs/expected.percontigs @@ -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 diff --git a/tests/contigs/expected.percontigs b/tests/contigs/expected.percontigs index ab77ace..5c6b96a 100644 --- a/tests/contigs/expected.percontigs +++ b/tests/contigs/expected.percontigs @@ -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 diff --git a/tests/reads.se/expected.percontigs b/tests/reads.se/expected.percontigs index ea16872..3565512 100644 --- a/tests/reads.se/expected.percontigs +++ b/tests/reads.se/expected.percontigs @@ -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 diff --git a/tests/reads/expected.percontigs b/tests/reads/expected.percontigs index de62281..62e1c85 100644 --- a/tests/reads/expected.percontigs +++ b/tests/reads/expected.percontigs @@ -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