-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path2_PhasingScriptMaker.sh
executable file
·559 lines (394 loc) · 23.3 KB
/
2_PhasingScriptMaker.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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#!/bin/bash
## Overview:
## ==================
## This script will:
# 1) Create the Bash scripts used to execute Phasing jobs (autosomal and the X chromosome) on a system
# 2) Submit the Bash scripts to the HPC queue at the user's request
# Splash Screen
# --------------
source .TitleSplash.txt
printf "$Logo"
# Source from .config files (Program options via Settings.conf & Program execs via Programs.conf)
# ----------------------------
source Settings.conf
# Load Odysseys Dependencies -- pick from several methods
if [ "${OdysseySetup,,}" == "one" ]; then
echo
printf "\n\nLoading Odyssey's Singularity Container Image \n\n"
source ./Configuration/Setup/Programs-Singularity.conf
elif [ "${OdysseySetup,,}" == "two" ]; then
echo
printf "\n\nLoading Odyssey's Manually Configured Dependencies \n\n"
source ./Configuration/Setup/Programs-Manual.conf
else
echo
echo User Input Not Recognized -- Please specify One or Two for OdysseySetup
echo Exiting Dependency Loading
echo
exit
fi
# Set Working Directory
# ------------------------
printf "\nChanging to Working Directory\n"
echo ----------------------------------------------
echo ${WorkingDir}
cd ${WorkingDir}
# Creating Imputation Project Folders within Phase Directory
# -----------------------------------------------------------
printf "\nCreating Imputation Project Folder within Phase Directory\n\n"
mkdir -p ./2_Phase/${BaseName}
# Perform Lustre Stripping?
if [ "${LustreStrip,,}" == "t" ]; then
lfs setstripe -c 2 ./2_Phase/${BaseName}
fi
mkdir -p ./2_Phase/${BaseName}/Scripts2Shapeit
## --------------------------------------------------------------------------------------
## ===========================================
## Download Default Ref Data
## ===========================================
## --------------------------------------------------------------------------------------
if [ "${DownloadDefaultRefPanel,,}" == "t" ]; then
printf "\nDownloading Default Ref Panel \nDetermining Phasing and Imputation Program Requested From Settings.conf\n "
echo "---------------------------------------------"
echo
# Make sure troublesome combos are not coded -- i.e. requesting several phasing or several imputations
if ([ "${UseShapeit,,}" == "t" ] && [ "${UseEagle,,}" == "t" ]) || ([ "${UseShapeit,,}" == "f" ] && [ "${UseEagle,,}" == "f" ]) || ([ "${UseImpute,,}" == "t" ] && [ "${UseMinimac,,}" == "t" ]) || ([ "${UseImpute,,}" == "f" ] && [ "${UseMinimac,,}" == "f" ]) ; then
printf "\nCombo Not Possible. Specify a single Phasing and Imputation Program to Use -- Exiting\n\n "
exit
# Valid Phase/Impute Combinations
elif ([ "${UseShapeit,,}" == "t" ] && [ "${UseImpute,,}" == "t" ]) || ([ "${UseShapeit,,}" == "t" ] && [ "${UseMinimac,,}" == "t" ]) || ([ "${UseEagle,,}" == "t" ] && [ "${UseMinimac,,}" == "t" ]) || ([ "${UseEagle,,}" == "t" ] && [ "${UseImpute,,}" == "t" ]) ; then
printf "Good Phase/Impute Combination Proceeding...\n\n"
# ================================Use Shapeit================================
if [ "${UseShapeit,,}" == "t" ]; then
# ====================================== Use Shapeit-Impute ======================================
if [ "${UseImpute,,}" == "t" ]; then
printf "Using a Shapeit-Impute Combo Downloading Necessary Default Ref Files"
# Retrieves the (default) Reference Genome from the IMPUTE Website
# ----------------------------------------------------------------------------------
# Collects the 1000Genome Reference Build from the Impute Site
#(https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3.html)
# Reference Build Specs: 1,000 Genomes haplotypes -- Phase 3 integrated variant set release in NCBI build 37 (hg19) coordinates
# Ref Build Updated Aug 3 2015
printf "\n\nRetrieving 1K Genome Phase 3 Ref Panel and hg19 Genetic Map from Impute2 Website \n-------------------------------------------------------------------------------\n\n\n"
wget --directory-prefix=${WorkingDir}Reference/ https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3.tgz
wget --directory-prefix=${WorkingDir}Reference/ https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3_chrX.tgz
#Unzip the packaged ref panel
printf "\n\nUnpackaging Ref Panel \n--------------------------\n\n"
tar -xzf ${WorkingDir}Reference/1000GP_Phase3.tgz -C ${WorkingDir}Reference/
tar -xzf ${WorkingDir}Reference/1000GP_Phase3_chrX.tgz -C ${WorkingDir}Reference/
# Since untar makes an additional directory, move all the files from the 1000GP_Phase3 folder and move it into the Ref Directory
printf "\n\nCleaning Up \n-------------------\n\n"
mv ${WorkingDir}Reference/1000GP_Phase3/* ${WorkingDir}Reference/
# Delete the now empty directory and the tgz zipped Ref panel
rmdir ${WorkingDir}Reference/1000GP_Phase3/
rm ${WorkingDir}Reference/*.tgz
# ====================================== Use Shapeit-Minimac ====================================
elif [ "${UseMinimac,,}" == "t" ]; then
printf "Using a Shapeit-Minimac Combo Downloading Necessary Default Ref Files"
# Retrieves the (default) Reference Genome from the IMPUTE Website
# ----------------------------------------------------------------------------------
# Collects the 1000Genome Reference Build from the Impute Site
#(https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3.html)
# Reference Build Specs: 1,000 Genomes haplotypes -- Phase 3 integrated variant set release in NCBI build 37 (hg19) coordinates
# Ref Build Updated Aug 3 2015
printf "\n\nRetrieving 1K Genome Phase 3 Ref Panel and hg19 Genetic Map from Impute2 Website \n-------------------------------------------------------------------------------\n\n\n"
wget --directory-prefix=${WorkingDir}Reference/ https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3.tgz
wget --directory-prefix=${WorkingDir}Reference/ https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3_chrX.tgz
#Unzip the packaged ref panel
printf "\n\nUnpackaging Ref Panel \n--------------------------\n\n"
tar -xzf ${WorkingDir}Reference/1000GP_Phase3.tgz -C ${WorkingDir}Reference/
tar -xzf ${WorkingDir}Reference/1000GP_Phase3_chrX.tgz -C ${WorkingDir}Reference/
# Since untar makes an additional directory, move all the files from the 1000GP_Phase3 folder and move it into the Ref Directory
printf "\n\nCleaning Up \n-------------------\n\n"
mv ${WorkingDir}Reference/1000GP_Phase3/* ${WorkingDir}Reference/
# Delete the now empty directory and the tgz zipped Ref panel
rmdir ${WorkingDir}Reference/1000GP_Phase3/
rm ${WorkingDir}Reference/*.tgz
# Remove the .hap.gz and .legend.gz files since we are using the Minimac mvcf Ref Panel
rm ${WorkingDir}Reference/*hap.gz
rm ${WorkingDir}Reference/*legend.gz
# Download the Minimac4 mvcf
wget --directory-prefix=${WorkingDir}Reference/ ftp://share.sph.umich.edu/minimac3/G1K_P3_M3VCF_FILES_WITH_ESTIMATES.tar.gz
#Unpack
tar -xzf ${WorkingDir}Reference/G1K_P3_M3VCF_FILES_WITH_ESTIMATES.tar.gz -C ${WorkingDir}Reference/
# Remove original .tar.gz Minimac Ref Panel
rm ${WorkingDir}Reference/*tar.gz
else
printf "Invalid Phasing/Imputation Program Combo -- Exiting \n\n"
exit
fi
# ================================Use Eagle================================
elif [ "${UseEagle,,}" == "t" ]; then
# ====================================== Use Eagle-Impute ======================================
if [ "${UseImpute,,}" == "t" ]; then
printf "Using a Eagle-Impute Combo Downloading Necessary Default Ref Files"
# Retrieves the (default) Reference Genome from the IMPUTE Website
# ----------------------------------------------------------------------------------
# Collects the 1000Genome Reference Build from the Impute Site
#(https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3.html)
# Reference Build Specs: 1,000 Genomes haplotypes -- Phase 3 integrated variant set release in NCBI build 37 (hg19) coordinates
# Ref Build Updated Aug 3 2015
printf "\n\nRetrieving 1K Genome Phase 3 Ref Panel and hg19 Genetic Map from Impute2 Website \n-------------------------------------------------------------------------------\n\n\n"
wget --directory-prefix=${WorkingDir}Reference/ https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3.tgz
wget --directory-prefix=${WorkingDir}Reference/ https://mathgen.stats.ox.ac.uk/impute/1000GP_Phase3_chrX.tgz
wget --directory-prefix=${WorkingDir}Reference/ https://data.broadinstitute.org/alkesgroup/Eagle/downloads/tables/genetic_map_hg19_withX.txt.gz
#Unzip the packaged ref panel
printf "\n\nUnpackaging Ref Panel \n--------------------------\n\n"
tar -xzf ${WorkingDir}Reference/1000GP_Phase3.tgz -C ${WorkingDir}Reference/
tar -xzf ${WorkingDir}Reference/1000GP_Phase3_chrX.tgz -C ${WorkingDir}Reference/
${gzip_Exec} -dc < ${WorkingDir}Reference/genetic_map_hg19_withX.txt.gz > ${WorkingDir}Reference/genetic_map_hg19_withX.txt
# Since untar makes an additional directory, move all the files from the 1000GP_Phase3 folder and move it into the Ref Directory
printf "\n\nCleaning Up \n-------------------\n\n"
mv ${WorkingDir}Reference/1000GP_Phase3/* ${WorkingDir}Reference/
# Delete the now empty directory and the tgz zipped Ref panel
rmdir ${WorkingDir}Reference/1000GP_Phase3/
rm ${WorkingDir}Reference/*.tgz
rm ${WorkingDir}Reference/*txt.gz
# ====================================== Use Eagle-Minimac ======================================
elif [ "${UseMinimac,,}" == "t" ]; then
printf "Using a Eagle-Minimac Combo Downloading Necessary Default Ref Files"
# Download the Minimac4 mvcf
wget --directory-prefix=${WorkingDir}Reference/ ftp://share.sph.umich.edu/minimac3/G1K_P3_M3VCF_FILES_WITH_ESTIMATES.tar.gz
wget --directory-prefix=${WorkingDir}Reference/ https://data.broadinstitute.org/alkesgroup/Eagle/downloads/tables/genetic_map_hg19_withX.txt.gz
#Unpack
printf "\n\nUnpackaging Ref Panel \n--------------------------\n\n"
tar -xzf ${WorkingDir}Reference/G1K_P3_M3VCF_FILES_WITH_ESTIMATES.tar.gz -C ${WorkingDir}Reference/
${gzip_Exec} -dc < ${WorkingDir}Reference/genetic_map_hg19_withX.txt.gz > ${WorkingDir}Reference/genetic_map_hg19_withX.txt
# Remove original .tar.gz Minimac Ref Panel
rm ${WorkingDir}Reference/*tar.gz
rm ${WorkingDir}Reference/*txt.gz
else
printf "Invalid Phasing/Imputation Program Combo -- Exiting \n\n"
exit
fi
fi
else
printf "Invalid Phasing/Imputation Program Combo -- Exiting \n\n"
exit
fi
elif [ "${DownloadDefaultRefPanel,,}" == "f" ]; then
printf "\nWill Not Download Default Phasing and Imputation Ref Panels\nIn This Case Make Sure the Proper Genetic Map File/s and Ref Panel are Located in the ./Reference Directory \n\nRefer to the Reference Dataset Section in Settings.conf for Supported Reference Naming Schemes\n"
echo "---------------------------------------------"
echo
else
printf "Command Not Recognized Please Specify either T or F for DownloadRefPanel -- Exiting \n\n"
exit
fi
## --------------------------------------------------------------------------------------
## ===========================================
## Phasing Using Shapeit2
## ===========================================
## --------------------------------------------------------------------------------------
if [ "${UseShapeit,,}" == "t" ]; then
printf "\n\nUsing Shapeit for Phasing\n=======================\n\n"
## -------------------------------------------
## Phasing Script Creation for Autosomes (Chr1-22)
## -------------------------------------------
if [ "${PhaseAutosomes,,}" == "t" ]; then
#Set Chromosome Start and End Parameters
for chr in `eval echo {$PhaseChrStart..$PhaseChrEnd}`; do
#Search the reference directory for the chromosome specific reference map, legend, and hap files and create their respective variables on the fly
printf "\n\nProcessing Chromosome ${chr} Script \n"
echo -----------------------------------
echo "Pre-Check: Looking in ./Reference For Reference Files "
echo "Found the Following Shapeit References for Chromosome ${chr}: "
GeneticMap="$(ls ./Reference/ | egrep --ignore-case ".*map.*chr${chr}[^[:digit:]]{1}.*|.*chr${chr}[^[:digit:]]{1}.*map.*")"
printf " Genetic Map File: $GeneticMap \n"
HapFile="$(ls ./Reference/ | egrep --ignore-case ".*chr${chr}[^[:digit:]]{1}.*hap\.gz")"
printf " Haplotpe File: $HapFile \n"
LegendFile="$(ls ./Reference/ | egrep --ignore-case ".*chr${chr}[^[:digit:]]{1}.*legend\.gz")"
printf " Legend File: $LegendFile \n \n"
echo "#!/bin/bash
cd ${WorkingDir}
# Phase Command to Phase Chromosomes
# Manual Command to Run:
# qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.out -N PChr${chr}_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh
${Shapeit2_Exec} \
--thread ${PhaseThreads} \
--input-bed ./1_Target/${BaseName}/Ody2_${BaseName}_PhaseReady.chr${chr} \
--input-map ./Reference/${GeneticMap} \
-O ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr${chr}_Phased.haps.gz ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr${chr}_Phased.sample \
--output-log ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr${chr}_Phased.log" > ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh
# Toggle that will turn script submission on/off
# -----------------------------------------------
if [ "${ExecutePhasingScripts,,}" == "t" ]; then
if [ "${HPS_Submit,,}" == "t" ]; then
echo
echo Submitting Phasing script to HPC Queue
echo
qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.out -N PChr${chr}_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh
sleep 0.2
else
echo
echo Submitting Phasing script to Desktop Queue
echo
bash ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh > ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.out 2>&1 &
fi
fi
done
elif [ "${PhaseAutosomes,,}" == "f" ]; then
printf "\n\n---Ok Will Not Phase the Autosomes---\n\n"
fi
## ---------------------------------------
## Extra Step to Phase the X Chromosome
## ---------------------------------------
if [ "${PhaseX,,}" == "t" ]; then
## -------------------------------------------
## Phasing Script Creation for HPC (Chr23/X)
## -------------------------------------------
printf "\n\nProcessing X Chromosome Script \n"
echo -----------------------------------
# Search the reference directory for the X chromosome specific reference map, legend, and hap files and create their respective variables on the fly
echo "Pre-Check: Looking in ./Reference For Reference Files "
echo "Found the Following Shapeit References for Chromosome X: "
XGeneticMap="$(ls ./Reference/ | egrep --ignore-case ".*map.*${XChromIdentifier}.*|.*${XChromIdentifier}.*map.*")"
printf " Genetic Map: $XGeneticMap \n"
XHapFile="$(ls ./Reference/ | egrep --ignore-case ".*${XChromIdentifier}.*hap\.gz")"
printf " Haplotpe File: $XHapFile \n"
XLegendFile="$(ls ./Reference/ | egrep --ignore-case ".*${XChromIdentifier}.*legend\.gz")"
printf " Legend File: $XLegendFile \n \n"
echo "#!/bin/bash
cd ${WorkingDir}
# Phase Command to Phase X Chromosome
# Manual Command to Run:
# qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.out -N PChr23_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh
${Shapeit2_Exec} \
--thread ${PhaseThreads} \
--chrX \
--input-bed ./1_Target/${BaseName}/Ody2_${BaseName}_PhaseReady.chr23 \
--input-map ./Reference/${XGeneticMap} \
-O ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr23_Phased.haps.gz ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr23}_Phased.sample \
--output-log ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr23_Phased.log" > ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh
# Toggle that will turn script submission on/off
# -----------------------------------------------
if [ "${ExecutePhasingScripts,,}" == "t" ]; then
if [ "${HPS_Submit,,}" == "t" ]; then
echo
echo Submitting Phasing script to HPC Queue
echo
qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.out -N PChr23_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh
sleep 0.2
else
echo
echo Submitting Phasing script to Desktop Queue
echo
sh ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh > ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.out 2>&1 &
fi
fi
elif [ "${PhaseX,,}" == "f" ]; then
printf "\n\n---Ok Will Not Phase the X Chromosome---\n\n"
fi
fi
## --------------------------------------------------------------------------------------
## ===========================================
## Phasing Using Eagle2
## ===========================================
## --------------------------------------------------------------------------------------
if [ "${UseEagle,,}" == "t" ]; then
printf "\n\nUsing Eagle for Phasing\n=======================\n\n"
## -------------------------------------------
## Phasing Script Creation for Autosomes (Chr1-22)
## -------------------------------------------
if [ "${PhaseAutosomes,,}" == "t" ]; then
#Set Chromosome Start and End Parameters
for chr in `eval echo {$PhaseChrStart..$PhaseChrEnd}`; do
#Search the reference directory for the chromosome specific reference map, legend, and hap files and create their respective variables on the fly
printf "\n\nProcessing Chromosome ${chr} Script \n"
echo -----------------------------------
echo "Pre-Check: Looking in ./Reference For Reference Files "
echo "Found the Following Eagle References for Chromosome ${chr}: "
GeneticMap="$(ls ./Reference/ | egrep --ignore-case ".*genetic_map.*")"
printf " Genetic Map File: $GeneticMap \n"
echo "#!/bin/bash
cd ${WorkingDir}
# Phase Command to Phase Chromosomes
# Manual Command to Run:
# qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.out -N PChr${chr}_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh
## Execute Phasing without a ref dataset
printf '\n\n'
echo ========================================
printf 'Phase Chr${chr} Using Eagle\n'
echo ========================================
printf '\n\n'
${Eagle2_Exec} --bfile ./1_Target/${BaseName}/Ody2_${BaseName}_PhaseReady.chr${chr} \
--geneticMapFile=./Reference/${GeneticMap} \
--outPrefix=./2_Phase/${BaseName}/Ody3_${BaseName}_Chr${chr}_Phased \
--chrom ${chr} \
--numThreads ${PhaseThreads}
#Unzip Phased Output
printf '\n\n'
echo ========================================
printf 'Gzip Chr${chr}\n'
echo ========================================
printf '\n\n'
${gzip_Exec} -dc < ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr${chr}_Phased.haps.gz > ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr${chr}_Phased.haps" > ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh
# Toggle that will turn script submission on/off
# -----------------------------------------------
if [ "${ExecutePhasingScripts,,}" == "t" ]; then
if [ "${HPS_Submit,,}" == "t" ]; then
echo Submitting Phasing script to HPC Queue
echo
qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.out -N PChr${chr}_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh
sleep 0.2
else
echo Submitting Phasing script to Desktop Queue
echo
bash ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.sh > ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr${chr}_P.out 2>&1 &
fi
fi
done
elif [ "${PhaseAutosomes,,}" == "f" ]; then
printf "\n\n---Ok Will Not Phase the Autosomes---\n\n"
fi
## ---------------------------------------
## Extra Step to Phase the X Chromosome
## ---------------------------------------
if [ "${PhaseX,,}" == "t" ]; then
## -------------------------------------------
## Phasing Script Creation for HPC (Chr23/X)
## -------------------------------------------
printf "\n\nProcessing X Chromosome Script \n"
echo -----------------------------------
#Search the reference directory for the chromosome specific reference map, legend, and hap files and create their respective variables on the fly
echo "Pre-Check: Looking in ./Reference For Reference Files "
echo "Found the Following Eagle References for Chromosome X: "
GeneticMap="$(ls ./Reference/ | egrep --ignore-case ".*genetic_map.*")"
printf " Genetic Map File: $GeneticMap \n"
echo "#!/bin/bash
cd ${WorkingDir}
# Phase Command to Phase X Chromosome
# Manual Command to Run:
# qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.out -N PChr23_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh
## Execute Phasing without a ref dataset
${Eagle2_Exec} --bfile ./1_Target/${BaseName}/Ody2_${BaseName}_PhaseReady.chr23 \
--geneticMapFile=./Reference/${GeneticMap} \
-O ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr23_Phased.haps.gz ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr23_Phased.sample \
--chrom 23 \
--numThreads ${PhaseThreads}
#Unzip Phased Output
${gzip_Exec} -dc < ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr23_Phased.haps.gz > ./2_Phase/${BaseName}/Ody3_${BaseName}_Chr23_Phased.haps" > ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh
# Toggle that will turn script submission on/off
# -----------------------------------------------
if [ "${ExecutePhasingScripts,,}" == "t" ]; then
if [ "${HPS_Submit,,}" == "t" ]; then
echo Submitting Phasing script to HPC Queue
echo
qsub -l nodes=1:ppn=${PhaseThreads},vmem=${Phase_Memory}gb,walltime=${Phase_Walltime} -M ${Email} -m ae -j oe -o ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.out -N PChr23_${BaseName} ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh
sleep 0.2
else
echo Submitting Phasing script to Desktop Queue
echo
bash ./2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.sh > ${WorkingDir}2_Phase/${BaseName}/Scripts2Shapeit/${BaseName}_Chr23_P.out 2>&1 &
fi
fi
elif [ "${PhaseX,,}" == "f" ]; then
printf "\n\n---Ok Will Not Phase the X Chromosome---\n\n"
fi
fi
# Termination Message
echo
echo ============
echo " Phew Done!"
echo ============
echo
echo