-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_alignment_2020_tmp.sh
341 lines (266 loc) · 6.13 KB
/
read_alignment_2020_tmp.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
#!/bin/bash
#$ -cwd
#$ -S /bin/bash
#$ -N align
#$ -e align0err
#$ -o align0out
#$ -q !gbs
# #$ -l mem_free=10G
#$ -V
# #$ -h
#$ -t 1-2:1
i=$(expr $SGE_TASK_ID - 1)
echo "PATH:"
echo $PATH
echo
##### ##### ##### ##### #####
# User provided materials
#EVAL="TRUE"
EVAL="FALSE"
# Reference sequence
#REF="/home/bpp/knausb/Grunwald_Lab/home/knausb/pinf_bwa/bwaref/pinf_super_contigs.fa"
#
BREF="bwaref/pinfsc50b.fa"
# GATK reference
GREF="gatkref/pinfsc50b.fa"
# The file samples.txt contains info about sample names and files.
# Each line is one sample and one job.
# The line is a semi colon delimited list.
# The first element is the sample name.
# The second element is the fastq file including any path info.
#
# t30-4;../fastqs/ATCGGC.fastq.gz
#
FILE=( `cat "samples.txt" `)
IFS=';' read -a arr <<< "${FILE[$i]}"
echo "${arr[1]}"
# Our system has scratch space on each worker node.
# This distributes load on the hard drives.
TEMP="/data/knausb/"
##### ##### ##### ##### #####
# Software
# http://bio-bwa.sourceforge.net/bwa.shtml
BWA="~/bin/bwa-0.7.17/bwa"
SAMT="~/bin/samtools-1.9/samtools-1.9/samtools "
# MarkDuplicates (Picard)
# SortSam (Picard)
# https://gatk.broadinstitute.org/hc/en-us/articles/360037225972-MarkDuplicates-Picard-
# http://broadinstitute.github.io/picard/
# http://broadinstitute.github.io/picard/command-line-overview.html
PICARD="~/bin/picard/picard_2.21.6/picard.jar"
# https://gatk.broadinstitute.org/hc/en-us/sections/360007226651-Best-Practices-Workflows
GATK="~/bin/gatk4/gatk-4.1.4.1/gatk"
JAVA="/home/bpp/knausb/bin/javadir/jre1.8.0_25/bin/java"
##### ##### ##### ##### #####
# Report what we ended up with
echo "Evaluate: "$EVAL
echo
echo -n "Running on: "
hostname
echo "SGE job id: $JOB_ID"
date
echo
bEpoch=(`date +%s`)
echo "Epoch start:" $bEpoch
# http://bio-bwa.sourceforge.net/bwa.shtml
# Align reads with bwa.
# Report bwa version info.
echo "bwa info"
CMD="$BWA 2>&1"
echo
echo $CMD
eval $CMD
echo
# http://www.htslib.org/doc/
# Echo samtools version info.
echo "samtools info"
CMD="$SAMT --version"
echo
eval $CMD
echo
# Picard version.
echo "picard info"
CMD="$JAVA -jar $PICARD MarkDuplicates --version 2>&1"
echo $CMD
eval $CMD
echo
echo "GATK info"
CMD="~/bin/gatk4/gatk-4.1.4.1/gatk --version"
echo $CMD
eval $CMD
echo
# Java version.
echo "java info"
CMD="$JAVA -version 2>&1"
echo $CMD
eval $CMD
echo
##### ##### ##### ##### #####
# Processing
echo "##### ##### ##### ##### #####"
echo "Begin processing."
if [ ! -d "$TEMP" ]; then
CMD="mkdir $TEMP"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
fi
##### ##### ##### ##### #####
# Map reads
# The GATK needs read group info:
# https://software.broadinstitute.org/gatk/guide/article?id=6472
# SM: sample
# LB: library, may be sequenced multiple times
# ID: Read Group Identifier, a unique identifier
# PL: Platform/technology used
RG="@RG\tID:${arr[0]}\tLB:${arr[0]}\tPL:illumina\tSM:${arr[0]}\tPU:${arr[0]}"
CMD="$BWA mem -M -R \"$RG\" $BREF ${arr[1]} ${arr[2]} > "$TEMP${arr[0]}".sam"
echo
#
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
echo
date
echo
##### ##### ##### ##### #####
# Generate stats to validate the sam.
CMD="$SAMT stats $TEMP${arr[0]}.sam | gzip -c > $TEMP${arr[0]}_stats.txt.gz"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
echo
##### ##### ##### ##### #####
# Mark duplicates and sort
# Mark duplicates.
# http://gatkforums.broadinstitute.org/dsde/discussion/comment/28837/#Comment_28837
# One thing MarkDuplicates attempts is to identify reads that were physically
# close to one another on the flow cell.
# If you got your reads from an online database this information may have been
# removed from each sequence's header.
# If this is your case you may want to include:
# READ_NAME_REGEX=null
# Sort
CMD="$JAVA -Djava.io.tmpdir=/data/ \
-jar $PICARD SortSam \
I=$TEMP${arr[0]}.sam \
O=$TEMP${arr[0]}_sorted.bam \
TMP_DIR=/data/ \
SORT_ORDER=coordinate"
date
echo
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
echo
date
echo
# Mark duplicates
CMD="$JAVA -Djava.io.tmpdir=/data/ \
-jar $PICARD MarkDuplicates \
I=$TEMP${arr[0]}_sorted.bam \
O=$TEMP${arr[0]}_dupmrk.bam \
MAX_FILE_HANDLES_FOR_READ_ENDS_MAP=8000 \
ASSUME_SORT_ORDER=coordinate \
M=$TEMP${arr[0]}_marked_dup_metrics.txt"
#date
#echo
echo $CMD
#eval $CMD
echo
date
echo
##### ##### ##### ##### #####
# Index
#CMD="$SAMT index $TEMP${arr[0]}_sorted.bam"
CMD="$SAMT index $TEMP${arr[0]}_dupmrk.bam"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
echo
date
echo
# Generate stats to validate the bam.
CMD="$SAMT stats $TEMP${arr[0]}_dupmark.bam | gzip -c > $TEMP${arr[0]}_dupmark_stats.txt.gz"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
#myEpoch=(`date +%s`)
#echo "Epoch start:" $myEpoch
##### ##### ##### ##### #####
# Create gvcf
CMD="$GATK --java-options \"-Djava.io.tmpdir=/data/ -Xmx4g\" HaplotypeCaller \
-R $GREF \
-I $TEMP${arr[0]}_dupmrk.bam \
-O $TEMP${arr[0]}.g.vcf.gz \
-ERC GVCF"
# -I $TEMP${arr[0]}_sorted.bam \
echo
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
echo
##### ##### ##### ##### #####
# Manage files.
echo
echo "##### ##### ##### ##### #####"
echo "Managing files"
CMD="cp $TEMP${arr[0]}.sam ."
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="rm -f $TEMP${arr[0]}.sam"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="cp $TEMP${arr[0]}_stats.txt.gz ."
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="rm -f $TEMP${arr[0]}_stats.txt.gz"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="rm -f $TEMP${arr[0]}_sorted.bam"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="rm -f $TEMP${arr[0]}_dupmrk.bam"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="rm -f $TEMP${arr[0]}_dupmrk.bam.bai"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="cp $TEMP${arr[0]}.g.vcf.gz ."
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
CMD="rm -f $TEMP${arr[0]}.g.vcf.gz"
echo $CMD
if [[ $EVAL == "TRUE" ]]; then
eval $CMD
fi
##### ##### ##### ##### #####
eEpoch=(`date +%s`)
echo
echo "Epoch begin:" $bEpoch
echo "Epoch end:" $eEpoch
echo $((eEpoch-bEpoch))
# EOF.