-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrealignSample.sh
More file actions
executable file
·245 lines (217 loc) · 12.4 KB
/
realignSample.sh
File metadata and controls
executable file
·245 lines (217 loc) · 12.4 KB
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
#!/bin/bash
#
# script to realign and recalibrate the aligned file(s)
########################################################
redmine=hpcbio-redmine@igb.illinois.edu
set -x
if [ $# != 11 ];
then
MSG="parameter mismatch."
echo -e "program=$0 stopped. Reason=$MSG" | mail -s 'Variant Calling Workflow failure message' "$redmine"
exit 1;
else
echo `date`
umask 0027
scriptfile=$0
realigndir=$1
outputfile=$2
chr=$3
infile=$4
realparms=$5
sample=$6
runfile=$7
elog=$8
olog=$9
email=${10}
qsubfile=${11}
LOGS="jobid:${PBS_JOBID}\nqsubfile=$qsubfile\nerrorlog=$elog\noutputlog=$olog"
if [ ! -s $runfile ]
then
MSG="$runfile configuration file not found"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
set +x; echo -e "\n\n############# CHECKING PARAMETERS ###############\n\n" >&2; set -x;
javadir=$( cat $runfile | grep -w JAVADIR | cut -d '=' -f2 )
threads=$( cat $runfile | grep -w PBSTHREADS | cut -d '=' -f2 )
refdir=$( cat $runfile | grep -w REFGENOMEDIR | cut -d '=' -f2 )
ref=$( cat $runfile | grep -w REFGENOME | cut -d '=' -f2 )
picardir=$( cat $runfile | grep -w PICARDIR | cut -d '=' -f2 )
samdir=$( cat $runfile | grep -w SAMDIR | cut -d '=' -f2 )
gatk=$( cat $runfile | grep -w GATKDIR | cut -d '=' -f2 )
realignparams=$( cat $runfile | grep -w REALIGNPARMS | cut -d '=' -f2 )
outputrootdir=$( cat $runfile | grep -w OUTPUTDIR | cut -d '=' -f2 )
memprof=$( cat $runfile | grep -w MEMPROFCOMMAND | cut -d '=' -f2 )
thr=`expr $threads "-" 1`
#thr=`expr $threads "/" 2`
real2parms=$( echo $realparms | tr ":" " " | sed "s/known /-known /g" )
realparms=$( echo $realparms | tr ":" " " | sed "s/known /--known /g" )
if [ ! -d $picardir ]
then
MSG="$picardir picard directory not found"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
if [ ! -d $samdir ]
then
MSG="$samdir samtools directory not found"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
if [ ! -d $gatk ]
then
MSG="$gatk GATK directory not found"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
if [ -z $javadir ]
then
MSG="Value for JAVADIR must be specified in configuration file"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
#else
#`/usr/local/modules-3.2.9.iforge/Modules/bin/modulecmd bash load $javamodule`
# `module load $javamodule`
fi
if [ ! -d $refdir ]
then
MSG="$refdir reference genome directory not found"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
if [ ! -s $refdir/$ref ]
then
MSG="$ref reference genome not found"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
if [ ! -s $infile ]
then
MSG="$infile sample file to split not found"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
set +x; echo -e "\n\n" >&2;
echo "#################################################################################" >&2
echo "################## STEP1: splitting sample=$sample by chr=$chr...################" >&2
echo "#################################################################################" >&2
echo -e "\n\n" >&2; set -x;
cd $realigndir
tmpfile=`basename $infile`
$samdir/samtools view -bu -@ $thr $infile $chr > ${chr}.$tmpfile
exitcode=$?
echo `date`
if [ $exitcode -ne 0 ]
then
MSG="split by chr, samtools command failed exitcode=$exitcode. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit $exitcode;
fi
if [ ! -s ${chr}.$tmpfile ]
then
MSG="${chr}.$tmpfile bam file not created for chr $chr1. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
$samdir/samtools index ${chr}.$tmpfile
$samdir/samtools view -H -@ $thr $tmpfile $chr > ${chr}.$tmpfile.header
echo `date`
set +x; echo -e "\n\n" >&2;
echo "#################################################################################" >&2
echo "################## STEP2: realign SAMPLE $sample on chr=$chr ###################" >&2
echo "#################################################################################" >&2
echo -e "\n\n" >&2; set -x;
echo "GATK is creating a target list...."
$javadir/java -Xmx8g -Xms1024m -Djava.io.tmpdir=$realigndir -jar $gatk/GenomeAnalysisTK.jar \
-R $refdir/$ref \
-I $chr.$tmpfile \
-T RealignerTargetCreator \
-nt $thr \
-o $chr.${tmpfile}.list $realparms
exitcode=$?
echo `date`
if [ $exitcode -ne 0 ]
then
MSG="realignertargetcreator command failed exitcode=$exitcode. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit $exitcode;
fi
if [ ! -s ${chr}.${tmpfile}.list ]
then
MSG="${chr}.${tmpfile}.list realignertargetcreator file not created. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
echo `date`
echo "executing GATK IndelRealigner command and generating $outputfile"
$javadir/java -Xmx8g -Xms1024m -Djava.io.tmpdir=$realigndir -jar $gatk/GenomeAnalysisTK.jar \
-R $refdir/$ref \
-I $chr.$tmpfile \
-T IndelRealigner \
-L $chr \
-o ${chr}.${tmpfile}.realigned.bam \
-targetIntervals ${chr}.${tmpfile}.list $realignparams $real2parms
exitcode=$?
echo `date`
if [ $exitcode -ne 0 ]
then
MSG="indelrealigner command failed exitcode=$exitcode. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit $exitcode;
fi
if [ ! -s ${chr}.${tmpfile}.realigned.bam ]
then
MSG="${chr}.${tmpfile}.realigned.bam indelrealigner file not created. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
set +x; echo -e "\n\n" >&2;
echo "#################################################################################" >&2
echo "################## STEP3: samtools calmd ###################" >&2
echo "#################################################################################" >&2
echo -e "\n\n" >&2; set -x;
$samdir/samtools calmd -Erbu ${chr}.${tmpfile}.realigned.bam $refdir/$ref > $outputfile
exitcode=$?
echo `date`
if [ $exitcode -ne 0 ]
then
MSG="samtools calmd command failed exitcode=$exitcode. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit $exitcode;
fi
if [ ! -s $outputfile ]
then
MSG="$outputfile output file not created. realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit 1;
fi
set +x; echo -e "\n\n#############generating stats for $outputfile before exiting###############\n\n" >&2; set -x;
$samdir/samtools index $outputfile
$samdir/samtools view -H $outputfile > ${outputfile}.header
$samdir/samtools flagstat $outputfile > ${outputfile}.flagstat
exitcode=$?
echo `date`
if [ $exitcode -ne 0 ]
then
MSG="samtools flagstat command failed exitcode=$exitcode realignment for sample $sample stopped"
echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" #| ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
#echo -e "program=$scriptfile stopped at line=$LINENO.\nReason=$MSG\n$LOGS" | ssh iforge "mailx -s '[Support #200] variant identification pipeline' "$redmine,$email""
exit $exitcode;
fi
echo "done $outputfile was created. exiting now"
fi