-
Notifications
You must be signed in to change notification settings - Fork 29
/
sambamba.wdl
201 lines (175 loc) · 8.3 KB
/
sambamba.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
version 1.0
# Copyright (c) 2017 Leiden University Medical Center
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
task Flagstat {
input {
File inputBam
File inputBamIndex
String outputPath = "./flagstat.txt"
Int threads = 2
String memory = "8GiB"
Int timeMinutes = 320
String dockerImage = "quay.io/biocontainers/sambamba:0.7.1--h148d290_2"
}
command {
sambamba flagstat \
-t ~{threads} \
~{inputBam} \
> ~{outputPath}
}
output {
File stats = outputPath
}
runtime {
cpu: threads
memory: memory
time_minutes: timeMinutes # !UnknownRuntimeKey
docker: dockerImage
}
parameter_meta {
inputBam: {description: "The input BAM file.", category: "required"}
inputBamIndex: {description: "The index for the BAM file.", category: "required"}
outputPath: {description: "The path to write the ouput to.", category: "required"}
threads: {description: "The number of threads that will be used for this task.", category: "advanced"}
memory: {description: "The amount of memory available to the job.", category: "advanced"}
timeMinutes: {description: "The maximum amount of time the job will run in minutes.", category: "advanced"}
dockerImage: {description: "The docker image used for this task. Changing this may result in errors which the developers may choose not to address.", category: "advanced"}
}
}
task Markdup {
input {
Array[File] inputBams
String outputPath
Int compressionLevel = 1
# sortBufferSize and ioBufferSize taken from markdup defaults as of sambamba 0.7.1.
Int sortBufferSize = 4096
Int ioBufferSize = 128
Boolean removeDuplicates = false
Int? hashTableSize
Int? overFlowListSize
# Sambamba scales like this: 1 thread is fully utilized (1).
# 2 threads 1.8 utilized. 3 -> 2.4, 4-> 2.7.
# 2 threads reduces wall clock time by more than 40%.
Int threads = 2
# According to the manual sambamba markdup uses the sortbufferSize + 2 times the ioBuffer size.
# Added 8192 mb as a margin of safety. Real life use with this setting uses 2.7 GiB.
Int memoryMb = 8192 + sortBufferSize + 2 * ioBufferSize
# Time minute calculation does not work well for higher number of threads.
Int timeMinutes = 1 + ceil(size(inputBams, "GiB") * 25) / threads
String dockerImage = "quay.io/biocontainers/sambamba:0.7.1--h148d290_2"
}
String bamIndexPath = sub(outputPath, "\.bam$", ".bai")
command {
set -e
mkdir -p "$(dirname ~{outputPath})"
sambamba markdup \
--nthreads ~{threads} \
-l ~{compressionLevel} \
~{true="-r" false="" removeDuplicates} \
~{"--hash-table-size " + hashTableSize} \
~{"--overflow-list-size " + overFlowListSize} \
~{"--sort-buffer-size " + sortBufferSize} \
~{"--io-buffer-size " + ioBufferSize} \
~{sep=' ' inputBams} ~{outputPath}
# sambamba creates an index for us.
mv ~{outputPath}.bai ~{bamIndexPath}
}
output {
File outputBam = outputPath
File outputBamIndex = bamIndexPath
}
runtime {
cpu: threads
memory: "~{memoryMb}MiB"
time_minutes: timeMinutes
docker: dockerImage
}
parameter_meta {
# inputs
inputBams: {description: "The input BAM files.", category: "required"}
outputPath: {description: "Output directory path + output file.", category: "required"}
compressionLevel: {description: "Compression level from 0 (uncompressed) to 9 (best).", category: "advanced"}
sortBufferSize: {description: "The amount of mb allocated to the sort buffer.", category: "advanced"}
ioBufferSize: {description: "The amount of mb allocated to each IO buffer. Sambamba uses two IO buffers.", category: "advanced"}
removeDuplicates: {description: "Whether to remove the duplicates (instead of only marking them).", category: "advanced"}
hashTableSize: {description: "Sets sambamba's hash table size.", category: "advanced"}
overFlowListSize: {description: "Sets sambamba's overflow list size.", category: "advanced"}
threads: {description: "The number of threads that will be used for this task.", category: "advanced"}
memoryMb: {description: "The amount of memory available to the job in megabytes.", category: "advanced"}
timeMinutes: {description: "The maximum amount of time the job will run in minutes.", category: "advanced"}
dockerImage: {description: "The docker image used for this task. Changing this may result in errors which the developers may choose not to address.", category: "advanced"}
# outputs
outputBam: {description: "Sorted BAM file."}
outputBamIndex: {description: "Sorted BAM file index."}
}
}
task Sort {
input {
File inputBam
String outputPath = basename(inputBam, "\.bam") + ".sorted.bam"
Boolean sortByName = false
Int compressionLevel = 1
Int memoryPerThreadGb = 4
Int threads = 1
Int memoryGb = 1 + threads * memoryPerThreadGb
Int timeMinutes = 1 + ceil(size(inputBam, "GiB") * 3)
String dockerImage = "quay.io/biocontainers/sambamba:0.7.1--h148d290_2"
}
# Select first needed as outputPath is optional input (bug in cromwell).
String bamIndexPath = sub(select_first([outputPath]), "\.bam$", ".bai")
command {
set -e
mkdir -p "$(dirname ~{outputPath})"
sambamba sort \
-l ~{compressionLevel} \
~{true="-n" false="" sortByName} \
~{"--nthreads " + threads} \
-m ~{memoryPerThreadGb}G \
-o ~{outputPath} \
~{inputBam}
# sambamba creates an index for us.
mv ~{outputPath}.bai ~{bamIndexPath}
}
output {
File outputBam = outputPath
File outputBamIndex = bamIndexPath
}
runtime {
cpu: threads
memory: "~{memoryGb}GiB"
docker: dockerImage
time_minutes: timeMinutes
}
parameter_meta {
# inputs
inputBam: {description: "The input SAM file.", category: "required"}
outputPath: {description: "Output directory path + output file.", category: "required"}
sortByName: {description: "Sort the inputBam by read name instead of position.", category: "advanced"}
compressionLevel: {description: "Compression level from 0 (uncompressed) to 9 (best).", category: "advanced"}
memoryPerThreadGb: {description: "The amount of memory used per sort thread in gigabytes.", category: "advanced"}
threads: {description: "The number of threads that will be used for this task.", category: "advanced"}
memoryGb: {description: "The amount of memory available to the job in gigabytes.", category: "advanced"}
timeMinutes: {description: "The maximum amount of time the job will run in minutes.", category: "advanced"}
dockerImage: {description: "The docker image used for this task. Changing this may result in errors which the developers may choose not to address.", category: "advanced"}
# outputs
outputBam: {description: "Sorted BAM file."}
outputBamIndex: {description: "Sorted BAM file index."}
}
}