-
Notifications
You must be signed in to change notification settings - Fork 5
/
pipeline_inheritance.sh
281 lines (238 loc) · 7.37 KB
/
pipeline_inheritance.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
#!/bin/bash
#SBATCH --job-name=vip_inheritance
#SBATCH --output=vip_inheritance.out
#SBATCH --error=vip_inheritance.err
#SBATCH --time=01:00:00
#SBATCH --cpus-per-task=4
#SBATCH --mem=4gb
#SBATCH --nodes=1
#SBATCH --export=NONE
#SBATCH --get-user-env=L60
#SBATCH --tmp=4gb
# Retrieve directory containing the collection of scripts (allows using other scripts with & without Slurm).
if [[ -n "${SLURM_JOB_ID}" ]]; then SCRIPT_DIR=$(dirname "$(scontrol show job "${SLURM_JOB_ID}" | awk -F= '/Command=/{print $2}' | cut -d ' ' -f 1)"); else SCRIPT_DIR=$(dirname "$(realpath "$0")"); fi
SCRIPT_NAME="$(basename "$0")"
# shellcheck source=utils/header.sh
source "${SCRIPT_DIR}"/utils/header.sh
# shellcheck source=utils/utils.sh
source "${SCRIPT_DIR}"/utils/utils.sh
usage() {
echo -e "usage: ${SCRIPT_NAME} -i <arg> -p <arg>
-i, --input <arg> required: Input VCF file (.vcf or .vcf.gz).
-o, --output <arg> optional: Output VCF file (.vcf.gz).
-b, --probands <arg> optional: Subjects being reported on (comma-separated VCF sample names).
-p, --pedigree <arg> required: Pedigree file (.ped).
-c, --config <arg> optional: Comma separated list of configuration files (.cfg)
-f, --force optional: Override the output file if it already exists.
-k, --keep optional: Keep intermediate files.
-h, --help optional: Print this message and exit.
config:
cpu_cores see 'bash pipeline.sh --help' for usage."
}
# arguments:
# $1 path to input file
# $2 path to output file
# $3 path to pedigree file
# $4 cpu cores
annotateGeneticModels() {
local -r inputFilePath="${1}"
local -r outputFilePath="${2}"
local -r pedFilePath="${3}"
local -r cpuCores="${4}"
module load "${MOD_PYTHON_PLUS}"
module load "${MOD_HTS_LIB}"
args=()
args+=("models")
args+=("${inputFilePath}")
args+=("-f" "${pedFilePath}")
args+=("--vep")
args+=("-p" "${cpuCores}")
args+=("-r" "/apps/data/UMCG/non_penetrance/UMCG_non_penetrantie_genes_entrez_20210125.tsv")
genmod "${args[@]}" | bgzip >"${outputFilePath}"
module purge
}
# arguments:
# $1 path to input file
# $2 path to output file
# $3 path to pedigree file
# $4 probands (optional)
matchInheritance() {
local -r inputFilePath="${1}"
local -r outputFilePath="${2}"
local -r pedFilePath="${3}"
local -r probands="${4}"
module load "${MOD_VCF_INHERITANCE_MATCHER}"
args=()
args+=("-Djava.io.tmpdir=${TMPDIR}")
args+=("-XX:ParallelGCThreads=2")
args+=("-jar" "${EBROOTVCFMININHERITANCEMINMATCHER}/vcf-inheritance-matcher.jar")
args+=("-i" "${inputFilePath}")
args+=("-pd" "${pedFilePath}")
args+=("-o" "${outputFilePath}")
if [ -n "${probands}" ]; then
args+=("-pb" "${probands}")
fi
java "${args[@]}"
module purge
}
# arguments:
# $1 path to input file
# $2 path to output file
# $3 cpu cores
removeAnnotations() {
local -r inputFilePath="${1}"
local -r outputFilePath="${2}"
local -r cpuCores="${3}"
module load "${MOD_BCF_TOOLS}"
args=()
args+=("annotate")
args+=("-x" "INFO/Compounds,INFO/GeneticModels,INFO/ModelScore")
args+=("-O" "z")
args+=("-o" "${outputFilePath}")
args+=("--no-version")
args+=("--threads" "${cpuCores}")
args+=("${inputFilePath}")
echo 'removing INFO inheritance annotations ...'
bcftools "${args[@]}"
echo 'removing INFO inheritance annotations done'
module purge
}
# arguments:
# $1 path to input file
# $2 path to output file
# $3 comma-separated proband identifiers (optional)
# $4 path to pedigree file
# $5 force
# $6 cpu cores
validate() {
local -r inputFilePath="${1}"
local -r outputFilePath="${2}"
local -r probands="${3}"
local -r pedFilePath="${4}"
local -r force="${5}"
local -r cpuCores="${6}"
if ! validateInputPath "${inputFilePath}"; then
echo -e "Try '${SCRIPT_NAME} --help' for more information."
exit 1
fi
if ! validateOutputPath "${outputFilePath}" "${force}"; then
echo -e "Try '${SCRIPT_NAME} --help' for more information."
exit 1
fi
if [[ -n "${probands}" ]] && ! containsProbands "${probands}" "${inputFilePath}"; then
echo -e "Try '${SCRIPT_NAME} --help' for more information."
exit 1
fi
if [[ -z "${pedFilePath}" ]]; then
echo -e "missing required option -p."
return 1
fi
if [[ ! -f "${pedFilePath}" ]]; then
echo -e "pedigree ${pedFilePath} does not exist."
exit 1
fi
}
main() {
local inputFilePath=""
local outputFilePath=""
local probands=""
local pedFilePath=""
local cfgFilePaths=""
local force=0
local keep=0
local -r parsedArguments=$(getopt -a -n pipeline -o i:o:b:p:c:fkh --long input:,output:,probands:,pedigree:,config:,force,keep,help -- "$@")
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then
usage
exit 2
fi
eval set -- "$parsedArguments"
while :; do
case "$1" in
-h | --help)
usage
exit 0
shift
;;
-i | --input)
inputFilePath=$(realpath "$2")
shift 2
;;
-o | --output)
outputFilePath="$2"
shift 2
;;
-b | --probands)
probands="$2"
shift 2
;;
-p | --pedigree)
pedFilePath=$(realpath "$2")
shift 2
;;
-c | --config)
cfgFilePaths="$2"
shift 2
;;
-f | --force)
force=1
shift
;;
-k | --keep)
keep=1
shift
;;
--)
shift
break
;;
*)
usage
exit 2
;;
esac
done
if [[ -z "${inputFilePath}" ]]; then
echo -e "missing required option -i or --input."
echo -e "try bash '${SCRIPT_NAME} -h or --help' for more information."
exit 1
fi
local cpuCores=""
local parseCfgFilePaths="${SCRIPT_DIR}/config/default.cfg"
if [[ -n "${cfgFilePaths}" ]]; then
parseCfgFilePaths="${parseCfgFilePaths},${cfgFilePaths}"
fi
parseCfgs "${parseCfgFilePaths}"
if [[ -n "${VIP_CFG_MAP["cpu_cores"]+unset}" ]]; then
cpuCores="${VIP_CFG_MAP["cpu_cores"]}"
fi
if [[ -z "${outputFilePath}" ]]; then
outputFilePath="$(createOutputPathFromPostfix "${inputFilePath}" "vip_inheritance")"
fi
validate "${inputFilePath}" "${outputFilePath}" "${probands}" "${pedFilePath}" "${force}" "${cpuCores}"
mkdir -p "$(dirname "${outputFilePath}")"
local -r outputDir="$(realpath "$(dirname "${outputFilePath}")")"
local -r outputFilename="$(basename "${outputFilePath}")"
outputFilePath="${outputDir}/${outputFilename}"
if [[ -f "${outputFilePath}" ]] && [[ "${force}" == "1" ]]; then
rm "${outputFilePath}"
fi
initWorkDir "${outputFilePath}" "${keep}"
local -r workDir="${VIP_WORK_DIR}"
local currentInputFilePath="${inputFilePath}" currentOutputDir currentOutputFilePath
# step 1: genmod
currentOutputDir="${workDir}/1_genmod"
currentOutputFilePath="${currentOutputDir}/${outputFilename}"
mkdir -p "${currentOutputDir}"
annotateGeneticModels "${currentInputFilePath}" "${currentOutputFilePath}" "${pedFilePath}" "${cpuCores}"
currentInputFilePath="${currentOutputFilePath}"
# step 2: inheritance matching
currentOutputDir="${workDir}/2_match"
currentOutputFilePath="${currentOutputDir}/${outputFilename}"
mkdir -p "${currentOutputDir}"
matchInheritance "${currentInputFilePath}" "${currentOutputFilePath}" "${pedFilePath}" "${probands}"
currentInputFilePath="${currentOutputFilePath}"
# step 3: remove INFO annotations
removeAnnotations "${currentInputFilePath}" "${outputFilePath}" "${cpuCores}"
}
main "${@}"