Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix empty bin_info.tsv with --skip-abundances #127

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aviary/modules/binning/scripts/finalise_stats.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you need to update the second merge as well. For safety, it should likely be a left join as well to keep all of the checkm output, also should change the column it is joining on to on=[merged_out.columns[0]] right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case taxonomy is missing a genome?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I know there are cases where GTDB-tk will randomly fail to assign taxonomy to genomes due to some pplacer issue. Not sure what happens to the gtdb-tk output in that case, like it might just end up missing from the file. Additionally, there probably exists a world where running gtdb-tk ends up being an optional step so making it a left join future proofs against that I suppose

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_taxonomy(rename_columns="Bin Id"):

taxa = get_taxonomy(checkm_output.columns[0])

merged_out = pd.merge(checkm_output, coverage_file, on=[checkm_output.columns[0]])
merged_out = pd.merge(checkm_output, coverage_file, on=[checkm_output.columns[0]], how="left")
merged_out = pd.merge(merged_out, taxa, on=[checkm_output.columns[0]])
merged_out.to_csv(snakemake.output.bin_stats, sep='\t', index=False)

Expand Down
20 changes: 17 additions & 3 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ def test_short_read_recovery(self):
)
subprocess.run(cmd, shell=True, check=True)

self.assertTrue(os.path.isfile(f"{tmpdir}/aviary_out/bins/bin_info.tsv"))
bin_info_path = f"{tmpdir}/aviary_out/bins/bin_info.tsv"
self.assertTrue(os.path.isfile(bin_info_path))
with open(bin_info_path) as f:
num_lines = sum(1 for _ in f)
self.assertTrue(num_lines > 1)

self.assertTrue(os.path.isfile(f"{tmpdir}/aviary_out/data/final_contigs.fasta"))
self.assertTrue(os.path.islink(f"{tmpdir}/aviary_out/assembly/final_contigs.fasta"))

Expand All @@ -97,7 +102,11 @@ def test_short_read_recovery_skip_binners(self):
)
subprocess.run(cmd, shell=True, check=True)

self.assertTrue(os.path.isfile(f"{tmpdir}/aviary_out/bins/bin_info.tsv"))
bin_info_path = f"{tmpdir}/aviary_out/bins/bin_info.tsv"
self.assertTrue(os.path.isfile(bin_info_path))
with open(bin_info_path) as f:
num_lines = sum(1 for _ in f)
self.assertTrue(num_lines > 1)
self.assertFalse(os.path.isfile(f"{tmpdir}/aviary_out/data/final_contigs.fasta"))


Expand All @@ -117,7 +126,12 @@ def test_short_read_recovery_skip_abundances(self):
)
subprocess.run(cmd, shell=True, check=True)

self.assertTrue(os.path.isfile(f"{tmpdir}/aviary_out/bins/bin_info.tsv"))
bin_info_path = f"{tmpdir}/aviary_out/bins/bin_info.tsv"
self.assertTrue(os.path.isfile(bin_info_path))
with open(bin_info_path) as f:
num_lines = sum(1 for _ in f)
self.assertEqual(num_lines, 3)

self.assertFalse(os.path.isfile(f"{tmpdir}/aviary_out/data/final_contigs.fasta"))


Expand Down