Skip to content

Commit

Permalink
summarise: Adjustment for polars 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
wwood committed Aug 10, 2024
1 parent e13b7f5 commit 8062303
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion singlem/summariser.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def write_taxonomic_level_coverage_table(**kwargs):
levels = ['root','domain','phylum','class','order','family','genus','species']
level_id_to_level_name = {i: levels[i] for i in range(len(levels))}
all_profiles = all_profiles.with_columns(
level = pl.col('level').replace(level_id_to_level_name)
level = pl.col('level').replace_strict(level_id_to_level_name, return_dtype=pl.Utf8)
)

all_profiles = all_profiles.select([
Expand Down
29 changes: 28 additions & 1 deletion test/test_summariser.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,34 @@ def test_output_taxonomic_profile_with_extras(self):
land 2.17 2.17 30.26 phylum Root; d__Bacteria; p__Proteobacteria
""")
self.assertEqual(expected, stdout)


def test_taxonomic_profile_coverage_not_down_to_species(self):
stdout = extern.run(f'singlem summarise --input-taxonomic-profile {path_to_data}/summarise/marine0.head5.profile \
--output-taxonomic-level-coverage /dev/stdout')
expected = """sample level coverage relative abundance (%)
marine0.1 1 3.64 50.77
marine0.1 2 3.53 49.23
"""
# replace multiple spaces with tabs
expected = re.compile(r' +').sub('\t', expected)
self.assertEqual(stdout, expected)

def test_taxonomic_profile_coverage_down_to_species(self):
stdout = extern.run(f'singlem summarise --input-taxonomic-profile {path_to_data}/summarise/land.profile \
--output-taxonomic-level-coverage /dev/stdout')
expected = """sample level coverage relative abundance (%)
land0.1 domain 0.0 0.0
land0.1 phylum 0.0 0.0
land0.1 class 0.0 0.0
land0.1 order 0.0 0.0
land0.1 family 0.0 0.0
land0.1 genus 0.0 0.0
land0.1 species 132.9 100.0
"""
# replace multiple spaces with tabs
expected = re.compile(r' +').sub('\t', expected)
self.assertEqual(stdout, expected)


if __name__ == "__main__":
unittest.main()

0 comments on commit 8062303

Please sign in to comment.