-
Notifications
You must be signed in to change notification settings - Fork 4
/
hlapers
executable file
·406 lines (349 loc) · 7.75 KB
/
hlapers
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
#!/usr/bin/env bash
# script directory
if [[ "$OSTYPE" == "linux-gnu" ]]; then
myexecpath="$( readlink -f "$0" )"
elif [[ "$OSTYPE" == "darwin"* ]]; then
myexecpath="$( readlink "$0" )"
else
myexecpath="$( pwd )"
fi
execdir="$( dirname "$myexecpath" )"
scriptdir=$execdir/script
# Usage functions
usage() {
echo "Usage: hlapers [modes]"
echo ""
printf "%-20s %s\n" "prepare-ref" "Prepare transcript fasta files."
printf "%-20s %s\n" "index" "Create index for read alignment."
printf "%-20s %s\n" "bam2fq" "Convert BAM to fastq."
printf "%-20s %s\n" "genotype" "Infer HLA genotypes."
printf "%-20s %s\n" "quant" "Quantify HLA expression."
}
usage_prepare() {
echo "Usage: hlapers prepare-ref [options]"
echo ""
printf "%-20s %s\n" "-t | --transcripts" "Fasta with Gencode transcript sequences."
printf "%-20s %s\n" "-a | --annotations" "GTF from Gencode for the same Genome version."
printf "%-20s %s\n" "-i | --imgt" "Path to IMGT directory."
printf "%-20s %s\n" "-o | --out" "Output directory."
}
usage_index() {
echo "Usage: hlapers index [options]"
echo ""
printf "%-20s %s\n" "-t | --transcripts" "Fasta with Gencode transcript sequences."
printf "%-20s %s\n" "-p | --threads" "Number of threads."
printf "%-20s %s\n" "-o | --out" "Output directory."
printf "%-20s %s\n" "--kallisto" "Create index for kallisto pipeline instead of STARsalmon."
}
usage_genotype() {
echo "Usage: hlapers genotype [options]"
echo ""
printf "%-20s %s\n" "-i | --index" "Index generated by 'hlapers index'."
printf "%-20s %s\n" "-t | --transcripts" "Fasta with Gencode transcripts sequences used for 'hlapers index'."
printf "%-20s %s\n" "-1 | --fq1" "Fastq for READ 1."
printf "%-20s %s\n" "-2 | --fq2" "Fastq for READ 2."
printf "%-20s %s\n" "-p | --threads" "Number of threads."
printf "%-20s %s\n" "-o | --outprefix" "Output prefix name."
printf "%-20s %s\n" "--kallisto" "Use kallisto for genotyping."
}
usage_quant() {
echo "Usage: hlapers quant [options]"
echo ""
printf "%-20s %s\n" "-t | --transcripts" "Reference transcripts directory."
printf "%-20s %s\n" "-g | --genotypes" "*_genotypes.tsv file generated by 'hlapers genotype'."
printf "%-20s %s\n" "-1 | --fq1" "Fastq for READ 1."
printf "%-20s %s\n" "-2 | --fq2" "Fastq for READ 2."
printf "%-20s %s\n" "-p | --threads" "Number of threads."
printf "%-20s %s\n" "-o | --out" "Output prefix name."
printf "%-20s %s\n" "--salmonreads" "Use Salmon lightweight alignment for quantification (NOT TESTED)"
printf "%-20s %s\n" "--kallisto" "Use kallisto for quantification."
}
usage_bam2fq() {
echo "Usage: hlapers bam2fq [options]"
echo ""
printf "%-20s %s\n" "-m | --mhc-coords" "Genomic coordinates of the MHC region in chrN:start-end format if MHC fastq is desired."
printf "%-20s %s\n" "-b | --bam" "BAM file (if -m is specified, needs to be sorted by coordinate; otherwise use --sort)."
printf "%-20s %s\n" "-o | --outprefix" "Output prefix name."
printf "%-20s %s\n" "--sort" "Sort input BAM file by coordinate (REQUIRED if -m is specified and BAM is not sorted by coordinate)."
}
# Mode functions
run_prepref () {
if [[ "$#" -eq 0 ]]; then
usage_prepare
exit 1
fi
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h|--help)
usage_prepare
exit
;;
-t|--transcripts)
transcripts="$2"
shift 2
;;
-a|--annotations)
annotations="$2"
shift 2
;;
-i|--imgt)
imgt="$2"
shift 2
;;
-o|-out)
out="$2"
shift 2
;;
*)
echo "ERROR: unknown parameter $1"
usage_prepare
exit 1
;;
esac
done
Rscript $scriptdir/make_index_files.R $transcripts $annotations $imgt $out
}
run_index() {
if [[ "$#" -eq 0 ]]; then
usage_index
exit 1
fi
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h|--help)
usage_index
exit
;;
-t|--transcripts)
transcripts="$2"
shift 2
;;
-p|--threads)
threads="$2"
shift 2
;;
-o|--out)
out="$2"
shift 2
;;
--kallisto)
k=1
shift
;;
*)
echo "ERROR: unknown parameter $1"
usage_index
exit 1
;;
esac
done
kallisto=${k-0}
if [[ "$kallisto" -eq 0 ]]; then
$scriptdir/run_starindex.sh $transcripts $out $threads
elif [[ "$kallisto" -eq 1 ]]; then
$scriptdir/run_kallistoindex.sh $transcripts $out
fi
}
run_genotype() {
if [[ "$#" -eq 0 ]]; then
usage_genotype
exit 1
fi
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h|--help)
usage_genotype
exit
;;
-i|--index)
index="$2"
shift 2
;;
-t|--transcripts)
transcripts="$2"
shift 2
;;
-1|--fq1)
fq1="$2"
shift 2
;;
-2|--fq2)
fq2="$2"
shift 2
;;
-p|--threads)
threads="$2"
shift 2
;;
-o|--out)
outprefix="$2"
shift 2
;;
--kallisto)
k=1
shift
;;
*)
echo "ERROR: unknown parameter $1"
usage_genotype
exit 1
;;
esac
done
kallisto=${k-0}
if [[ "$kallisto" -eq 0 ]]; then
$scriptdir/run_genotyping.sh $index $transcripts $fq1 $fq2 $outprefix $threads
elif [[ "$kallisto" -eq 1 ]]; then
$scriptdir/run_genotypingkallisto.sh $index $fq1 $fq2 $outprefix $threads
fi
}
run_quant() {
if [[ "$#" -eq 0 ]]; then
usage_quant
exit 1
fi
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h|--help)
usage_quant
exit
;;
-t|--transcripts)
transcripts="$2"
shift 2
;;
-g|--genotypes)
genos="$2"
shift 2
;;
-1|--fq1)
fq1="$2"
shift 2
;;
-2|--fq2)
fq2="$2"
shift 2
;;
-p|--threads)
threads="$2"
shift 2
;;
-o|--outprefix)
outprefix="$2"
shift 2
;;
--kallisto)
k=1
shift
;;
--salmonreads)
s=1
shift
;;
*)
echo "ERROR: unknown parameter $1"
usage_quant
exit 1
;;
esac
done
kallisto=${k-0}
salmonreads=${s-0}
if [[ "$kallisto" -eq 0 ]] && [[ "$salmonreads" -eq 0 ]]; then
$scriptdir/run_quant.sh $transcripts $genos $fq1 $fq2 $outprefix $threads
elif [[ "$kallisto" -eq 1 ]] && [[ "$salmonreads" -eq 0 ]]; then
$scriptdir/run_quantkallisto.sh $transcripts $genos $fq1 $fq2 $outprefix $threads
elif [[ "$kallisto" -eq 0 ]] && [[ "$salmonreads" -eq 1 ]]; then
$scriptdir/run_quantSalmonReads.sh $transcripts $genos $fq1 $fq2 $outprefix $threads
fi
}
run_bam2fq() {
if [[ "$#" -eq 0 ]]; then
usage_bam2fq
exit 1
fi
while [[ "$#" -gt 0 ]]; do
case "$1" in
-h|--help)
usage_bam2fq
exit
;;
-b|--bam)
bam="$2"
shift 2
;;
-m|--mhc)
if [[ -n "$2" ]] && [[ "$2" != -* ]]; then
mhc="$2"
shift 2
else
echo "ERROR: missing MHC coordinates."
exit 1
fi
;;
-o|--out)
out="$2"
shift 2
;;
--sort)
s=1
shift
;;
*)
echo "ERROR: unknown parameter $1"
usage_bam2fq
exit 1
;;
esac
done
sort=${s-0}
if [[ -n "$mhc" ]]; then
$scriptdir/run_bam2fq_mhc.sh $bam $mhc $out $sort
else
$scriptdir/run_bam2fq.sh $bam $out $sort
fi
}
# main
if [[ "$#" -eq 0 ]]; then
usage
exit 1
fi
while [[ $# -gt 0 ]]
do
case "$1" in
-h|--help)
usage
exit
;;
prepare-ref)
shift
run_prepref "$@"
break
;;
index)
shift
run_index "$@"
break
;;
genotype)
shift
run_genotype "$@"
break
;;
quant)
shift
run_quant "$@"
break
;;
bam2fq)
shift
run_bam2fq "$@"
break
;;
*)
echo "ERROR: unknown parameter $1"
usage
exit 1
;;
esac
done