Skip to content

Commit

Permalink
Creating log files (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnmitchell authored Jul 10, 2024
1 parent 3c2b19b commit aac73a4
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 19 deletions.
29 changes: 19 additions & 10 deletions lusSTR/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -208,7 +208,7 @@ def test_STRmixoutput_format(outputdir, datatype, tmp_path):
"-w",
str_path,
"--input",
"WD",
str(inputfile),
"-o",
"STRmix_Files",
"--str-type",
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -288,7 +297,7 @@ def test_efm_reference(outputdir, datatype, software, tmp_path):
"-w",
str_path,
"--input",
"WD",
str(inputfile),
"--software",
software,
"--reference",
Expand Down Expand Up @@ -316,7 +325,7 @@ def test_strmix_reference(outputdir, datatype, tmp_path):
"-w",
str_path,
"--input",
"WD",
str(inputfile),
"-o",
"STRmix_Files",
"--reference",
Expand All @@ -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"))
Expand Down Expand Up @@ -392,7 +401,7 @@ def test_forward_strand_orientation(tmp_path):
"-w",
str_path,
"--input",
"WD",
str(inputfile),
"-o",
"STRmix_Files",
"--strand",
Expand All @@ -416,7 +425,7 @@ def test_lusplus_sequence_info(tmp_path):
"-w",
str_path,
"--input",
"WD",
str(inputfile),
"-o",
"LUSPlus",
"--strand",
Expand Down
24 changes: 24 additions & 0 deletions lusSTR/tests/test_snps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
30 changes: 22 additions & 8 deletions lusSTR/tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_convert_full_nocombine(
"-o",
infile,
"--input",
"WD",
str(inputfile),
]
else:
arglist = [
Expand All @@ -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))
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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))
Expand All @@ -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"))
Expand Down Expand Up @@ -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",
]
Expand All @@ -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",
Expand Down Expand Up @@ -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")
)
20 changes: 20 additions & 0 deletions lusSTR/workflows/snps.smk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import lusSTR


Expand All @@ -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),
Expand Down Expand Up @@ -49,3 +62,10 @@ rule convert:
thresh=config["thresh"]
script:
lusSTR.wrapper("snps_convert")


onsuccess:
create_log(log)

onerror:
create_log(log)
22 changes: 21 additions & 1 deletion lusSTR/workflows/strs.smk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import glob
import lusSTR
import openpyxl
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -115,7 +128,7 @@ rule convert:
kit=config["kit"],
custom=config["custom_ranges"]
script:
lusSTR.wrapper("convert")
lusSTR.wrapper("convert")


rule filter:
Expand All @@ -139,4 +152,11 @@ rule filter:
custom=config["custom_ranges"]
script:
lusSTR.wrapper("filter")


onsuccess:
create_log(log)

onerror:
create_log(log)

0 comments on commit aac73a4

Please sign in to comment.