-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbammetrics.wdl
154 lines (137 loc) · 7.5 KB
/
bammetrics.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
version 1.0
# Copyright (c) 2018 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.
import "tasks/common.wdl" as common
import "tasks/picard.wdl" as picard
import "tasks/samtools.wdl" as samtools
workflow BamMetrics {
input {
File bam
File bamIndex
String outputDir = "."
File referenceFasta
File referenceFastaFai
File referenceFastaDict
String strandedness = "None"
Boolean collectAlignmentSummaryMetrics = true
Boolean meanQualityByCycle = true
File? refRefflat
Array[File]+? targetIntervals
File? ampliconIntervals
Map[String, String] dockerImages = {
"samtools":"quay.io/biocontainers/samtools:1.11--h6270b1f_0",
"picard":"quay.io/biocontainers/picard:2.23.8--0",
}
}
meta {
allowNestedInputs: true
}
String prefix = outputDir + "/" + basename(bam, ".bam")
call samtools.Flagstat as Flagstat {
input:
inputBam = bam,
outputPath = prefix + ".flagstats",
dockerImage = dockerImages["samtools"]
}
call picard.CollectMultipleMetrics as picardMetrics {
input:
inputBam = bam,
inputBamIndex = bamIndex,
basename = prefix,
referenceFasta = referenceFasta,
referenceFastaDict = referenceFastaDict,
referenceFastaFai = referenceFastaFai,
collectAlignmentSummaryMetrics = collectAlignmentSummaryMetrics,
meanQualityByCycle = meanQualityByCycle,
dockerImage = dockerImages["picard"]
}
if (defined(refRefflat)) {
Map[String, String] strandednessConversion = {"None": "NONE", "FR":"FIRST_READ_TRANSCRIPTION_STRAND", "RF": "SECOND_READ_TRANSCRIPTION_STRAND"}
call picard.CollectRnaSeqMetrics as rnaSeqMetrics {
input:
inputBam = bam,
inputBamIndex = bamIndex,
refRefflat = select_first([refRefflat]),
basename = prefix,
strandSpecificity = strandednessConversion[strandedness],
dockerImage = dockerImages["picard"]
}
}
if (defined(targetIntervals)) {
Array[File] targetBeds = select_first([targetIntervals])
scatter (targetBed in targetBeds) {
call picard.BedToIntervalList as targetIntervalsLists {
input:
bedFile = targetBed,
outputPath = prefix + "_intervalLists/" + basename(targetBed) + ".interval_list",
dict = referenceFastaDict,
dockerImage = dockerImages["picard"]
}
}
call picard.BedToIntervalList as ampliconIntervalsLists {
input:
bedFile = select_first([ampliconIntervals]),
outputPath = prefix + "_intervalLists/" + basename(select_first([ampliconIntervals])) + ".interval_list",
dict = referenceFastaDict,
dockerImage = dockerImages["picard"]
}
call picard.CollectTargetedPcrMetrics as targetMetrics {
input:
inputBam = bam,
inputBamIndex = bamIndex,
referenceFasta = referenceFasta,
referenceFastaDict = referenceFastaDict,
referenceFastaFai = referenceFastaFai,
basename = prefix,
targetIntervals = targetIntervalsLists.intervalList,
ampliconIntervals = ampliconIntervalsLists.intervalList,
dockerImage = dockerImages["picard"]
}
}
output {
File flagstats = Flagstat.flagstat
Array[File] picardMetricsFiles = picardMetrics.allStats
Array[File] rnaMetrics = select_all([rnaSeqMetrics.metrics, rnaSeqMetrics.chart])
Array[File] targetedPcrMetrics = select_all([targetMetrics.perTargetCoverage, targetMetrics.perBaseCoverage, targetMetrics.metrics])
Array[File] reports = flatten([picardMetricsFiles, rnaMetrics, targetedPcrMetrics, [flagstats]])
}
parameter_meta {
# inputs
bam: {description: "The BAM file for which metrics will be collected.", category: "required"}
bamIndex: {description: "The index for the bam file.", category: "required"}
outputDir: {description: "The directory to which the outputs will be written.", category: "common"}
referenceFasta: {description: "The reference fasta file.", category: "required"}
referenceFastaDict: {description: "The sequence dictionary associated with the reference fasta file.", category: "required"}
referenceFastaFai: {description: "The index for the reference fasta file.", category: "required"}
strandedness: {description: "The strandedness of the RNA sequencing library preparation. One of \"None\" (unstranded), \"FR\" (forward-reverse: first read equal transcript) or \"RF\" (reverse-forward: second read equals transcript).", category: "common"}
collectAlignmentSummaryMetrics: {description: "Equivalent to the `PROGRAM=CollectAlignmentSummaryMetrics` argument in Picard.", category: "advanced"}
meanQualityByCycle: {description: "Equivalent to the `PROGRAM=MeanQualityByCycle` argument in Picard.", category: "advanced"}
refRefflat: {description: "A refflat file containing gene annotations. If defined RNA sequencing metrics will be collected.", category: "common"}
targetIntervals: {description: "An interval list describing the coordinates of the targets sequenced. This should only be used for targeted sequencing or WES. If defined targeted PCR metrics will be collected. Requires `ampliconIntervals` to also be defined.", category: "common"}
ampliconIntervals: {description: "An interval list describinig the coordinates of the amplicons sequenced. This should only be used for targeted sequencing or WES. Required if `ampliconIntervals` is defined.", category: "common"}
dockerImages: {description: "The docker images used. Changing this may result in errors which the developers may choose not to address.", category: "advanced"}
# outputs
flagstats: {description: "Statistics output from flagstat."}
picardMetricsFiles: {description: "All statistics from the CollectMultipleMetrics tool."}
rnaMetrics: {description: "Statistics from the RNA metrics tool."}
targetedPcrMetrics: {description: "Statistics from the targeted PCR metrics tool."}
reports: {description: "All reports from this pipeline gathered into one array."}
}
}