Commit 1d306afd authored by Peter van 't Hof's avatar Peter van 't Hof

Added scala docs to report code

parent 6142593f
...@@ -6,17 +6,24 @@ import nl.lumc.sasc.biopet.core.report.{ ReportBuilder, ReportPage, ReportSectio ...@@ -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.core.summary.{ SummaryValue, Summary }
import nl.lumc.sasc.biopet.extensions.rscript.{ XYPlot, StackedBarPlot } 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. * Created by pjvan_thof on 3/30/15.
*/ */
object BammetricsReport extends ReportBuilder { object BammetricsReport extends ReportBuilder {
// FIXME: Not yet finished
/** Name of report */
val reportName = "Bam Metrics" val reportName = "Bam Metrics"
/** Root page for single BamMetrcis report */
def indexPage = ReportPage(List(), List(), Map()) 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 = ( val targets = (
summary.getLibraryValue(sampleId, libId, "bammetrics", "settings", "amplicon_name"), summary.getLibraryValue(sampleId, libId, "bammetrics", "settings", "amplicon_name"),
summary.getLibraryValue(sampleId, libId, "bammetrics", "settings", "roi_name") summary.getLibraryValue(sampleId, libId, "bammetrics", "settings", "roi_name")
...@@ -35,10 +42,18 @@ object BammetricsReport extends ReportBuilder { ...@@ -35,10 +42,18 @@ object BammetricsReport extends ReportBuilder {
"Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp"), "Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp"),
"Insert Size" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp", Map("showPlot" -> true)) "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, def alignmentSummaryPlot(outputDir: File,
prefix: String, prefix: String,
summary: Summary, summary: Summary,
...@@ -94,6 +109,14 @@ object BammetricsReport extends ReportBuilder { ...@@ -94,6 +109,14 @@ object BammetricsReport extends ReportBuilder {
plot.runLocal() 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, def insertSizePlot(outputDir: File,
prefix: String, prefix: String,
summary: Summary, summary: Summary,
...@@ -174,6 +197,14 @@ object BammetricsReport extends ReportBuilder { ...@@ -174,6 +197,14 @@ object BammetricsReport extends ReportBuilder {
plot.runLocal() 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, def wgsHistogramPlot(outputDir: File,
prefix: String, prefix: String,
summary: Summary, summary: Summary,
......
...@@ -4,22 +4,28 @@ package nl.lumc.sasc.biopet.core.report ...@@ -4,22 +4,28 @@ package nl.lumc.sasc.biopet.core.report
* Created by pjvan_thof on 3/30/15. * Created by pjvan_thof on 3/30/15.
*/ */
trait MultisampleReportBuilder extends ReportBuilder { trait MultisampleReportBuilder extends ReportBuilder {
/** Method to generate a single sample page */
def samplePage(sampleId: String, args: Map[String, Any]): ReportPage def samplePage(sampleId: String, args: Map[String, Any]): ReportPage
/** Default list of samples, can be override */
def samplesSections: List[(String, ReportSection)] = { def samplesSections: List[(String, ReportSection)] = {
List( List(
("Samples", ReportSection("/nl/lumc/sasc/biopet/core/report/samplesList.ssp")) ("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 def libraryPage(sampleId: String, libraryId: String, args: Map[String, Any]): ReportPage
/** Default list of libraries, can be override */
def libririesSections: List[(String, ReportSection)] = { def libririesSections: List[(String, ReportSection)] = {
List( List(
("Libraries", ReportSection("/nl/lumc/sasc/biopet/core/report/librariesList.ssp")) ("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 = { def generateSamplesPage(args: Map[String, Any]): ReportPage = {
val samplePages = summary.samples val samplePages = summary.samples
.map(sampleId => (sampleId -> samplePage(sampleId, args ++ Map("sampleId" -> Some(sampleId))))) .map(sampleId => (sampleId -> samplePage(sampleId, args ++ Map("sampleId" -> Some(sampleId)))))
...@@ -27,6 +33,7 @@ trait MultisampleReportBuilder extends ReportBuilder { ...@@ -27,6 +33,7 @@ trait MultisampleReportBuilder extends ReportBuilder {
ReportPage(samplePages, samplesSections, args) 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 = { def generateLibraryPage(args: Map[String, Any]): ReportPage = {
val sampleId = args("sampleId") match { val sampleId = args("sampleId") match {
case Some(x) => x.toString case Some(x) => x.toString
......
...@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.core.report ...@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.core.report
import java.io._ 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 nl.lumc.sasc.biopet.core.summary.Summary
import org.broadinstitute.gatk.utils.commandline.Input import org.broadinstitute.gatk.utils.commandline.Input
import org.fusesource.scalate.{ TemplateSource, TemplateEngine } import org.fusesource.scalate.{ TemplateSource, TemplateEngine }
...@@ -13,13 +13,16 @@ import nl.lumc.sasc.biopet.utils.IoUtils ...@@ -13,13 +13,16 @@ import nl.lumc.sasc.biopet.utils.IoUtils
*/ */
trait ReportBuilderExtension extends ToolCommandFuntion { trait ReportBuilderExtension extends ToolCommandFuntion {
/** Report builder object */
val builder: ReportBuilder val builder: ReportBuilder
@Input(required = true) @Input(required = true)
var summaryFile: File = _ var summaryFile: File = _
/** OutputDir for the report */
var outputDir: File = _ var outputDir: File = _
/** Arguments that are passed on the commandline */
var args: Map[String, String] = Map() var args: Map[String, String] = Map()
override def beforeGraph: Unit = { override def beforeGraph: Unit = {
...@@ -28,6 +31,7 @@ trait ReportBuilderExtension extends ToolCommandFuntion { ...@@ -28,6 +31,7 @@ trait ReportBuilderExtension extends ToolCommandFuntion {
javaMainClass = builder.getClass.getName.takeWhile(_ != '$') javaMainClass = builder.getClass.getName.takeWhile(_ != '$')
} }
/** Command to generate the report */
override def commandLine: String = { override def commandLine: String = {
super.commandLine + super.commandLine +
required("--summary", summaryFile) + required("--summary", summaryFile) +
...@@ -52,15 +56,19 @@ trait ReportBuilder extends ToolCommand { ...@@ -52,15 +56,19 @@ trait ReportBuilder extends ToolCommand {
} }
} }
/** summary object internaly */
private var setSummary: Summary = _ private var setSummary: Summary = _
/** Retrival of summary, read only */
final def summary = setSummary final def summary = setSummary
/** default args that are passed to all page withing the report */
def pageArgs: Map[String, Any] = Map() def pageArgs: Map[String, Any] = Map()
private var done = 0 private var done = 0
private var total = 0 private var total = 0
/** Main function to for building the report */
def main(args: Array[String]): Unit = { def main(args: Array[String]): Unit = {
logger.info("Start") logger.info("Start")
...@@ -95,7 +103,7 @@ trait ReportBuilder extends ToolCommand { ...@@ -95,7 +103,7 @@ trait ReportBuilder extends ToolCommand {
logger.info("Parsing summary") logger.info("Parsing summary")
setSummary = new Summary(cmdArgs.summary) setSummary = new Summary(cmdArgs.summary)
total = countPages(indexPage) total = ReportBuilder.countPages(indexPage)
logger.info(total + " pages to be generated") logger.info(total + " pages to be generated")
logger.info("Generate pages") logger.info("Generate pages")
...@@ -106,14 +114,21 @@ trait ReportBuilder extends ToolCommand { ...@@ -106,14 +114,21 @@ trait ReportBuilder extends ToolCommand {
logger.info(jobs + " Done") logger.info(jobs + " Done")
} }
/** This must be implemented, this will be the root page of the report */
def indexPage: ReportPage def indexPage: ReportPage
/** This must be implemented, this will because the title of the report */
def reportName: String 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, def generatePage(summary: Summary,
page: ReportPage, page: ReportPage,
outputDir: File, outputDir: File,
...@@ -151,10 +166,17 @@ trait ReportBuilder extends ToolCommand { ...@@ -151,10 +166,17 @@ trait ReportBuilder extends ToolCommand {
object ReportBuilder { object ReportBuilder {
/** Single template render engine, this will have a cache for all compile templates */
protected val engine = new TemplateEngine() protected val engine = new TemplateEngine()
/** Cache of temp file for templates from the classpath / jar */
private var templateCache: Map[String, File] = Map() 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 * This method will render a template that is located in the classpath / jar
* @param location location in the classpath / jar * @param location location in the classpath / jar
......
...@@ -2,6 +2,10 @@ package nl.lumc.sasc.biopet.core.report ...@@ -2,6 +2,10 @@ package nl.lumc.sasc.biopet.core.report
/** /**
* Created by pjvan_thof on 3/27/15. * 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)], case class ReportPage(subPages: List[(String, ReportPage)],
sections: List[(String, ReportSection)], sections: List[(String, ReportSection)],
......
...@@ -2,15 +2,18 @@ package nl.lumc.sasc.biopet.core.report ...@@ -2,15 +2,18 @@ package nl.lumc.sasc.biopet.core.report
/** /**
* Created by pjvan_thof on 4/8/15. * 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, case class ReportSection(location: String,
args: Map[String, Any] = Map(), args: Map[String, Any] = Map()) {
intro: Option[String] = None) { /**
* This method will render this section
def render(args: Map[String, Any]): String = { * @param args Possible to give more arguments
(intro match { * @return Rendered result for this section
case Some(template) => ReportBuilder.renderTemplate(location, args ++ this.args) */
case _ => "" def render(args: Map[String, Any] = Map()): String = {
}) + ReportBuilder.renderTemplate(location, args ++ this.args) ReportBuilder.renderTemplate(location, args ++ this.args)
} }
} }
...@@ -6,21 +6,27 @@ import nl.lumc.sasc.biopet.core.report.{ ReportSection, ReportPage, ReportBuilde ...@@ -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.core.summary.{ SummaryValue, Summary }
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot 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. * Created by pjvan_thof on 3/30/15.
*/ */
object FlexiprepReport extends ReportBuilder { object FlexiprepReport extends ReportBuilder {
val reportName = "Flexiprep" val reportName = "Flexiprep"
def indexPage = ReportPage(List( /** Index page for a flexiprep report */
"QC" -> flexiprepPage def indexPage = {
), List( val flexiprepPage = this.flexiprepPage
"Report" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepFront.ssp") ReportPage(List(
), "QC" -> flexiprepPage
Map() ), 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(),
List( List(
"Read Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"), "Read Summary" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
...@@ -41,8 +47,14 @@ object FlexiprepReport extends ReportBuilder { ...@@ -41,8 +47,14 @@ object FlexiprepReport extends ReportBuilder {
name -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepFastaqcPlot.ssp", Map("plot" -> tag)) 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, def readSummaryPlot(outputDir: File,
prefix: String, prefix: String,
read: String, read: String,
...@@ -92,6 +104,14 @@ object FlexiprepReport extends ReportBuilder { ...@@ -92,6 +104,14 @@ object FlexiprepReport extends ReportBuilder {
plot.runLocal() 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, def baseSummaryPlot(outputDir: File,
prefix: String, prefix: String,
read: String, read: String,
......
...@@ -18,10 +18,10 @@ class ShivaReport(val root: Configurable) extends ReportBuilderExtension { ...@@ -18,10 +18,10 @@ class ShivaReport(val root: Configurable) extends ReportBuilderExtension {
override val defaultCoreMemory = 3.0 override val defaultCoreMemory = 3.0
} }
/** Object for report generation for Shiva pipeline */
object ShivaReport extends MultisampleReportBuilder { object ShivaReport extends MultisampleReportBuilder {
// FIXME: Not yet finished /** Root page for the shiva report */
def indexPage = { def indexPage = {
val regions = regionsPage val regions = regionsPage
ReportPage( ReportPage(
...@@ -52,7 +52,9 @@ object ShivaReport extends MultisampleReportBuilder { ...@@ -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 roi = summary.getValue("shiva", "settings", "regions_of_interest")
val amplicon = summary.getValue("shiva", "settings", "amplicon_bed") val amplicon = summary.getValue("shiva", "settings", "amplicon_bed")
...@@ -88,7 +90,8 @@ object ShivaReport extends MultisampleReportBuilder { ...@@ -88,7 +90,8 @@ object ShivaReport extends MultisampleReportBuilder {
else None 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"), "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"), "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)), "Bam files per lib" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/mapping/outputBamfiles.ssp", Map("sampleLevel" -> false)),
...@@ -97,7 +100,8 @@ object ShivaReport extends MultisampleReportBuilder { ...@@ -97,7 +100,8 @@ object ShivaReport extends MultisampleReportBuilder {
"VCF files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/outputVcfFiles.ssp", Map("sampleId" -> None)) "VCF files" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/outputVcfFiles.ssp", Map("sampleId" -> None))
), Map()) ), Map())
def samplePage(sampleId: String, args: Map[String, Any]) = { /** Single sample page */
def samplePage(sampleId: String, args: Map[String, Any]): ReportPage = {
ReportPage(List( ReportPage(List(
"Libraries" -> generateLibraryPage(args), "Libraries" -> generateLibraryPage(args),
"Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), None), "Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), None),
...@@ -112,7 +116,8 @@ object ShivaReport extends MultisampleReportBuilder { ...@@ -112,7 +116,8 @@ object ShivaReport extends MultisampleReportBuilder {
), args) ), 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( ReportPage(List(
"Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), Some(libId)), "Alignment" -> BammetricsReport.bamMetricsPage(summary, Some(sampleId), Some(libId)),
"QC" -> FlexiprepReport.flexiprepPage "QC" -> FlexiprepReport.flexiprepPage
...@@ -123,8 +128,17 @@ object ShivaReport extends MultisampleReportBuilder { ...@@ -123,8 +128,17 @@ object ShivaReport extends MultisampleReportBuilder {
), args) ), args)
} }
/** Name of the report */
def reportName = "Shiva 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, def variantSummaryPlot(outputDir: File,
prefix: String, prefix: String,
summary: Summary, summary: Summary,
......
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