-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenemapis.sh
executable file
·518 lines (453 loc) · 17.9 KB
/
genemapis.sh
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
#!/usr/bin/env sh
#--- genemapimputation workflow wrapper ---#
function usage() {
echo """
=================================================================
GeneMAP-NGS ~ a wrapper for the nextflow-based genemapis workflow
=================================================================
Usage: genemapis <workflow> <profile> [options] ...
workflows:
---------
test: Run test to see if workfow installed correctly.
align: Check strand and reference allele overlap.
phase: Phase (and Impute) genotypes.
impute: Only impute missing genotypes.
xxxxxxxx: .
xxxxxxxx: .
xxxxxxxxx: .
profiles: <executor>,<container>,<reference>
---------
executors: local, slurm
containers: singularity, aptainer, docker
reference: hg19, hg38, t2t
examples:
---------
genemapis test slurm,singularity,hg38 [options]
genemapis align local,singularity,hg19 --vcf my-vcf.vcf.gz
"""
}
#####################################################################################################################
function checkprofile() {
#profile was passed as only argument
#so it takes position $1 here
if [[ "$1" == "" ]]; then
echo "ERROR: please specify a profile to use!";
usage;
exit 1;
elif [[ $1 == -* ]]; then
echo "ERROR: please specify a valid profile!";
usage;
exit 1;
else
local profile="$1"
fi
}
function check_required_params() {
for params_vals in $@; do
#get each param and its value as an array
param_val=( $(echo ${params_vals} | sed 's/,/ /g') )
#slice the array to its consituent params and values
param=${param_val[0]}
val=${param_val[1]}
#now check each param and its value
if [[ $val == -* ]] || [[ $val == NULL ]]; then
echo "ERROR: Invalid paramter value for option '--${param}'";
break;
exit 1;
fi
done
}
function check_optional_params() {
for params_vals in $@; do
#get each param and its value as an array
param_val=( $(echo ${params_vals} | sed 's/,/ /g') )
#slice the array to its consituent params and values
param=${param_val[0]}
val=${param_val[1]}
#now check each param and its value
if [[ $val == -* ]]; then
echo "ERROR: Invalid paramter value for option '--${param}'";
break;
exit 1;
fi
done
}
function setglobalparams() {
#- create the project nextflow config file
echo """includeConfig \"\${projectDir}/nextflow.config\"
includeConfig \"\${projectDir}/configs/profile-selector.config\"
includeConfig \"\${projectDir}/configs/resource-selector.config\"
"""
}
##################################################### USAGE #########################################################
function alignusage() {
echo -e "\nUsage: genemapis align <profile> [options] ..."
echo """
options:
--------
--autosome : (optional) specify this flag to process autosomes only.
--vcf : (required) VCF file. Must specify full path.
--output_prefix : (optional) output prefix [default: myout].
--output_dir : (required) path to save output files.
--exclude_sample : (optional) reference samples to exclude. Single column, one sample per line.
--threads : (optional) number of computer cpus to use [default: 8].
--njobs : (optional) number of jobs to submit at once [default: 4]
--help : print this help message.
"""
}
function phaseusage() {
echo -e "\nUsage: genemapis phase <profile> [options] ..."
echo """
options:
--------
--with_ref : (optional) specify this flag to phase with reference
--phase_tool : (optional) shapeit4, eagle2, beagle5 [default: shapeit4]
--impute : (optional) to phase and impute in one run, add this flag
--impute_tool : (optional) minimac4, impute2, beagle5 [default: minimac4]
--vcf : (required) VCF file. Must specify full path
--autosome : (optional) specify this flag to process autosomes only
--output_prefix : (optional) output prefix [default: myout]
--output_dir : (required) path to save output files
--burnit : (optional) number of BEAGLE burn in iterations [default: 2000]
--mainit : (optional) number of BEAGLE main iterations [default: 1000]
--kpbwt : (optional) number of BEAGLE and EAGLE conditioning haplotypes [default: 50000]
--pbwt : (optional) number of SHAPEIT PBWT iterations [default: 8]
--threads : (optional) number of computer cpus to use [default: 8]
--njobs : (optional) number of jobs to submit at once [default: 4]
--help : print this help message
"""
}
function imputeusage() {
echo -e "\nUsage: genemapis impute <profile> [options] ..."
echo """
options:
--------
--impute_tool : (optional) minimac4, impute2, beagle5 [default: minimac4]
--panel : (optional) available panels: custom, kgp, h3a [default: kgp]
--vcf : (required) VCF file. Must specify full path
--autosome : (optional) specify this flag to process autosomes only
--output_prefix : (optional) output prefix [default: myout]
--output_dir : (required) path to save output files
--burnit : (optional) number of BEAGLE burn in iterations [default: 2000]
--mainit : (optional) number of BEAGLE main iterations [default: 1000]
--kpbwt : (optional) number of BEAGLE and EAGLE conditioning haplotypes [default: 50000]
--pbwt : (optional) number of SHAPEIT PBWT iterations [default: 8]
--threads : (optional) number of computer cpus to use [default: 8]
--njobs : (optional) number of jobs to submit at once [default: 4]
--help : print this help message
"""
}
############################################# CONFIGURATION FILES ####################################################
function testconfig() {
#check and remove test config file if it exists
[ -e test.config ] && rm test.config
# $indir $bpm $csv $cluster $fasta $bam $out $outdir $thrds
echo """includeConfig \"\${projectDir}/nextflow.config\"
includeConfig \"\${projectDir}/configs/profile-selector.config\"
includeConfig \"\${projectDir}/configs/test.config\"
""" >> test.config
}
function alignconfig() { #params passed as arguments
#check and remove config file if it exists
[ -e ${3}-align.config ] && rm ${3}-align.config
#alignconfig $autosome $vcf $output_prefix $output_dir $exclude_sample $threads $njobs
echo """`setglobalparams`
params {
//====================================
// genemapis align workflow parameters
//====================================
autosome = $1 // (optional) include this argument if you wish to only process autosomes [default: false]
vcf = '$2' // (required) VCF file. Must specify full path.
output_prefix = '$3' // (optional) output prefix [default: myout]
output_dir = '$4' // (required) path to save output files.
exclude_sample = '$5' // (optional) reference samples to exclude. Single column, one sample per line.
threads = $6 // number of computer cpus to use [default: 8]
njobs = $7 // (optional) number of jobs to submit at once [default: 4]
}
""" >> ${3}-align.config
}
function phaseconfig() { #params passed as arguments
#check and remove config file if it exists
[ -e ${7}-phase.config ] && rm ${7}-phase.config
echo """
params {
//====================================
// genemapis phase workflow parameters
//====================================
phase = true
with_ref = ${1}
phase_tool = '${2}'
impute = ${3}
impute_tool = '${4}'
vcf = '${5}'
autosome = ${6}
output_prefix = '${7}'
output_dir = '${8}'
burnit = ${9}
mainit = ${10}
kpbwt = ${11}
pbwt = ${12}
threads = ${13}
njobs = ${14}
/***************************************************************************************
~ with_ref: (optional) specify this flag to phase with reference
available ref: kgp
~ phase_tool: (optional) shapeit4, eagle2, beagle5 [default: shapeit4]
~ impute: (optional) specify this flag to impute
~ impute_tool: (optional) minimac4, impute2, beagle5 [default: minimac4]
~ panel: (optional) available imputation panels: custom, kgp, h3a [default: kgp]
~ vcf: (required) VCF file. Must specify full path
~ autosome: (optional) specify this flag to process autosomes only
~ output_prefix: (optional) output prefix [default: myout]
~ output_dir: (required) path to save output files
~ burnit: (optional) number of BEAGLE burn in iterations [default: 2000]
~ mainit: (optional) number of BEAGLE main iterations [default: 1000]
~ kpbwt: (optional) number of BEAGLE and EAGLE conditioning haplotypes [default: 50000]
~ pbwt: (optional) number of SHAPEIT PBWT iterations [default: 8]
~ threads: (optional) number of computer cpus to use [default: 8]
~ njobs: number of simultaneous jobs to submit [default: 4]
****************************************************************************************/
}
`setglobalparams`
""" >> ${7}-phase.config
}
function imputeconfig() { #params passed as arguments
#check and remove config file if it exists
[ -e ${5}-impute.config ] && rm ${5}-impute.config
echo """
params {
//=====================================
// genemapis impute workflow parameters
//=====================================
impute = true
phase = false
impute_tool = '${1}'
panel = '${2}'
vcf = '${3}'
autosome = ${4}
output_prefix = '${5}'
output_dir = '${6}'
burnit = ${7}
mainit = ${8}
kpbwt = ${9}
pbwt = ${10}
threads = ${11}
njobs = ${12}
/***************************************************************************************
~ impute_tool: (optional) minimac4, impute2, beagle5 [default: minimac4]
~ panel: (optional) available imputation panels: custom, kgp, h3a [default: kgp]
~ vcf: (required) VCF file. Must specify full path
~ autosome: (optional) specify this flag to process autosomes only
~ output_prefix: (optional) output prefix [default: myout]
~ output_dir: (required) path to save output files
~ burnit: (optional) number of BEAGLE burn in iterations [default: 2000]
~ mainit: (optional) number of BEAGLE main iterations [default: 1000]
~ kpbwt: (optional) number of BEAGLE and EAGLE conditioning haplotypes [default: 50000]
~ pbwt: (optional) number of SHAPEIT PBWT iterations [default: 8]
~ threads: (optional) number of computer cpus to use [default: 8]
****************************************************************************************/
}
`setglobalparams`
""" >> ${5}-impute.config
}
if [ $# -lt 1 ]; then
usage; exit 1;
else
case $1 in
test)
profile='local,singularity,hg19'
testconfig
;;
align)
#pass profile as argument
checkprofile $2;
profile=$2;
shift;
if [ $# -lt 2 ]; then
alignusage;
exit 1;
fi
prog=`getopt -a --long "help,autosome,vcf:,output_prefix:,output_dir:,exclude_sample:,threads:,njobs:" -n "${0##*/}" -- "$@"`;
# defaults
autosome=false #// (optional) include this argument if you wish to only process autosomes [default: false]
vcf=NULL #// (required) VCF file. Must specify full path.
output_prefix=myout #// (optional) output prefix [default: myout]
output_dir=NULL #// (required) path to save output files.
exclude_sample=NULL #// (optional) reference samples to exclude. Single column, one sample per line.
threads=8 #// number of computer cpus to use [default: 8]
njobs=4 #// (optional) number of jobs to submit at once [default: 4]
eval set -- "$prog"
while true; do
case $1 in
--autosome) autosome=true; shift;;
--vcf) vcf="$2"; shift 2;;
--output_prefix) output_prefix="$2"; shift 2;;
--output_dir) output_dir="$2"; shift 2;;
--exclude_sample) exclude_sample="$2"; shift 2;;
--threads) threads="$2"; shift 2;;
--njobs) njobs="$2"; shift 2;;
--help) shift; alignusage; 1>&2; exit 1;;
--) shift; break;;
*) shift; alignusage; 1>&2; exit 1;;
esac
done
#- check required options
check_required_params vcf,$vcf
check_output_dir $output_dir
check_optional_params output_prefix,$output_prefix exclude_sample,$exclude_sample threads,$threads njobs,$njobs
alignconfig $autosome $vcf $output_prefix $output_dir $exclude_sample $threads $njobs
#echo `nextflow -c ${out}-qc.config run qualitycontrol.nf -profile $profile -w ${outdir}/work/`
;;
phase)
#pass profile as argument
checkprofile $2;
profile=$2;
shift;
if [ $# -lt 2 ]; then
phaseusage;
exit 1;
fi
prog=`getopt -a --long "with_ref,phase_tool:,impute,impute_tool:,vcf:,autosome,output_prefix:,output_dir:,burnit:,mainit:,kpbwt:,pbwt:,threads:,njobs:" -n "${0##*/}" -- "$@"`;
#- defaults
with_ref=false
phase_tool=shapeit4
impute=false
impute_tool=minimac4
vcf=NULL
autosome=false
output_prefix=my-phase
output_dir=NULL
burnit=2000
mainit=1000
kpbwt=50000
pbwt=8
threads=8
eval set -- "$prog"
while true; do
case $1 in
--with_ref) with_ref=true; shift;;
--phase_tool) phase_tool=$2; shift 2;;
--impute) impute=true; shift;;
--impute_tool) impute_tool=$2; shift 2;;
--vcf) vcf=$2; shift 2;;
--autosome) autosome=true; shift;;
--output_prefix) output_prefix=$2; shift 2;;
--output_dir) output_dir=$2; shift 2;;
--burnit) burnit=$2; shift 2;;
--mainit) mainit=$2; shift 2;;
--kpbwt) kpbwt=$2; shift 2;;
--pbwt) pbwt=$2; shift 2;;
--threads) threads="$2"; shift 2;;
--njobs) njobs="$2"; shift 2;;
--help) shift; phaseusage; 1>&2; exit 1;;
--) shift; break;;
*) shift; phaseusage; 1>&2; exit 1;;
esac
continue; shift;
done
#- check required options
#check_ftype $ftype
check_required_params \
vcf,$vcf \
output_dir,$output_dir && \
check_optional_params \
phase_tool,$phase_tool \
impute_tool,$impute_tool \
output_prefix,$output_prefix \
burnit,$burnit \
mainit,$mainit \
kpbwt,$kpbwt \
pbwt,$pbwt \
threads,$threads \
njpbs,$njobs && \
phaseconfig \
$with_ref \
$phase_tool \
$impute \
$impute_tool \
$vcf \
$autosome \
$output_prefix \
$output_dir \
$burnit \
$mainit \
$kpbwt \
$pbwt \
$threads \
$njobs
;;
impute)
#pass profile as argument
checkprofile $2;
profile=$2;
shift;
if [ $# -lt 2 ]; then
imputeusage;
exit 1;
fi
prog=`getopt -a --long "impute_tool:,panel:,vcf:,autosome,output_prefix:,output_dir:,burnit:,mainit:,kpbwt:,pbwt:,threads:,njobs:" -n "${0##*/}" -- "$@"`;
#- defaults
impute_tool=minimac4
panel=kgp
vcf=NULL
autosome=false
output_prefix=my-impute
output_dir=NULL
burnit=2000
mainit=1000
kpbwt=50000
pbwt=8
threads=8
eval set -- "$prog"
while true; do
case $1 in
--impute_tool) impute_tool=$2; shift 2;;
--panel) panel=$2; shift 2;;
--vcf) vcf=$2; shift 2;;
--autosome) autosome=true; shift;;
--output_prefix) output_prefix=$2; shift 2;;
--output_dir) output_dir=$2; shift 2;;
--burnit) burnit=$2; shift 2;;
--mainit) mainit=$2; shift 2;;
--kpbwt) kpbwt=$2; shift 2;;
--pbwt) pbwt=$2; shift 2;;
--threads) threads="$2"; shift 2;;
--njobs) njobs="$2"; shift 2;;
--help) shift; imputeusage; 1>&2; exit 1;;
--) shift; break;;
*) shift; imputeusage; 1>&2; exit 1;;
esac
continue; shift;
done
#- check required options
#check_ftype $ftype
check_required_params \
vcf,$vcf \
output_dir,$output_dir && \
check_optional_params \
impute_tool,$impute_tool \
panel,$panel \
output_prefix,$output_prefix \
burnit,$burnit \
mainit,$mainit \
kpbwt,$kpbwt \
pbwt,$pbwt \
threads,$threads \
njpbs,$njobs && \
imputeconfig \
$impute_tool \
$panel \
$vcf \
$autosome \
$output_prefix \
$output_dir \
$burnit \
$mainit \
$kpbwt \
$pbwt \
$threads \
$njobs
;;
*) shift; usage; exit 1;;
esac
fi