Skip to content

Commit

Permalink
summarise: --output-taxonomic-profile-with-extras: Name the taxon level.
Browse files Browse the repository at this point in the history
  • Loading branch information
wwood committed Apr 23, 2024
1 parent 2230e71 commit 92733e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions singlem/summariser.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ def write_taxonomic_profile_with_extras(**kwargs):

print("\t".join(["sample", "coverage", "full_coverage", "relative_abundance", "level", "taxonomy"]), file=output_io)

levels = ['root','domain','phylum','class','order','family','genus','species']

# For each profile
num_printed = 0
for profile_file in input_taxonomic_profile_files:
Expand All @@ -623,19 +625,17 @@ def write_taxonomic_profile_with_extras(**kwargs):
# Now write out the profile
for wn in profile.breadth_first_iter():
level = wn.calculate_level()
if level >= len(levels):
raise Exception("Unexpected level number: %s, this summariser method only know of %s" % (level, levels))
full_coverage = wn.get_full_coverage()
print("\t".join([
profile.sample,
str(wn.coverage),
str(round(full_coverage, 2)),
str(round(full_coverage / total_coverage * 100, 2)),
str(level),
str(levels[level]),
'; '.join(wn.get_taxonomy())
]), file=output_io)
num_printed += 1

logging.info("Wrote {} lines of taxonomic profile with extras".format(num_printed))

@staticmethod
def write_site_by_species_by_prefix(self):
pass
24 changes: 12 additions & 12 deletions test/test_summariser.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,18 @@ def test_output_taxonomic_profile_with_extras(self):
'--output-taxonomic-profile-with-extras /dev/stdout'
stdout = extern.run(cmd)
expected = re.compile(r' +').sub('\t', """sample coverage full_coverage relative_abundance level taxonomy
marine0.1 0 7.17 100.0 0 Root
marine0.1 3.64 4.2 58.58 1 Root; d__Archaea
marine0.1 0 2.97 41.42 1 Root; d__Bacteria
marine0.1 0.56 0.56 7.81 2 Root; d__Archaea; p__Thermoproteota
marine0.1 0.8 0.8 11.16 2 Root; d__Bacteria; p__Desulfobacterota
marine0.1 2.17 2.17 30.26 2 Root; d__Bacteria; p__Proteobacteria
land 0 7.17 100.0 0 Root
land 3.64 4.2 58.58 1 Root; d__Archaea
land 0 2.97 41.42 1 Root; d__Bacteria
land 0.56 0.56 7.81 2 Root; d__Archaea; p__Thermoproteota
land 0.8 0.8 11.16 2 Root; d__Bacteria; p__Desulfobacterota
land 2.17 2.17 30.26 2 Root; d__Bacteria; p__Proteobacteria
marine0.1 0 7.17 100.0 root Root
marine0.1 3.64 4.2 58.58 domain Root; d__Archaea
marine0.1 0 2.97 41.42 domain Root; d__Bacteria
marine0.1 0.56 0.56 7.81 phylum Root; d__Archaea; p__Thermoproteota
marine0.1 0.8 0.8 11.16 phylum Root; d__Bacteria; p__Desulfobacterota
marine0.1 2.17 2.17 30.26 phylum Root; d__Bacteria; p__Proteobacteria
land 0 7.17 100.0 root Root
land 3.64 4.2 58.58 domain Root; d__Archaea
land 0 2.97 41.42 domain Root; d__Bacteria
land 0.56 0.56 7.81 phylum Root; d__Archaea; p__Thermoproteota
land 0.8 0.8 11.16 phylum Root; d__Bacteria; p__Desulfobacterota
land 2.17 2.17 30.26 phylum Root; d__Bacteria; p__Proteobacteria
""")
self.assertEqual(expected, stdout)

Expand Down

0 comments on commit 92733e4

Please sign in to comment.