From 1d306afd2b248a9e666b939d01d4125e84eb17e5 Mon Sep 17 00:00:00 2001
From: Peter van 't Hof
Date: Wed, 24 Jun 2015 11:27:34 +0200
Subject: [PATCH] Added scala docs to report code
---
.../bammetrics/BammetricsReport.scala | 37 +++++++++++++++--
.../report/MultisampleReportBuilder.scala | 7 ++++
.../biopet/core/report/ReportBuilder.scala | 34 +++++++++++++---
.../sasc/biopet/core/report/ReportPage.scala | 4 ++
.../biopet/core/report/ReportSection.scala | 19 +++++----
.../pipelines/flexiprep/FlexiprepReport.scala | 40 ++++++++++++++-----
.../biopet/pipelines/shiva/ShivaReport.scala | 26 +++++++++---
7 files changed, 134 insertions(+), 33 deletions(-)
diff --git a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
index d12c307cb..aa2b635fb 100644
--- a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
+++ b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
@@ -6,17 +6,24 @@ import nl.lumc.sasc.biopet.core.report.{ ReportBuilder, ReportPage, ReportSectio
import nl.lumc.sasc.biopet.core.summary.{ SummaryValue, Summary }
import nl.lumc.sasc.biopet.extensions.rscript.{ XYPlot, StackedBarPlot }
+//TODO: Add basic report to BamMetrics as single pipeline
+
/**
* Created by pjvan_thof on 3/30/15.
*/
object BammetricsReport extends ReportBuilder {
- // FIXME: Not yet finished
+ /** Name of report */
val reportName = "Bam Metrics"
+ /** Root page for single BamMetrcis report */
def indexPage = ReportPage(List(), List(), Map())
- def bamMetricsPage(summary: Summary, sampleId: Option[String], libId: Option[String]) = {
+ /** Generates a page with alignment stats */
+ def bamMetricsPage(summary: Summary,
+ sampleId: Option[String],
+ libId: Option[String],
+ metricsTag: String = "bammetrics") = {
val targets = (
summary.getLibraryValue(sampleId, libId, "bammetrics", "settings", "amplicon_name"),
summary.getLibraryValue(sampleId, libId, "bammetrics", "settings", "roi_name")
@@ -35,10 +42,18 @@ object BammetricsReport extends ReportBuilder {
"Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp"),
"Insert Size" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp", Map("showPlot" -> true))
),
- Map()
+ Map("metricsTag" -> metricsTag)
)
}
+ /**
+ * Generate a stackbar plot for alignment stats
+ * @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 alignmentSummaryPlot(outputDir: File,
prefix: String,
summary: Summary,
@@ -94,6 +109,14 @@ object BammetricsReport extends ReportBuilder {
plot.runLocal()
}
+ /**
+ * Generate a line plot for insertsize
+ * @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 insertSizePlot(outputDir: File,
prefix: String,
summary: Summary,
@@ -174,6 +197,14 @@ object BammetricsReport extends ReportBuilder {
plot.runLocal()
}
+ /**
+ * Generate a line plot for wgs coverage
+ * @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 wgsHistogramPlot(outputDir: File,
prefix: String,
summary: Summary,
diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/MultisampleReportBuilder.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/MultisampleReportBuilder.scala
index 3b43b435b..98bc9225f 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/MultisampleReportBuilder.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/MultisampleReportBuilder.scala
@@ -4,22 +4,28 @@ package nl.lumc.sasc.biopet.core.report
* Created by pjvan_thof on 3/30/15.
*/
trait MultisampleReportBuilder extends ReportBuilder {
+
+ /** Method to generate a single sample page */
def samplePage(sampleId: String, args: Map[String, Any]): ReportPage
+ /** Default list of samples, can be override */
def samplesSections: List[(String, ReportSection)] = {
List(
("Samples", ReportSection("/nl/lumc/sasc/biopet/core/report/samplesList.ssp"))
)
}
+ /** Method to generate a single library page */
def libraryPage(sampleId: String, libraryId: String, args: Map[String, Any]): ReportPage
+ /** Default list of libraries, can be override */
def libririesSections: List[(String, ReportSection)] = {
List(
("Libraries", ReportSection("/nl/lumc/sasc/biopet/core/report/librariesList.ssp"))
)
}
+ /** Generate the samples page including a single sample page for each sample in the summary */
def generateSamplesPage(args: Map[String, Any]): ReportPage = {
val samplePages = summary.samples
.map(sampleId => (sampleId -> samplePage(sampleId, args ++ Map("sampleId" -> Some(sampleId)))))
@@ -27,6 +33,7 @@ trait MultisampleReportBuilder extends ReportBuilder {
ReportPage(samplePages, samplesSections, args)
}
+ /** Generate the libraries page for a single sample with a subpage for eacht library */
def generateLibraryPage(args: Map[String, Any]): ReportPage = {
val sampleId = args("sampleId") match {
case Some(x) => x.toString
diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala
index bf40c89ee..1f030352e 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala
@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.core.report
import java.io._
-import nl.lumc.sasc.biopet.core.{ ToolCommandFuntion, BiopetJavaCommandLineFunction, ToolCommand }
+import nl.lumc.sasc.biopet.core.{ ToolCommandFuntion, ToolCommand }
import nl.lumc.sasc.biopet.core.summary.Summary
import org.broadinstitute.gatk.utils.commandline.Input
import org.fusesource.scalate.{ TemplateSource, TemplateEngine }
@@ -13,13 +13,16 @@ import nl.lumc.sasc.biopet.utils.IoUtils
*/
trait ReportBuilderExtension extends ToolCommandFuntion {
+ /** Report builder object */
val builder: ReportBuilder
@Input(required = true)
var summaryFile: File = _
+ /** OutputDir for the report */
var outputDir: File = _
+ /** Arguments that are passed on the commandline */
var args: Map[String, String] = Map()
override def beforeGraph: Unit = {
@@ -28,6 +31,7 @@ trait ReportBuilderExtension extends ToolCommandFuntion {
javaMainClass = builder.getClass.getName.takeWhile(_ != '$')
}
+ /** Command to generate the report */
override def commandLine: String = {
super.commandLine +
required("--summary", summaryFile) +
@@ -52,15 +56,19 @@ trait ReportBuilder extends ToolCommand {
}
}
+ /** summary object internaly */
private var setSummary: Summary = _
+ /** Retrival of summary, read only */
final def summary = setSummary
+ /** default args that are passed to all page withing the report */
def pageArgs: Map[String, Any] = Map()
private var done = 0
private var total = 0
+ /** Main function to for building the report */
def main(args: Array[String]): Unit = {
logger.info("Start")
@@ -95,7 +103,7 @@ trait ReportBuilder extends ToolCommand {
logger.info("Parsing summary")
setSummary = new Summary(cmdArgs.summary)
- total = countPages(indexPage)
+ total = ReportBuilder.countPages(indexPage)
logger.info(total + " pages to be generated")
logger.info("Generate pages")
@@ -106,14 +114,21 @@ trait ReportBuilder extends ToolCommand {
logger.info(jobs + " Done")
}
+ /** This must be implemented, this will be the root page of the report */
def indexPage: ReportPage
+ /** This must be implemented, this will because the title of the report */
def reportName: String
- def countPages(page: ReportPage): Int = {
- page.subPages.map(x => countPages(x._2)).fold(1)(_ + _)
- }
-
+ /**
+ * This method will render the page and the subpages recursivly
+ * @param summary The summary object
+ * @param page Page to render
+ * @param outputDir Root output dir of the report
+ * @param path Path from root to current page
+ * @param args Args to add to this sub page, are args from current page are passed automaticly
+ * @return Number of pages including all subpages that are rendered
+ */
def generatePage(summary: Summary,
page: ReportPage,
outputDir: File,
@@ -151,10 +166,17 @@ trait ReportBuilder extends ToolCommand {
object ReportBuilder {
+ /** Single template render engine, this will have a cache for all compile templates */
protected val engine = new TemplateEngine()
+ /** Cache of temp file for templates from the classpath / jar */
private var templateCache: Map[String, File] = Map()
+ /** This will give the total number of pages including all nested pages */
+ def countPages(page: ReportPage): Int = {
+ page.subPages.map(x => countPages(x._2)).fold(1)(_ + _)
+ }
+
/**
* This method will render a template that is located in the classpath / jar
* @param location location in the classpath / jar
diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportPage.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportPage.scala
index 533c18384..2253d338f 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportPage.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportPage.scala
@@ -2,6 +2,10 @@ package nl.lumc.sasc.biopet.core.report
/**
* Created by pjvan_thof on 3/27/15.
+ *
+ * @param subPages Subpages for this page
+ * @param sections Sections for this page
+ * @param args Arguments for this page, this arguments get passed to all section and subpages
*/
case class ReportPage(subPages: List[(String, ReportPage)],
sections: List[(String, ReportSection)],
diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportSection.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportSection.scala
index a2a258f2a..53825b142 100644
--- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportSection.scala
+++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportSection.scala
@@ -2,15 +2,18 @@ package nl.lumc.sasc.biopet.core.report
/**
* Created by pjvan_thof on 4/8/15.
+ *
+ * @param location Location inside the classpath / jar
+ * @param args arguments only for current section, this is not passed to other sub pages
*/
case class ReportSection(location: String,
- args: Map[String, Any] = Map(),
- intro: Option[String] = None) {
-
- def render(args: Map[String, Any]): String = {
- (intro match {
- case Some(template) => ReportBuilder.renderTemplate(location, args ++ this.args)
- case _ => ""
- }) + ReportBuilder.renderTemplate(location, args ++ this.args)
+ args: Map[String, Any] = Map()) {
+ /**
+ * This method will render this section
+ * @param args Possible to give more arguments
+ * @return Rendered result for this section
+ */
+ def render(args: Map[String, Any] = Map()): String = {
+ ReportBuilder.renderTemplate(location, args ++ this.args)
}
}
diff --git a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala
index 5981f2a33..35eb027a2 100644
--- a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala
+++ b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala
@@ -6,21 +6,27 @@ import nl.lumc.sasc.biopet.core.report.{ ReportSection, ReportPage, ReportBuilde
import nl.lumc.sasc.biopet.core.summary.{ SummaryValue, Summary }
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot
+//TODO: add basic report to flexiprep as single pipeline
/**
* Created by pjvan_thof on 3/30/15.
*/
object FlexiprepReport extends ReportBuilder {
val reportName = "Flexiprep"
- def indexPage = ReportPage(List(
- "QC" -> flexiprepPage
- ), List(
- "Report" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepFront.ssp")
- ),
- Map()
- )
+ /** Index page for a flexiprep report */
+ def indexPage = {
+ val flexiprepPage = this.flexiprepPage
+ ReportPage(List(
+ "QC" -> flexiprepPage
+ ), List(
+ "Report" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepFront.ssp")
+ ) ::: flexiprepPage.sections,
+ Map()
+ )
+ }
- def flexiprepPage = ReportPage(
+ /** Generate a QC report page for 1 single library, sampleId and libId must be defined in the arguments */
+ def flexiprepPage: ReportPage = ReportPage(
List(),
List(
"Read Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
@@ -41,8 +47,14 @@ object FlexiprepReport extends ReportBuilder {
name -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepFastaqcPlot.ssp", Map("plot" -> tag))
}
- // FIXME: Not yet finished
-
+ /**
+ * Generated a stacked bar plot for reads QC
+ * @param outputDir OutputDir for plot
+ * @param prefix prefix for tsv and png file
+ * @param read Must give "R1" or "R2"
+ * @param summary Summary class
+ * @param sampleId Default selects all samples, when given plot is limits on given sample
+ */
def readSummaryPlot(outputDir: File,
prefix: String,
read: String,
@@ -92,6 +104,14 @@ object FlexiprepReport extends ReportBuilder {
plot.runLocal()
}
+ /**
+ * Generated a stacked bar plot for bases QC
+ * @param outputDir OutputDir for plot
+ * @param prefix prefix for tsv and png file
+ * @param read Must give "R1" or "R2"
+ * @param summary Summary class
+ * @param sampleId Default selects all samples, when given plot is limits on given sample
+ */
def baseSummaryPlot(outputDir: File,
prefix: String,
read: String,
diff --git a/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala b/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala
index e3a263489..9e5770cb6 100644
--- a/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala
+++ b/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaReport.scala
@@ -18,10 +18,10 @@ class ShivaReport(val root: Configurable) extends ReportBuilderExtension {
override val defaultCoreMemory = 3.0
}
+/** Object for report generation for Shiva pipeline */
object ShivaReport extends MultisampleReportBuilder {
- // FIXME: Not yet finished
-
+ /** Root page for the shiva report */
def indexPage = {
val regions = regionsPage
ReportPage(
@@ -52,7 +52,9 @@ object ShivaReport extends MultisampleReportBuilder {
)
}
- def regionsPage = {
+ //TODO: Add variants per target
+ /** 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")
@@ -88,7 +90,8 @@ object ShivaReport extends MultisampleReportBuilder {
else None
}
- def filesPage = ReportPage(List(), List(
+ /** Files page, can be used general or at sample level */
+ def filesPage: ReportPage = ReportPage(List(), List(
"Input fastq files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepInputfiles.ssp"),
"After QC fastq files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepOutputfiles.ssp"),
"Bam files per lib" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/mapping/outputBamfiles.ssp", Map("sampleLevel" -> false)),
@@ -97,7 +100,8 @@ object ShivaReport extends MultisampleReportBuilder {
"VCF files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/outputVcfFiles.ssp", Map("sampleId" -> None))
), Map())
- def samplePage(sampleId: String, args: Map[String, Any]) = {
+ /** Single sample page */
+ def samplePage(sampleId: String, args: Map[String, Any]): ReportPage = {
ReportPage(List(
"Libraries" -> generateLibraryPage(args),
"Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), None),
@@ -112,7 +116,8 @@ object ShivaReport extends MultisampleReportBuilder {
), args)
}
- def libraryPage(sampleId: String, libId: String, args: Map[String, Any]) = {
+ /** Library page */
+ def libraryPage(sampleId: String, libId: String, args: Map[String, Any]): ReportPage = {
ReportPage(List(
"Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), Some(libId)),
"QC" -> FlexiprepReport.flexiprepPage
@@ -123,8 +128,17 @@ object ShivaReport extends MultisampleReportBuilder {
), args)
}
+ /** Name of the report */
def reportName = "Shiva Report"
+ /**
+ * Generate a stackbar plot for found variants
+ * @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,
--
GitLab