Skip to content

Commit

Permalink
move to onstart to avoid double printing
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimens committed Aug 5, 2024
1 parent f7ee57b commit 2a441d4
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 94 deletions.
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/align_bwa.smk
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ genome_zip = True if bn.lower().endswith(".gz") else False
bn_idx = f"{bn}.gzi" if genome_zip else f"{bn}.fai"
skipreports = config["skip_reports"]
windowsize = config["depth_windowsize"]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/align_ema.smk
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ bn_idx = f"{bn}.gzi" if genome_zip else f"{bn}.fai"
envdir = os.getcwd() + "/.harpy_envs"
windowsize = config["depth_windowsize"]
skipreports = config["skip_reports"]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/align_strobealign.smk
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ windowsize = config["depth_windowsize"]
molecule_distance = config["molecule_distance"]
readlen = config["average_read_length"]
autolen = isinstance(readlen, str)
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
11 changes: 6 additions & 5 deletions src/harpy/snakefiles/deconvolve.smk
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ kmer_length = config["kmer_length"]
window_size = config["window_size"]
density = config["density"]
dropout = config["dropout"]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)


bn_r = r"([_\.][12]|[_\.][FR]|[_\.]R[12](?:\_00[0-9])*)?\.((fastq|fq)(\.gz)?)$"
samplenames = {re.sub(bn_r, "", os.path.basename(i), flags = re.IGNORECASE) for i in fqlist}

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onsuccess:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/demultiplex_gen1.smk
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ samplefile = config["inputs"]["demultiplex_schema"]
skipreports = config["skip_reports"]
outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

def barcodedict(smpl):
d = {}
Expand All @@ -36,6 +32,12 @@ def barcodedict(smpl):
samples = barcodedict(samplefile)
samplenames = [i for i in samples.keys()]

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
11 changes: 6 additions & 5 deletions src/harpy/snakefiles/impute.smk
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ skipreports = config["skip_reports"]
outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
paramspace = Paramspace(pd.read_csv(paramfile, sep=r"\s+", skip_blank_lines=True).rename(columns=str.lower), param_sep = "", filename_params = ["k", "s", "ngen", "bxlimit"])
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

with open(biallelic, "r") as f_open:
contigs = [i.rstrip() for i in f_open.readlines()]

Expand All @@ -36,6 +31,12 @@ def sam_index(infile):
if not os.path.exists(f"{infile}.bai"):
subprocess.run(f"samtools index {infile} {infile}.bai".split())

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
12 changes: 6 additions & 6 deletions src/harpy/snakefiles/phase.smk
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ skipreports = config["skip_reports"]
samples_from_vcf = config["samples_from_vcf"]
variantfile = config["inputs"]["variantfile"]
bamlist = config["inputs"]["alignments"]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

# toggle linked-read aware mode
if config["ignore_bx"]:
fragfile = outdir + "/extract_hairs/{sample}.unlinked.frags"
Expand All @@ -40,7 +35,6 @@ if samples_from_vcf:
else:
samplenames = [Path(i).stem for i in bamlist]


# toggle indel mode
if config["inputs"].get("genome", None):
genomefile = config["inputs"]["genome"]
Expand All @@ -63,6 +57,12 @@ else:
wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
12 changes: 7 additions & 5 deletions src/harpy/snakefiles/preflight_bam.smk
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ from rich.panel import Panel
outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
bamlist = config["inputs"]
samplenames = {Path(i).stem for i in bamlist}
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)
samplenames = {Path(i).stem for i in bamlist}

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/preflight_fastq.smk
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
bn_r = r"([_\.][12]|[_\.][FR]|[_\.]R[12](?:\_00[0-9])*)?\.((fastq|fq)(\.gz)?)$"
samplenames = {re.sub(bn_r, "", os.path.basename(i), flags = re.IGNORECASE) for i in fqlist}
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/qc.smk
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ if deconvolve:
decon_d = deconvolve["density"]
decon_a = deconvolve["dropout"]
skipreports = config["skip_reports"]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

bn_r = r"([_\.][12]|[_\.][FR]|[_\.]R[12](?:\_00[0-9])*)?\.((fastq|fq)(\.gz)?)$"
samplenames = {re.sub(bn_r, "", os.path.basename(i), flags = re.IGNORECASE) for i in fqlist}

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onsuccess:
print("")
rprint(
Expand Down
9 changes: 5 additions & 4 deletions src/harpy/snakefiles/simulate_linkedreads.smk
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ if barcodes:
barcodefile = barcodes
else:
barcodefile = f"{outdir}/workflow/input/4M-with-alts-february-2016.txt"
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onsuccess:
shutil.rmtree('./_Inline', ignore_errors=True)
Expand Down
11 changes: 6 additions & 5 deletions src/harpy/snakefiles/simulate_snpindel.smk
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ snp_vcf = config["inputs"].get("snp_vcf", None)
indel_vcf = config["inputs"].get("indel_vcf", None)
heterozygosity = config["heterozygosity"]
outprefix = config["prefix"]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

in_vcfs = []
snp = False
indel = False
Expand Down Expand Up @@ -65,6 +60,12 @@ else:

variants = [i for i,j in zip(["snp", "indel"], [snp, indel]) if j]

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onsuccess:
print("")
rprint(
Expand Down
11 changes: 6 additions & 5 deletions src/harpy/snakefiles/simulate_variants.smk
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ genome = config["inputs"]["genome"]
vcf = config["inputs"].get("vcf", None)
heterozygosity = float(config["heterozygosity"])
vcf_correct = "None"
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

if vcf:
vcf_correct = vcf[:-4] + ".vcf.gz" if vcf.lower().endswith("bcf") else vcf
variant_params = f"-{variant}_vcf {vcf_correct}"
Expand Down Expand Up @@ -52,6 +47,12 @@ else:
cnv_ratio =config.get("cnv_ratio", None)
variant_params += f" --cnv_gain_loss_ratio {cnv_ratio}" if cnv_ratio else ""

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onsuccess:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/snp_freebayes.smk
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ else:
cont,startpos,endpos = line.split()
intervals.add(f"{cont}:{startpos}-{endpos}")
regions = dict(zip(intervals, intervals))
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/snp_mpileup.smk
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ else:
cont,startpos,endpos = line.split()
intervals.add(f"{cont}:{startpos}-{endpos}")
regions = dict(zip(intervals, intervals))
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/sv_leviathan.smk
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ bn = os.path.basename(genomefile)
genome_zip = True if bn.lower().endswith(".gz") else False
if genome_zip:
bn = bn[:-3]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
10 changes: 6 additions & 4 deletions src/harpy/snakefiles/sv_leviathan_pop.smk
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ skipreports = config["skip_reports"]
bn = os.path.basename(genomefile)
if bn.lower().endswith(".gz"):
bn = bn[:-3]
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

wildcard_constraints:
sample = "[a-zA-Z0-9._-]+",
population = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
dt_string = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
extra_logfile_handler = pylogging.FileHandler(f"{outdir}/logs/snakemake/{dt_string}.snakelog")
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Expand Down
Loading

0 comments on commit 2a441d4

Please sign in to comment.