Commit 12a6539a authored by Peter van 't Hof's avatar Peter van 't Hof

Prevent double adding

parent 159c6184
...@@ -32,6 +32,8 @@ trait Summarizable { ...@@ -32,6 +32,8 @@ trait Summarizable {
/** Can be used to add additional Summarizable, this is executed at the start of WriteSummary*/ /** Can be used to add additional Summarizable, this is executed at the start of WriteSummary*/
def addToQscriptSummary(qscript: SummaryQScript) {} def addToQscriptSummary(qscript: SummaryQScript) {}
private[summary] var addToQscriptSummaryDone = false
/** /**
* This function is used to merge value that are found at the same path in the map. Default there will throw a exception at conflicting values. * This function is used to merge value that are found at the same path in the map. Default there will throw a exception at conflicting values.
* @param v1 Value of new map * @param v1 Value of new map
......
...@@ -55,32 +55,6 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript => ...@@ -55,32 +55,6 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript =>
case _ => throw new IllegalStateException("Root should be a SummaryQScript") case _ => throw new IllegalStateException("Root should be a SummaryQScript")
} }
/**
* Add a module to summary for this pipeline
*
* Auto detect sample and library from pipeline
*
* @param summarizable summarizable to add to summary for this pipeline
* @param name Name of module
*/
def addSummarizable(summarizable: Summarizable, name: String): Unit = {
this match {
case tag: SampleLibraryTag => addSummarizable(summarizable, name, tag.sampleId, tag.libId)
case _ => addSummarizable(summarizable, name, None, None)
}
}
/**
* Add a module to summary for this pipeline
*
* @param summarizable summarizable to add to summary for this pipeline
* @param name Name of module
* @param sampleId Id of sample
*/
def addSummarizable(summarizable: Summarizable, name: String, sampleId: Option[String]): Unit = {
addSummarizable(summarizable, name, sampleId, None)
}
/** /**
* Add a module to summary for this pipeline * Add a module to summary for this pipeline
* *
...@@ -88,10 +62,19 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript => ...@@ -88,10 +62,19 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript =>
* @param name Name of module * @param name Name of module
* @param sampleId Id of sample * @param sampleId Id of sample
* @param libraryId Id of libary * @param libraryId Id of libary
* @param forceSingle If true it replaces summarizable instead of adding to it
*/ */
def addSummarizable(summarizable: Summarizable, name: String, sampleId: Option[String], libraryId: Option[String]): Unit = { def addSummarizable(summarizable: Summarizable, name: String,
if (libraryId.isDefined) require(sampleId.isDefined) // Library always require a sample sampleId: Option[String] = None,
summarizables += (name, sampleId, libraryId) -> (summarizable :: summarizables.getOrElse((name, sampleId, libraryId), Nil)) libraryId: Option[String] = None,
forceSingle: Boolean = false): Unit = {
val (sId, lId) = this match {
case tag: SampleLibraryTag => (tag.sampleId, tag.libId)
case _ => (sampleId, libraryId)
}
if (lId.isDefined) require(sId.isDefined) // Library always require a sample
if (forceSingle) summarizables = summarizables.filterNot(_._1 == (name, sId, lId))
summarizables += (name, sId, lId) -> (summarizable :: summarizables.getOrElse((name, sId, lId), Nil))
} }
/** Add an other qscript to merge in output summary */ /** Add an other qscript to merge in output summary */
......
...@@ -53,7 +53,10 @@ class WriteSummary(val parent: SummaryQScript) extends InProcessFunction with Co ...@@ -53,7 +53,10 @@ class WriteSummary(val parent: SummaryQScript) extends InProcessFunction with Co
} }
def init(): Unit = { def init(): Unit = {
qscript.summarizables.foreach(_._2.foreach(_.addToQscriptSummary(qscript))) qscript.summarizables.foreach(_._2.foreach { s =>
if (!s.addToQscriptSummaryDone) s.addToQscriptSummary(qscript)
s.addToQscriptSummaryDone = true
})
val db = SummaryDb.openSqliteSummary(qscript.summaryDbFile) val db = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
if (qscript == root) { // This initialize the database if (qscript == root) { // This initialize the database
......
...@@ -98,18 +98,18 @@ class CollectMultipleMetrics(val parent: Configurable) extends Picard with Summa ...@@ -98,18 +98,18 @@ class CollectMultipleMetrics(val parent: Configurable) extends Picard with Summa
.foreach { p => .foreach { p =>
p match { p match {
case _ if p == Programs.CollectAlignmentSummaryMetrics.toString => case _ if p == Programs.CollectAlignmentSummaryMetrics.toString =>
qscript.addSummarizable(summarizable(() => Picard.getMetrics(new File(outputName + ".alignment_summary_metrics"), groupBy = Some("CATEGORY"))), p) qscript.addSummarizable(summarizable(() => Picard.getMetrics(new File(outputName + ".alignment_summary_metrics"), groupBy = Some("CATEGORY"))), p, forceSingle = true)
case _ if p == Programs.CollectInsertSizeMetrics.toString => case _ if p == Programs.CollectInsertSizeMetrics.toString =>
qscript.addSummarizable(summarizable(() => Map( qscript.addSummarizable(summarizable(() => Map(
"metrics" -> Picard.getMetrics(new File(outputName + ".insert_size_metrics")), "metrics" -> Picard.getMetrics(new File(outputName + ".insert_size_metrics")),
"histogram" -> Picard.getHistogram(new File(outputName + ".insert_size_metrics")) "histogram" -> Picard.getHistogram(new File(outputName + ".insert_size_metrics"))
)), p) )), p, forceSingle = true)
case _ if p == Programs.QualityScoreDistribution.toString => case _ if p == Programs.QualityScoreDistribution.toString =>
qscript.addSummarizable(summarizable(() => Picard.getHistogram(new File(outputName + ".quality_distribution_metrics"))), p) qscript.addSummarizable(summarizable(() => Picard.getHistogram(new File(outputName + ".quality_distribution_metrics"))), p, forceSingle = true)
case _ if p == Programs.MeanQualityByCycle.toString => case _ if p == Programs.MeanQualityByCycle.toString =>
qscript.addSummarizable(summarizable(() => Picard.getHistogram(new File(outputName + ".quality_by_cycle_metrics"))), p) qscript.addSummarizable(summarizable(() => Picard.getHistogram(new File(outputName + ".quality_by_cycle_metrics"))), p, forceSingle = true)
case _ if p == Programs.CollectBaseDistributionByCycle.toString => case _ if p == Programs.CollectBaseDistributionByCycle.toString =>
qscript.addSummarizable(summarizable(() => Picard.getHistogram(new File(outputName + ".base_distribution_by_cycle_metrics"), tag = "METRICS CLASS")), p) qscript.addSummarizable(summarizable(() => Picard.getHistogram(new File(outputName + ".base_distribution_by_cycle_metrics"), tag = "METRICS CLASS")), p, forceSingle = true)
case _ => None case _ => None
} }
} }
......
...@@ -78,7 +78,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { ...@@ -78,7 +78,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
List("Reference" -> ReportPage(List(), List( List("Reference" -> ReportPage(List(), List(
"Reference" -> ReportSection("/nl/lumc/sasc/biopet/core/report/reference.ssp", Map("pipeline" -> pipelineName)) "Reference" -> ReportSection("/nl/lumc/sasc/biopet/core/report/reference.ssp", Map("pipeline" -> pipelineName))
), Map()), ), Map()),
"Files" -> filesPage, "Files" -> filesPage(),
"Versions" -> ReportPage(List(), List("Executables" -> ReportSection("/nl/lumc/sasc/biopet/core/report/executables.ssp" "Versions" -> ReportPage(List(), List("Executables" -> ReportSection("/nl/lumc/sasc/biopet/core/report/executables.ssp"
)), Map()) )), Map())
), ),
...@@ -112,7 +112,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { ...@@ -112,7 +112,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
} }
/** Files page, can be used general or at sample level */ /** Files page, can be used general or at sample level */
def filesPage: ReportPage = { def filesPage(sampleId: Option[Int] = None, libraryId: Option[Int] = None): ReportPage = {
val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Right("flexiprep"), Some(None), mustHaveLibrary = true), Duration.Inf) >= 1 val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Right("flexiprep"), Some(None), mustHaveLibrary = true), Duration.Inf) >= 1
ReportPage(List(), Nil, Map()) ReportPage(List(), Nil, Map())
...@@ -140,7 +140,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { ...@@ -140,7 +140,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
"Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp" "Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
)), Map())) )), Map()))
else Nil) ++ else Nil) ++
List("Files" -> filesPage List("Files" -> filesPage()
), List( ), List(
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp", "Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
Map("showPlot" -> true)), Map("showPlot" -> true)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment