From 58034e0efc90345db85d1f13191c788a89528ff2 Mon Sep 17 00:00:00 2001 From: Mahmudur Date: Thu, 9 Nov 2023 14:39:32 -0500 Subject: [PATCH 1/6] added test tests --- tests/test_utils.py | 103 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index c94a9f1..1db085c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,6 +8,14 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from srcs import utils import sourmash +import unittest +import math +import json +import pytest +import tempfile +import gzip +import sys +import shutil def to_testing_data(file): @@ -53,9 +61,104 @@ def test_load_signature_with_ksize3(): assert type(sig) == sourmash.signature.FrozenSourmashSignature assert sig.jaccard(sig) == 1.0 +class TestGetColumnIndices(unittest.TestCase): + def test_1(self): + column_name_to_index = { + "TAXID": 1, + "RANK": 0, + "PERCENTAGE": 2, + "TAXPATH": 3, + "TAXPATHSN": 4 + } + indices = utils.get_column_indices(column_name_to_index) + assert indices == (0, 1, 2, 3, 4) + + def test_2(self): + column_name_to_index = { + "RANK": 0, + "PERCENTAGE": 2, + "TAXPATH": 3, + "TAXPATHSN": 4 + } + with self.assertRaises(RuntimeError): + indices = utils.get_column_indices(column_name_to_index) + + def test_3(self): + column_name_to_index = { + "TAXID": 1, + "PERCENTAGE": 2, + "TAXPATH": 3, + "TAXPATHSN": 4 + } + with self.assertRaises(RuntimeError): + indices = utils.get_column_indices(column_name_to_index) + + def test_4(self): + column_name_to_index = { + "TAXID": 1, + "RANK": 0, + "TAXPATH": 3, + "TAXPATHSN": 4 + } + with self.assertRaises(RuntimeError): + indices = utils.get_column_indices(column_name_to_index) + + def test_5(self): + column_name_to_index = { + "TAXID": 1, + "RANK": 0, + "PERCENTAGE": 2, + "TAXPATHSN": 4 + } + with self.assertRaises(RuntimeError): + indices = utils.get_column_indices(column_name_to_index) + + def test_6(self): + column_name_to_index = { + "TAXID": 1, + "RANK": 0, + "PERCENTAGE": 2, + "TAXPATH": 3 + } + indices = utils.get_column_indices(column_name_to_index) + assert indices[4] is None + +class TestGetCamiProfile(unittest.TestCase): + def test_1(self): + file_path = os.path.join(os.path.dirname(__file__), 'testdata/sample_cami.txt') + with open(file_path, 'r') as file: + sample_cami_content = file.readlines() + + profiles = utils.get_cami_profile(sample_cami_content) + expected_header = { + 'SAMPLEID': 'CAMI_LOW_S001', + 'VERSION': '0.9.1', + 'RANKS': 'superkingdom|phylum|class|order|family|genus|species|strain', + 'TAXONOMYID': 'ncbi-taxonomy_DATE', + '__PROGRAM__': 'unknown' + } + assert len(profiles) == 1 + sample_id, header, profile = profiles[0] + assert sample_id == "CAMI_LOW_S001" + assert header == expected_header + assert len(profile) == 2044 + prediction1 = profile[0] + assert prediction1.rank == 'superkingdom' + assert prediction1.taxid == '2157' + assert math.isclose(prediction1.percentage, 0.029528, abs_tol=1e-6) + assert prediction1.taxpath == '2157' + assert prediction1.taxpathsn == 'Archaea' + prediction2 = profile[1] + assert prediction2.rank == 'superkingdom' + assert prediction2.taxid == '2' + assert math.isclose(prediction2.percentage, 29.183763, rel_tol=1e-6) + assert prediction2.taxpath == '2' + assert prediction2.taxpathsn == 'Bacteria' +if __name__ == '__main__': + unittest.main() From c4c09266c14cc0a73a07f5a552b72778bfe081f8 Mon Sep 17 00:00:00 2001 From: Mahmudur Date: Thu, 9 Nov 2023 22:22:26 -0500 Subject: [PATCH 2/6] removed duplications, added assertion --- tests/test_utils.py | 8 ++--- tests/test_workflow.py | 6 ++-- tests/unittests.py | 71 +++++++----------------------------------- 3 files changed, 19 insertions(+), 66 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 1db085c..862ff05 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -81,7 +81,7 @@ def test_2(self): "TAXPATHSN": 4 } with self.assertRaises(RuntimeError): - indices = utils.get_column_indices(column_name_to_index) + utils.get_column_indices(column_name_to_index) def test_3(self): column_name_to_index = { @@ -91,7 +91,7 @@ def test_3(self): "TAXPATHSN": 4 } with self.assertRaises(RuntimeError): - indices = utils.get_column_indices(column_name_to_index) + utils.get_column_indices(column_name_to_index) def test_4(self): column_name_to_index = { @@ -101,7 +101,7 @@ def test_4(self): "TAXPATHSN": 4 } with self.assertRaises(RuntimeError): - indices = utils.get_column_indices(column_name_to_index) + utils.get_column_indices(column_name_to_index) def test_5(self): column_name_to_index = { @@ -111,7 +111,7 @@ def test_5(self): "TAXPATHSN": 4 } with self.assertRaises(RuntimeError): - indices = utils.get_column_indices(column_name_to_index) + utils.get_column_indices(column_name_to_index) def test_6(self): column_name_to_index = { diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 1495198..cb04531 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -82,6 +82,6 @@ def test_demo_workflow(): cmd = "cd demo; python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads 1 --min_coverage_list 1 0.6 0.2 0.1 --out result.xlsx" _ = subprocess.run(cmd, shell=True, check=True) cmd = "cd demo; python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./" - _ = subprocess.run(cmd, shell=True, check=True) - - + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + assert exists('./cami_result.cami') diff --git a/tests/unittests.py b/tests/unittests.py index ec7bf18..641e373 100644 --- a/tests/unittests.py +++ b/tests/unittests.py @@ -33,54 +33,7 @@ def test_check_file_existence(): non_existing_file = os.path.join(tmp_dir, "non_existing_file.txt") with pytest.raises(ValueError, match=dont_exist): check_file_existence(non_existing_file, dont_exist) - -def test_get_column_indices(): - column_name_to_index = { - "TAXID": 1, - "RANK": 0, - "PERCENTAGE": 2, - "TAXPATH": 3, - "TAXPATHSN": 4 - } - indices = get_column_indices(column_name_to_index) - assert indices == (0, 1, 2, 3, 4) - -def test_get_cami_profile(): - file_path = os.path.join(os.path.dirname(__file__), 'testdata/sample_cami.txt') - with open(file_path, 'r') as file: - sample_cami_content = file.readlines() - - profiles = get_cami_profile(sample_cami_content) - - expected_header = { - 'SAMPLEID': 'CAMI_LOW_S001', - 'VERSION': '0.9.1', - 'RANKS': 'superkingdom|phylum|class|order|family|genus|species|strain', - 'TAXONOMYID': 'ncbi-taxonomy_DATE', - '__PROGRAM__': 'unknown' - } - - assert len(profiles) == 1 - sample_id, header, profile = profiles[0] - - assert sample_id == "CAMI_LOW_S001" - assert header == expected_header - assert len(profile) == 2044 - - prediction1 = profile[0] - assert prediction1.rank == 'superkingdom' - assert prediction1.taxid == '2157' - assert math.isclose(prediction1.percentage, 0.029528, abs_tol=1e-6) - assert prediction1.taxpath == '2157' - assert prediction1.taxpathsn == 'Archaea' - - prediction2 = profile[1] - assert prediction2.rank == 'superkingdom' - assert prediction2.taxid == '2' - assert math.isclose(prediction2.percentage, 29.183763, rel_tol=1e-6) - assert prediction2.taxpath == '2' - assert prediction2.taxpathsn == 'Bacteria' - + def test_get_alt_mut_rate(): nu = 10 thresh = 5 @@ -89,7 +42,7 @@ def test_get_alt_mut_rate(): result = get_alt_mut_rate(nu, thresh, ksize, significance) expected_result = 0.047902071844405425 assert math.isclose(result, expected_result, rel_tol=1e-6, abs_tol=1e-6) - + def test_get_alt_mut_rate_zero_nu(): nu = 0 thresh = 5 @@ -107,10 +60,10 @@ def test_get_alt_mut_rate_large_thresh(): result = get_alt_mut_rate(nu, thresh, ksize, significance) expected_result = -1 assert result == expected_result - + def test_get_info_from_single_sig(): sig_list_file = 'gtdb_ani_thresh_0.95_intermediate_files/training_sig_files.txt' - + with open(sig_list_file, 'r') as file: lines = file.readlines() if lines: @@ -143,7 +96,7 @@ def test_get_info_from_single_sig(): def test_collect_signature_info(): num_threads = 2 ksize = 0 - path_to_temp_dir = 'gtdb_ani_thresh_0.95_intermediate_files/' + path_to_temp_dir = 'gtdb_ani_thresh_0.95_intermediate_files/' result = collect_signature_info(num_threads, ksize, path_to_temp_dir) @@ -167,16 +120,16 @@ def test_run_multisearch(): result = run_multisearch(num_threads, ani_thresh, ksize, scale, path_to_temp_dir) for signature_name, expected_related_genomes in expected_results.items(): - assert signature_name in result - actual_related_genomes = result[signature_name] + assert signature_name in result + actual_related_genomes = result[signature_name] assert set(actual_related_genomes) == set(expected_related_genomes) - + def test_single_hyp_test(): exclusive_hashes_info_org = (100, 90) ksize = 31 - + result = single_hyp_test(exclusive_hashes_info_org, ksize) - + in_sample_est, p_val, num_exclusive_kmers, num_exclusive_kmers_coverage, num_matches, \ acceptance_threshold_with_coverage, actual_confidence_with_coverage, alt_confidence_mut_rate_with_coverage = result @@ -189,6 +142,6 @@ def test_single_hyp_test(): assert isinstance(actual_confidence_with_coverage, float) assert isinstance(alt_confidence_mut_rate_with_coverage, float) - + if __name__ == '__main__': - pytest.main() \ No newline at end of file + pytest.main() From 070a6de168c98e27a888adcfa78303588e68be37 Mon Sep 17 00:00:00 2001 From: Mahmudur Date: Thu, 9 Nov 2023 22:54:01 -0500 Subject: [PATCH 3/6] added assertions, fixed path --- tests/integration_tests.py | 28 +++++++++++++++++++++++----- tests/test_workflow.py | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/integration_tests.py b/tests/integration_tests.py index 4d15e35..14eaa8e 100644 --- a/tests/integration_tests.py +++ b/tests/integration_tests.py @@ -22,15 +22,15 @@ def make_train_fasta(): def test_sourmash_sketch_command(): with tempfile.TemporaryDirectory() as tmp_dir: make_train_fasta() - + fasta_file = "example.fasta" output_file = os.path.join(tmp_dir, "training_database.sig.zip") cmd = [ "sourmash", "sketch", "dna", "-f", "-p", "k=31,scaled=1000,abund", "--singleton", fasta_file, "-o", output_file ] - + subprocess.run(cmd, check=True) - + assert os.path.isfile(output_file) def test_make_training_data_from_sketches(): @@ -63,11 +63,29 @@ def test_make_training_data_from_sketches(): config = json.load(f) assert config['ksize'] == int(ksize) assert config['ani_thresh'] == float(ani_thresh) - + def test_run_yacht(): cmd = "python run_YACHT.py --json gtdb_ani_thresh_0.95_config.json --sample_file 'tests/testdata/sample.sig.zip' --significance 0.99 --min_coverage_list 1 0.6 0.2 0.1" - + res = subprocess.run(cmd, shell=True, check=True) assert res.returncode == 0 assert exists('result.xlsx') + +def test_run_yacht_and_standardizer(): + cmd = "cd demo; sourmash sketch dna -f -p k=31,scaled=1000,abund -o sample.sig.zip query_data/query_data.fq" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + cmd = "cd demo; sourmash sketch fromfile ref_paths.csv -p dna,k=31,scaled=1000,abund -o ref.sig.zip --force-output-already-exists" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + cmd = "cd demo; python ../make_training_data_from_sketches.py --force --ref_file ref.sig.zip --ksize 31 --num_threads 1 --ani_thresh 0.95 --prefix 'demo_ani_thresh_0.95' --outdir ./" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + cmd = "cd demo; python ../run_YACHT.py --json demo_ani_thresh_0.95_config.json --sample_file sample.sig.zip --significance 0.99 --num_threads 1 --min_coverage_list 1 0.6 0.2 0.1 --out result.xlsx" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + cmd = "cd demo; python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + assert exists('demo/cami_result.cami') diff --git a/tests/test_workflow.py b/tests/test_workflow.py index cb04531..6e7d927 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -84,4 +84,4 @@ def test_demo_workflow(): cmd = "cd demo; python ../srcs/standardize_yacht_output.py --yacht_output result.xlsx --sheet_name min_coverage0.2 --genome_to_taxid toy_genome_to_taxid.tsv --mode cami --sample_name 'MySample' --outfile_prefix cami_result --outdir ./" res = subprocess.run(cmd, shell=True, check=True) assert res.returncode == 0 - assert exists('./cami_result.cami') + assert exists('demo/cami_result.cami') From 041bd805f052f6a1b0835521b6fb24a7a8ac610f Mon Sep 17 00:00:00 2001 From: Mahmudur Date: Sun, 12 Nov 2023 15:16:19 -0500 Subject: [PATCH 4/6] added tests for standardize output --- tests/test_standardize_output.py | 95 ++++++++++++++++++ .../cami_result.cami | 21 ++++ .../standardize_output_testdata/result.xlsx | Bin 0 -> 8846 bytes .../toy_genome_to_taxid.tsv | 16 +++ .../standardize_output_testdata/~$result.xlsx | Bin 0 -> 165 bytes 5 files changed, 132 insertions(+) create mode 100644 tests/test_standardize_output.py create mode 100644 tests/testdata/standardize_output_testdata/cami_result.cami create mode 100644 tests/testdata/standardize_output_testdata/result.xlsx create mode 100644 tests/testdata/standardize_output_testdata/toy_genome_to_taxid.tsv create mode 100644 tests/testdata/standardize_output_testdata/~$result.xlsx diff --git a/tests/test_standardize_output.py b/tests/test_standardize_output.py new file mode 100644 index 0000000..e0ef8fe --- /dev/null +++ b/tests/test_standardize_output.py @@ -0,0 +1,95 @@ +import unittest +import os +import subprocess + +class TestScript(unittest.TestCase): + def test_everything_exists(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') + assert os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') + assert os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata') + assert os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + assert os.path.exists(os.path.join(outdir, 'cami_result.cami')) + + def test_wrong_yacht_output(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result_nonexisting.xlsx') + assert not os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') + assert os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata') + assert os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + with self.assertRaises(subprocess.CalledProcessError): + res = subprocess.run(cmd, shell=True, check=True) + + def test_wrong_genome_to_taxid(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') + assert os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid_nonexisting.tsv') + assert not os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata') + assert os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + with self.assertRaises(subprocess.CalledProcessError): + res = subprocess.run(cmd, shell=True, check=True) + + def test_wrong_outdir(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') + assert os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') + assert os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata_nonexisting') + cmd = 'rm -rf ' + outdir + try: + subprocess.run(cmd, shell=True, check=True) + except: + pass + assert not os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + assert os.path.exists(outdir) + + cmd = 'rm -rf ' + outdir + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/testdata/standardize_output_testdata/cami_result.cami b/tests/testdata/standardize_output_testdata/cami_result.cami new file mode 100644 index 0000000..a5ca06d --- /dev/null +++ b/tests/testdata/standardize_output_testdata/cami_result.cami @@ -0,0 +1,21 @@ +@SampleID:MySample +@Version:0.9.1 +@Ranks:superkingdom|phylum|class|order|family|genus|species + +@@TAXID RANK TAXPATH TAXPATHSN PERCENTAGE +2 superkingdom 2 Bacteria 100.0 +1239 phylum 2|1239 Bacteria|Bacillota 100.0 +186801 class 2|1239|186801 Bacteria|Bacillota|Clostridia 100.0 +186802 order 2|1239|186801|186802 Bacteria|Bacillota|Clostridia|Eubacteriales 100.0 +216572 family 2|1239|186801|186802|216572 Bacteria|Bacillota|Clostridia|Eubacteriales|Oscillospiraceae 40.0 +186803 family 2|1239|186801|186802|186803 Bacteria|Bacillota|Clostridia|Eubacteriales|Lachnospiraceae 20.0 +186806 family 2|1239|186801|186802|186806 Bacteria|Bacillota|Clostridia|Eubacteriales|Eubacteriaceae 40.0 +1017280 genus 2|1239|186801|186802|216572|1017280 Bacteria|Bacillota|Clostridia|Eubacteriales|Oscillospiraceae|Pseudoflavonifractor 20.0 +35829 genus 2|1239|186801|186802|216572|35829 Bacteria|Bacillota|Clostridia|Eubacteriales|Oscillospiraceae|Acetivibrio 20.0 +572511 genus 2|1239|186801|186802|186803|572511 Bacteria|Bacillota|Clostridia|Eubacteriales|Lachnospiraceae|Blautia 20.0 +1730 genus 2|1239|186801|186802|186806|1730 Bacteria|Bacillota|Clostridia|Eubacteriales|Eubacteriaceae|Eubacterium 40.0 +2841525 species 2|1239|186801|186802|216572|1017280|2841525 Bacteria|Bacillota|Clostridia|Eubacteriales|Oscillospiraceae|Pseudoflavonifractor|Pseudoflavonifractor sp. MSJ-30 20.0 +2841523 species 2|1239|186801|186802|216572|35829|2841523 Bacteria|Bacillota|Clostridia|Eubacteriales|Oscillospiraceae|Acetivibrio|Acetivibrio sp. MSJd-27 20.0 +2841517 species 2|1239|186801|186802|186803|572511|2841517 Bacteria|Bacillota|Clostridia|Eubacteriales|Lachnospiraceae|Blautia|Blautia sp. MSJ-19 20.0 +2841519 species 2|1239|186801|186802|186806|1730|2841519 Bacteria|Bacillota|Clostridia|Eubacteriales|Eubacteriaceae|Eubacterium|Eubacterium sp. MSJ-21 20.0 +2841513 species 2|1239|186801|186802|186806|1730|2841513 Bacteria|Bacillota|Clostridia|Eubacteriales|Eubacteriaceae|Eubacterium|Eubacterium sp. MSJ-13 20.0 diff --git a/tests/testdata/standardize_output_testdata/result.xlsx b/tests/testdata/standardize_output_testdata/result.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..44da4cd21a7fd5a5d45bd91de18150228c3a9229 GIT binary patch literal 8846 zcmZ{K1yEeu()D1$9fJEH0fNimPVnFw9D=(I1kYf>Ex227cXtTE9fFhK?*4Og>wEV- z{`Y3;oT*bay{2pL?$x_{jiM|JEDitwKmd5vS!hUVccS<|KUF?o7|)l9ow1^$oxKyY zp}jp5*v48uLLRw`1w;HvW@pJ(?UTHY<< z7S8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*$U9l`wmkgL=>Aiv%~@wi$Naf8agqh zTT1N^pG&mABdvl<}51zbUN|d{3ojtl~^N99&JR*>Ge)kxr_v zvD@ze;RtQon4QJranVKKF)xkqq|lOTW>qrD!3ti{M6L$i6}dQvPWWj#!Mg=6yt)uH zxF&TT&!w9!}vB zo|ecV9}hGs1lkE^Z|+FCNJ15fSIi1L9mlqrJ)WhxPuYoxQsioudDd8Jl$XH=(n1)_ z?J;EO!@DoEH0kfiwq4H~Q2D$Ognw_u-$D29+wms=hhurrKC@s*lpEau+>80MVV+ zbUL&Z){x+gj?WmVju#SAfYOXAbOL|GyjA&0`?(#%MXeT2&*cQ)ev{b%Y`LiPc|iGR zd}*`_V!1a7He=Ayu*sWKwsH+LyTwO4%BfxhcXF31rVfN<;G%9^oRv| zw-VTpPY|n_Y_owPQ?-51E-ovbmy*mV5posy9ivPR$C)8aCrCx@U(O&xA2j>r6nkv$ z6Wh1=k29=HT;EFCmiG=U`4GCh*?R3TXD&KX#gm`}Ur#d$K9^-EXdIaTt+YSK)t{H| z^K$?Hy8BD(m%8`gwg7-HRK>qr|DOu}()^`5{EzwI^Uwbmt@tItOLgF10Dedae*pfg zR`3$#<-qhG6oF@Ee|F;~%AfJ+OO%(>oPSV$qy1NuKeL^eC@=f7e^9ia_4EJY%b#xT zCCba=*1u4o#_|53{B!tvY5KCR{bQQ*OgjHouyj#T*xR literal 0 HcmV?d00001 From da7e05b3db0f479d31bf513e6c242764ca374a77 Mon Sep 17 00:00:00 2001 From: Mahmudur Date: Sun, 12 Nov 2023 15:21:55 -0500 Subject: [PATCH 5/6] added the test to utils --- tests/test_utils.py | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 862ff05..26cdb5e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -160,5 +160,95 @@ def test_1(self): assert prediction2.taxpath == '2' assert prediction2.taxpathsn == 'Bacteria' + +class TestStandardizeOutput(unittest.TestCase): + def test_everything_exists(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') + assert os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') + assert os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata') + assert os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + assert os.path.exists(os.path.join(outdir, 'cami_result.cami')) + + def test_wrong_yacht_output(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result_nonexisting.xlsx') + assert not os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') + assert os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata') + assert os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + with self.assertRaises(subprocess.CalledProcessError): + res = subprocess.run(cmd, shell=True, check=True) + + def test_wrong_genome_to_taxid(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') + assert os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid_nonexisting.tsv') + assert not os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata') + assert os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + with self.assertRaises(subprocess.CalledProcessError): + res = subprocess.run(cmd, shell=True, check=True) + + def test_wrong_outdir(self): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + script_dir = os.path.join(script_dir, 'srcs') + script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') + assert os.path.exists(script_full_path) + + yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') + assert os.path.exists(yacht_output) + + genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') + assert os.path.exists(genome_to_taxid) + + outdir = os.path.join(os.path.dirname(__file__), 'testdata_nonexisting') + cmd = 'rm -rf ' + outdir + try: + subprocess.run(cmd, shell=True, check=True) + except: + pass + assert not os.path.exists(outdir) + + cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + assert os.path.exists(outdir) + + cmd = 'rm -rf ' + outdir + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + + if __name__ == '__main__': unittest.main() From acd913b6eca15fc15ca69a17239412eda96bf387 Mon Sep 17 00:00:00 2001 From: Maksym Date: Thu, 7 Dec 2023 14:02:00 -0500 Subject: [PATCH 6/6] refactoring --- tests/test_standardize_output.py | 112 +++++++++++++++---------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/tests/test_standardize_output.py b/tests/test_standardize_output.py index e0ef8fe..8e30203 100644 --- a/tests/test_standardize_output.py +++ b/tests/test_standardize_output.py @@ -1,95 +1,93 @@ -import unittest +import unittest import os import subprocess +def get_script_path(): + script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + return os.path.join(script_dir, 'srcs', 'standardize_yacht_output.py') + +def assert_file_exists(file_path): + assert os.path.exists(file_path) + +def assert_file_not_exists(file_path): + assert not os.path.exists(file_path) + +def create_outdir(outdir): + cmd = f'rm -rf {outdir}' + try: + subprocess.run(cmd, shell=True, check=True) + except: + pass + assert not os.path.exists(outdir) + +def cleanup_outdir(outdir): + cmd = f'rm -rf {outdir}' + res = subprocess.run(cmd, shell=True, check=True) + assert res.returncode == 0 + class TestScript(unittest.TestCase): - def test_everything_exists(self): - script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - script_dir = os.path.join(script_dir, 'srcs') - script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') - assert os.path.exists(script_full_path) + def setUp(self): + self.script_full_path = get_script_path() + def test_everything_exists(self): yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') - assert os.path.exists(yacht_output) - genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') - assert os.path.exists(genome_to_taxid) - outdir = os.path.join(os.path.dirname(__file__), 'testdata') - assert os.path.exists(outdir) - cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + assert_file_exists(self.script_full_path) + assert_file_exists(yacht_output) + assert_file_exists(genome_to_taxid) + assert_file_exists(outdir) + + cmd = f"python {self.script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" res = subprocess.run(cmd, shell=True, check=True) assert res.returncode == 0 - assert os.path.exists(os.path.join(outdir, 'cami_result.cami')) + assert_file_exists(os.path.join(outdir, 'cami_result.cami')) def test_wrong_yacht_output(self): - script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - script_dir = os.path.join(script_dir, 'srcs') - script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') - assert os.path.exists(script_full_path) - yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result_nonexisting.xlsx') - assert not os.path.exists(yacht_output) - genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') - assert os.path.exists(genome_to_taxid) - outdir = os.path.join(os.path.dirname(__file__), 'testdata') - assert os.path.exists(outdir) - - cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + + assert_file_exists(self.script_full_path) + assert_file_not_exists(yacht_output) + assert_file_exists(genome_to_taxid) + assert_file_exists(outdir) + + cmd = f"python {self.script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" with self.assertRaises(subprocess.CalledProcessError): res = subprocess.run(cmd, shell=True, check=True) def test_wrong_genome_to_taxid(self): - script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - script_dir = os.path.join(script_dir, 'srcs') - script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') - assert os.path.exists(script_full_path) - yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') - assert os.path.exists(yacht_output) - genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid_nonexisting.tsv') - assert not os.path.exists(genome_to_taxid) - outdir = os.path.join(os.path.dirname(__file__), 'testdata') - assert os.path.exists(outdir) - cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" + assert_file_exists(self.script_full_path) + assert_file_exists(yacht_output) + assert_file_not_exists(genome_to_taxid) + assert_file_exists(outdir) + + cmd = f"python {self.script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" with self.assertRaises(subprocess.CalledProcessError): res = subprocess.run(cmd, shell=True, check=True) def test_wrong_outdir(self): - script_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - script_dir = os.path.join(script_dir, 'srcs') - script_full_path = os.path.join(script_dir, 'standardize_yacht_output.py') - assert os.path.exists(script_full_path) - yacht_output = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/result.xlsx') - assert os.path.exists(yacht_output) - genome_to_taxid = os.path.join(os.path.dirname(__file__), 'testdata/standardize_output_testdata/toy_genome_to_taxid.tsv') - assert os.path.exists(genome_to_taxid) - outdir = os.path.join(os.path.dirname(__file__), 'testdata_nonexisting') - cmd = 'rm -rf ' + outdir - try: - subprocess.run(cmd, shell=True, check=True) - except: - pass - assert not os.path.exists(outdir) - - cmd = f"python {script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" - res = subprocess.run(cmd, shell=True, check=True) - assert res.returncode == 0 - assert os.path.exists(outdir) - cmd = 'rm -rf ' + outdir + assert_file_exists(self.script_full_path) + assert_file_exists(yacht_output) + assert_file_exists(genome_to_taxid) + create_outdir(outdir) + + cmd = f"python {self.script_full_path} --yacht_output {yacht_output} --sheet_name min_coverage0.2 --genome_to_taxid {genome_to_taxid} --outfile_prefix cami_result --outdir {outdir}" res = subprocess.run(cmd, shell=True, check=True) assert res.returncode == 0 + assert_file_exists(outdir) + cleanup_outdir(outdir) if __name__ == '__main__': unittest.main() \ No newline at end of file