Skip to content

Commit

Permalink
remove now-deprecated onstarts/onerrors
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimens committed Aug 12, 2024
1 parent a500729 commit c0117e6
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 769 deletions.
39 changes: 2 additions & 37 deletions harpy/snakefiles/align_bwa.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ containerized: "docker://pdimens/harpy:latest"
import os
import re
import sys
import glob
import logging as pylogging
from datetime import datetime
from rich.panel import Panel
from rich import print as rprint

outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
Expand All @@ -21,46 +17,15 @@ 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"]
## the log file ##
attempts = glob.glob(f"{outdir}/logs/snakemake/*.snakelog")
if not attempts:
logfile = f"{outdir}/logs/snakemake/align_bwa.run1." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
else:
increment = sorted([int(i.split(".")[1].replace("run","")) for i in attempts])[-1] + 1
logfile = f"{outdir}/logs/snakemake/align_bwa.run{increment}." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
snakemake_log = config["snakemake_log"]

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

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
extra_logfile_handler = pylogging.FileHandler(logfile)
extra_logfile_handler = pylogging.FileHandler(snakemake_log)
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Panel(
f"The workflow has terminated due to an error. See the log file for more details:\n[bold]{logfile}[/bold]",
title = "[bold]harpy align bwa",
title_align = "left",
border_style = "red"
),
file = sys.stderr
)

onsuccess:
print("")
rprint(
Panel(
f"The workflow has finished successfully! Find the results in [bold]{outdir}[/bold]",
title = "[bold]harpy align bwa",
title_align = "left",
border_style = "green"
),
file = sys.stderr
)

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}
d = dict(zip(samplenames, samplenames))
Expand Down
41 changes: 2 additions & 39 deletions harpy/snakefiles/align_ema.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ containerized: "docker://pdimens/harpy:latest"

import os
import re
import glob
import shutil
import logging as pylogging
from datetime import datetime
from pathlib import Path
from rich.panel import Panel
from rich import print as rprint

outdir = config["output_directory"]
nbins = config["EMA_bins"]
Expand All @@ -25,48 +21,15 @@ envdir = os.getcwd() + "/.harpy_envs"
windowsize = config["depth_windowsize"]
keep_unmapped = config["keep_unmapped"]
skipreports = config["skip_reports"]

## the log file ##
attempts = glob.glob(f"{outdir}/logs/snakemake/*.snakelog")
if not attempts:
logfile = f"{outdir}/logs/snakemake/align_ema.run1." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
else:
increment = sorted([int(i.split(".")[1].replace("run","")) for i in attempts])[-1] + 1
logfile = f"{outdir}/logs/snakemake/align_ema.run{increment}." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
snakemake_log = config["snakemake_log"]

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

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
extra_logfile_handler = pylogging.FileHandler(logfile)
extra_logfile_handler = pylogging.FileHandler(snakemake_log)
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Panel(
f"The workflow has terminated due to an error. See the log file for more details:\n[bold]{logfile}[/bold]",
title = "[bold]harpy align ema",
title_align = "left",
border_style = "red"
),
file = sys.stderr
)

onsuccess:
print("")
shutil.rmtree(f'{outdir}/bxcount', ignore_errors=True)
rprint(
Panel(
f"The workflow has finished successfully! Find the results in [bold]{outdir}[/bold]",
title = "[bold]harpy align ema",
title_align = "left",
border_style = "green"
),
file = sys.stderr
)

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}
d = dict(zip(samplenames, samplenames))
Expand Down
40 changes: 2 additions & 38 deletions harpy/snakefiles/align_strobealign.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ containerized: "docker://pdimens/harpy:latest"
import os
import re
import sys
import glob
import logging as pylogging
from datetime import datetime
from rich.panel import Panel
from rich import print as rprint

outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
Expand All @@ -23,47 +19,15 @@ molecule_distance = config["molecule_distance"]
keep_unmapped = config["keep_unmapped"]
readlen = config["average_read_length"]
autolen = isinstance(readlen, str)

