diff --git a/config/amplicon_cov.yaml b/config/amplicon_cov.yaml index 1cb5efa..ff3ac71 100644 --- a/config/amplicon_cov.yaml +++ b/config/amplicon_cov.yaml @@ -1,14 +1,15 @@ #### Parameters # The name of the batch to process -batch: "20240705_AAFH52MM5" +batch: "20200729" ###### Inputs # where to find the list of samples i.e. samples.tsv -sample_list_dir: "../../data/amplicon_cov_data/cluster/project/pangolin/work-amplicon-coverage/test_data/" +sample_list_dir: "workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/samples/" + # where to find the samples from the list -sample_dir: "../../data/amplicon_cov_data/cluster/project/pangolin/work-amplicon-coverage/test_data/samples" +sample_dir: "workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/results" # bed file with the primers -primers_fp: "../../data/amplicon_cov_data/resources/amplicon_cov/articV3primers.bed" +primers_fp: "workflow/.tests/unit/amplicon_cov/data/primer_schemes/articV3primers.bed" ##### Outputs output_dir: "results/" diff --git a/workflow/.tests/unit/amplicon_cov/amplicon_cov.yaml b/workflow/.tests/unit/amplicon_cov/amplicon_cov.yaml new file mode 100644 index 0000000..ffba60a --- /dev/null +++ b/workflow/.tests/unit/amplicon_cov/amplicon_cov.yaml @@ -0,0 +1,15 @@ +#### Parameters +# The name of the batch to process +batch: "20200729" + +###### Inputs +# where to find the list of samples i.e. samples.tsv +sample_list_dir: "data/subset_vpipe_smkdeploy/test_output_sars-cov-2/samples/" + +# where to find the samples from the list +sample_dir: "data/subset_vpipe_smkdeploy/test_output_sars-cov-2/results" +# bed file with the primers +primers_fp: "data/primer_schemes/articV3primers.bed" + +##### Outputs +output_dir: "" diff --git a/workflow/.tests/integration/primer_schemes/articV3primers.bed b/workflow/.tests/unit/amplicon_cov/data/primer_schemes/articV3primers.bed similarity index 100% rename from workflow/.tests/integration/primer_schemes/articV3primers.bed rename to workflow/.tests/unit/amplicon_cov/data/primer_schemes/articV3primers.bed diff --git a/workflow/.tests/integration/subset_vpipe_smkdploy/README.md b/workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/README.md similarity index 100% rename from workflow/.tests/integration/subset_vpipe_smkdploy/README.md rename to workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/README.md diff --git a/workflow/.tests/integration/subset_vpipe_smkdploy/test_ouput_sars-cov-2/results/pos_MN908947_3_1/20200729/alignments/coverage.tsv.gz b/workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/results/pos_MN908947_3_1/20200729/alignments/coverage.tsv.gz similarity index 100% rename from workflow/.tests/integration/subset_vpipe_smkdploy/test_ouput_sars-cov-2/results/pos_MN908947_3_1/20200729/alignments/coverage.tsv.gz rename to workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/results/pos_MN908947_3_1/20200729/alignments/coverage.tsv.gz diff --git a/workflow/.tests/integration/subset_vpipe_smkdploy/test_ouput_sars-cov-2/results/pos_MT007544_1_1/20200729/alignments/coverage.tsv.gz b/workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/results/pos_MT007544_1_1/20200729/alignments/coverage.tsv.gz similarity index 100% rename from workflow/.tests/integration/subset_vpipe_smkdploy/test_ouput_sars-cov-2/results/pos_MT007544_1_1/20200729/alignments/coverage.tsv.gz rename to workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/results/pos_MT007544_1_1/20200729/alignments/coverage.tsv.gz diff --git a/workflow/.tests/integration/subset_vpipe_smkdploy/test_ouput_sars-cov-2/samples/samples.tsv b/workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/samples/samples.tsv similarity index 100% rename from workflow/.tests/integration/subset_vpipe_smkdploy/test_ouput_sars-cov-2/samples/samples.tsv rename to workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/samples/samples.tsv diff --git a/workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/samples/samples20200729.tsv b/workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/samples/samples20200729.tsv new file mode 100644 index 0000000..43dd050 --- /dev/null +++ b/workflow/.tests/unit/amplicon_cov/data/subset_vpipe_smkdeploy/test_output_sars-cov-2/samples/samples20200729.tsv @@ -0,0 +1,2 @@ +pos_MN908947_3_1 20200729 250 v3 +pos_MT007544_1_1 20200729 250 v3 diff --git a/workflow/.tests/unit/amplicon_cov/expected/20200729/amplicons_coverages.csv b/workflow/.tests/unit/amplicon_cov/expected/20200729/amplicons_coverages.csv new file mode 100644 index 0000000..0db51af --- /dev/null +++ b/workflow/.tests/unit/amplicon_cov/expected/20200729/amplicons_coverages.csv @@ -0,0 +1,3 @@ +sample,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97 +pos_MN908947_3_1,264.0,10.0,256.0,255.0,255.0,253.0,255.0,256.0,255.0,1.0,256.0,13.0,253.0,484.5,65.0,81.0,0.0,22.0,253.0,254.0,255.0,476.0,15.0,126.0,256.0,255.0,254.0,95.0,255.0,255.0,65.5,255.0,0.0,256.0,256.0,255.0,256.0,327.0,255.0,410.0,161.0,253.0,255.0,256.0,257.0,255.0,255.0,255.0,218.0,0.0,254.0,256.0,255.0,38.0,254.0,253.0,255.0,92.0,255.0,256.0,256.0,256.0,197.0,255.0,254.5,22.0,181.0,256.0,252.0,256.0,254.0,255.0,256.0,220.0,252.0,37.0,256.0,263.0,253.0,256.0,256.0,0.0,18.0,255.0,255.0,254.0,251.0,255.0,256.0,253.0,255.0,254.0,251.0,255.0,73.0,255.0,431.5,74.0 +pos_MT007544_1_1,256.0,10.0,254.0,254.0,254.0,255.0,257.0,255.0,256.0,10.0,255.0,33.0,253.0,506.0,59.0,0.0,0.0,38.0,253.0,251.0,256.0,494.5,39.0,149.0,255.0,256.0,255.0,184.0,256.0,255.0,258.0,253.0,0.0,255.0,255.0,256.0,256.0,315.0,256.0,404.5,163.0,256.0,256.0,256.0,256.0,256.0,255.0,256.0,255.0,0.0,256.0,256.0,256.0,95.0,254.0,254.0,256.0,107.0,256.0,253.0,255.0,255.0,253.0,255.0,253.0,0.0,255.0,255.0,255.0,254.0,253.0,255.0,256.0,300.5,254.0,47.0,258.0,256.0,255.0,255.0,256.0,0.0,0.0,256.0,255.0,255.0,256.0,255.0,256.0,256.0,256.0,256.0,255.0,254.0,73.0,255.5,490.0,9.0 diff --git a/workflow/.tests/unit/amplicon_cov/expected/20200729/amplicons_coverages_norm.csv b/workflow/.tests/unit/amplicon_cov/expected/20200729/amplicons_coverages_norm.csv new file mode 100644 index 0000000..8af132a --- /dev/null +++ b/workflow/.tests/unit/amplicon_cov/expected/20200729/amplicons_coverages_norm.csv @@ -0,0 +1,3 @@ +sample,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97 +pos_MN908947_3_1,0.012546932180029466,0.00047526258257687374,0.012166722113967967,0.01211919585571028,0.01211919585571028,0.012024143339194906,0.01211919585571028,0.012166722113967967,0.01211919585571028,4.752625825768737e-05,0.012166722113967967,0.0006178413573499358,0.012024143339194906,0.02302647212584953,0.003089206786749679,0.0038496269188726773,0.0,0.0010455776816691222,0.012024143339194906,0.012071669597452593,0.01211919585571028,0.02262249893065919,0.0007128938738653106,0.005988308540468609,0.012166722113967967,0.01211919585571028,0.012071669597452593,0.004514994534480301,0.01211919585571028,0.01211919585571028,0.003112969915878523,0.01211919585571028,0.0,0.012166722113967967,0.012166722113967967,0.01211919585571028,0.012166722113967967,0.015541086450263772,0.01211919585571028,0.01948576588565182,0.007651727579487667,0.012024143339194906,0.01211919585571028,0.012166722113967967,0.012214248372225655,0.01211919585571028,0.01211919585571028,0.01211919585571028,0.010360724300175848,0.0,0.012071669597452593,0.012166722113967967,0.01211919585571028,0.0018059978137921202,0.012071669597452593,0.012024143339194906,0.01211919585571028,0.004372415759707238,0.01211919585571028,0.012166722113967967,0.012166722113967967,0.012166722113967967,0.009362672876764412,0.01211919585571028,0.012095432726581437,0.0010455776816691222,0.008602252744641414,0.012166722113967967,0.011976617080937217,0.012166722113967967,0.012071669597452593,0.01211919585571028,0.012166722113967967,0.010455776816691222,0.011976617080937217,0.0017584715555344329,0.012166722113967967,0.012499405921771779,0.012024143339194906,0.012166722113967967,0.012166722113967967,0.0,0.0008554726486383727,0.01211919585571028,0.01211919585571028,0.012071669597452593,0.01192909082267953,0.01211919585571028,0.012166722113967967,0.012024143339194906,0.01211919585571028,0.012071669597452593,0.01192909082267953,0.01211919585571028,0.0034694168528111784,0.01211919585571028,0.0205075804381921,0.0035169431110688657 +pos_MT007544_1_1,0.011828851307642546,0.000462064504204787,0.011736438406801589,0.011736438406801589,0.011736438406801589,0.011782644857222068,0.011875057758063025,0.011782644857222068,0.011828851307642546,0.000462064504204787,0.011782644857222068,0.001524812863875797,0.01169023195638111,0.02338046391276222,0.002726180574808243,0.0,0.0,0.0017558451159781906,0.01169023195638111,0.011597819055540153,0.011828851307642546,0.022849089732926715,0.0018020515663986693,0.006884761112651326,0.011782644857222068,0.011828851307642546,0.011782644857222068,0.00850198687736808,0.011828851307642546,0.011782644857222068,0.011921264208483504,0.01169023195638111,0.0,0.011782644857222068,0.011782644857222068,0.011828851307642546,0.011828851307642546,0.01455503188245079,0.011828851307642546,0.018690509195083634,0.007531651418538028,0.011828851307642546,0.011828851307642546,0.011828851307642546,0.011828851307642546,0.011828851307642546,0.011782644857222068,0.011828851307642546,0.011782644857222068,0.0,0.011828851307642546,0.011828851307642546,0.011828851307642546,0.004389612789945476,0.011736438406801589,0.011736438406801589,0.011828851307642546,0.004944090194991221,0.011828851307642546,0.01169023195638111,0.011782644857222068,0.011782644857222068,0.01169023195638111,0.011782644857222068,0.01169023195638111,0.0,0.011782644857222068,0.011782644857222068,0.011782644857222068,0.011736438406801589,0.01169023195638111,0.011782644857222068,0.011828851307642546,0.01388503835135385,0.011736438406801589,0.002171703169762499,0.011921264208483504,0.011828851307642546,0.011782644857222068,0.011782644857222068,0.011828851307642546,0.0,0.0,0.011828851307642546,0.011782644857222068,0.011782644857222068,0.011828851307642546,0.011782644857222068,0.011828851307642546,0.011828851307642546,0.011828851307642546,0.011828851307642546,0.011782644857222068,0.011736438406801589,0.003373070880694945,0.011805748082432307,0.02264116070603456,0.0004158580537843083 diff --git a/workflow/.tests/unit/amplicon_cov/expected/20200729/cov_heatmap.pdf b/workflow/.tests/unit/amplicon_cov/expected/20200729/cov_heatmap.pdf new file mode 100644 index 0000000..d2d4e02 Binary files /dev/null and b/workflow/.tests/unit/amplicon_cov/expected/20200729/cov_heatmap.pdf differ diff --git a/workflow/.tests/unit/test_amplicon_cov.py b/workflow/.tests/unit/test_amplicon_cov.py index 5056400..e81e9d4 100644 --- a/workflow/.tests/unit/test_amplicon_cov.py +++ b/workflow/.tests/unit/test_amplicon_cov.py @@ -1 +1,94 @@ """Tests for the `amplicon_cov` rules.""" + + +import os +import subprocess as sp +from tempfile import TemporaryDirectory +import shutil +from pathlib import Path + +from common import OutputCheckerV2 + + +def print_directory_contents(path): + """Prints the contents of the directory at the given path.""" + try: + with os.scandir(path) as entries: + for entry in entries: + print(entry.name) + except FileNotFoundError: + print(f"Directory not found: {path}") + + +def test_get_coverage_for_batch(): + """ + Test the get_coverage_for_batch rule. + using test data from sars-cov-2. + + This version of the test automatically finds the necessary files. + """ + with TemporaryDirectory() as tmpdir: + workdir = Path(tmpdir) / "workdir" + workdir.mkdir(exist_ok=True) + + # Create necessary subdirectories + (workdir / "config").mkdir(exist_ok=True) + (workdir / "data").mkdir(exist_ok=True) + (workdir / "results").mkdir(exist_ok=True) + + # Define paths + mock_data_path = Path("workflow/.tests/unit/amplicon_cov/data") + expected_path = Path("workflow/.tests/unit/amplicon_cov/expected") + config_path = Path("workflow/.tests/unit/amplicon_cov/amplicon_cov.yaml") + + # Copy config to the temporary workdir + wrk_config_path = workdir / "config" / config_path.name + shutil.copy(config_path, wrk_config_path) + + # Copy mock data to the temporary workdir + wrk_mock_data_path = Path(workdir, "data") + shutil.copytree(mock_data_path, wrk_mock_data_path, dirs_exist_ok=True) + + # Print the contents of the workdir + + # Print the contents of the current directory + print_directory_contents(workdir) + print_directory_contents(wrk_mock_data_path) + + # Run the test job + + sp.check_output( + [ + "snakemake", + "--snakefile", + "workflow/rules/amplicon_cov.smk", + "--configfile", + str(wrk_config_path), + "--config", + "--directory", + str(workdir), + "--cores", + "1", + "20200729/cov_heatmap.pdf", + ] + ) + + # Check the output + # assert (workdir / "results/").exists() + + # show me the full tree of files in the workdir + for root, dirs, files in os.walk(workdir): + print(root) + for file in files: + print(f" {file}") + + # Compare output with expected result using the OutputChecker + checker = OutputCheckerV2( + workdir / "data", + expected_path, + workdir, + configdir=workdir / "config", + tolerance=1e-4, + ) + + checker.check()