Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
ea7282d9
Commit
ea7282d9
authored
Mar 02, 2017
by
Peter van 't Hof
Committed by
GitHub
Mar 02, 2017
Browse files
Merge pull request #24 from biopet/fix-BIOPET-546
Fix biopet 546
parents
7812d950
8314da08
Changes
326
Hide whitespace changes
Inline
Side-by-side
bam2wig/src/main/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/Bam2Wig.scala
View file @
ea7282d9
...
...
@@ -27,7 +27,7 @@ import org.broadinstitute.gatk.queue.QScript
*
* Created by pjvan_thof on 1/29/15.
*/
class
Bam2Wig
(
val
roo
t
:
Configurable
)
extends
QScript
with
BiopetQScript
{
class
Bam2Wig
(
val
paren
t
:
Configurable
)
extends
QScript
with
BiopetQScript
{
def
this
()
=
this
(
null
)
@Input
(
doc
=
"Input bam file"
,
required
=
true
)
...
...
bam2wig/src/main/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/BamToChromSizes.scala
View file @
ea7282d9
...
...
@@ -28,7 +28,7 @@ import scala.collection.JavaConversions._
*
* Created by pjvan_thof on 1/29/15.
*/
class
BamToChromSizes
(
val
roo
t
:
Configurable
)
extends
InProcessFunction
with
Configurable
{
class
BamToChromSizes
(
val
paren
t
:
Configurable
)
extends
InProcessFunction
with
Configurable
{
@Input
var
bamFile
:
File
=
_
...
...
bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp
View file @
ea7282d9
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.
db.
Summary
Db
)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[
String
] = None %>
<%@ var libId: Option[
String
] = None %>
<%@ var summary: Summary
Db
%>
<%@ var sampleId: Option[
Int
] = None %>
<%@ var libId: Option[
Int
] = None %>
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
<%@ var showIntro: Boolean = true%>
<%@ var runId: Int %>
#{
val samples = sampleId match {
case Some(sample) => {
List(sample.toString)
}
case _ => summary.samples.toList
}
val samples = Await.result(summary.getSamples(runId = Some(runId)), Duration.Inf)
}#
#if (showIntro)
<br/>
...
...
@@ -69,24 +67,31 @@
<th>(%)</th>
</tr></thead>
<tbody>
#for (sample <- samples.
toList.sorted
)
#for (sample <- samples.
sortBy(_.name)
)
#{
val libs = (libId, sampleLevel) match {
case (_, true) => List(
""
)
case (Some(
libId
), _) => List(libId
.toString).sorted
case _ => summary.
l
ibraries(sample).toList
.sorted
val libs
: List[Option[Int]]
= (libId, sampleLevel) match {
case (_, true) => List(
None
)
case (Some(
_
), _) => List(libId
)
case _ =>
Await.result(
summary.
getL
ibraries(sample
Id = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)
).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample
.name
}/index.html">${sample
.name
}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${lib
Id
}/index.html">${lib
Id
}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample
.name
}/Libraries/${lib
Name
}/index.html">${lib
Name
}</a></td> #end
#{
val prefixPath = List("samples", sample) ::: (if (libId.isEmpty) Nil else List("libraries", libId)) ::: List("bammetrics", "stats")
val total = summary.getValue((prefixPath ::: List("bamstats", "flagstats", "All")):_*).getOrElse(0L).asInstanceOf[Long]
val mapped = summary.getValue((prefixPath ::: List("bamstats", "flagstats", "Mapped")):_*).getOrElse(0L).asInstanceOf[Long]
val duplicates = summary.getValue((prefixPath ::: List("bamstats", "flagstats", "Duplicates")):_*).getOrElse(0L).asInstanceOf[Long]
val secondary = summary.getValue((prefixPath ::: List("bamstats", "flagstats", "NotPrimaryAlignment")):_*).getOrElse(0L).asInstanceOf[Long]
val statsPaths = Map(
"All" -> List("flagstats", "All"),
"Mapped" -> List("flagstats", "Mapped"),
"Duplicates" -> List("flagstats", "Duplicates"),
"NotPrimaryAlignment" -> List("flagstats", "NotPrimaryAlignment")
)
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("bamstats")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
val total = results("All").getOrElse(0L).asInstanceOf[Long]
val mapped = results("Mapped").getOrElse(0L).asInstanceOf[Long]
val duplicates = results("Duplicates").getOrElse(0L).asInstanceOf[Long]
val secondary = results("NotPrimaryAlignment").getOrElse(0L).asInstanceOf[Long]
}#
<td>${total}</td>
<td>${mapped}</td>
...
...
bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/clipping.ssp
View file @
ea7282d9
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.
db.
Summary
Db
)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(org.apache.commons.io.FileUtils)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var metricsTag: String = "bammetrics" %>
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var fields: List[String] = List("min", "max", "mean", "median", "modal")%>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
<%@ var showIntro: Boolean = true%>
<%@ var runId: Int %>
<%@ var fields: List[String] = List("min", "max", "mean", "median", "modal")%>
#{
val samples = sampleId match {
case Some(sample) => {
List(sample.toString)
}
case _ => summary.samples.toList
}
val samples = Await.result(summary.getSamples(runId = Some(runId)), Duration.Inf)
}#
#if (showIntro)
...
...
@@ -42,7 +38,7 @@
#end
#if (showPlot)
#{ BammetricsReport.clippingPlot(outputDir, "clipping", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
#{ BammetricsReport.clippingPlot(outputDir, "clipping", summary, !sampleLevel, sampleId = sampleId, lib
rary
Id = libId) }#
<div class="panel-body">
<img src="clipping.png" class="img-responsive" />
...
...
@@ -71,27 +67,25 @@
#end
</tr></thead>
<tbody>
#for (sample <- samples.
toList.sorted
)
#for (sample <- samples.
sortBy(_.name)
)
#{
val libs = (libId, sampleLevel) match {
case (_, true) => List(
""
)
case (Some(
libId
), _) => List(libId
.toString
)
case _ => summary.
l
ibraries(sample).toList
val libs
: List[Option[Int]]
= (libId, sampleLevel) match {
case (_, true) => List(
None
)
case (Some(
_
), _) => List(libId)
case _ =>
Await.result(
summary.
getL
ibraries(sample
Id = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)
).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample
.name
}/index.html">${sample
.name
}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${lib
Id
}/index.html">${lib
Id
}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample
.name
}/Libraries/${lib
Name
}/index.html">${lib
Name
}</a></td> #end
#{
val prefixPath = List("samples", sample) ::: (if (libId.isEmpty) Nil else List("libraries", libId)) ::: List("bammetrics", "stats")
val fieldValues = for (field <- fields) yield {
summary.getValue((prefixPath ::: List("bamstats", "clipping", "general", field)):_*).getOrElse("N/A")
}
val statsPaths = fields.map(x => x -> List("clipping", "general", x)).toMap
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("bamstats")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
}#
#for (
value
<- field
Value
s)
<td>${
value
}</td>
#for (
field
<- fields)
<td>${
results(field)
}</td>
#end
</tr>
#end
...
...
bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp
View file @
ea7282d9
...
...
@@ -43,7 +43,7 @@
#end
#if (showPlot)
#{ BammetricsReport.insertSizePlot(outputDir, "insertsize", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
#{ BammetricsReport.insertSizePlot(outputDir, "insertsize", summary, !sampleLevel, sampleId = sampleId, lib
rary
Id = libId) }#
<div class="panel-body">
<img src="insertsize.png" class="img-responsive" />
...
...
bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/mappingQuality.ssp
View file @
ea7282d9
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.
db.
Summary
Db
)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(org.apache.commons.io.FileUtils)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var metricsTag: String = "bammetrics" %>
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var fields: List[String] = List("min", "max", "mean", "median", "modal")%>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
<%@ var showIntro: Boolean = true%>
<%@ var runId: Int %>
<%@ var fields: List[String] = List("min", "max", "mean", "median", "modal")%>
#{
val samples = sampleId match {
case Some(sample) => {
List(sample.toString)
}
case _ => summary.samples.toList
}
val samples = Await.result(summary.getSamples(runId = Some(runId)), Duration.Inf)
}#
#if (showIntro)
...
...
@@ -42,7 +39,7 @@
#end
#if (showPlot)
#{ BammetricsReport.mappingQualityPlot(outputDir, "mapping_quality", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
#{ BammetricsReport.mappingQualityPlot(outputDir, "mapping_quality", summary, !sampleLevel, sampleId = sampleId, lib
rary
Id = libId) }#
<div class="panel-body">
<img src="mapping_quality.png" class="img-responsive" />
...
...
@@ -71,27 +68,25 @@
#end
</tr></thead>
<tbody>
#for (sample <- samples.
toList.sorted
)
#for (sample <- samples.
sortBy(_.name)
)
#{
val libs = (libId, sampleLevel) match {
case (_, true) => List(
""
)
case (Some(
libId
), _) => List(libId
.toString
)
case _ => summary.
l
ibraries(sample).toList
val libs
: List[Option[Int]]
= (libId, sampleLevel) match {
case (_, true) => List(
None
)
case (Some(
_
), _) => List(libId)
case _ =>
Await.result(
summary.
getL
ibraries(sample
Id = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)
).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample
.name
}/index.html">${sample
.name
}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${lib
Id
}/index.html">${lib
Id
}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample
.name
}/Libraries/${lib
Name
}/index.html">${lib
Name
}</a></td> #end
#{
val prefixPath = List("samples", sample) ::: (if (libId.isEmpty) Nil else List("libraries", libId)) ::: List("bammetrics", "stats")
val fieldValues = for (field <- fields) yield {
summary.getValue((prefixPath ::: List("bamstats", "mapping_quality", "general", field)):_*).getOrElse("N/A")
}
val statsPaths = fields.map(x => x -> List("mapping_quality", "general", x)).toMap
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("bamstats")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
}#
#for (
value
<- field
Value
s)
<td>${
value
}</td>
#for (
field
<- fields)
<td>${
results(field)
}</td>
#end
</tr>
#end
...
...
bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp
View file @
ea7282d9
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.
db.
Summary
Db
)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(org.apache.commons.io.FileUtils)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var metricsTag: String = "bammetrics" %>
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var fields: List[String] = List("mean_coverage", "pct_5x", "pct_10x", "pct_15x", "pct_20x", "pct_25x", "pct_30x", "pct_40x", "pct_50x", "pct_60x", "pct_70x", "pct_80x", "pct_90x", "pct_100x")%>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
<%@ var showIntro: Boolean = true%>
<%@ var runId: Int %>
<%@ var fields: List[String] = List("mean_coverage", "pct_5x", "pct_10x", "pct_15x", "pct_20x", "pct_25x", "pct_30x", "pct_40x", "pct_50x", "pct_60x", "pct_70x", "pct_80x", "pct_90x", "pct_100x")%>
#{
val samples = sampleId match {
case Some(sample) => {
List(sample.toString)
}
case _ => summary.samples.toList
}
val samples = Await.result(summary.getSamples(runId = Some(runId)), Duration.Inf)
}#
#if (showIntro)
...
...
@@ -36,7 +32,7 @@
#end
#if (showPlot)
#{ BammetricsReport.wgsHistogramPlot(outputDir, "wgs", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
#{ BammetricsReport.wgsHistogramPlot(outputDir, "wgs", summary, !sampleLevel, sampleId = sampleId, lib
rary
Id = libId) }#
<div class="panel-body">
<img src="wgs.png" class="img-responsive" />
...
...
@@ -62,27 +58,25 @@
#end
</tr></thead>
<tbody>
#for (sample <- samples.
toList.sorted
)
#for (sample <- samples.
sortBy(_.name)
)
#{
val libs = (libId, sampleLevel) match {
case (_, true) => List(
""
)
case (Some(
libId
), _) => List(libId
.toString
)
case _ => summary.
l
ibraries(sample).toList
val libs
: List[Option[Int]]
= (libId, sampleLevel) match {
case (_, true) => List(
None
)
case (Some(
_
), _) => List(libId)
case _ =>
Await.result(
summary.
getL
ibraries(sample
Id = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)
).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample
.name
}/index.html">${sample
.name
}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${lib
Id
}/index.html">${lib
Id
}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample
.name
}/Libraries/${lib
Name
}/index.html">${lib
Name
}</a></td> #end
#{
val prefixPath = List("samples", sample) ::: (if (libId.isEmpty) Nil else List("libraries", libId)) ::: List("bammetrics", "stats")
val fieldValues = for (field <- fields) yield {
summary.getValue((prefixPath ::: List("wgs", "metrics", field.toUpperCase)):_*).getOrElse(prefixPath ::: metricsTag :: Nil)
}
val statsPaths = fields.map(x => x -> List("metrics", x)).toMap
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("wgs")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
}#
#for (
value
<- field
Value
s)
<td>${
value
}</td>
#for (
field
<- fields)
<td>${
results(field)
}</td>
#end
</tr>
#end
...
...
bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala
View file @
ea7282d9
...
...
@@ -28,7 +28,7 @@ import nl.lumc.sasc.biopet.utils.config.Configurable
import
nl.lumc.sasc.biopet.utils.intervals.BedCheck
import
org.broadinstitute.gatk.queue.QScript
class
BamMetrics
(
val
roo
t
:
Configurable
)
extends
QScript
class
BamMetrics
(
val
paren
t
:
Configurable
)
extends
QScript
with
SummaryQScript
with
SampleLibraryTag
with
Reference
...
...
@@ -43,13 +43,6 @@ class BamMetrics(val root: Configurable) extends QScript
override
def
defaults
=
Map
(
"bedtoolscoverage"
->
Map
(
"sorted"
->
true
))
/** return location of summary file */
def
summaryFile
=
(
sampleId
,
libId
)
match
{
case
(
Some
(
s
),
Some
(
l
))
=>
new
File
(
outputDir
,
s
+
"-"
+
l
+
".BamMetrics.summary.json"
)
case
(
Some
(
s
),
_
)
=>
new
File
(
outputDir
,
s
+
".BamMetrics.summary.json"
)
case
_
=>
new
File
(
outputDir
,
"BamMetrics.summary.json"
)
}
/** returns files to store in summary */
def
summaryFiles
=
Map
(
"reference"
->
referenceFasta
(),
"input_bam"
->
inputBam
)
++
...
...
@@ -63,7 +56,7 @@ class BamMetrics(val root: Configurable) extends QScript
override
def
reportClass
=
{
val
bammetricsReport
=
new
BammetricsReport
(
this
)
bammetricsReport
.
outputDir
=
new
File
(
outputDir
,
"report"
)
bammetricsReport
.
summaryFile
=
summaryFile
bammetricsReport
.
summary
Db
File
=
summary
Db
File
bammetricsReport
.
args
=
if
(
libId
.
isDefined
)
Map
(
"sampleId"
->
sampleId
.
getOrElse
(
"."
),
"libId"
->
libId
.
getOrElse
(
"."
))
...
...
bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
View file @
ea7282d9
...
...
@@ -17,11 +17,16 @@ package nl.lumc.sasc.biopet.pipelines.bammetrics
import
java.io.
{
File
,
PrintWriter
}
import
nl.lumc.sasc.biopet.utils.config.Configurable
import
nl.lumc.sasc.biopet.core.report.
{
ReportBuilderExtension
,
ReportBuilder
,
ReportPage
,
ReportSection
}
import
nl.lumc.sasc.biopet.utils.summary.
{
Summary
,
SummaryValue
}
import
nl.lumc.sasc.biopet.utils.rscript.
{
StackedBarPlot
,
LinePlot
}
import
nl.lumc.sasc.biopet.core.report.
{
ReportBuilder
,
ReportBuilderExtension
,
ReportPage
,
ReportSection
}
import
nl.lumc.sasc.biopet.utils.ConfigUtils
import
nl.lumc.sasc.biopet.utils.rscript.
{
LinePlot
,
StackedBarPlot
}
import
nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
class
BammetricsReport
(
val
root
:
Configurable
)
extends
ReportBuilderExtension
{
import
scala.concurrent.ExecutionContext.Implicits.global
import
scala.concurrent.Await
import
scala.concurrent.duration.Duration
class
BammetricsReport
(
val
parent
:
Configurable
)
extends
ReportBuilderExtension
{
def
builder
=
BammetricsReport
}
...
...
@@ -52,23 +57,25 @@ object BammetricsReport extends ReportBuilder {
}
/** Generates a page with alignment stats */
def
bamMetricsPage
(
summary
:
Summary
,
sampleId
:
Option
[
String
],
libId
:
Option
[
String
],
def
bamMetricsPage
(
summary
:
Summary
Db
,
sampleId
:
Option
[
Int
],
libId
:
Option
[
Int
],
metricsTag
:
String
=
"bammetrics"
)
=
{
val
wgsExecuted
=
summary
.
getValue
(
sampleId
,
libId
,
metricsTag
,
"stats"
,
"wgs"
).
isDefined
val
rnaExecuted
=
summary
.
getValue
(
sampleId
,
libId
,
metricsTag
,
"stats"
,
"rna"
).
isDefined
//val pipelineId: Int = summary.getPipelineId(runId, metricsTag).map(_.get)
val
insertsizeMetrics
=
summary
.
getValue
(
sampleId
,
libId
,
metricsTag
,
"stats"
,
"CollectInsertSizeMetrics"
,
"metrics"
)
match
{
case
Some
(
None
)
=>
false
case
Some
(
_
)
=>
true
case
_
=>
false
}
val
wgsExecuted
=
summary
.
getStatsSize
(
runId
,
Right
(
metricsTag
),
Some
(
Right
(
"wgs"
)),
sample
=
sampleId
.
map
(
Left
(
_
)),
library
=
libId
.
map
(
Left
(
_
)))
>=
1
val
rnaExecuted
=
summary
.
getStatsSize
(
runId
,
Right
(
metricsTag
),
Some
(
Right
(
"rna"
)),
sample
=
sampleId
.
map
(
Left
(
_
)),
library
=
libId
.
map
(
Left
(
_
)))
>=
1
val
insertsizeMetrics
=
summary
.
getStatKeys
(
runId
,
Right
(
metricsTag
),
Some
(
Right
(
"CollectInsertSizeMetrics"
)),
sample
=
sampleId
.
map
(
Left
(
_
)),
library
=
libId
.
map
(
Left
(
_
)),
Map
(
"metrics"
->
List
(
"metrics"
)))
.
exists
(
_
.
_2
.
isDefined
)
val
targetSettings
=
summary
.
getSettingKeys
(
runId
,
Right
(
metricsTag
),
None
,
sample
=
sampleId
.
map
(
Left
(
_
)),
library
=
libId
.
map
(
Left
(
_
)),
Map
(
"amplicon_name"
->
List
(
"amplicon_name"
),
"roi_name"
->
List
(
"roi_name"
)))
val
targets
=
(
summary
.
getValue
(
sampleId
,
libId
,
metricsTag
,
"s
ettings
"
,
"amplicon_name"
),
summary
.
getValue
(
sampleId
,
libId
,
metricsTag
,
"s
ettings
"
,
"roi_name"
)
targetS
ettings
(
"amplicon_name"
),
targetS
ettings
(
"roi_name"
)
)
match
{
case
(
Some
(
amplicon
:
String
),
Some
(
roi
:
List
[
_
]))
=>
amplicon
::
roi
.
map
(
_
.
toString
)
case
(
_
,
Some
(
roi
:
List
[
_
]))
=>
roi
.
map
(
_
.
toString
)
...
...
@@ -108,44 +115,42 @@ object BammetricsReport extends ReportBuilder {
*/
def
alignmentSummaryPlot
(
outputDir
:
File
,
prefix
:
String
,
summary
:
Summary
,
summary
:
Summary
Db
,
libraryLevel
:
Boolean
=
false
,
sampleId
:
Option
[
String
]
=
None
)
:
Unit
=
{
sampleId
:
Option
[
Int
]
=
None
)
:
Unit
=
{
val
tsvFile
=
new
File
(
outputDir
,
prefix
+
".tsv"
)
val
pngFile
=
new
File
(
outputDir
,
prefix
+
".png"
)
val
tsvWriter
=
new
PrintWriter
(
tsvFile
)
if
(
libraryLevel
)
tsvWriter
.
print
(
"Library"
)
else
tsvWriter
.
print
(
"Sample"
)
tsvWriter
.
println
(
"\tMapped\tDuplicates\tUnmapped\tSecondary"
)
def
getLine
(
summary
:
Summary
,
sample
:
String
,
lib
:
Option
[
String
]
=
None
)
:
String
=
{
val
mapped
=
new
SummaryValue
(
List
(
"bammetrics"
,
"stats"
,
"bamstats"
,
"flagstats"
,
"Mapped"
),
summary
,
Some
(
sample
),
lib
).
value
.
getOrElse
(
0
).
toString
.
toLong
val
duplicates
=
new
SummaryValue
(
List
(
"bammetrics"
,
"stats"
,
"bamstats"
,
"flagstats"
,
"Duplicates"
),
summary
,
Some
(
sample
),
lib
).
value
.
getOrElse
(
0
).
toString
.
toLong
val
total
=
new
SummaryValue
(
List
(
"bammetrics"
,
"stats"
,
"bamstats"
,
"flagstats"
,
"All"
),
summary
,
Some
(
sample
),
lib
).
value
.
getOrElse
(
0
).
toString
.
toLong
val
secondary
=
new
SummaryValue
(
List
(
"bammetrics"
,
"stats"
,
"bamstats"
,
"flagstats"
,
"NotPrimaryAlignment"
),
summary
,
Some
(
sample
),
lib
).
value
.
getOrElse
(
0
).
toString
.
toLong
val
statsPaths
=
Map
(
"Mapped"
->
List
(
"flagstats"
,
"Mapped"
),
"Duplicates"
->
List
(
"flagstats"
,
"Duplicates"
),
"All"
->
List
(
"flagstats"
,
"All"
),
"NotPrimaryAlignment"
->
List
(
"flagstats"
,
"NotPrimaryAlignment"
)
)
val
results
:
Map
[(
Int
,
Option
[
Int
])
,
Map
[
String
,
Option
[
Any
]]]
=
if
(
libraryLevel
)
{
summary
.
getStatsForLibraries
(
runId
,
Right
(
"bammetrics"
),
Some
(
Right
(
"bamstats"
)),
sampleId
=
sampleId
,
keyValues
=
statsPaths
).
map
(
x
=>
(
x
.
_1
.
_1
,
Some
(
x
.
_1
.
_2
))
->
x
.
_2
)
}
else
summary
.
getStatsForSamples
(
runId
,
Right
(
"bammetrics"
),
Some
(
Right
(
"bamstats"
)),
sample
=
sampleId
.
map
(
Left
(
_
)),
keyValues
=
statsPaths
).
map
(
x
=>
(
x
.
_1
,
None
)
->
x
.
_2
)
for
(((
s
,
l
),
result
)
<-
results
)
{
val
sampleName
:
String
=
summary
.
getSampleName
(
s
).
map
(
_
.
get
)
val
libName
:
Option
[
String
]
=
l
.
flatMap
(
x
=>
Await
.
result
(
summary
.
getLibraryName
(
x
),
Duration
.
Inf
))
val
sb
=
new
StringBuffer
()
if
(
lib
.
isDefined
)
sb
.
append
(
sample
+
"-"
+
lib
.
get
+
"\t"
)
else
sb
.
append
(
sample
+
"\t"
)
if
(
libName
.
isDefined
)
sb
.
append
(
sampleName
+
"-"
+
libName
.
get
+
"\t"
)
else
sb
.
append
(
sampleName
+
"\t"
)
val
mapped
=
ConfigUtils
.
any2long
(
result
(
"Mapped"
))
val
duplicates
=
ConfigUtils
.
any2long
(
result
(
"Duplicates"
))
val
total
=
ConfigUtils
.
any2long
(
result
(
"All"
))
val
secondary
=
ConfigUtils
.
any2long
(
result
(
"NotPrimaryAlignment"
))
sb
.
append
((
mapped
-
duplicates
-
secondary
)
+
"\t"
)
sb
.
append
(
duplicates
+
"\t"
)
sb
.
append
((
total
-
mapped
)
+
"\t"
)
sb
.
append
(
secondary
)
sb
.
toString
}
if
(
libraryLevel
)
{
for
(
sample
<-
summary
.
samples
if
sampleId
.
isEmpty
||
sample
==
sampleId
.
get
;
lib
<-
summary
.
libraries
(
sample
)
)
{
tsvWriter
.
println
(
getLine
(
summary
,
sample
,
Some
(
lib
)))
}
}
else
{
for
(
sample
<-
summary
.
samples
if
sampleId
.
isEmpty
||
sample
==
sampleId
.
get
)
{
tsvWriter
.
println
(
getLine
(
summary
,
sample
))
}
tsvWriter
.
println
(
sb
.
toString
)
}
tsvWriter
.
close
()
...
...
@@ -155,12 +160,56 @@ object BammetricsReport extends ReportBuilder {
plot
.
output
=
pngFile
plot
.
ylabel
=
Some
(
"Reads"
)
if
(
libraryLevel
)
{
plot
.
width
=
Some
(
200
+
(
summary
.
libraries
.
filter
(
s
=>
sampleId
.
getOrElse
(
s
.
_1
)
==
s
.
_1
).
foldLeft
(
0
)(
_
+
_
.
_2
.
size
)
*
10
)
)
}
else
plot
.
width
=
Some
(
200
+
(
summary
.
samples
.
count
(
s
=>
sampleId
.
getOrElse
(
s
)
==
s
)
*
10
))
plot
.
width
=
Some
(
200
+
(
libraries
.
filter
(
s
=>
sampleId
.
getOrElse
(
s
.
id
)
==
s
.
id
)
.
size
)
*
10
)
}
else
plot
.
width
=
Some
(
200
+
(
samples
.
count
(
s
=>
sampleId
.
getOrElse
(
s
)
==
s
)
*
10
))
plot
.
title
=
Some
(
"Aligned reads"
)
plot
.
runLocal
()
}
def
writePlotFromSummary
(
outputDir
:
File
,
prefix
:
String
,
summary
:
SummaryDb
,
libraryLevel
:
Boolean
=
false
,
sampleId
:
Option
[
Int
]
=
None
,
libraryId
:
Option
[
Int
]
=
None
,
statsPaths
:
Map
[
String
,
List
[
String
]],
xKey
:
String
,
yKey
:
String
,
pipeline
:
Either
[
Int
,
String
],
module
:
Option
[
Either
[
Int
,
String
]],
xlabel
:
Option
[
String
]
=
None
,
ylabel
:
Option
[
String
]
=
None
,
title
:
Option
[
String
]
=
None
,
removeZero
:
Boolean
=
true
)
:
Unit
=
{
val
tsvFile
=
new
File
(
outputDir
,
prefix
+
".tsv"
)
val
pngFile
=
new
File
(
outputDir
,
prefix
+
".png"
)
val
results
:
Map
[(
Int
,
Option
[
Int
])
,
Map
[
String
,
Option
[
Array
[
Any
]]]]
=
if
(
libraryLevel
)
{
summary
.
getStatsForLibraries
(
runId
,
pipeline
,
module
,
sampleId
=
sampleId
,
keyValues
=
statsPaths
)
.
map
(
x
=>
(
x
.
_1
.
_1
,
Some
(
x
.
_1
.
_2
))
->
x
.
_2
.
map
(
x
=>
x
.
_1
->
x
.
_2
.
map
(
ConfigUtils
.
any2list
(
_
).
toArray
)))
}
else
summary
.
getStatsForSamples
(
runId
,
pipeline
,
module
,
sample
=
sampleId
.
map
(
Left
(
_
)),
keyValues
=
statsPaths
)
.
map
(
x
=>
(
x
.
_1
,
None
)
->
x
.
_2
.
map
(
x
=>
x
.
_1
->
x
.
_2
.
map
(
ConfigUtils
.
any2list
(
_
).
toArray
)))
val
tables
:
Array
[
Map
[
String
,
Array
[
Any
]]]
=
results
.
map
{
case
((
sample
,
library
),
map
)
=>
val
sampleName
=
Await
.
result
(
summary
.
getSampleName
(
sample
),
Duration
.
Inf
)
.
getOrElse
(
throw
new
IllegalStateException
(
"Sample must be there"
))
val
libraryName
=
library
.
flatMap
(
l
=>
Await
.
result
(
summary
.
getLibraryName
(
l
),
Duration
.
Inf
))
Map
(
yKey
->
map
(
yKey
).
getOrElse
(
Array
()),