Skip to content
Snippets Groups Projects

wrapper for zarp execution

Closed BIOPZ-Katsantoni Maria requested to merge snakemake_call_wrapper into dev
1 file
+ 128
0
Compare changes
  • Side-by-side
  • Inline
+ 128
0
@@ -10,6 +10,7 @@ import math
@@ -10,6 +10,7 @@ import math
import os
import os
import sys
import sys
from typing import Tuple
from typing import Tuple
 
import subprocess
from Bio import SeqIO
from Bio import SeqIO
import labkey
import labkey
@@ -55,6 +56,28 @@ def parse_cli_args() -> argparse.Namespace:
@@ -55,6 +56,28 @@ def parse_cli_args() -> argparse.Namespace:
metavar="STR",
metavar="STR",
)
)
 
zarp = parser.add_argument_group("ZARP execution")
 
zarp.add_argument(
 
"--execution_env",
 
choices=['local', 'slurm', None],
 
default=None,
 
help="zarp execution wrapper",
 
metavar="STR",
 
)
 
zarp.add_argument(
 
"--cluster_json",
 
type=str,
 
default=None,
 
help="slurm specific resources config for the zarp rules",
 
metavar="STR",
 
)
 
zarp.add_argument(
 
"--snakefile_path",
 
type=str,
 
default=None,
 
help="path of the snakefile to be executed",
 
metavar="STR",
 
)
io = parser.add_argument_group("input/output")
io = parser.add_argument_group("input/output")
io.add_argument(
io.add_argument(
"--input-to-output-mapping",
"--input-to-output-mapping",
@@ -195,6 +218,14 @@ def parse_cli_args() -> argparse.Namespace:
@@ -195,6 +218,14 @@ def parse_cli_args() -> argparse.Namespace:
"\n[ERROR] Either none or both of '--labkey-domain' and "
"\n[ERROR] Either none or both of '--labkey-domain' and "
"'--labkey-path' are required."
"'--labkey-path' are required."
)
)
 
 
if (args.execution_env and not args.cluster_json) or \
 
(args.cluster_json and not args.execution_env):
 
parser.print_help()
 
sys.exit(
 
"\n[ERROR] Either none or both of '--execution_env' and "
 
"'--cluster_json' are required."
 
)
return args
return args
@@ -451,6 +482,95 @@ def expand_path(
@@ -451,6 +482,95 @@ def expand_path(
return os.path.normpath(path)
return os.path.normpath(path)
 
def run_zarp(
 
execution_env: str,
 
config: str,
 
result_dir: str,
 
cluster_json: str,
 
snakefile_path: str,
 
anchor: str = os.getcwd()):
 
"""
 
trigger zarp snakemake workflow execution, according to
 
the environment chosen by the user if no environment is
 
chosen zarp workflow is not triggered
 
 
:param execution_env: environment where zarp will be executed;
 
for now support only local and slurm
 
 
: config: config file to be executed
 
: samples: samples table for which zarp is triggered
 
 
:returns: tuple of ALFA strand name suffixes for two coverage tracks of a
 
paired-end sequencing library
 
"""
 
report_path = os.path.join(result_dir, "snakemake_report.html")
 
if execution_env == "local":
 
try:
 
command = [
 
'snakemake',
 
f'--snakefile="{snakefile_path}"',
 
f'--configfile="{config}"',
 
'--cores=4',
 
'--printshellcmds',
 
'--rerun-incomplete',
 
'--use-singularity',
 
f'--singularity-args="--bind {anchor}"',
 
'--verbose']
 
subprocess.check_call(
 
command,
 
stdout=sys.stdout,
 
stderr=sys.stderr)
 
except subprocess.CalledProcessError:
 
pass
 
except OSError:
 
pass
 
 
elif execution_env == "slurm":
 
try:
 
command = [
 
'snakemake',
 
f'--snakefile="{snakefile_path}"',
 
f'--configfile="{config}"',
 
f'--cluster-config="{cluster_json}"',
 
'--cluster="sbatch \
 
--cpus-per-task={cluster.threads} \
 
--mem={cluster.mem} \
 
--qos={cluster.queue} \
 
--time={cluster.time} \
 
--job-name={cluster.name} \
 
-o {cluster.out} \
 
-p scicore"',
 
'--cores=256',
 
'--printshellcmds',
 
'--rerun-incomplete',
 
'--use-singularity',
 
f'--singularity-args="--bind {anchor}"',
 
'--verbose']
 
subprocess.check_call(
 
command,
 
stdout=sys.stdout,
 
stderr=sys.stderr)
 
except subprocess.CalledProcessError:
 
pass
 
except OSError:
 
pass
 
try:
 
report_command = [
 
'snakemake',
 
'--snakefile="Snakefile"',
 
f'--configfile="{config}"',
 
f'--report="{report_path}"']
 
subprocess.check_call(
 
report_command,
 
stdout=sys.stdout,
 
stderr=sys.stderr)
 
except subprocess.CalledProcessError:
 
pass
 
except OSError:
 
pass
 
return
 
 
def main(args):
def main(args):
"""
"""
Create input table and config for ZARP.
Create input table and config for ZARP.
@@ -686,6 +806,14 @@ def main(args):
@@ -686,6 +806,14 @@ def main(args):
args.config_file.write(config_file_content)
args.config_file.write(config_file_content)
args.config_file.close()
args.config_file.close()
 
if args.execution_env:
 
run_zarp(
 
args.execution_env,
 
args.config_file,
 
results_dir,
 
args.cluster_json,
 
args.snakefile_path)
 
if __name__ == '__main__':
if __name__ == '__main__':
args = parse_cli_args()
args = parse_cli_args()
Loading