-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgbastoolkit.sh
executable file
·470 lines (410 loc) · 29.6 KB
/
gbastoolkit.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
#!/bin/bash
### Creating display functions
### Setting colouring
NONE='\033[00m'
OPAQUE='\033[2m'
FLASHING='\033[5m'
BOLD='\033[1m'
ITALIC='\033[3m'
UNDERLINE='\033[4m'
STRIKETHROUGH='\033[9m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
function echobold { #'echobold' is the function name
echo -e "${BOLD}${1}${NONE}" # this is whatever the function needs to execute, note ${1} is the text for echo
}
function echoitalic {
echo -e "${ITALIC}${1}${NONE}"
}
function echonooption {
echo -e "${OPAQUE}${RED}${1}${NONE}"
}
function echoerrorflash {
echo -e "${RED}${BOLD}${FLASHING}${1}${NONE}"
}
function echoerror {
echo -e "${RED}${1}${NONE}"
}
# errors no option
function echoerrornooption {
echo -e "${YELLOW}${1}${NONE}"
}
function echoerrorflashnooption {
echo -e "${YELLOW}${BOLD}${FLASHING}${1}${NONE}"
}
script_copyright_message() {
echo ""
THISYEAR=$(date +'%Y')
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "+ The MIT License (MIT) +"
echo "+ Copyright (c) 2015-${THISYEAR} Sander W. van der Laan +"
echo "+ +"
echo "+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +"
echo "+ associated documentation files (the \"Software\"), to deal in the Software without restriction, +"
echo "+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +"
echo "+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +"
echo "+ subject to the following conditions: +"
echo "+ +"
echo "+ The above copyright notice and this permission notice shall be included in all copies or substantial +"
echo "+ portions of the Software. +"
echo "+ +"
echo "+ THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +"
echo "+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +"
echo "+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +"
echo "+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +"
echo "+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +"
echo "+ +"
echo "+ Reference: http://opensource.org. +"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
}
script_arguments_error() {
echoerror "$1" # Additional message
echoerror "- Argument #1 is path_to/filename of the configuration file."
echoerror "- Argument #2 is path_to/filename of the list of GWAS files with names."
echoerror ""
echoerror "An example command would be: gbastoolkit.sh [arg1] [arg2]"
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo ""
script_copyright_message
exit 1
}
echobold "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echobold " GASToolKit: A TOOLKIT FOR GENE-BASED ASSOCIATION STUDIES"
echoitalic " --- prepare and perform gene-based studies using VEGAS2 or MAGMA---"
echobold ""
echobold "* Version: v1.0.5"
echobold ""
echobold "* Last update: 2019-04-03"
echobold "* Written by: Sander W. van der Laan | s.w.vanderlaan@gmail.com."
echobold "* Description: Prepare and perform gene-based association studies. It will do the following:"
echobold " - Automatically parse the summary statistics of some (meta-analysis of) GWAS."
echobold " - Perform VEGAS2 based analyses."
echobold " - Perform MAGMA based analyses."
echobold ""
echobold "* REQUIRED: "
echobold " - A high-performance computer cluster with a qsub system"
echobold " - R v3.2+, Python 2.7+, Perl."
echobold " - Required Python 2.7+ modules: [pandas], [scipy], [numpy]."
echobold " - Required Perl modules: [YAML], [Statistics::Distributions], [Getopt::Long]."
echobold " - Note: it will also work on a Mac OS X system with R and Python installed."
### ADD-IN:
### - function to check requirements... This might be a viable option! https://gist.github.com/JamieMason/4761049
### - rsIDs from a given reference -- MAGMA/VEGAS only take rsIDs
echobold ""
echobold "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
##########################################################################################
### SET THE SCENE FOR THE SCRIPT
##########################################################################################
### START of if-else statement for the number of command-line arguments passed ###
if [[ $# -lt 2 ]]; then
echo ""
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echoerrorflash " *** Oh, oh, computer says no! Number of arguments found "$#". ***"
echoerror "You must supply [2] arguments when running *** GBASToolKit ***!"
script_arguments_error
else
echo "These are the "$#" arguments that passed:"
echo "The configuration file.................: "$(basename ${1}) # argument 1
echo "The list of GWAS files.................: "$(basename ${2}) # argument 2
### SETTING DIRECTORIES (from configuration file).
# Loading the configuration file (please refer to the GBASToolKit-Manual for specifications of this file).
source "$1" # Depends on arg1.
CONFIGURATIONFILE="$1" # Depends on arg1 -- but also on where it resides!!!
GWASFILES="$2" # Depends on arg2 -- all the GWAS dataset information
# Where GBASToolKit resides
GBASTOOLKIT=${GBASTOOLKITDIR} # from configuration file
SCRIPTS=${GBASTOOLKIT}/SCRIPTS
# Project information
ORIGINALS=${DATA_UPLOAD_FREEZE} # from configuration file
##########################################################################################
### CREATE THE OUTPUT DIRECTORIES
echo ""
echo "Checking for the existence of the output directory [ ${OUTPUTDIRNAME} ]."
if [ ! -d ${PROJECTDIR}/${OUTPUTDIRNAME} ]; then
echo "> Output directory doesn't exist - Mr. Bourne will create it for you."
mkdir -v ${PROJECTDIR}/${OUTPUTDIRNAME}
else
echo "> Output directory already exists."
fi
OUTPUTDIR=${OUTPUTDIRNAME}
echo ""
echo "Checking for the existence of the subproject directory [ ${OUTPUTDIR}/${SUBPROJECTDIRNAME} ]."
if [ ! -d ${PROJECTDIR}/${OUTPUTDIR}/${SUBPROJECTDIRNAME} ]; then
echo "> Subproject directory doesn't exist - Mr. Bourne will create it for you."
mkdir -v ${PROJECTDIR}/${OUTPUTDIR}/${SUBPROJECTDIRNAME}
else
echo "> Subproject directory already exists."
fi
SUBPROJECTDIR=${PROJECTDIR}/${OUTPUTDIR}/${SUBPROJECTDIRNAME}
echo ""
echo "Checking for the existence of the parsed data directory [ ${OUTPUTDIR}/${SUBPROJECTDIRNAME}/PARSED ]."
if [ ! -d ${PROJECTDIR}/${OUTPUTDIR}/${SUBPROJECTDIRNAME}/PARSED ]; then
echo "> Parsed data directory doesn't exist - Mr. Bourne will create it for you."
mkdir -v ${PROJECTDIR}/${OUTPUTDIR}/${SUBPROJECTDIRNAME}/PARSED
else
echo "> Parsed data directory already exists."
fi
PARSEDDIR=${PROJECTDIR}/${OUTPUTDIR}/${SUBPROJECTDIRNAME}/PARSED
##########################################################################################
### SETTING UP THE OUTPUT AND PARSEDDATA DIRECTORIES
echo ""
### Making raw data directories, unless they already exist. Depends on arg2.
if [[ ${REFERENCE} == "1Gp1" ]]; then
echo ""
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo ""
echo "The scene is properly set, and directories are created! 🖖"
echo "GBASToolKit program............................: "${GBASTOOLKIT}
echo "GBASToolKit scripts............................: "${SCRIPTS}
echo "Reference and population used..................: ${REFERENCE} - ${POPULATION}"
echo "Main directory.................................: "${PROJECTDIR}
echo "Main analysis output directory.................: "${OUTPUTDIR}
echo "Original data directory........................: "${ORIGINALS}
echo "Subproject's analysis output directory.........: "${SUBPROJECTDIR}
echo "Parsed data is stored in.......................: "${PARSEDDIR}
echo "We are processing these cohort(s)..............:"
while IFS='' read -r GWASCOHORT || [[ -n "$GWASCOHORT" ]]; do
LINE=${GWASCOHORT}
COHORT=$(echo "${LINE}" | awk '{ print $1 }')
echo " * ${COHORT}"
done < ${GWASFILES}
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo ""
elif [[ ${REFERENCE} == "HM2" || ${REFERENCE} == "GONL4" || ${REFERENCE} == "GONL5" || ${REFERENCE} == "1Gp3" || ${REFERENCE} == "1Gp3GONL5" ]]; then
echoerrornooption "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echoerrornooption ""
echoerrorflashnooption " *** Oh, computer says no! This option is not available yet. ***"
echoerrornooption "Unfortunately using ${REFERENCE} as a reference is not possible yet. Currently only 1Gp1 is available."
echoerrornooption "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
### The wrong arguments are passed, so we'll exit the script now!
echo ""
script_copyright_message
exit 1
else
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echoerror ""
echoerrorflash " *** Oh, computer says no! Argument not recognised. ***"
echoerror "You have the following options as reference for the quality control"
echoerror "and meta-analysis:"
echonooption " - [HM2] HapMap2 (r27, b36, hg18). Legacy."
echoerror " - [1Gp1] 1000G (phase 1, release 3, 20101123 version, updated on 20110521 "
echoerror " and revised on Feb/Mar 2012, b37, hg19)."
echonooption " - [1Gp3] 1000G (phase 3, release 5, 20130502 version, b37, hg19)."
echonooption " - [GoNL4] Genome of the Netherlands, version 4."
echonooption " - [GONL5] Genome of the Netherlands, version 5."
echonooption " - [1Gp3GONL5] integrated 1000G phase 3, version 5 and GoNL5."
echonooption "(Opaque: not an option yet)"
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
### The wrong arguments are passed, so we'll exit the script now!
echo ""
script_copyright_message
exit 1
fi
echobold "#########################################################################################################"
echobold "### REFORMAT AND PARSE ORIGINAL GWAS DATA"
echobold "#########################################################################################################"
echobold "#"
echo ""
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "Start the reformatting and parsing of each cohort and dataset. "
echo ""
while IFS='' read -r GWASCOHORT || [[ -n "$GWASCOHORT" ]]; do
LINE=${GWASCOHORT}
COHORT=$(echo "${LINE}" | awk '{ print $1 }')
FILE=$(echo "${LINE}" | awk '{ print $2 }')
BASEFILE=$(basename ${FILE} .txt.gz)
if [ ! -d ${PARSEDDIR}/${COHORT} ]; then
echo "Making subdirectory for ${COHORT}..."
mkdir -v ${PARSEDDIR}/${COHORT}
else
echo "Directory for ${COHORT} already there."
fi
RAWDATACOHORT=${PARSEDDIR}/${COHORT}
echobold "#========================================================================================================"
echobold "#== REFORMAT AND PARSE ORIGINAL GWAS DATA"
echobold "#========================================================================================================"
echobold "#"
echo ""
echo "* Chopping up GWAS summary statistics into chunks of ${CHUNKSIZE} variants -- for parallelisation and speedgain..."
### Split up the file in increments of 1000K -- note: the period at the end of '${BASEFILE}' is a separator character
zcat ${ORIGINALS}/${FILE} | tail -n +2 | split -a 3 -l ${CHUNKSIZE} - ${RAWDATACOHORT}/${BASEFILE}.
## Adding headers -- this is ABSOLUTELY required for the 'gwas.parser.R'.
for SPLITFILE in ${RAWDATACOHORT}/${BASEFILE}.*; do
### determine basename of the splitfile
BASESPLITFILE=$(basename ${SPLITFILE} )
echo ""
echo "* Prepping split chunk: [ ${BASESPLITFILE} ]..."
echo ""
echo " - heading a temporary file."
zcat ${ORIGINALS}/${FILE} | head -1 > ${RAWDATACOHORT}/tmp_file
echo " - adding the split data to the temporary file."
cat ${SPLITFILE} >> ${RAWDATACOHORT}/tmp_file
echo " - renaming the temporary file."
mv -fv ${RAWDATACOHORT}/tmp_file ${SPLITFILE}
echobold "#========================================================================================================"
echobold "#== PARSING AND REFORMATTING THE GWAS DATA"
echobold "#========================================================================================================"
echobold "#"
echo ""
echo "* Parsing data for cohort ${COHORT} [ file: ${BASESPLITFILE} ]."
### FOR DEBUGGING LOCALLY -- Mac OS X
### Rscript ${SCRIPTS}/gwas.parser.R -p ${PROJECTDIR} -d ${SPLITFILE} -o ${OUTPUTDIRNAME}/${SUBPROJECTDIRNAME}/PARSED/${COHORT}
echo "Rscript ${SCRIPTS}/gwas.parser.R -p ${PROJECTDIR} -d ${SPLITFILE} -o ${OUTPUTDIRNAME}/${SUBPROJECTDIRNAME}/PARSED/${COHORT} " > ${RAWDATACOHORT}/gwas.parser.${BASESPLITFILE}.sh
qsub -S /bin/bash -N gwas.parser.${BASEFILE} -o ${RAWDATACOHORT}/gwas.parser.${BASESPLITFILE}.log -e ${RAWDATACOHORT}/gwas.parser.${BASESPLITFILE}.errors -l h_rt=${QRUNTIMEPARSER} -l h_vmem=${QMEMPARSER} -M ${QMAIL} -m ${QMAILOPTIONS} -cwd ${RAWDATACOHORT}/gwas.parser.${BASESPLITFILE}.sh
if [[ ${GWASQC} == "YES" ]]; then
echobold "#========================================================================================================"
echobold "#== CLEANING UP THE REFORMATTED GWAS DATA"
echobold "#========================================================================================================"
echobold "#"
echo ""
echo "* Cleaning harmonized data for [ ${BASESPLITFILE} ] file for cohort ${COHORT} with ${REFERENCE}"
echo " using the following pre-specified settings:"
echo " - MAF = ${MAF}"
echo " - MAC = ${MAC}"
echo " - HWE = ${HWE}"
echo " - INFO = ${INFO}"
echo " - BETA = ${BETA}"
echo " - SE = ${SE}"
### FOR DEBUGGING LOCALLY -- Mac OS X
### ${SCRIPTS}/gwas.cleaner.R -d ${SPLITFILE}.pdat -f ${BASESPLITFILE} -o ${RAWDATACOHORT} -e ${BETA} -s ${SE} -m ${MAF} -c ${MAC} -i ${INFO} -w ${HWE}
echo "${SCRIPTS}/gwas.cleaner.R -d ${SPLITFILE}.pdat -f ${BASESPLITFILE} -o ${RAWDATACOHORT} -e ${BETA} -s ${SE} -m ${MAF} -c ${MAC} -i ${INFO} -w ${HWE}" >> ${RAWDATACOHORT}/gwas.cleaner.${BASESPLITFILE}.sh
qsub -S /bin/bash -N gwas.cleaner.${BASEFILE} -hold_jid gwas.parser.${BASEFILE} -o ${RAWDATACOHORT}/gwas.cleaner.${BASESPLITFILE}.log -e ${RAWDATACOHORT}/gwas.cleaner.${BASESPLITFILE}.errors -l h_rt=${QRUNTIMECLEANER} -l h_vmem=${QMEMCLEANER} -M ${QMAIL} -m ${QMAILOPTIONS} -cwd ${RAWDATACOHORT}/gwas.cleaner.${BASESPLITFILE}.sh
elif [[ ${GWASQC} == "NO" ]]; then
echobold "#========================================================================================================"
echobold "#== THE REFORMATTED GWAS DATA IS NOT CLEANED"
echobold "#========================================================================================================"
echobold "#"
else
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echoerror ""
echoerrorflash " *** Oh, computer says no! Argument not recognised. ***"
echoerror "You should choose whether you want to apply quality control on the parsed and reformatted GWAS data, you"
echoerror "have the following options (please also refer to the configuration-file and the GBASToolKit Manual):"
echoerror " - [YES] apply quality control."
echoerror " - [No] do not apply quality control."
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
### The wrong arguments are passed, so we'll exit the script now!
echo ""
script_copyright_message
exit 1
fi
done
echobold "#========================================================================================================"
echobold "#== WRAPPING THE REFORMATTED GWAS DATA"
echobold "#========================================================================================================"
echobold "#"
if [[ ${GWASQC} == "YES" ]]; then
echo ""
echo "* Wrapping up parsed, reformatted, and cleaned data for cohort ${COHORT}..."
### FOR DEBUGGING LOCALLY -- Mac OS X
### ${SCRIPTS}/gwas.wrapper.sh ${CONFIGURATIONFILE} ${RAWDATACOHORT} ${COHORT} ${BASEFILE}
echo "${SCRIPTS}/gwas.wrapper.sh ${CONFIGURATIONFILE} ${RAWDATACOHORT} ${COHORT} ${BASEFILE}" > ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.sh
qsub -S /bin/bash -N gwas.wrapper -hold_jid gwas.cleaner.${BASEFILE} -o ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.log -e ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.errors -l h_rt=${QRUNTIMEWRAPPER} -l h_vmem=${QMEMWRAPPER} -M ${QMAIL} -m ${QMAILOPTIONS} -cwd ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.sh
elif [[ ${GWASQC} == "NO" ]]; then
echo ""
echo "* Wrapping up parsed and reformatted data for cohort ${COHORT}..."
### FOR DEBUGGING LOCALLY -- Mac OS X
### ${SCRIPTS}/gwas.wrapper.sh ${CONFIGURATIONFILE} ${RAWDATACOHORT} ${COHORT} ${BASEFILE}
echo "${SCRIPTS}/gwas.wrapper.sh ${CONFIGURATIONFILE} ${RAWDATACOHORT} ${COHORT} ${BASEFILE}" > ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.sh
qsub -S /bin/bash -N gwas.wrapper -hold_jid gwas.parser.${BASEFILE} -o ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.log -e ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.errors -l h_rt=${QRUNTIMEWRAPPER} -l h_vmem=${QMEMWRAPPER} -M ${QMAIL} -m ${QMAILOPTIONS} -cwd ${RAWDATACOHORT}/gwas.wrapper.${BASEFILE}.sh
else
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echoerror ""
echoerrorflash " *** Oh, computer says no! Argument not recognised. ***"
echoerror "You should choose whether you want to apply quality control on the parsed and reformatted GWAS data, you"
echoerror "have the following options (please also refer to the configuration-file and the GBASToolKit Manual):"
echoerror " - [YES] apply quality control."
echoerror " - [No] do not apply quality control."
echoerror "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
### The wrong arguments are passed, so we'll exit the script now!
echo ""
script_copyright_message
exit 1
fi
done < ${GWASFILES}
echobold "#========================================================================================================"
echobold "#== GENE-BASED ANALYSIS OF META-ANALYSIS RESULTS USING VEGAS2"
echobold "#========================================================================================================"
echobold "#"
### REQUIRED: VEGAS/VEGAS2 settings.
### Note: we do `cd ${VEGASDIR}` because VEGAS is making temp-files in a special way,
### adding a date-based number in front of the input/output files.
echo "Creating VEGAS input files..."
mkdir -v ${SUBPROJECTDIR}/vegas
VEGASRESULTDIR=${SUBPROJECTDIR}/vegas
chmod -Rv a+rwx ${VEGASRESULTDIR}
echo "...per chromosome."
while IFS='' read -r GWASCOHORT || [[ -n "$GWASCOHORT" ]]; do
LINE=${GWASCOHORT}
COHORT=$(echo "${LINE}" | awk '{ print $1 }')
echo " * ${COHORT}"
if [ ! -d ${VEGASRESULTDIR}/${COHORT} ]; then
echo "> VEGAS results directory doesn't exist - Mr. Bourne will create it for you."
mkdir -v ${VEGASRESULTDIR}/${COHORT}
chmod -Rv a+rwx ${VEGASRESULTDIR}/${COHORT}
else
echo "> VEGAS results directory already exists."
chmod -Rv a+rwx ${VEGASRESULTDIR}/${COHORT}
fi
for CHR in $(seq 1 23); do
if [[ $CHR -le 22 ]]; then
echo "Processing chromosome ${CHR}..."
echo "zcat ${PARSEDDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.FINAL.txt.gz | ${SCRIPTS}/parseTable.pl --col ${VARIANTID},CHR,P | awk ' \$2==${CHR} ' | awk '{ print \$1, \$3 }' | tail -n +2 > ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.forVEGAS.txt " > ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.sh
qsub -S /bin/bash -N VEGAS2.${PROJECTNAME}.chr${CHR}.create -hold_jid gwas.wrapper -o ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.log -e ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.errors -l h_vmem=${QMEMVEGAS} -l h_rt=${QRUNTIMEVEGAS} -wd ${VEGASRESULTDIR} ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.sh
echo "cd ${VEGASRESULTDIR}/${COHORT} " > ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.sh
echo "$VEGAS2 -G -snpandp ${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.forVEGAS.txt -custom ${VEGAS2POP}.chr${CHR} -glist ${VEGAS2GENELIST} -upper ${VEGAS2UPPER} -lower ${VEGAS2LOWER} -chr ${CHR} -out ${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.fromVEGAS " >> ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.sh
qsub -S /bin/bash -N VEGAS2.${PROJECTNAME}.chr${CHR} -hold_jid VEGAS2.${PROJECTNAME}.chr${CHR}.create -o ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.log -e ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.errors -l h_vmem=${QMEMVEGAS} -l h_rt=${QRUNTIMEVEGAS} -wd ${VEGASRESULTDIR} ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.sh
elif [[ $CHR -eq 23 ]]; then
echo "Processing chromosome X..."
echo "zcat ${PARSEDDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.FINAL.txt.gz | ${SCRIPTS}/parseTable.pl --col ${VARIANTID},CHR,P | awk ' \$2==\"X\" ' | awk '{ print \$1, \$3 }' | tail -n +2 > ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.forVEGAS.txt " > ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.sh
qsub -S /bin/bash -N VEGAS2.${PROJECTNAME}.chr${CHR}.create -hold_jid gwas.wrapper -o ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.log -e ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.errors -l h_vmem=${QMEMVEGAS} -l h_rt=${QRUNTIMEVEGAS} -wd ${VEGASRESULTDIR} ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.createVEGAS.sh
echo "cd ${VEGASRESULTDIR}/${COHORT} " > ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.sh
echo "$VEGAS2 -G -snpandp ${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.forVEGAS.txt -custom ${VEGAS2POP}.chr${CHR} -glist ${VEGAS2GENELIST} -upper ${VEGAS2UPPER} -lower ${VEGAS2LOWER} -chr ${CHR} -out ${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.fromVEGAS " >> ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.sh
qsub -S /bin/bash -N VEGAS2.${PROJECTNAME}.chr${CHR} -hold_jid VEGAS2.${PROJECTNAME}.chr${CHR}.create -o ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.log -e ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.errors -l h_vmem=${QMEMVEGAS} -l h_rt=${QRUNTIMEVEGAS} -wd ${VEGASRESULTDIR} ${VEGASRESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.chr${CHR}.runVEGAS.sh
else
echo "*** ERROR *** Something is rotten in the City of Gotham; most likely a typo. Double back, please."
exit 1
fi
done
done < ${GWASFILES}
echobold "#========================================================================================================"
echobold "#== GENE-BASED ANALYSIS OF META-ANALYSIS RESULTS USING MAGMA"
echobold "#========================================================================================================"
echobold "#"
### REQUIRED: MAGMA settings.
### Head for MAGMA input
### SNP CHR BP P NOBS
echo "Creating MAGMA input files..."
mkdir -v ${SUBPROJECTDIR}/magma
MAGMARESULTDIR=${SUBPROJECTDIR}/magma
chmod -Rv a+rwx ${MAGMARESULTDIR}
echo " - whole-genome..."
while IFS='' read -r GWASCOHORT || [[ -n "$GWASCOHORT" ]]; do
LINE=${GWASCOHORT}
COHORT=$(echo "${LINE}" | awk '{ print $1 }')
echo " * ${COHORT}"
if [ ! -d ${MAGMARESULTDIR}/${COHORT} ]; then
echo "> MAGMA results directory doesn't exist - Mr. Bourne will create it for you."
mkdir -v ${MAGMARESULTDIR}/${COHORT}
chmod -Rv a+rwx ${MAGMARESULTDIR}/${COHORT}
else
echo "> MAGMA results directory already exists."
chmod -Rv a+rwx ${MAGMARESULTDIR}/${COHORT}
fi
# NOTE: MAGMA needs rsIDs so we hardcoded MarkerOriginal -- we need to fix the gwas.parser.R script to put in rsID when available.
echo "echo \"SNP CHR BP P NOBS\" > ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.forMAGMA.txt " > ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.runMAGMA.sh
echo "zcat ${PARSEDDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.FINAL.txt.gz | ${SCRIPTS}/parseTable.pl --col MarkerOriginal,CHR,BP,P,N | tail -n +2 | awk '{ print \$1, \$2, \$3, \$4, int(\$5) }' >> ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.forMAGMA.txt " >> ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.runMAGMA.sh
echo "${MAGMA} --annotate --snp-loc ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.forMAGMA.txt --gene-loc ${MAGMAGENES} --out ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.fromMAGMA.annotated " >> ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.runMAGMA.sh
qsub -S /bin/bash -N MAGMA.ANALYSIS.${PROJECTNAME} -hold_jid gwas.wrapper -o ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.runMAGMA.log -e ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.runMAGMA.errors -l h_vmem=${QMEMMAGMA} -l h_rt=${QRUNTIMEMAGMA} -wd ${MAGMARESULTDIR} ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.runMAGMA.sh
echo "${MAGMA} --bfile ${MAGMAPOP} synonyms=${MAGMADBSNP} synonym-dup=drop-dup --pval ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.forMAGMA.txt use=SNP,P ncol=NOBS --gene-annot ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.fromMAGMA.annotated.genes.annot --out ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.fromMAGMA.genesannotated " > ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.annotMAGMA.sh
qsub -S /bin/bash -N MAGMA.ANNOTATION.${PROJECTNAME} -hold_jid MAGMA.ANALYSIS.${PROJECTNAME} -o ${MAGMARESULTDIR}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.annotMAGMA.log -e ${MAGMARESULTDIR}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.annotMAGMA.errors -l h_vmem=${QMEMMAGMA} -l h_rt=${QRUNTIMEMAGMA} -wd ${MAGMARESULTDIR} ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.annotMAGMA.sh
echo "${MAGMA} --gene-results ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.fromMAGMA.genesannotated.genes.raw --set-annot ${MAGMAGENESETS} --out ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.fromMAGMA.gsea " > ${MAGMARESULTDIR}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.gseaMAGMA.sh
qsub -S /bin/bash -N MAGMA.GSEA.${PROJECTNAME} -hold_jid MAGMA.ANNOTATION.${PROJECTNAME} -o ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.gseaMAGMA.log -e ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.gseaMAGMA.errors -l h_vmem=${QMEMMAGMA} -l h_rt=${QRUNTIMEMAGMA} -wd ${MAGMARESULTDIR} ${MAGMARESULTDIR}/${COHORT}/${COHORT}.${PROJECTNAME}.${REFERENCE}.${POPULATION}.gseaMAGMA.sh
done < ${GWASFILES}
### END of if-else statement for the number of command-line arguments passed ###
fi
script_copyright_message