Commit 4a5d4fd9 authored by Peter van 't Hof's avatar Peter van 't Hof

Added plots for front page of report

parent 0062bfa8
#import(nl.lumc.sasc.biopet.core.summary.Summary)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
#{
val samples = sampleId match {
case Some(sample) => List(sample.toString)
case _ => summary.samples.toList
case Some(sample) => {
List(sample.toString)
}
case _ => summary.samples.toList
}
}#
#if (showPlot)
#{ BammetricsReport.alignmentSummaryPlot(outputDir, "alignmentSummary", summary, !sampleLevel, sampleId = sampleId) }#
<img src="alignmentSummary.png"><br>
<a href="alignmentSummary.tsv">Tsv file</a>
#end
#if (showTable)
<table>
<thead><tr>
<th>Sample</th>
......@@ -52,4 +66,5 @@
#end
#end
</tbody>
</table>
\ No newline at end of file
</table>
#end
\ No newline at end of file
package nl.lumc.sasc.biopet.pipelines.bammetrics
import java.io.{PrintWriter, File}
import nl.lumc.sasc.biopet.core.report.{ ReportBuilder, ReportPage, ReportSection }
import nl.lumc.sasc.biopet.core.summary.{SummaryValue, Summary}
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot
/**
* Created by pjvan_thof on 3/30/15.
*/
object BammetricsReport extends ReportBuilder {
// FIXME: Not yet finished
val reportName = "Bam Metrics"
def indexPage = ReportPage(Map(
......@@ -29,5 +35,55 @@ object BammetricsReport extends ReportBuilder {
Map()
)
// FIXME: Not yet finished
def alignmentSummaryPlot(outputDir: File,
prefix: String,
summary: Summary,
libraryLevel: Boolean = false,
sampleId: 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("\tMapped\tDuplicates\tUnmapped\tSecondary")
def getLine(summary: Summary, sample: String, lib: Option[String] = None): String = {
val mapped = new SummaryValue(List("bammetrics", "stats", "biopet_flagstat", "Mapped"),
summary, Some(sample), lib).value.getOrElse(0).toString.toLong
val duplicates = new SummaryValue(List("bammetrics", "stats", "biopet_flagstat", "Duplicates"),
summary, Some(sample), lib).value.getOrElse(0).toString.toLong
val total = new SummaryValue(List("bammetrics", "stats", "biopet_flagstat", "All"),
summary, Some(sample), lib).value.getOrElse(0).toString.toLong
val secondary = new SummaryValue(List("bammetrics", "stats", "biopet_flagstat", "NotPrimaryAlignment"),
summary, Some(sample), 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((mapped - duplicates) + "\t")
sb.append(duplicates + "\t")
sb.append((total - mapped - secondary) + "\t")
sb.append(secondary)
sb.toString
}
if (libraryLevel) {
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
tsvWriter.println(getLine(summary, sample, Some(lib)))
}
} else {
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get)) {
tsvWriter.println(getLine(summary, sample))
}
}
tsvWriter.close()
val plot = new StackedBarPlot(null)
plot.input = tsvFile
plot.output = pngFile
plot.ylabel = Some("Reads")
plot.width = Some(750)
plot.runLocal()
}
}
......@@ -64,7 +64,14 @@ trait RscriptCommandLineFunction extends BiopetCommandLineFunction {
def runLocal(logger: ProcessLogger): Unit = {
checkScript(local = true)
Process(cmdLine).run(logger)
this.logger.info(cmdLine)
val cmd = cmdLine.stripPrefix(" '").stripSuffix("' ").split("' *'")
this.logger.info(cmd.mkString(" "))
val process = Process(cmd.toSeq).run(logger)
this.logger.info(process.exitValue())
}
/**
......
#import(nl.lumc.sasc.biopet.core.summary.Summary)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
#{
val samples = sampleId match {
case Some(sample) => List(sample.toString)
case _ => summary.samples.toList
}
}#
#if (showPlot)
#{
FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R1","R1", summary, sampleId = sampleId)
FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R2","R2", summary, sampleId = sampleId)
}#
<table>
<tr><th>R1</th><th>R2</th></tr>
<tr>
<td><img src="QC_Bases_R1.png"><br><a href="QC_Bases_R1.tsv">Tsv file</a></td>
<td><img src="QC_Bases_R2.png"><br><a href="QC_Bases_R2.tsv">Tsv file</a></td>
</tr>
</table>
#end
#if (showTable)
<table>
<thead><tr>
<th>Sample</th>
......@@ -54,4 +73,5 @@
#end
#end
</tbody>
</table>
\ No newline at end of file
</table>
#end
\ No newline at end of file
#import(nl.lumc.sasc.biopet.core.summary.Summary)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
#{
val samples = sampleId match {
case Some(sample) => List(sample.toString)
case _ => summary.samples.toList
}
}#
#if (showPlot)
#{
FlexiprepReport.readSummaryPlot(outputDir, "QC_Reads_R1","R1", summary, sampleId = sampleId)
FlexiprepReport.readSummaryPlot(outputDir, "QC_Reads_R2","R2", summary, sampleId = sampleId)
}#
<table>
<tr><th>R1</th><th>R2</th></tr>
<tr>
<td><img src="QC_Reads_R1.png"><br><a href="QC_Reads_R1.tsv">Tsv file</a></td>
<td><img src="QC_Reads_R2.png"><br><a href="QC_Reads_R2.tsv">Tsv file</a></td>
</tr>
</table>
#end
#if (showTable)
<table>
<thead><tr>
<th>Sample</th>
......@@ -56,4 +76,5 @@
#end
#end
</tbody>
</table>
\ No newline at end of file
</table>
#end
\ No newline at end of file
package nl.lumc.sasc.biopet.pipelines.flexiprep
import java.io.{PrintWriter, File}
import nl.lumc.sasc.biopet.core.report.{ ReportSection, ReportPage, ReportBuilder }
import nl.lumc.sasc.biopet.core.summary.{SummaryValue, Summary}
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot
/**
* Created by pjvan_thof on 3/30/15.
......@@ -38,4 +42,88 @@ object FlexiprepReport extends ReportBuilder {
}
// FIXME: Not yet finished
def readSummaryPlot(outputDir: File,
prefix: String,
read: String,
summary: Summary,
sampleId: Option[String] = None): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
val tsvWriter = new PrintWriter(tsvFile)
tsvWriter.println("Library\tAfter_QC\tClipping\tTrimming\tSynced")
def getLine(summary: Summary, sample: String, lib: String): String = {
val beforeTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read, "reads", "num_total"),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val afterTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read + "_after", "reads", "num_total"),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val clippingDiscardedToShort = new SummaryValue(List("flexiprep", "stats", "clipping_" + read, "num_reads_discarded_too_short"),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val clippingDiscardedToLong = new SummaryValue(List("flexiprep", "stats", "clipping_" + read, "num_reads_discarded_too_long"),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val trimmingDiscarded = new SummaryValue(List("flexiprep", "stats", "trimming", "num_reads_discarded_" + read),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val sb = new StringBuffer()
sb.append(sample + "-" + lib + "\t")
sb.append(afterTotal + "\t")
sb.append((clippingDiscardedToShort + clippingDiscardedToLong) + "\t")
sb.append(trimmingDiscarded + "\t")
sb.append(beforeTotal - afterTotal - trimmingDiscarded - clippingDiscardedToShort - clippingDiscardedToLong)
sb.toString
}
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
tsvWriter.println(getLine(summary, sample, lib))
}
tsvWriter.close()
val plot = new StackedBarPlot(null)
plot.input = tsvFile
plot.output = pngFile
plot.ylabel = Some("Reads")
plot.width = Some(750)
plot.runLocal()
}
def baseSummaryPlot(outputDir: File,
prefix: String,
read: String,
summary: Summary,
sampleId: Option[String] = None): Unit = {
val tsvFile = new File(outputDir, prefix + ".tsv")
val pngFile = new File(outputDir, prefix + ".png")
val tsvWriter = new PrintWriter(tsvFile)
tsvWriter.println("Library\tAfter_QC\tDiscarded")
def getLine(summary: Summary, sample: String, lib: String): String = {
val beforeTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read, "bases", "num_total"),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val afterTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read + "_after", "bases", "num_total"),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val sb = new StringBuffer()
sb.append(sample + "-" + lib + "\t")
sb.append(afterTotal + "\t")
sb.append(beforeTotal - afterTotal)
sb.toString
}
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
tsvWriter.println(getLine(summary, sample, lib))
}
tsvWriter.close()
val plot = new StackedBarPlot(null)
plot.input = tsvFile
plot.output = pngFile
plot.ylabel = Some("Bases")
plot.width = Some(750)
plot.runLocal()
}
}
#import(nl.lumc.sasc.biopet.core.summary.Summary)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(nl.lumc.sasc.biopet.pipelines.shiva.ShivaReport)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
#{
val fields = List("Hom", "HomVar", "HomRef", "NoCall", "Variant", "NonInformative", "Total")
val samples = sampleId match {
......@@ -11,6 +16,12 @@
}
}#
#if (showPlot)
#{ ShivaReport.variantSummaryPlot(outputDir, "variantSummary", summary, sampleId = sampleId) }#
<img src="variantSummary.png"><br>
<a href="variantSummary.tsv">Tsv file</a>
#end
#if (showTable)
<table>
<thead><tr><th>Sample</th>
#for (field <- fields) <th>${field}</th> #end
......@@ -24,4 +35,5 @@
</tr>
#end
</tbody>
</table>
\ No newline at end of file
</table>
#end
\ No newline at end of file
package nl.lumc.sasc.biopet.pipelines.shiva
import java.io.{PrintWriter, File}
import nl.lumc.sasc.biopet.core.report.{ ReportSection, MultisampleReportBuilder, ReportPage }
import nl.lumc.sasc.biopet.core.summary.{SummaryValue, Summary}
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot
import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport
import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
......@@ -8,32 +12,47 @@ import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
* Created by pjvan_thof on 3/30/15.
*/
object ShivaReport extends MultisampleReportBuilder {
def indexPage = ReportPage(
Map(
/*"General" -> ReportPage(Map(), List(
"Variantcalling" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/sampleVariants.ssp"),
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp", Map("sampleLevel" -> true)),
"QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
"QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp")
), Map()),*/
"Samples" -> generateSamplesPage(pageArgs)
),
List(
"Report" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/shivaFront.ssp"),
"Variantcalling" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/sampleVariants.ssp"),
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp", Map("sampleLevel" -> true)),
"QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
"QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp")
),
pageArgs
)
// FIXME: Not yet finished
def indexPage = {
ReportPage(
Map(
"MultiSample" -> ReportPage(Map(), List(
"Variantcalling" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/sampleVariants.ssp",
Map("showPlot" -> true, "showTable" -> true)),
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> true)),
"QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp",
Map("showPlot" -> true, "showTable" -> true)),
"QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp",
Map("showPlot" -> true, "showTable" -> true))
), Map()),
"Samples" -> generateSamplesPage(pageArgs)
),
List(
"Report" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/shivaFront.ssp"),
"Variantcalling" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/sampleVariants.ssp",
Map("showPlot" -> true, "showTable" -> false)),
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
Map("sampleLevel" -> true, "showPlot" -> true, "showTable" -> false)
),
"QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp",
Map("showPlot" -> true, "showTable" -> false)),
"QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp",
Map("showPlot" -> true, "showTable" -> false))
),
pageArgs
)
}
def samplePage(sampleId: String, args: Map[String, Any]) = {
ReportPage(Map(
"Libraries" -> generateLibraryPage(args),
"Alignment" -> BammetricsReport.bamMetricsPage
), List(
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp"),
"Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
if (summary.libraries(sampleId).size > 1) Map("showPlot" -> true) else Map()),
"Preprocessing" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp", Map("sampleLevel" -> true)),
"Variantcalling" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/shiva/sampleVariants.ssp"),
"QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
......@@ -54,5 +73,53 @@ object ShivaReport extends MultisampleReportBuilder {
def reportName = "Shiva Report"
// FIXME: Not yet finished
def variantSummaryPlot(outputDir: File,
prefix: String,
summary: Summary,
libraryLevel: Boolean = false,
sampleId: 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, lib: Option[String] = None): String = {
val homVar = new SummaryValue(List("shivavariantcalling", "stats", "multisample-vcfstats-final", "genotype", "HomVar"),
summary, Some(sample), lib).value.getOrElse(0).toString.toLong
val homRef = new SummaryValue(List("shivavariantcalling", "stats", "multisample-vcfstats-final", "genotype", "HomRef"),
summary, Some(sample), lib).value.getOrElse(0).toString.toLong
val noCall = new SummaryValue(List("shivavariantcalling", "stats", "multisample-vcfstats-final", "genotype", "NoCall"),
summary, Some(sample), lib).value.getOrElse(0).toString.toLong
val het = new SummaryValue(List("shivavariantcalling", "stats", "multisample-vcfstats-final", "genotype", "Het"),
summary, Some(sample), 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
}
if (libraryLevel) {
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get);
lib <- summary.libraries(sample)) {
tsvWriter.println(getLine(summary, sample, Some(lib)))
}
} else {
for (sample <- summary.samples if (sampleId.isEmpty || sample == sampleId.get)) {
tsvWriter.println(getLine(summary, sample))
}
}
tsvWriter.close()
val plot = new StackedBarPlot(null)
plot.input = tsvFile
plot.output = pngFile
plot.ylabel = Some("VCF records")
plot.width = Some(750)
plot.runLocal()
}
}
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