forked from YuSugihara/MutMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.py
executable file
·461 lines (405 loc) · 19.8 KB
/
params.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import os
import sys
import argparse
from multiprocessing import Pool
import multiprocessing as multi
from mutmap.utils import time_stamp
from mutmap.__init__ import __version__
class Params(object):
def __init__(self, program_name):
self.program_name = program_name
def set_options(self):
if self.program_name == 'mutmap':
parser = self.mutmap_options()
elif self.program_name == 'mutplot':
parser = self.mutplot_options()
if len(sys.argv) == 1:
args = parser.parse_args(['-h'])
else:
args = parser.parse_args()
return args
def mutmap_options(self):
parser = argparse.ArgumentParser(description='MutMap version {}'.format(__version__),
formatter_class=argparse.RawTextHelpFormatter)
parser.usage = ('mutmap -r <FASTA> -c <BAM|FASTQ> -b <BAM|FASTQ>\n'
' -n <INT> -o <OUT_DIR> [-T] [-e <DATABASE>]')
# set options
parser.add_argument('-r',
'--ref',
action='store',
required=True,
type=str,
help='Reference fasta.',
metavar='')
parser.add_argument('-c',
'--cultivar',
action='append',
required=True,
type=str,
help=('fastq or bam of cultivar. If you specify\n'
'fastq, please separate pairs by commma,\n'
'e.g. -c fastq1,fastq2. You can use this\n'
'optiion multiple times'),
metavar='')
parser.add_argument('-b',
'--bulk',
action='append',
required=True,
type=str,
help=('fastq or bam of mutnat bulk. If you specify\n'
'fastq, please separate pairs by commma,\n'
'e.g. -b fastq1,fastq2. You can use this\n'
'optiion multiple times'),
metavar='')
parser.add_argument('-n',
'--N-bulk',
action='store',
required=True,
type=int,
help='Number of individuals in mutant bulk.',
metavar='')
parser.add_argument('-o',
'--out',
action='store',
required=True,
type=str,
help=('Output directory. Specified name must not\n'
'exist.'),
metavar='')
parser.add_argument('-t',
'--threads',
action='store',
default=2,
type=int,
help=('Number of threads. If you specify the number\n'
'below one, then MutMap will use the threads\n'
'as many as possible. [2]'),
metavar='')
parser.add_argument('-w',
'--window',
action='store',
default=2000,
type=int,
help='Window size (kb). [2000]',
metavar='')
parser.add_argument('-s',
'--step',
action='store',
default=100,
type=int,
help='Step size (kb). [100]',
metavar='')
parser.add_argument('-D',
'--max-depth',
action='store',
default=250,
type=int,
help=('Maximum depth of variants which will be used.\n'
'This cutoff will be applied in both of cultivar\n'
'and bulk. [250]'),
metavar='')
parser.add_argument('-d',
'--min-depth',
action='store',
default=8,
type=int,
help=('Minimum depth of variants which will be used.\n'
'This cutoff will be applied in both of cultivar\n'
'and bulk. [8]'),
metavar='')
parser.add_argument('-N',
'--N-rep',
action='store',
default=5000,
type=int,
help=('Number of replicates for simulation to make \n'
'null distribution. [5000]'),
metavar='')
parser.add_argument('-T',
'--trim',
action='store_true',
default=False,
help='Trim fastq using trimmomatic.')
parser.add_argument('-a',
'--adapter',
action='store',
type=str,
help=('FASTA of adapter sequences. This will be used\n'
'when you specify "-T" for trimming.'),
metavar='')
parser.add_argument('--trim-params',
action='store',
type=str,
help=('Parameters for trimmomatic. Input parameters\n'
'must be separated by comma with following\n'
'order: phred, ILLUMINACLIP, LEADING, TRAILING,\n'
'SLIDINGWINDOW, MINLEN. If you want to remove\n'
'adapters of illumina, please specify FASTA of\n'
'the adapter sequences with "--adapter". Specified\n'
'name will be inserted into <ADAPTER_FASTA>. If you\n'
"don't specify it, adapter trimming will be skipped.\n"
'[33,<ADAPTER_FASTA>:2:30:10,20,20,4:15,75]'),
metavar='')
parser.add_argument('-e',
'--snpEff',
action='store',
type=str,
help=('Predict causal variant using SnpEff. Please\n'
'check available databases in SnpEff.'),
metavar='')
parser.add_argument('--mem',
action='store',
default='1G',
type=str,
help=('Maximum memory per thread when bam sorted;\n'
'suffix K/M/G recognized. [1G]'),
metavar='')
parser.add_argument('-q',
'--min-MQ',
action='store',
default=40,
type=int,
help='Minimum mapping quality in mpileup. [40]',
metavar='')
parser.add_argument('-Q',
'--min-BQ',
action='store',
default=18,
type=int,
help='Minimum base quality in mpileup. [18]',
metavar='')
parser.add_argument('-C',
'--adjust-MQ',
action='store',
default=50,
type=int,
help=('"adjust-MQ" in mpileup. Default parameter\n'
'is suited for BWA. [50]'),
metavar='')
# set version
parser.add_argument('-v',
'--version',
action='version',
version='%(prog)s {}'.format(__version__))
return parser
def mutplot_options(self):
parser = argparse.ArgumentParser(description='MutPlot version {}'.format(__version__),
formatter_class=argparse.RawTextHelpFormatter)
parser.usage = ('mutplot -v <VCF> -o <OUT_DIR> -n <INT> [-w <INT>] [-s <INT>]\n'
' [-D <INT>] [-d <INT>] [-N <INT>] [-m <FLOAT>]\n'
' [-S <INT>] [-e <DATABASE>] [--igv] [--indel]')
# set options
parser.add_argument('-v',
'--vcf',
action='store',
required=True,
type=str,
help='VCF which contains cultivar and mutant bulk.',
metavar='')
parser.add_argument('-o',
'--out',
action='store',
required=True,
type=str,
help='Output directory. Specified name can exist.',
metavar='')
parser.add_argument('-n',
'--N-bulk',
action='store',
required=True,
type=int,
help='Number of individuals in mutant bulk.',
metavar='')
parser.add_argument('-w',
'--window',
action='store',
default=2000,
type=int,
help='Window size (kb). [2000]',
metavar='')
parser.add_argument('-s',
'--step',
action='store',
default=100,
type=int,
help='Step size (kb). [100]',
metavar='')
parser.add_argument('-D',
'--max-depth',
action='store',
default=250,
type=int,
help=('Maximum depth of variants which will be used.\n'
'This cutoff will be applied in both of cultivar\n'
'and bulk. [250]'),
metavar='')
parser.add_argument('-d',
'--min-depth',
action='store',
default=8,
type=int,
help=('Minimum depth of variants which will be used.\n'
'This cutoff will be applied in both of cultivar\n'
'and bulk. [8]'),
metavar='')
parser.add_argument('-N',
'--N-rep',
action='store',
default=5000,
type=int,
help=('Number of replicates for simulation to make \n'
'null distribution. [5000]'),
metavar='')
parser.add_argument('-m',
'--min-SNPindex',
action='store',
default=0.3,
type=float,
help='Cutoff of minimum SNP-index for clear results. [0.3]',
metavar='')
parser.add_argument('-S',
'--strand-bias',
action='store',
default=7,
type=int,
help=('Filter spurious homo genotypes in cultivar using\n'
'strand bias. If ADF (or ADR) is higher than this\n'
'cutoff when ADR (or ADF) is 0, that SNP will be\n'
'filtered out. If you want to supress this filtering,\n'
'please set this cutoff to 0. [7]\n'),
metavar='')
parser.add_argument('-e',
'--snpEff',
action='store',
type=str,
help=('Predict causal variant using SnpEff. Please\n'
'check available databases in SnpEff.'),
metavar='')
parser.add_argument('--igv',
action='store_true',
default=False,
help='Output IGV format file to check results on IGV.')
parser.add_argument('--indel',
action='store_true',
default=False,
help='Plot SNP-index with INDEL.')
parser.add_argument('--fig-width',
action='store',
default=7.5,
type=float,
help='Width allocated in chromosome figure. [7.5]',
metavar='')
parser.add_argument('--fig-height',
action='store',
default=4.0,
type=float,
help='Height allocated in chromosome figure. [4.0]',
metavar='')
parser.add_argument('--white-space',
action='store',
default=0.6,
type=float,
help=('White space between figures. (This option\n'
'only affect vertical direction.) [0.6]'),
metavar='')
# set version
parser.add_argument('--version',
action='version',
version='%(prog)s {}'.format(__version__))
return parser
def check_max_threads(self, args):
max_cpu = multi.cpu_count()
print(time_stamp(),
'maximum number of threads which you can use is up to {}.'.format(max_cpu),
flush=True)
if max_cpu <= args.threads:
sys.stderr.write(('!!WARNING!! You can use up to {0} threads. '
'This program will use {0} threads.\n').format(max_cpu))
sys.stderr.flush()
args.threads = max_cpu
elif args.threads < 1:
args.threads = max_cpu
return args
def check_args(self, args):
if os.path.isdir(args.out):
sys.stderr.write((' Output directory already exist.\n'
' Please rename output directory or '
'remove existing directory\n\n'))
sys.exit()
if args.adapter is not None:
if not args.trim:
sys.stderr.write(('!!WARNING!! You specified "--adapter", but you '
'did not spesify "--trim".\n'
'!!WARNING!! "--trim" was added.\n'))
sys.stderr.flush()
if args.trim:
if args.trim_params is None:
args.trim_params = '33,<ADAPTER_FASTA>:2:30:10,20,20,4:15,75'
else:
if args.trim_params is not None:
sys.stderr.write(('!!WARNING!! You specified "--trim-params", but you '
'did not spesify "--trim".\n'
'!!WARNING!! "--trim" was added.\n'))
sys.stderr.flush()
N_fastq = 0
for input_name in args.cultivar:
n_comma = input_name.count(',')
if n_comma == 0:
root, ext = os.path.splitext(input_name)
if ext != '.bam':
sys.stderr.write((' Please check "{}".\n'
' The extension of this file is not "bam".\n'
' If you wanted to specify fastq, please '
'input them as paired-end reads which is separated '
'by comma. e.g. -c fastq1,fastq2\n\n').format(input_name))
sys.exit()
elif n_comma == 1:
fastqs = input_name.split(',')
for fastq in fastqs:
root, ext = os.path.splitext(fastq)
if ext == '.bam':
sys.stderr.write((' Please check "{}".\n'
' The extension must not be "bam".\n'
' If you wanted to specify bam, please '
'input them separately. e.g. -c bam1 '
'-c bam2\n\n').format(input_name))
sys.exit()
N_fastq += 1
else:
sys.stderr.write((' Please check "{}".\n'
' You specified too much files, or '
'your file name includes ",".\n\n').format(input_name))
sys.exit()
for input_name in args.bulk:
n_comma = input_name.count(',')
if n_comma == 0:
root, ext = os.path.splitext(input_name)
if ext != '.bam':
sys.stderr.write((' Please check "{}".\n'
' The extension of this file is not "bam".\n'
' If you wanted to specify fastq, please '
'input them as paired-end reads which is separated '
'by comma. e.g. -b fastq1,fastq2\n\n').format(input_name))
sys.exit()
elif n_comma == 1:
fastqs = input_name.split(',')
for fastq in fastqs:
root, ext = os.path.splitext(fastq)
if ext == '.bam':
sys.stderr.write((' Please check "{}".\n'
' The extension must not be "bam".\n'
' If you wanted to specify bam, please '
'input them separately. e.g. -b bam1 '
'-b bam2\n\n').format(input_name))
sys.exit()
N_fastq += 1
else:
sys.stderr.write((' Please check "{}".\n'
' You specified too much files, or '
'your file name includes ",".\n\n').format(input_name))
sys.exit()
if N_fastq == 0 and args.trim:
sys.stderr.write((' You can specify "--trim" only when '
'you input fastq.\n\n'))
sys.exit()
return N_fastq