## the log file ##
attempts = glob.glob(f"{outdir}/logs/snakemake/*.snakelog")
if not attempts:
logfile = f"{outdir}/logs/snakemake/align_strobe.run1." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
else:
increment = sorted([int(i.split(".")[1].replace("run","")) for i in attempts])[-1] + 1
logfile = f"{outdir}/logs/snakemake/align_strobe.run{increment}." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
snakemake_log = config["snakemake_log"]

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

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
extra_logfile_handler = pylogging.FileHandler(logfile)
extra_logfile_handler = pylogging.FileHandler(snakemake_log)
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Panel(
f"The workflow has terminated due to an error. See the log file for more details:\n[bold]{logfile}[/bold]",
title = "[bold]harpy align strobealign",
title_align = "left",
border_style = "red"
),
file = sys.stderr
)

onsuccess:
print("")
rprint(
Panel(
f"The workflow has finished successfully! Find the results in [bold]{outdir}[/bold]",
title = "[bold]harpy align strobealign",
title_align = "left",
border_style = "green"
),
file = sys.stderr
)

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}
d = dict(zip(samplenames, samplenames))
Expand Down
40 changes: 2 additions & 38 deletions harpy/snakefiles/deconvolve.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ containerized: "docker://pdimens/harpy:latest"
import os
import re
import sys
import glob
import logging as pylogging
from datetime import datetime
from rich.panel import Panel
from rich import print as rprint

envdir = os.getcwd() + "/.harpy_envs"
fqlist = config["inputs"]
Expand All @@ -16,14 +12,7 @@ kmer_length = config["kmer_length"]
window_size = config["window_size"]
density = config["density"]
dropout = config["dropout"]

## the log file ##
attempts = glob.glob(f"{outdir}/logs/snakemake/*.snakelog")
if not attempts:
logfile = f"{outdir}/logs/snakemake/deconvolve.run1." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
else:
increment = sorted([int(i.split(".")[1].replace("run","")) for i in attempts])[-1] + 1
logfile = f"{outdir}/logs/snakemake/deconvolve.run{increment}." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
snakemake_log = config["snakemake_log"]

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}
Expand All @@ -32,34 +21,9 @@ wildcard_constraints:
sample = "[a-zA-Z0-9._-]+"

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
extra_logfile_handler = pylogging.FileHandler(logfile)
extra_logfile_handler = pylogging.FileHandler(snakemake_log)
logger.logger.addHandler(extra_logfile_handler)

onsuccess:
print("")
rprint(
Panel(
f"The workflow has finished successfully! Find the results in [bold]{outdir}/[/bold]",
title = "[bold]harpy deconvolve",
title_align = "left",
border_style = "green"
),
file = sys.stderr
)

onerror:
print("")
rprint(
Panel(
f"The workflow has terminated due to an error. See the log file for more details:\n[bold]{logfile}[/bold]",
title = "[bold]harpy deconvolve",
title_align = "left",
border_style = "red"
),
file = sys.stderr
)

def get_fq1(wildcards):
# returns a list of fastq files for read 1 based on *wildcards.sample* e.g.
r = re.compile(fr"(.*/{re.escape(wildcards.sample)})([_\.]1|[_\.]F|[_\.]R1(?:\_00[0-9])*)?\.((fastq|fq)(\.gz)?)$", flags = re.IGNORECASE)
Expand Down
39 changes: 2 additions & 37 deletions harpy/snakefiles/demultiplex_gen1.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ containerized: "docker://pdimens/harpy:latest"
import os
import re
import sys
import glob
import logging as pylogging
from datetime import datetime
from rich.panel import Panel
from rich import print as rprint

