forked from MERobinson/sbatch_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_var_mutect2.sh
More file actions
218 lines (205 loc) · 5.51 KB
/
Copy pathcall_var_mutect2.sh
File metadata and controls
218 lines (205 loc) · 5.51 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
#!/user/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
# default arg
check='T'
callgermline='true'
# help message
help_message="
Wrapper to run Mutect2 (GATK v4.2.2).
usage:
bash $(basename "$0") [-options] -t <TUMOR_BAM> -f <FASTA>
required arguments:
-t|--tumor : tumor sample BAM file [BAM]
-f|--fasta : whole genome FASTA file [FASTA]
optional arguments:
-n|--normal : matched normal sample [BAM] (default = NULL)
--intervals : intervals file [BED,interval] (default = NULL)
--chr : chromosome to restrict analysis to [string] (default = NULL)
--germline : germline AF resource [VCF] (default = NULL)
--pon : PON file [VCF] (default = NULL)
--callgermline : whether to call germline sites [true|false] (default = true)
-o|--outdir : output directory [string] (default = pwd)
-l|--logdir : output directory for log files [string] (default = --outdir)
--name : prefix to give output files [string] (default = extracted from bam)
--check : whether to check input files [T|F] (default=T)
additional info:
# check argument is useful for scheduling jobs where input files
may not presently exist
# control, intervals, dbsnp, cosmic and pon arguments are all optional but
if provided, they will be passed to mutect2
output:
# creates logs and variants directories in outdir containing
run log and output VCF files respectively
"
# parse arg
while [[ $# -gt 1 ]]; do
key=$1
case $key in
-t|--tumor)
tumor=$2
shift
;;
-f|--fasta)
fasta=$2
shift
;;
-n|--normal)
normal=$2
shift
;;
-o|--outdir)
outdir=$2
shift
;;
-l|--logdir)
logdir=$2
shift
;;
--name)
name=$2
shift
;;
--check)
check=$2
shift
;;
--intervals)
intervals=$2
shift
;;
--chr)
chr=$2
shift
;;
--germline)
germline=$2
shift
;;
--pon)
pon=$2
shift
;;
--callgermline)
callgermline=$2
shift
;;
*)
printf "\nERROR: Undefined argument provided: %s %s\n" $1 $2
echo "$help_message"; exit 2
;;
esac
shift
done
# set logdir
if [[ -z ${outdir:-} ]]; then
outdir=$PWD
fi
if [[ -z ${logdir:-} ]]; then
logdir=$outdir
fi
# check required arg
if [[ -z ${tumor:-} ]]; then
printf "\nERROR: no tumor argument provided\n"
echo "$help_message"; exit 2
elif [[ -z ${fasta:-} ]]; then
printf "\nERROR: no FASTA argument provided\n"
echo "$help_message"; exit 2
fi
# check files if flagged
if [[ $check = T ]]; then
if [[ ! -r ${tumor} ]]; then
printf "\nERROR: tumor file is not readable: %s\n" $tumor
echo "$help_message"; exit 2
elif [[ ! -r ${fasta} ]]; then
printf "\nERROR: FASTA file is not readable: %s\n" $fasta
echo "$help_message"; exit 2
fi
fi
# get sample name if not provided
if [[ -z ${name:-} ]]; then
name=$(basename ${tumor})
name=${name%%.*}
fi
# setup output directories
mkdir -p ${outdir}
mkdir -p ${logdir}
# set optional arguments
if [[ ! -z ${normal:-} ]]; then
if [[ $check = T ]] && [[ ! -r ${normal} ]]; then
printf "\nERROR: normal file is not readable: %s\n" ${normal}
echo "$help_message"; exit 2
else
normal_input="-I ${normal}"
module load SAMtools/1.11-GCCcore-10.2.0
normal_sm=$(samtools view -H ${normal} | grep "@RG" | grep -Po 'SM:\K[^\s]+')
normal_name="-normal ${normal_sm}"
fi
fi
if [[ ! -z ${intervals:-} ]]; then
if [[ $check = T ]] && [[ ! -r ${intervals} ]]; then
printf "\nERROR: intervals file is not readable: %s\n" ${intervals}
echo "$help_message"; exit 2
else
intervals_arg="-L ${intervals}"
fi
fi
if [[ ! -z ${germline:-} ]]; then
if [[ $check = T ]] && [[ ! -r ${germline} ]]; then
printf "\nERROR: germline file is not readable: %s\n" ${germline}
echo "$help_message"; exit 2
else
germline_arg="--germline-resource ${germline}"
fi
fi
if [[ ! -z ${pon:-} ]]; then
if [[ $check = T ]] && [[ ! -r $pon ]]; then
printf "\nERROR: PON file is not readable: %s\n" ${pon}
echo "$help_message"; exit 2
else
pon_arg="--panel-of-normals ${pon}"
fi
fi
if [[ ! -z ${chr:-} ]]; then
chr_arg="-L $chr"
fi
if [[ ${callgermline} = "true" ]]; then
callgermarg="--genotype-germline-sites true"
fi
# call variants
std_log="${logdir}/${name}.call_var_mutect2.log"
scr_log="${logdir}/${name}.call_var_mutect2.scr"
script=$(cat <<- EOS
#!/bin/bash
#SBATCH --time=24:00:00
#SBATCH -n 8
#SBATCH -N 1
#SBATCH --mem=32gb
#SBATCH --job-name=mutect2
#SBATCH --output=$std_log
${depend:-}
# load modules
module load Java/11.0.16
module load SAMtools/1.11-GCCcore-10.2.0
module load picard/2.25.6-Java-11
module load GATK/4.2.2.0-GCCcore-10.2.0-Java-11
# call
gatk Mutect2 \
${normal_input:-} \
${normal_name:-} \
${intervals_arg:-} \
${chr_arg:-} \
${germline_arg:-} \
${pon_arg:-} \
${callgermarg:-} \
--bam-output ${name}.mutect2.bam \
-R ${fasta} \
-I ${tumor} \
-O ${name}.mutect2.vcf.gz
EOS
)
echo "$script" > ${scr_log}
subm=$(sbatch "$scr_log")
echo $subm
exit 0