-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
90 lines (73 loc) · 2.7 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""
A small wrapper around the Snakefile to match wgddetector.pl CLI
ref. https://charlesreid1.github.io/building-snakemake-command-line-wrappers-for-workflows.html
"""
import os
import argparse
import subprocess, sys
thisdir = os.path.abspath(os.path.dirname(__file__))
def config_to_args(config):
"""Convert config dict into a string of --config KEY=VAL"""
return " ".join(
[""] + [f"--config {key}={value}" for key, value in config.items()]
)
def args_to_config(args):
config = {}
config["input_cds"] = args.input_cds
config["input_pep"] = args.input_pep
config["outdir"] = args.output_dir
config["tmpdir"] = args.tmp_dir
config["threads"] = args.thread_num
config["cluster_engine"] = args.cluster_engine
return config
def snakemake_cli(snakefile, cores, dryrun, configfile, configoptions):
"""Build the snakemake system call"""
dryoption = "--dry-run " if dryrun else ""
return f"""snakemake --cores "{cores}" --snakefile "{snakefile}" {dryoption} --use-conda \
--configfile "{configfile}" {configoptions}
"""
def launch(args):
config = args_to_config(args)
configoptions = config_to_args(config)
snakefile = os.path.join(thisdir, "workflow", "Snakefile")
command = snakemake_cli(
snakefile,
args.cores,
configfile=args.configfile,
dryrun=args.dry_run,
configoptions=configoptions,
)
return subprocess.run(command, shell = True)
def main():
parser = argparse.ArgumentParser(
prog="WGDdetector.smk",
description="Whole Genome Duplication detection pipeline ported to Snakemake",
epilog="Sequence IDs within CDS and protein files must be the same.",
)
# wgddetector.pl arguments
parser.add_argument("--input_cds", default=None, help="input CDS in FASTA format")
parser.add_argument(
"--input_pep", default=None, help="input protein in FASTA format"
)
parser.add_argument("--output_dir", default=None, help="output directory")
parser.add_argument(
"--tmp_dir", default=None, help="temporary files directory"
) # TODO: decide whether to use this.
parser.add_argument("--thread_num", default=None, help="number of threads to use")
parser.add_argument(
"--cluster_engine",
choices=["blastp", "mmseqs2"],
default=None,
help="local alignment method",
)
# Snakemake arguments
parser.add_argument(
"--configfile", default="config/config.yaml", help="config file"
)
parser.add_argument("-n", "--dry-run")
parser.add_argument("--cores", default=1)
args = parser.parse_args()
launch(args)
if __name__ == "__main__":
main()