R1 = config["inputs"]["R1"]
R2 = config["inputs"]["R2"]
Expand All @@ -17,15 +13,9 @@ samplefile = config["inputs"]["demultiplex_schema"]
skipreports = config["skip_reports"]
outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
snakemake_log = config["snakemake_log"]

## the log file ##
attempts = glob.glob(f"{outdir}/logs/snakemake/*.snakelog")
if not attempts:
logfile = f"{outdir}/logs/snakemake/demultiplex_gen1.run1." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
else:
increment = sorted([int(i.split(".")[1].replace("run","")) for i in attempts])[-1] + 1
logfile = f"{outdir}/logs/snakemake/demultiplex_gen1.run{increment}." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"

def barcodedict(smpl):
d = {}
with open(smpl, "r") as f:
Expand All @@ -42,34 +32,9 @@ samples = barcodedict(samplefile)
samplenames = [i for i in samples.keys()]

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
extra_logfile_handler = pylogging.FileHandler(logfile)
extra_logfile_handler = pylogging.FileHandler(snakemake_log)
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Panel(
f"The workflow has terminated due to an error. See the log file for more details:\n[bold]{logfile}[/bold]",
title = "[bold]harpy demultiplex",
title_align = "left",
border_style = "red"
),
file = sys.stderr
)

onsuccess:
print("")
rprint(
Panel(
f"The workflow has finished successfully! Find the results in [bold]{outdir}[/bold]",
title = "[bold]harpy demultiplex",
title_align = "left",
border_style = "green"
),
file = sys.stderr
)

rule link_R1:
input:
R1
Expand Down
43 changes: 3 additions & 40 deletions harpy/snakefiles/impute.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@ containerized: "docker://pdimens/harpy:latest"
import os
import re
import sys
import glob
import subprocess
import pandas as pd
import multiprocessing
import logging as pylogging
from datetime import datetime
from rich.panel import Panel
from rich import print as rprint
from snakemake.utils import Paramspace

bamlist = config["inputs"]["alignments"]
variantfile = config["inputs"]["variantfile"]
paramfile = config["inputs"]["paramfile"]
biallelic = config["inputs"]["biallelic_contigs"]
skipreports = config["skip_reports"]
outdir = config["output_directory"]
envdir = os.getcwd() + "/.harpy_envs"
skipreports = config["skip_reports"]
snakemake_log = config["snakemake_log"]
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"])
with open(biallelic, "r") as f_open:
contigs = [i.rstrip() for i in f_open.readlines()]


## the log file ##
attempts = glob.glob(f"{outdir}/logs/snakemake/*.snakelog")
if not attempts:
logfile = f"{outdir}/logs/snakemake/impute.run1." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"
else:
increment = sorted([int(i.split(".")[1].replace("run","")) for i in attempts])[-1] + 1
logfile = f"{outdir}/logs/snakemake/impute.run{increment}." + datetime.now().strftime("%d_%m_%Y") + ".snakelog"

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

Expand All @@ -42,34 +30,9 @@ def sam_index(infile):
subprocess.run(f"samtools index {infile} {infile}.bai".split())

onstart:
os.makedirs(f"{outdir}/logs/snakemake", exist_ok = True)
extra_logfile_handler = pylogging.FileHandler(logfile)
extra_logfile_handler = pylogging.FileHandler(snakemake_log)
logger.logger.addHandler(extra_logfile_handler)

onerror:
print("")
rprint(
Panel(
f"The workflow has terminated due to an error. See the log file for more details:\n[bold]{logfile}[/bold]",
title = "[bold]harpy impute",
title_align = "left",
border_style = "red"
),
file = sys.stderr
)

onsuccess:
print("")
rprint(
Panel(
f"The workflow has finished successfully! Find the results in [bold]{outdir}/[/bold]",
title = "[bold]harpy impute",
title_align = "left",
border_style = "green"
),
file = sys.stderr
)

rule sort_bcf:
input:
variantfile
Expand Down
Loading

0 comments on commit c0117e6

Please sign in to comment.