Repository navigation
Expand file tree
/
Copy pathkorusEncode
More file actions
executable file
·148 lines (114 loc) · 3.12 KB
/
Copy pathkorusEncode
File metadata and controls
executable file
·148 lines (114 loc) · 3.12 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
#!/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 = "v0.1.0"
def set_up_parser():
parser = argparse.ArgumentParser(
description="korusEncode: build KORUS feature matrices from sequencing reads",
formatter_class=argparse.RawTextHelpFormatter,
epilog="Input reads are identified using a shared prefix."
)
parser.add_argument(
"--reads",
required=True,
help="Prefix of input read files (FASTQ/FASTA/gz/bz2 compatible)"
)
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(
"--tile",
default=500000,
type=int,
help="Window/tile 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):
raise FileNotFoundError(
f"k-mer definition file not found: {args.kmer_file}"
)
base_dir = os.path.dirname(os.path.realpath(__file__))
reads_prefix = os.path.basename(args.reads)
intro = [
"Running korusEncode...",
"Parameter settings:",
f"\t--reads {args.reads}",
f"\t--kmer_file {args.kmer_file}",
f"\t-k {args.k}",
f"\t--tile {args.tile}",
f"\t-t {args.t}"
]
print("\n".join(intro), flush=True)
command = (
f"snakemake "
f"-s {base_dir}/korusEncode_pipeline.smk "
f"--nolock -p "
f"--cores {args.t} "
f"--config "
f"reads={args.reads} "
f"kmer_file={args.kmer_file} "
f"kmer={args.k} "
f"tile_size={args.tile} "
f"threads={args.t}"
)
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()