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 {
/** Can be used to add additional Summarizable, this is executed at the start of WriteSummary*/
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.
* @param v1 Value of new map
......
......@@ -55,32 +55,6 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript =>
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
*
......@@ -88,10 +62,19 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript =>
* @param name Name of module
* @param sampleId Id of sample
* @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 = {
if (libraryId.isDefined) require(sampleId.isDefined) // Library always require a sample
summarizables += (name, sampleId, libraryId) -> (summarizable :: summarizables.getOrElse((name, sampleId, libraryId), Nil))
def addSummarizable(summarizable: Summarizable, name: String,
sampleId: Option[String] = None,
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 */
......
......@@ -53,7 +53,10 @@ class WriteSummary(val parent: SummaryQScript) extends InProcessFunction with Co
}
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)
if (qscript == root) { // This initialize the database
......
......@@ -98,18 +98,18 @@ class CollectMultipleMetrics(val parent: Configurable) extends Picard with Summa
.foreach { p =>
p match {
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 =>
qscript.addSummarizable(summarizable(() => Map(
"metrics" -> Picard.getMetrics(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 =>
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 =>
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 =>
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
}
}
......
......@@ -78,7 +78,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
List("Reference" -> ReportPage(List(), List(
"Reference" -> ReportSection("/nl/lumc/sasc/biopet/core/report/reference.ssp", Map("pipeline" -> pipelineName))
), Map()),
"Files" -> filesPage,
"Files" -> filesPage(),
"Versions" -> ReportPage(List(), List("Executables" -> ReportSection("/nl/lumc/sasc/biopet/core/report/executables.ssp"
)), Map())
),
......@@ -112,7 +112,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
}
/** 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
ReportPage(List(), Nil, Map())
......@@ -140,7 +140,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder {
"Krona Plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
)), Map()))
else Nil) ++
List("Files" -> filesPage
List("Files" -> filesPage()
), List(
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
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