diff --git a/lusSTR/tests/test_filters.py b/lusSTR/tests/test_filters.py index b1095e0..adb82b3 100644 --- a/lusSTR/tests/test_filters.py +++ b/lusSTR/tests/test_filters.py @@ -183,7 +183,7 @@ def test_EFMoutput_format(outputdir, datatype, software, tmp_path): "--str-type", datatype, "--input", - "WD", + str(inputfile), ] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile, os.path.join(str_path, "test_output.csv")) @@ -208,7 +208,7 @@ def test_STRmixoutput_format(outputdir, datatype, tmp_path): "-w", str_path, "--input", - "WD", + str(inputfile), "-o", "STRmix_Files", "--str-type", @@ -230,7 +230,16 @@ def test_STRmixoutput_customranges(tmp_path): exp_info_out = data_file("NGS_stutter_test/custom/test_stutter_sequence_info.csv") obs_out = str(tmp_path / f"WD/test_stutter/Sample1_evidence_ngs.csv") obs_info_out = str(tmp_path / f"WD/test_stutter/test_stutter_sequence_info.csv") - arglist = ["config", "-w", str_path, "--input", "WD", "-o", "test_stutter", "--custom"] + arglist = [ + "config", + "-w", + str_path, + "--input", + str(inputfile), + "-o", + "test_stutter", + "--custom", + ] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile, os.path.join(str_path, "test_stutter.csv")) shutil.copyfile(inputfile, os.path.join(str_path, "test_stutter.txt")) @@ -247,7 +256,7 @@ def test_nofilters(tmp_path): inputfile = data_file("test_stutter.txt") exp_out = data_file("NGS_stutter_test/Sample1_nofilter.csv") obs_out = str(tmp_path / "WD/lusstr_output/Sample1_evidence_ngs.csv") - arglist = ["config", "-w", str_path, "--input", "WD", "--nofilter"] + arglist = ["config", "-w", str_path, "--input", str(inputfile), "--nofilter"] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile, os.path.join(str_path, "lusstr_output.csv")) shutil.copyfile(inputfile, os.path.join(str_path, "lusstr_output.txt")) @@ -261,7 +270,7 @@ def test_flags(tmp_path): inputfile = data_file("test_stutter.txt") exp_out = data_file("RU_stutter_test/Flagged_Loci.csv") obs_out = str(tmp_path / "WD/lusstr_output/lusstr_output_Flagged_Loci.csv") - arglist = ["config", "-w", str_path, "--input", "WD"] + arglist = ["config", "-w", str_path, "--input", str(inputfile)] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile, os.path.join(str_path, "lusstr_output.csv")) shutil.copyfile(inputfile, os.path.join(str_path, "lusstr_output.txt")) @@ -288,7 +297,7 @@ def test_efm_reference(outputdir, datatype, software, tmp_path): "-w", str_path, "--input", - "WD", + str(inputfile), "--software", software, "--reference", @@ -316,7 +325,7 @@ def test_strmix_reference(outputdir, datatype, tmp_path): "-w", str_path, "--input", - "WD", + str(inputfile), "-o", "STRmix_Files", "--reference", @@ -336,7 +345,7 @@ def test_D7(tmp_path): inputfile = data_file("test_D7.txt") exp_out = data_file("D7_microvariant_flagged.csv") obs_out = str(tmp_path / "WD/test/test_Flagged_Loci.csv") - arglist = ["config", "-w", str_path, "--input", "WD", "-o", "test"] + arglist = ["config", "-w", str_path, "--input", str(inputfile), "-o", "test"] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile, os.path.join(str_path, "test.csv")) shutil.copyfile(inputfile, os.path.join(str_path, "test.txt")) @@ -392,7 +401,7 @@ def test_forward_strand_orientation(tmp_path): "-w", str_path, "--input", - "WD", + str(inputfile), "-o", "STRmix_Files", "--strand", @@ -416,7 +425,7 @@ def test_lusplus_sequence_info(tmp_path): "-w", str_path, "--input", - "WD", + str(inputfile), "-o", "LUSPlus", "--strand", diff --git a/lusSTR/tests/test_snps.py b/lusSTR/tests/test_snps.py index a1dbea0..7df8221 100644 --- a/lusSTR/tests/test_snps.py +++ b/lusSTR/tests/test_snps.py @@ -260,3 +260,27 @@ def test_uas_version5(tmp_path): all_arglist = ["snps", "all", "-w", str(tmp_path)] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(all_arglist)) assert filecmp.cmp(exp_out, obs_out) is True + + +def test_snp_logs(tmp_path): + inputdb = data_file("snps") + arglist = [ + "config", + "-w", + str(tmp_path), + "-o", + "sr", + "--input", + str(inputdb), + "--snps", + "--analysis-software", + "straitrazor", + ] + lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) + format_arglist = ["snps", "format", "-w", str(tmp_path)] + lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(format_arglist)) + for dir in os.listdir(str(tmp_path / "logs/")): + assert os.path.exists(str(tmp_path / f"logs/{dir}/snp_config.yaml")) + assert os.path.exists( + str(tmp_path / f"logs/{dir}/input/Positive Control Sample Details Report 2315.xlsx") + ) diff --git a/lusSTR/tests/test_suite.py b/lusSTR/tests/test_suite.py index fd57e4a..8dde4d6 100644 --- a/lusSTR/tests/test_suite.py +++ b/lusSTR/tests/test_suite.py @@ -64,7 +64,7 @@ def test_convert_full_nocombine( "-o", infile, "--input", - "WD", + str(inputfile), ] else: arglist = [ @@ -78,7 +78,7 @@ def test_convert_full_nocombine( "-o", infile, "--input", - "WD", + str(inputfile), "--powerseq", ] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) @@ -110,7 +110,7 @@ def test_flanks(tmp_path): "--analysis-software", "straitrazor", "--input", - "WD", + str(inputfile), ] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile, os.path.join(str_path, "testflanks.csv")) @@ -135,7 +135,7 @@ def test_convert_combine(input, exp_length, tmp_path): "--analysis-software", "straitrazor", "--input", - "WD", + str(inputfile), ] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile, os.path.join(str_path, "testflanks.csv")) @@ -183,7 +183,7 @@ def test_powerseq_flanks(tmp_path): "--analysis-software", "straitrazor", "--input", - "WD", + str(inputfile), "--powerseq", ] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) @@ -199,7 +199,7 @@ def test_convert_uas_sexloci(tmp_path): inputfile_sex = data_file("testformat_uas_sexloci.csv") exp_sex_out = data_file("testformat_uas_sexloci.txt") obs_sex_out = str(tmp_path / "WD/testformatuas_sexloci.txt") - arglist = ["config", "-w", str_path, "-o", "testformatuas", "--sex", "--input", "WD"] + arglist = ["config", "-w", str_path, "-o", "testformatuas", "--sex", "--input", str(inputfile)] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) shutil.copyfile(inputfile_sex, os.path.join(str_path, "testformatuas_sexloci.csv")) shutil.copyfile(inputfile, os.path.join(str_path, "testformatuas.csv")) @@ -242,7 +242,7 @@ def test_convert_sr_sexloci(input, testoutput, flank_output, kit, tmp_path): "testformatsr", "--sex", "--input", - "WD", + str(inputfile), "--analysis-software", "straitrazor", ] @@ -255,7 +255,7 @@ def test_convert_sr_sexloci(input, testoutput, flank_output, kit, tmp_path): "testformatsr", "--sex", "--input", - "WD", + str(inputfile), "--analysis-software", "straitrazor", "--powerseq", @@ -380,3 +380,17 @@ def test_deletions(tmp_path): snakemake_arglist = ["strs", "convert", "-w", str(tmp_path)] lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(snakemake_arglist)) assert filecmp.cmp(exp_output, obs_output) is True + + +def test_log(tmp_path): + config = str(tmp_path / "config.yaml") + inputfile = data_file("UAS_bulk_input/Positive Control Sample Details Report 2315.xlsx") + arglist = ["config", "-w", str(tmp_path), "--input", str(inputfile)] + lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(arglist)) + snakemake_arglist = ["strs", "format", "-w", str(tmp_path)] + lusSTR.cli.main(lusSTR.cli.get_parser().parse_args(snakemake_arglist)) + for dir in os.listdir(str(tmp_path / "logs/")): + assert os.path.exists(str(tmp_path / f"logs/{dir}/config.yaml")) + assert os.path.exists( + str(tmp_path / f"logs/{dir}/input/Positive Control Sample Details Report 2315.xlsx") + ) diff --git a/lusSTR/workflows/snps.smk b/lusSTR/workflows/snps.smk index 026a561..2632fbb 100644 --- a/lusSTR/workflows/snps.smk +++ b/lusSTR/workflows/snps.smk @@ -1,3 +1,4 @@ +from datetime import datetime import lusSTR @@ -14,6 +15,18 @@ def format_filename(id, refs): return f"{id}_snp_reference" +def create_log(log): + now = datetime.now() + dt = now.strftime("%m%d%Y_%H_%M_%S") + shell("mkdir -p logs/{dt}/input/") + shell("cp {log} logs/{dt}/strs.log") + if os.path.isdir(input_name): + shell("cp {input_name}/* logs/{dt}/input/") + else: + shell("cp '{input_name}' logs/{dt}/input/") + shell("cp snp_config.yaml logs/{dt}/") + + rule all: input: expand("{name}.txt", name=output_name), @@ -49,3 +62,10 @@ rule convert: thresh=config["thresh"] script: lusSTR.wrapper("snps_convert") + + +onsuccess: + create_log(log) + +onerror: + create_log(log) \ No newline at end of file diff --git a/lusSTR/workflows/strs.smk b/lusSTR/workflows/strs.smk index b03bbc9..1214677 100644 --- a/lusSTR/workflows/strs.smk +++ b/lusSTR/workflows/strs.smk @@ -1,3 +1,4 @@ +from datetime import datetime import glob import lusSTR import openpyxl @@ -72,6 +73,18 @@ def parse_sample_details(filename): return sampleID +def create_log(log): + now = datetime.now() + dt = now.strftime("%m%d%Y_%H_%M_%S") + shell("mkdir -p logs/{dt}/input/") + shell("cp {log} logs/{dt}/strs.log") + if os.path.isdir(input_name): + shell("cp {input_name}/* logs/{dt}/input/") + else: + shell("cp '{input_name}' logs/{dt}/input/") + shell("cp config.yaml logs/{dt}/") + + def get_output(): if custom: outname = expand("{name}_custom_range.txt", name=output_name) @@ -115,7 +128,7 @@ rule convert: kit=config["kit"], custom=config["custom_ranges"] script: - lusSTR.wrapper("convert") + lusSTR.wrapper("convert") rule filter: @@ -139,4 +152,11 @@ rule filter: custom=config["custom_ranges"] script: lusSTR.wrapper("filter") + + +onsuccess: + create_log(log) + +onerror: + create_log(log) \ No newline at end of file