Repository navigation
Expand file tree
/
Copy pathkorusEncode
More file actions
executable file
·178 lines (139 loc) · 4.03 KB
/
Copy pathkorusEncode
File metadata and controls
executable file
·178 lines (139 loc) · 4.03 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
"""
Driver script for korusEncode
Pipeline:
ntCard -> ntStat -> korusMatrix.py
Builds windowed k-mer signal matrices for KORUS ancestry inference.
"""
import argparse
import os
import shlex
import subprocess
from packaging import version
import snakemake
KORUSENCODE_VERSION = "v1.2.0"
def set_up_parser():
parser = argparse.ArgumentParser(
description="korusEncode: build KORUS feature matrices from sequencing reads",
formatter_class=argparse.RawTextHelpFormatter,
epilog="When --reads specified, input reads are identified using a shared prefix."
)
parser.add_argument(
"--reads",
help="Prefix of input read files (FASTQ/FASTA/gz/bz2 compatible)"
)
parser.add_argument(
"--genome",
nargs="+",
help="Input diploid genome FASTA file(s)"
)
parser.add_argument(
"--prefix",
required=False,
help="Prefix for output files [default --reads or --genome inputs concatenated]"
)
parser.add_argument(
"--kmer_file",
required=True,
help="SNV k-mer definition file used by korusMatrix.py"
)
parser.add_argument(
"-k",
required=True,
type=int,
help="k-mer size"
)
parser.add_argument(
"--window_size",
default=500000,
type=int,
help="Window size for matrix aggregation [default=500000]"
)
parser.add_argument(
"-t",
default=4,
type=int,
help="Number of threads [default=4]"
)
parser.add_argument(
"-n",
"--dry-run",
action="store_true",
help="Print commands without executing"
)
parser.add_argument(
"-f",
"--force",
action="store_true",
help="Force rerun of all rules"
)
parser.add_argument(
"-V",
"--version",
action="version",
version=KORUSENCODE_VERSION
)
return parser
def main():
parser = set_up_parser()
args = parser.parse_args()
if not os.path.isfile(args.kmer_file):
parser.error(
f"k-mer definition file not found: {args.kmer_file}"
)
if args.reads is None and args.genome is None:
parser.error(
"Either --reads or --genome must be specified."
)
if args.reads is not None and args.genome is not None:
parser.error(
"Only one of --reads or --genome can be specified."
)
base_dir = os.path.dirname(os.path.realpath(__file__))
intro = [
"Running korusEncode...",
"Parameter settings:",
f"\t--reads {args.reads}" if args.reads else f"\t--genome {args.genome}",
f"\t--kmer_file {args.kmer_file}",
f"\t-k {args.k}",
f"\t--window_size {args.window_size}",
f"\t-t {args.t}",
f"\t--prefix {args.prefix}" if args.prefix else "",
]
print("\n".join(intro).strip(), flush=True)
rule = "all"
if args.genome:
rule = "genome"
command = (
f"snakemake "
f"-s {base_dir}/korusEncode_pipeline.smk {rule} "
f"--nolock -p "
f"--cores {args.t} "
f"--config "
f"kmer_file={args.kmer_file} "
f"kmer={args.k} "
f"window_size={args.window_size} "
f"threads={args.t} "
)
if args.reads:
command += f"reads={args.reads} "
elif args.genome:
command += f"genome=\"{args.genome}\" "
if args.prefix:
command += f"prefix={args.prefix} "
if version.parse(snakemake.__version__) >= version.parse("7.8.0"):
command += " --rerun-trigger mtime"
if args.dry_run:
command += " -n"
if args.force:
command += " -F"
print(f"Running {command}", flush=True)
command = shlex.split(command)
ret = subprocess.call(command)
if ret != 0:
raise subprocess.SubprocessError(
"korusEncode failed — check logs for details."
)
print("Done korusEncode!")
if __name__ == "__main__":
main()