-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from AroneyS/add-refinery-max-iterations-arg
Add refinery max iterations arg
- Loading branch information
Showing
7 changed files
with
195 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import subprocess | ||
import shutil | ||
import os | ||
from pathlib import Path | ||
|
||
def checkm(checkm2_db, bin_folder, bin_ext, refinery_max_iterations, output_folder, output_file, threads): | ||
if len([f for f in os.listdir(bin_folder) if f.endswith(bin_ext)]) == 0: | ||
print(f"No bins found in {bin_folder}") | ||
os.makedirs(output_folder) | ||
Path(output_file).touch() | ||
elif refinery_max_iterations == 0: | ||
print("Skipping pre-refinery CheckM2 rules") | ||
os.makedirs(output_folder) | ||
Path(output_file).touch() | ||
else: | ||
print(f"Using CheckM2 database {checkm2_db}/uniref100.KO.1.dmnd") | ||
subprocess.run(f"CHECKM2DB={checkm2_db}/uniref100.KO.1.dmnd checkm2 predict -i {bin_folder}/ -x {bin_ext} -o {output_folder} -t {threads} --force") | ||
shutil.copy(f"{output_folder}/quality_report.tsv", output_file) | ||
|
||
|
||
if __name__ == '__main__': | ||
checkm2_db = snakemake.params.checkm2_db_path | ||
bin_folder = snakemake.params.bin_folder | ||
bin_ext = snakemake.params.extension | ||
refinery_max_iterations = snakemake.params.refinery_max_iterations | ||
output_folder = snakemake.output.output_folder | ||
output_file = snakemake.output.output_file | ||
threads = snakemake.threads | ||
|
||
checkm(checkm2_db, bin_folder, bin_ext, refinery_max_iterations, output_folder, output_file, threads) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import unittest | ||
import os | ||
import tempfile | ||
from aviary.modules.binning.scripts.run_checkm import checkm | ||
from unittest.mock import patch | ||
import subprocess | ||
from pathlib import Path | ||
|
||
def create_output(_): | ||
os.makedirs("output_folder") | ||
Path(os.path.join("output_folder", "quality_report.tsv")).touch() | ||
|
||
class Tests(unittest.TestCase): | ||
def test_run_checkm(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
os.chdir(tmpdir) | ||
with patch.object(subprocess, "run", side_effect=create_output) as mock_subprocess: | ||
checkm2_db = os.path.join("checkm2_db") | ||
os.makedirs(checkm2_db) | ||
bin_folder = os.path.join("bin_folder") | ||
os.makedirs(bin_folder) | ||
Path(os.path.join(bin_folder, "bin_1.fna")).touch() | ||
|
||
checkm(checkm2_db, bin_folder, "fna", 1, "output_folder", "output_file", 1) | ||
self.assertTrue(os.path.exists("output_file")) | ||
mock_subprocess.assert_called_once_with(f"CHECKM2DB={checkm2_db}/uniref100.KO.1.dmnd checkm2 predict -i {bin_folder}/ -x fna -o output_folder -t 1 --force") | ||
|
||
def test_run_checkm_no_bins(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
os.chdir(tmpdir) | ||
with patch.object(subprocess, "run") as mock_subprocess: | ||
checkm2_db = os.path.join("checkm2_db") | ||
os.makedirs(checkm2_db) | ||
bin_folder = os.path.join("bin_folder") | ||
os.makedirs(bin_folder) | ||
|
||
checkm(checkm2_db, bin_folder, "fna", 1, "output_folder", "output_file", 1) | ||
self.assertTrue(os.path.exists("output_file")) | ||
mock_subprocess.assert_not_called() | ||
|
||
def test_run_checkm_no_refinery(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
os.chdir(tmpdir) | ||
with patch.object(subprocess, "run") as mock_subprocess: | ||
checkm2_db = os.path.join("checkm2_db") | ||
os.makedirs(checkm2_db) | ||
bin_folder = os.path.join("bin_folder") | ||
os.makedirs(bin_folder) | ||
Path(os.path.join(bin_folder, "bin_1.fna")).touch() | ||
|
||
checkm(checkm2_db, bin_folder, "fna", 0, "output_folder", "output_file", 1) | ||
self.assertTrue(os.path.exists("output_file")) | ||
mock_subprocess.assert_not_called() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |