From 74d3c3a9641d99ace7e615ba138518ca6c9b74a0 Mon Sep 17 00:00:00 2001 From: Peter van 't Hof Date: Tue, 21 Feb 2017 15:45:10 +0100 Subject: [PATCH] Fixed compile issues --- .../pipelines/bammetrics/insertSize.ssp | 2 +- .../bammetrics/BammetricsReport.scala | 212 +++++++----------- .../pipelines/mapping/MappingReport.scala | 14 +- .../mapping/MultisampleMappingReport.scala | 54 +++-- .../biopet/pipelines/shiva/ShivaReport.scala | 75 +++---- .../pipelines/tinycap/TinyCapReport.scala | 12 - 6 files changed, 158 insertions(+), 211 deletions(-) diff --git a/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp b/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp index 1b26934ca..1bf50b4eb 100644 --- a/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp +++ b/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp @@ -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, libraryId = libId) }#
diff --git a/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala b/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala index 54ce73424..622daaad9 100644 --- a/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala +++ b/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala @@ -132,12 +132,11 @@ object BammetricsReport extends ReportBuilder { "NotPrimaryAlignment" -> List("flagstats", "NotPrimaryAlignment") ) - val pipelineId: Int = summary.getPipelineId(runId, "bammetrics").map(_.get) - val moduleId: Option[Int] = summary.getmoduleId(runId, "bamstats", pipelineId) - val results: Map[(Int, Option[Int]), Map[String, Option[Any]]] = if (libraryLevel) { - summary.getStatsForLibraries(runId = runId, pipelineName = "bammetrics", moduleName = Some("bamstats"), sampleId = sampleId, keyValues = statsPaths).map(x => (x._1._1, Some(x._1._2)) -> x._2) - } else summary.getStatsForSamples(runId, pipelineId, moduleId, sample = sampleId, keyValues = statsPaths).map(x => (x._1, None) -> x._2) + 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) @@ -168,6 +167,49 @@ object BammetricsReport extends ReportBuilder { 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()), + (sampleName + libraryName.map("-" + _)getOrElse("")) -> map(xKey).getOrElse(Array()) + ) + }.toArray + + writeTableToTsv(tsvFile, mergeTables(tables, yKey), yKey) + + LinePlot(tsvFile, pngFile, + xlabel = xlabel, + ylabel = ylabel, + title = title, + removeZero = removeZero).runLocal() + } + /** * Generate a line plot for insertsize * @@ -182,36 +224,15 @@ object BammetricsReport extends ReportBuilder { summary: SummaryDb, libraryLevel: Boolean = false, sampleId: Option[Int] = None, - libId: Option[Int] = None): Unit = { - val tsvFile = new File(outputDir, prefix + ".tsv") - val pngFile = new File(outputDir, prefix + ".png") - + libraryId: Option[Int] = None): Unit = { val statsPaths = Map( "insert_size" -> List("histogram", "insert_size"), - "All_Reads.fr_count" -> List("histogram", "All_Reads.fr_count") + "count" -> List("histogram", "All_Reads.fr_count") ) - val pipelineId: Int = summary.getPipelineId(runId, "bammetrics").map(_.get) - val moduleId: Option[Int] = summary.getmoduleId(runId, "CollectInsertSizeMetrics", pipelineId) - - val results: Map[(Int, Option[Int]), Map[String, Option[Array[Any]]]] = if (libraryLevel) { - summary.getStatsForLibraries(runId, pipelineId, moduleId, 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, pipelineId, moduleId, sample = sampleId, keyValues = statsPaths) - .map(x => (x._1, None) -> x._2.map(x => x._1 -> x._2.map(ConfigUtils.any2list(_).toArray))) - - val tables = getSampleLibraries(summary, sampleId, libId, libraryLevel) - .map { - case (sample, lib) => - getTableFromSummary(summary, paths(lib.map(l => s"$sample-$l").getOrElse(sample)), Some(sample), lib) - } - writeTableToTsv(tsvFile, mergeTables(tables.toArray, "insert_size"), "insert_size") - - LinePlot(tsvFile, pngFile, - xlabel = Some("Insert size"), - ylabel = Some("Reads"), - title = Some("Insert size"), - removeZero = true).runLocal() + writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId,statsPaths, + "insert_size", "count", Right("bammetrics"), Some(Right("CollectInsertSizeMetrics")), + "Insert size", "Reads", "Insert size") } def mappingQualityPlot(outputDir: File, @@ -219,27 +240,15 @@ object BammetricsReport extends ReportBuilder { summary: SummaryDb, libraryLevel: Boolean = false, sampleId: Option[Int] = None, - libId: Option[Int] = None): Unit = { - val tsvFile = new File(outputDir, prefix + ".tsv") - val pngFile = new File(outputDir, prefix + ".png") - - def paths(name: String) = Map( - "mapping_quality" -> List("bammetrics", "stats", "bamstats", "mapping_quality", "histogram", "values"), - name -> List("bammetrics", "stats", "bamstats", "mapping_quality", "histogram", "counts") + libraryId: Option[Int] = None): Unit = { + val statsPaths = Map( + "mapping_quality" -> List("mapping_quality", "histogram", "values"), + "count" -> List("mapping_quality", "histogram", "counts") ) - val tables = getSampleLibraries(summary, sampleId, libId, libraryLevel) - .map { - case (sample, lib) => - getTableFromSummary(summary, paths(lib.map(l => s"$sample-$l").getOrElse(sample)), Some(sample), lib) - } - writeTableToTsv(tsvFile, mergeTables(tables.toArray, "mapping_quality"), "mapping_quality") - - LinePlot(tsvFile, pngFile, - xlabel = Some("Mapping Quality"), - ylabel = Some("Reads"), - title = Some("Mapping Quality"), - removeZero = true).runLocal() + writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths, + "mapping_quality", "count", Right("bammetrics"), Some(Right("bamstats")), + "Mapping quality", "Reads", "Mapping quality") } def clippingPlot(outputDir: File, @@ -247,27 +256,15 @@ object BammetricsReport extends ReportBuilder { summary: SummaryDb, libraryLevel: Boolean = false, sampleId: Option[Int] = None, - libId: Option[Int] = None): Unit = { - val tsvFile = new File(outputDir, prefix + ".tsv") - val pngFile = new File(outputDir, prefix + ".png") - - def paths(name: String) = Map( - "clipping" -> List("bammetrics", "stats", "bamstats", "clipping", "histogram", "values"), - name -> List("bammetrics", "stats", "bamstats", "clipping", "histogram", "counts") + libraryId: Option[Int] = None): Unit = { + val statsPaths = Map( + "clipping" -> List("clipping", "histogram", "values"), + "count" -> List("clipping", "histogram", "counts") ) - val tables = getSampleLibraries(summary, sampleId, libId, libraryLevel) - .map { - case (sample, lib) => - getTableFromSummary(summary, paths(lib.map(l => s"$sample-$l").getOrElse(sample)), Some(sample), lib) - } - writeTableToTsv(tsvFile, mergeTables(tables.toArray, "clipping"), "clipping") - - LinePlot(tsvFile, pngFile, - xlabel = Some("Clipping"), - ylabel = Some("Reads"), - title = Some("Clipping"), - removeZero = true).runLocal() + writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths, + "clipping", "count", Right("bammetrics"), Some(Right("bamstats")), + "Clipping", "Reads", "Clipping") } /** @@ -284,27 +281,15 @@ object BammetricsReport extends ReportBuilder { summary: SummaryDb, libraryLevel: Boolean = false, sampleId: Option[Int] = None, - libId: Option[Int] = None): Unit = { - val tsvFile = new File(outputDir, prefix + ".tsv") - val pngFile = new File(outputDir, prefix + ".png") - - def paths(name: String) = Map( - "coverage" -> List("bammetrics", "stats", "wgs", "histogram", "coverage"), - name -> List("bammetrics", "stats", "wgs", "histogram", "count") + libraryId: Option[Int] = None): Unit = { + val statsPaths = Map( + "coverage" -> List("wgs", "histogram", "coverage"), + "count" -> List("wgs", "histogram", "count") ) - val tables = getSampleLibraries(summary, sampleId, libId, libraryLevel) - .map { - case (sample, lib) => - getTableFromSummary(summary, paths(lib.map(l => s"$sample-$l").getOrElse(sample)), Some(sample), lib) - } - writeTableToTsv(tsvFile, mergeTables(tables.toArray, "coverage"), "coverage") - - LinePlot(tsvFile, pngFile, - xlabel = Some("Coverage"), - ylabel = Some("Bases"), - title = Some("Whole genome coverage"), - removeZero = true).runLocal() + writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths, + "coverage", "count", Right("bammetrics"), Some(Right("wgs")), + "Coverage", "Bases", "Whole genome coverage") } /** @@ -320,51 +305,16 @@ object BammetricsReport extends ReportBuilder { prefix: String, summary: SummaryDb, libraryLevel: Boolean = false, - sampleId: Option[String] = None, - libId: Option[String] = None): Unit = { - val tsvFile = new File(outputDir, prefix + ".tsv") - val pngFile = new File(outputDir, prefix + ".png") - - def paths(name: String) = Map( - "normalized_position" -> List("bammetrics", "stats", "rna", "histogram", "normalized_position"), - name -> List("bammetrics", "stats", "rna", "histogram", "All_Reads.normalized_coverage") + sampleId: Option[Int] = None, + libraryId: Option[Int] = None): Unit = { + val statsPaths = Map( + "position" -> List("rna", "histogram", "normalized_position"), + "count" -> List("rna", "histogram", "All_Reads.normalized_coverage") ) - val tables = getSampleLibraries(summary, sampleId, libId, libraryLevel) - .map { - case (sample, lib) => - getTableFromSummary(summary, paths(lib.map(l => s"$sample-$l").getOrElse(sample)), Some(sample), lib) - } - writeTableToTsv(tsvFile, mergeTables(tables.toArray, "normalized_position"), "normalized_position") - - LinePlot(tsvFile, pngFile, - xlabel = Some("Relative position"), - ylabel = Some("Coverage"), - title = Some("Rna coverage"), - removeZero = true).runLocal() - } - - private def getSampleLibraries(summary: SummaryDb, - sampleId: Option[Int] = None, - LibId: Option[Int] = None, - libraryLevel: Boolean = false): List[(Int, Option[Int])] = { - if (LibId.isDefined) require(sampleId.isDefined) - if (libraryLevel || LibId.isDefined) - for ((sample, libs) <- summary.libraries.toList; lib <- libs) yield (sample, Some(lib)) - else for ((sample, libs) <- summary.libraries.toList) yield (sample, None) - } - - def getTableFromSummary(summary: SummaryDb, - paths: Map[String, List[String]], - sampleId: Option[Int] = None, - libId: Option[Int] = None): Map[String, Array[Any]] = { - val pathValues: Map[String, Array[Any]] = paths.map { - case (key, path) => - val value = summary.getValueAsArray(sampleId, libId, path: _*) - key -> value.getOrElse(Array()) - } - require(pathValues.map(_._2.size).toList.distinct.size == 1, s"Arrays in summary does not have the same number of values, $paths") - pathValues + writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths, + "coverage", "count", Right("bammetrics"), Some(Right("rna")), + "Relative position", "Coverage", "Rna coverage") } def mergeTables(tables: Array[Map[String, Array[Any]]], diff --git a/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingReport.scala b/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingReport.scala index dd74e89d9..26b964d93 100644 --- a/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingReport.scala +++ b/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingReport.scala @@ -19,6 +19,9 @@ import nl.lumc.sasc.biopet.core.report._ import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport +import scala.concurrent.Await +import scala.concurrent.duration.Duration + class MappingReport(val parent: Configurable) extends ReportBuilderExtension { def builder = MappingReport } @@ -35,12 +38,17 @@ object MappingReport extends ReportBuilder { override def extFiles = super.extFiles ++ List("js/gears.js", "js/krona-2.0.js", "img/krona/loading.gif", "img/krona/hidden.png", "img/krona/favicon.ico") .map(x => ExtFile("/nl/lumc/sasc/biopet/pipelines/gears/report/ext/" + x, x)) - def krakenExecuted = summary.getValue(sampleId, libId, "gears", "stats", "krakenreport").isDefined + summary.getStatsSize(runId, Right("gears"), Some(Right("krakenreport")), + sample = sampleId.map(Left(_)), library = libId.map(Left(_))) + def krakenExecuted: Boolean = Await.result(summary.getStatsSize(runId, Right("gears"), Some(Right("krakenreport")), + sample = sampleId.map(Left(_)), library = libId.map(Left(_))), Duration.Inf) >= 1 /** Root page for single BamMetrcis report */ def indexPage = { - val skipFlexiprep = summary.getValue(sampleId, libId, "mapping", "settings", "skip_flexiprep").getOrElse(false) == true - val bamMetricsPage = if (summary.getValue(sampleId, libId, "mapping", "settings", "skip_metrics").getOrElse(false) != true) { + val mappingSettings = summary.getSettingKeys(runId, Right("mapping"), None, sample = sampleId.map(Left(_)), library = libId.map(Left(_)), + keyValues = Map("skip_flexiprep" -> List("skip_flexiprep"), "skip_metrics" -> List("skip_metrics"))) + val skipFlexiprep = mappingSettings.get("skip_flexiprep").flatten.getOrElse(false) == true + val bamMetricsPage = if (mappingSettings.get("skip_metrics").flatten.getOrElse(false) == true) { Some(BammetricsReport.bamMetricsPage(summary, sampleId, libId)) } else None ReportPage((if (skipFlexiprep) Nil else List("QC" -> FlexiprepReport.flexiprepPage)) ::: diff --git a/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MultisampleMappingReport.scala b/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MultisampleMappingReport.scala index 279dc88c7..0c0d80d64 100644 --- a/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MultisampleMappingReport.scala +++ b/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/MultisampleMappingReport.scala @@ -14,11 +14,14 @@ */ package nl.lumc.sasc.biopet.pipelines.mapping -import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportSection, ReportPage, MultisampleReportBuilder } +import nl.lumc.sasc.biopet.core.report.{MultisampleReportBuilder, ReportBuilderExtension, ReportPage, ReportSection} import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport import nl.lumc.sasc.biopet.utils.config.Configurable +import scala.concurrent.Await +import scala.concurrent.duration.Duration + /** * Created by pjvanthof on 11/01/16. */ @@ -45,15 +48,20 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { /** Root page for the carp report */ def indexPage = { - val krakenExecuted = summary.getSampleValues("gearskraken", "stats", "krakenreport").values.forall(_.isDefined) - val centrifugeExecuted = summary.getSampleValues("gearscentrifuge", "stats", "centrifuge_report").values.forall(_.isDefined) - val wgsExecuted = summary.getSampleValues("bammetrics", "stats", "wgs").values.exists(_.isDefined) - val rnaExecuted = summary.getSampleValues("bammetrics", "stats", "rna").values.exists(_.isDefined) - val insertsizeExecuted = summary.getSampleValues("bammetrics", "stats", "CollectInsertSizeMetrics", "metrics").values.exists(_ != Some(None)) - val mappingExecuted = summary.getLibraryValues("mapping").exists(_._2.isDefined) - val pairedFound = !mappingExecuted || summary.getLibraryValues("mapping", "settings", "paired").exists(_._2 == Some(true)) - val flexiprepExecuted = summary.getLibraryValues("flexiprep") - .exists { case ((sample, lib), value) => value.isDefined } + val krakenExecuted = Await.result(summary.getStatsSize(runId, Right("gearskraken"), Some(Right("krakenreport")), + library = Some(None), mustHaveSample = true), Duration.Inf) >= 1 + val centrifugeExecuted = Await.result(summary.getStatsSize(runId, Right("gearscentrifuge"), Some(Right("centrifuge_report")), + library = Some(None), mustHaveSample = true), Duration.Inf) >= 1 + val wgsExecuted = Await.result(summary.getStatsSize(runId, Right("bammetrics"), Some(Right("wgs")), + library = Some(None), mustHaveSample = true), Duration.Inf) >= 1 + val rnaExecuted = Await.result(summary.getStatsSize(runId, Right("bammetrics"), Some(Right("rna")), + library = Some(None), mustHaveSample = true), Duration.Inf) >= 1 + val insertsizeExecuted = Await.result(summary.getStatsSize(runId, Right("bammetrics"), Some(Right("CollectInsertSizeMetrics")), + library = Some(None), mustHaveSample = true), Duration.Inf) >= 1 + val mappingExecuted = Await.result(summary.getStatsSize(runId, Right("mapping"), Some(None), mustHaveLibrary = true), Duration.Inf) >= 1 + val pairedFound = !mappingExecuted || summary.getSettingsForLibraries(runId, Right("mapping"), None, keyValues = Map("paired" -> List("paired"))) + .exists(_._2.exists(_._2 == Some(true))) + val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Right("flexiprep"), Some(None), mustHaveLibrary = true), Duration.Inf) >= 1 ReportPage( List("Samples" -> generateSamplesPage(pageArgs)) ++ @@ -105,8 +113,7 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { /** Files page, can be used general or at sample level */ def filesPage: ReportPage = { - val flexiprepExecuted = summary.getLibraryValues("flexiprep") - .exists { case ((sample, lib), value) => value.isDefined } + val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Right("flexiprep"), Some(None), mustHaveLibrary = true), Duration.Inf) >= 1 ReportPage(List(), (if (flexiprepExecuted) List( "Input fastq files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepInputfiles.ssp"), @@ -118,11 +125,13 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { } /** Single sample page */ - def samplePage(sampleId: String, args: Map[String, Any]): ReportPage = { - val krakenExecuted = summary.getValue(Some(sampleId), None, "gearskraken", "stats", "krakenreport").isDefined - val centrifugeExecuted = summary.getValue(Some(sampleId), None, "gearscentrifuge", "stats", "centrifuge_report").isDefined - val flexiprepExecuted = summary.getLibraryValues("flexiprep") - .exists { case ((sample, lib), value) => sample == sampleId && value.isDefined } + def samplePage(sampleId: Int, args: Map[String, Any]): ReportPage = { + val krakenExecuted = Await.result(summary.getStatsSize(runId, Right("gearskraken"), Some(Right("krakenreport")), + library = Some(None), sample = Some(Left(sampleId))), Duration.Inf) >= 1 + val centrifugeExecuted = Await.result(summary.getStatsSize(runId, Right("gearscentrifuge"), Some(Right("centrifuge_report")), + library = Some(None), sample = Some(Left(sampleId)), mustHaveSample = true), Duration.Inf) >= 1 + val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Right("flexiprep"), Some(None), + sample = Some(Left(sampleId)), mustHaveLibrary = true), Duration.Inf) >= 1 ReportPage(List( "Libraries" -> generateLibraryPage(args), @@ -149,10 +158,13 @@ trait MultisampleMappingReportTrait extends MultisampleReportBuilder { } /** Library page */ - def libraryPage(sampleId: String, libId: String, args: Map[String, Any]): ReportPage = { - val krakenExecuted = summary.getValue(Some(sampleId), Some(libId), "gearskraken", "stats", "krakenreport").isDefined - val centrifugeExecuted = summary.getValue(Some(sampleId), Some(libId), "gearscentrifuge", "stats", "centrifuge_report").isDefined - val flexiprepExecuted = summary.getValue(Some(sampleId), Some(libId), "flexiprep").isDefined + def libraryPage(sampleId: Int, libId: Int, args: Map[String, Any]): ReportPage = { + val krakenExecuted = Await.result(summary.getStatsSize(runId, Right("gearskraken"), Some(Right("krakenreport")), + library = Some(Left(libId)), sample = Some(Left(sampleId))), Duration.Inf) >= 1 + val centrifugeExecuted = Await.result(summary.getStatsSize(runId, Right("gearscentrifuge"), Some(Right("centrifuge_report")), + library = Some(Left(libId)), sample = Some(Left(sampleId)), mustHaveSample = true), Duration.Inf) >= 1 + val flexiprepExecuted = Await.result(summary.getStatsSize(runId, Right("flexiprep"), Some(None), library = Some(Left(libId)), + sample = Some(Left(sampleId)), mustHaveLibrary = true), Duration.Inf) >= 1 ReportPage( ("Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), Some(libId))) :: diff --git a/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala b/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala index 3bcc85dcc..ea6be6eca 100644 --- a/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala +++ b/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala @@ -14,13 +14,17 @@ */ package nl.lumc.sasc.biopet.pipelines.shiva -import java.io.{ File, PrintWriter } +import java.io.{File, PrintWriter} import nl.lumc.sasc.biopet.core.report._ import nl.lumc.sasc.biopet.pipelines.mapping.MultisampleMappingReportTrait import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.rscript.StackedBarPlot -import nl.lumc.sasc.biopet.utils.summary.{ Summary, SummaryValue } +import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb +import nl.lumc.sasc.biopet.utils.summary.{Summary, SummaryValue} + +import scala.concurrent.Await +import scala.concurrent.duration.Duration /** * With this extension the report is executed within a pipeline @@ -37,7 +41,8 @@ object ShivaReport extends ShivaReportTrait /** Trait for report generation for Shiva pipeline, this can be extended */ trait ShivaReportTrait extends MultisampleMappingReportTrait { - def variantcallingExecuted = summary.getValue("shiva", "settings", "multisample_variantcalling") match { + def variantcallingExecuted = summary.getSettingKeys(runId, Right("shiva"), None, keyValues = Map("multisample_variantcalling" -> List("multisample_variantcalling"))).get("multisample_variantcalling") + .flatten match { case Some(true) => true case _ => false } @@ -60,8 +65,8 @@ trait ShivaReportTrait extends MultisampleMappingReportTrait { /** Generate a page with all target coverage stats */ def regionsPage: Option[(String, ReportPage)] = { - val roi = summary.getValue("shiva", "settings", "regions_of_interest") - val amplicon = summary.getValue("shiva", "settings", "amplicon_bed") + val roi = summary.getSetting(runId, Right("shiva")).get("regions_of_interest") + val amplicon = summary.getSetting(runId, Right("shiva")).get("amplicon_bed") var regionPages: Map[String, ReportPage] = Map() @@ -108,7 +113,7 @@ trait ShivaReportTrait extends MultisampleMappingReportTrait { } /** Single sample page */ - override def samplePage(sampleId: String, args: Map[String, Any]): ReportPage = { + override def samplePage(sampleId: Int, args: Map[String, Any]): ReportPage = { val variantcallingSection = if (variantcallingExecuted) List("Variantcalling" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/sampleVariants.ssp")) else Nil val oldPage = super.samplePage(sampleId, args) oldPage.copy(sections = variantcallingSection ++ oldPage.sections) @@ -123,51 +128,37 @@ trait ShivaReportTrait extends MultisampleMappingReportTrait { * @param outputDir OutputDir for the tsv and png file * @param prefix Prefix of the tsv and png file * @param summary Summary class - * @param libraryLevel Default false, when set true plot will be based on library stats instead of sample stats * @param sampleId Default it selects all sampples, when sample is giving it limits to selected sample */ def variantSummaryPlot(outputDir: File, prefix: String, - summary: Summary, - libraryLevel: Boolean = false, - sampleId: Option[String] = None, + summary: SummaryDb, + sampleId: Option[Int] = None, caller: String = "final", target: Option[String] = 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("\tHomVar\tHet\tHomRef\tNoCall") - - def getLine(summary: Summary, sample: String, summarySample: Option[String], lib: Option[String] = None): String = { - val path = target match { - case Some(t) => List("shivavariantcalling", "stats", s"multisample-vcfstats-$caller-$t", "genotype", sample) - case _ => List("shivavariantcalling", "stats", s"multisample-vcfstats-$caller", "total", "genotype", "general", sample) - } - val homVar = new SummaryValue(path :+ "HomVar", summary, summarySample, lib).value.getOrElse(0).toString.toLong - val homRef = new SummaryValue(path :+ "HomRef", summary, summarySample, lib).value.getOrElse(0).toString.toLong - val noCall = new SummaryValue(path :+ "NoCall", summary, summarySample, lib).value.getOrElse(0).toString.toLong - val het = new SummaryValue(path :+ "Het", summary, summarySample, lib).value.getOrElse(0).toString.toLong - val sb = new StringBuffer() - if (lib.isDefined) sb.append(sample + "-" + lib.get + "\t") else sb.append(sample + "\t") - sb.append(homVar + "\t") - sb.append(het + "\t") - sb.append(homRef + "\t") - sb.append(noCall) - sb.toString + tsvWriter.print("Sample") + val field = List("HomVar", "Het", "HomRef", "NoCall") + tsvWriter.println(s"\t${field.mkString("\t")}") + + val samples = Await.result(summary.getSamples(runId = runId, sampleId = sampleId), Duration.Inf) + val statsPaths = { + (for (sample <- Await.result(summary.getSamples(runId = runId), Duration.Inf)) yield { + field.map(f => s"${sample.name};HomVar" -> List("total", "genotype", "general", sample.name, f)).toMap + }).fold(Map())(_ ++ _) + } + + val moduleName = target match { + case Some(t) => s"multisample-vcfstats-$caller-$t" + case _ => s"multisample-vcfstats-$caller" } - if (libraryLevel) { - for ( - sample <- summary.samples if sampleId.isEmpty || sample == sampleId.get; - lib <- summary.libraries(sample) - ) { - tsvWriter.println(getLine(summary, sample, sampleId, Some(lib))) - } - } else { - for (sample <- summary.samples if sampleId.isEmpty || sample == sampleId.get) { - tsvWriter.println(getLine(summary, sample, sampleId)) - } + val results = summary.getStatKeys(runId, Right("shivavariantcalling"), Some(Right(moduleName)), sampleId.map(Left(_)), keyValues = statsPaths) + + for (sample <- samples if sampleId.isEmpty || sample.id == sampleId.get) { + tsvWriter.println(sample.name + "\t" + field.map(f => results(s"${sample.name};$f").getOrElse("")).mkString("\t")) } tsvWriter.close() @@ -176,9 +167,7 @@ trait ShivaReportTrait extends MultisampleMappingReportTrait { plot.input = tsvFile plot.output = pngFile plot.ylabel = Some("VCF records") - 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 + (samples.count(s => sampleId.getOrElse(s) == s) * 10)) plot.runLocal() } } diff --git a/tinycap/src/main/scala/nl/lumc/sasc/biopet/pipelines/tinycap/TinyCapReport.scala b/tinycap/src/main/scala/nl/lumc/sasc/biopet/pipelines/tinycap/TinyCapReport.scala index 97e7ed3cc..d62d598f8 100644 --- a/tinycap/src/main/scala/nl/lumc/sasc/biopet/pipelines/tinycap/TinyCapReport.scala +++ b/tinycap/src/main/scala/nl/lumc/sasc/biopet/pipelines/tinycap/TinyCapReport.scala @@ -33,17 +33,5 @@ object TinyCapReport extends MultisampleMappingReportTrait { /** Front section for the report */ override def frontSection: ReportSection = ReportSection("/nl/lumc/sasc/biopet/pipelines/tinycap/tinycapFront.ssp") - override def additionalSections = List( - "Fragments per gene" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gentrap/measure_plotreport.ssp", - Map("pipelineName" -> pipelineName, - "plotName" -> "fragmentspergene", - "plotPath" -> summary.getValue("fragmentspergene", "files", "pipeline", "fragments_per_gene_heatmap", "path") - )), - "Fragments per microRNA" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gentrap/measure_plotreport.ssp", - Map("pipelineName" -> pipelineName, - "plotName" -> "fragmentspersmallrna", - "plotPath" -> summary.getValue("fragmentspersmallrna", "files", "pipeline", "fragments_per_smallrna_heatmap", "path"))) - ) - override def pipelineName = "tinycap" } -- GitLab