forked from biowdl/tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamtools.wdl
265 lines (224 loc) · 6.29 KB
/
samtools.wdl
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
version 1.0
task BgzipAndIndex {
input {
File inputFile
String outputDir
String type = "vcf"
String dockerImage = "quay.io/biocontainers/tabix:0.2.6--ha92aebf_0"
}
String outputGz = outputDir + "/" + basename(inputFile) + ".gz"
command {
set -e
mkdir -p $(dirname ~{outputGz})
bgzip -c ~{inputFile} > ~{outputGz}
tabix ~{outputGz} -p ~{type}
}
output {
File compressed = outputGz
File index = outputGz + ".tbi"
}
runtime {
docker: dockerImage
}
}
task Index {
input {
File bamFile
String outputBamPath = basename(bamFile)
String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
}
# Select_first is needed, otherwise womtool validate fails.
String bamIndexPath = sub(select_first([outputBamPath]), "\.bam$", ".bai")
command {
bash -c '
set -e
# Make sure outputBamPath does not exist.
if [ ! -f ~{outputBamPath} ]
then
mkdir -p $(dirname ~{outputBamPath})
ln ~{bamFile} ~{outputBamPath}
fi
samtools index ~{outputBamPath} ~{bamIndexPath}
'
}
output {
File indexedBam = outputBamPath
File index = bamIndexPath
}
runtime {
docker: dockerImage
}
}
task Merge {
input {
Array[File]+ bamFiles
String outputBamPath = "merged.bam"
Boolean force = true
String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
}
String indexPath = sub(outputBamPath, "\.bam$",".bai")
command {
set -e
mkdir -p $(dirname ~{outputBamPath})
samtools merge ~{true="-f" false="" force} ~{outputBamPath} ~{sep=' ' bamFiles}
samtools index ~{outputBamPath} ~{indexPath}
}
output {
File outputBam = outputBamPath
File outputBamIndex = indexPath
}
runtime {
docker: dockerImage
}
}
task Markdup {
input {
File inputBam
String outputBamPath
String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
}
command {
set -e
mkdir -p $(dirname ~{outputBamPath})
samtools markdup ~{inputBam} ~{outputBamPath}
}
output {
File outputBam = outputBamPath
}
runtime {
docker: dockerImage
}
}
task Flagstat {
input {
File inputBam
String outputPath
String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
}
command {
set -e
mkdir -p $(dirname ~{outputPath})
samtools flagstat ~{inputBam} > ~{outputPath}
}
output {
File flagstat = outputPath
}
runtime {
docker: dockerImage
}
}
task Fastq {
input {
File inputBam
String outputRead1
String? outputRead2
String? outputRead0
Int? includeFilter
Int? excludeFilter
Int? excludeSpecificFilter
Boolean? appendReadNumber
Boolean? outputQuality
Int? compressionLevel
Int threads = 1
Int memory = 1
String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
}
command {
samtools fastq \
~{true="-1" false="-s" defined(outputRead2)} ~{outputRead1} \
~{"-2 " + outputRead2} \
~{"-0 " + outputRead0} \
~{"-f " + includeFilter} \
~{"-F " + excludeFilter} \
~{"-G " + excludeSpecificFilter} \
~{true="-N" false="-n" appendReadNumber} \
~{true="-O" false="" outputQuality} \
~{"-c " + compressionLevel} \
~{"--threads " + threads} \
~{inputBam}
}
output {
File read1 = outputRead1
File? read2 = outputRead2
File? read0 = outputRead0
}
runtime {
cpu: threads
memory: memory
docker: dockerImage
}
parameter_meta {
inputBam: "The bam file to process."
outputRead1: "If only outputRead1 is given '-s' flag is assumed. Else '-1'."
includeFilter: "Include reads with ALL of these flags. Corresponds to '-f'"
excludeFilter: "Exclude reads with ONE OR MORE of these flags. Corresponds to '-F'"
excludeSpecificFilter: "Exclude reads with ALL of these flags. Corresponds to '-G'"
appendReadNumber: "Append /1 and /2 to the read name, or don't. Corresponds to '-n/N"
}
}
task Tabix {
input {
File inputFile
String outputFilePath = "indexed.vcf.gz"
String type = "vcf"
String dockerImage = "quay.io/biocontainers/tabix:0.2.6--ha92aebf_0"
}
# FIXME: It is better to do the indexing on VCF creation. Not in a separate task. With file localization this gets hairy fast.
command {
set -e
mkdir -p $(dirname ~{outputFilePath})
if [ ! -f ~{outputFilePath} ]
then
ln ~{inputFile} ~{outputFilePath}
fi
tabix ~{outputFilePath} -p ~{type}
}
output {
File indexedFile = outputFilePath
File index = outputFilePath + ".tbi"
}
runtime {
docker: dockerImage
}
}
task View {
input {
File inFile
File? referenceFasta
String outputFileName = "view.bam"
Boolean? uncompressedBamOutput
Int? includeFilter
Int? excludeFilter
Int? excludeSpecificFilter
Int? MAPQthreshold
Int threads = 1
Int memory = 1
String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
}
String outputIndexPath = basename(outputFileName) + ".bai"
# Always output to bam and output header
command {
set -e
mkdir -p $(dirname ~{outputFileName})
samtools view -b \
~{"-T " + referenceFasta} \
~{"-o " + outputFileName} \
~{true="-u " false="" uncompressedBamOutput} \
~{"-f " + includeFilter} \
~{"-F " + excludeFilter} \
~{"-G " + excludeSpecificFilter} \
~{"-q " + MAPQthreshold} \
~{"--threads " + (threads - 1)} \
~{inFile}
samtools index ~{outputFileName} ~{outputIndexPath}
}
output {
File outputBam = outputFileName
File outputBamIndex = outputIndexPath
}
runtime {
cpu: threads
memory: memory
docker: dockerImage
}
}