-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun_svdss
More file actions
executable file
·209 lines (186 loc) · 4.72 KB
/
Copy pathrun_svdss
File metadata and controls
executable file
·209 lines (186 loc) · 4.72 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
#!/bin/sh
bindir=$(dirname $0)
SCRIPT_NAME=$(basename $0)
VERSION=2.1.1
DEFAULT_WD="."
DEFAULT_MQ=20
DEFAULT_ACCP=0.98
DEFAULT_SUPP=2
DEFAULT_MINL=50
DEFAULT_THREADS=4
DEFAULT_SVDSS="SVDSS"
DEFAULT_KANPIG="kanpig"
USAGE=$'\nUsage: '"${SCRIPT_NAME}"' <reference.fa> <alignments.bam>
Arguments:
-w output directory (default: '$DEFAULT_WD')
-i use this FMD index/store it here (default: build FMD index and store to <reference.fa.fmd>)
-q mapping quality (default: '$DEFAULT_MQ')
-p accuracy percentile (default: '$DEFAULT_ACCP')
-s minimum support for calling (default: '$DEFAULT_SUPP')
-l minimum length for SV (default: '$DEFAULT_MINL')
-t do not consider haplotagging information (default: consider it)
-@ number of threads (default: '$DEFAULT_THREADS')
-x path to SVDSS binary (default: '$DEFAULT_SVDSS')
-k path to kanpig binary (default: '$DEFAULT_KANPIG')
-v print version
-h print this help and exit
Positional arguments:
<reference.fa> reference file in FASTA format
<alignments.bam> alignments in BAM format
'
wd=${DEFAULT_WD}
supp=${DEFAULT_SUPP}
minl=${DEFAULT_MINL}
mq=${DEFAULT_MQ}
accp=${DEFAULT_ACCP}
threads=${DEFAULT_THREADS}
svdss=${DEFAULT_SVDSS}
kanpig=${DEFAULT_KANPIG}
FMD=""
noht=""
while getopts "w:i:s:l:p:q:@:x:r:k:tvh" flag; do
case "${flag}" in
h)
$(echo >&2 "${USAGE}")
exit 0
;;
w)
wd=${OPTARG}
;;
i)
FMD=${OPTARG}
;;
s)
supp=${OPTARG}
;;
l)
minl=${OPTARG}
;;
p)
accp=${OPTARG}
;;
q)
mq=${OPTARG}
;;
x)
svdss=${OPTARG}
;;
r)
rb3=${OPTARG}
;;
k)
kanpig=${OPTARG}
;;
@)
threads=${OPTARG}
;;
t)
noht="--noht"
;;
v)
(echo >&2 "SVDSS, v${VERSION}")
exit 0
;;
*)
$(echo >&2 "${USAGE}")
exit 1
esac
done
# === Checking positions arguments ===
if [[ $# -lt $((${OPTIND} + 1)) ]]; then
(echo >&2 "ERROR: Wrong number of arguments.")
(echo >&2 "")
(echo >&2 "${USAGE}")
exit 1
fi
FA=${@:$OPTIND:1}
BAM=${@:$OPTIND+1:1}
if [[ ! -f $FA ]]; then
(echo >&2 "ERROR: input FASTA does not exist")
(echo >&2 "")
(echo >&2 "${USAGE}")
exit 1
fi
if [[ ! -f $BAM ]]; then
(echo >&2 "ERROR: input BAM does not exist")
(echo >&2 "")
(echo >&2 "${USAGE}")
exit 1
fi
# === Checking SVDSS ===
if [[ ! -f $svdss && ! $(which $svdss 2>/dev/null) ]]; then
(echo >&2 "ERROR: cannot execute SVDSS.")
(echo >&2 "Current binary: $svdss Add it to your \$PATH or set it via -x")
(echo >&2 "")
exit 1
fi
echo "Using SVDSS ($svdss)"
echo ""
mkdir -p $wd
# === INDEXING ===
if [[ -z $FMD ]]; then
FMD="${FA}.fmd"
fi
if [[ ! -f $FMD ]]; then
echo "[$(date)] Building FMD index: $FMD..."
/usr/bin/time -vo ${wd}/indexing.time $svdss index -t $threads -d $FA -o $FMD
echo ""
else
echo "[$(date)] Using existing FMD index: $FMD"
echo ""
fi
# === SMOOTHING ===
echo "[$(date)] Smoothing input BAM file (--min-mapq $mq --accp $accp)..."
/usr/bin/time -vo $wd/smoothing.time $svdss smooth \
--threads $threads \
--min-mapq $mq \
--accp $accp \
--reference $FA \
--bam $BAM >$wd/smoothed.bam
samtools index $wd/smoothed.bam
echo ""
# === SEARCHING ===
echo "[$(date)] Searching for specific strings..."
/usr/bin/time -vo $wd/searching.time $svdss search \
--threads $threads \
--index $FMD \
--bam $wd/smoothed.bam >$wd/specifics.txt
echo ""
# === CALLING ===
echo "[$(date)] Calling SVs (--min-cluster-weight $supp --min-sv-length $minl --min-mapq $mq $noht)..."
/usr/bin/time -vo ${wd}/calling.time $svdss call \
$noht \
--threads $threads \
--min-cluster-weight $supp \
--min-sv-length $minl \
--min-mapq $mq \
--reference $FA \
--bam $BAM \
--sfs $wd/specifics.txt >$wd/variations.vcf
bgzip -f $wd/variations.vcf
tabix -p vcf $wd/variations.vcf.gz
echo ""
FINAL_VCF="$wd/variations-final.vcf.gz"
# === GENOTYPING ===
if ! command -v ${kanpig} 2>&1 >/dev/null; then
echo "[$(date)] Skipping genotyping since $kanpig can not be found"
mv $wd/variations.vcf.gz $FINAL_VCF
tabix -p vcf $FINAL_VCF
echo ""
else
echo "[$(date)] Genotyping variations..."
if [[ ! -f ${FA}.fai ]]; then
samtools faidx $FA
fi
# sed "s/FT/KF/g"
/usr/bin/time -vo ${wd}/genotyping.time ${kanpig} gt --input $wd/variations.vcf.gz --reads $BAM --reference $FA | bcftools sort -Oz >$wd/variations-gt.vcf.gz
tabix -p vcf $wd/variations-gt.vcf.gz
# VAF computation
bcftools +fill-tags $wd/variations-gt.vcf.gz -- -t VAF | bcftools view -Oz > $FINAL_VCF
tabix -p vcf $FINAL_VCF
echo ""
fi
echo "[$(date)] Done!"
echo ""
echo "VCF: ${FINAL_VCF}"
echo ""