Commit dd62378d authored by Ruben Vorderman's avatar Ruben Vorderman
Browse files

readsummaryplot defutured. New summaryPlotLines function added.

parent 4e394bc9
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
<%@ var seqstatQCStats: Map[(Int, Int), Map[String, Option[Any]]] %> <%@ var seqstatQCStats: Map[(Int, Int), Map[String, Option[Any]]] %>
<%@ var clippingStats: Map[(Int, Int), Map[String, Option[Any]]] %> <%@ var clippingStats: Map[(Int, Int), Map[String, Option[Any]]] %>
<%@ var trimmingStats: Map[(Int, Int), Map[String, Option[Any]]] %> <%@ var trimmingStats: Map[(Int, Int), Map[String, Option[Any]]] %>
<%@ var summaryPlotLinesR1: Seq[String] %>
<%@ var summaryPlotLinesR2: Seq[String] %>
#if showIntro #if showIntro
<br/> <br/>
...@@ -68,8 +70,8 @@ ...@@ -68,8 +70,8 @@
#if (showPlot) #if (showPlot)
#{ #{
FlexiprepReport.readSummaryPlot(outputDir, "QC_Reads_R1","R1", summary, sampleId = sampleId) FlexiprepReport.readSummaryPlot(outputDir, "QC_Reads_R1","R1", summaryPlotLinesR1)
if (paired) FlexiprepReport.readSummaryPlot(outputDir, "QC_Reads_R2","R2", summary, sampleId = sampleId) if (paired) FlexiprepReport.readSummaryPlot(outputDir, "QC_Reads_R2","R2", summaryPlotLinesR2)
}# }#
<div class="panel-body"> <div class="panel-body">
<div class="row"> <div class="row">
......
...@@ -17,12 +17,8 @@ package nl.lumc.sasc.biopet.pipelines.flexiprep ...@@ -17,12 +17,8 @@ package nl.lumc.sasc.biopet.pipelines.flexiprep
import java.io.{File, PrintWriter} import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.core.report.{ import nl.lumc.sasc.biopet.core.report.{ReportBuilder, ReportBuilderExtension, ReportPage, ReportSection}
ReportBuilder, import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport.runId
ReportBuilderExtension,
ReportPage,
ReportSection
}
import nl.lumc.sasc.biopet.utils.rscript.StackedBarPlot import nl.lumc.sasc.biopet.utils.rscript.StackedBarPlot
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import nl.lumc.sasc.biopet.utils.summary.db.Schema.Sample import nl.lumc.sasc.biopet.utils.summary.db.Schema.Sample
...@@ -31,6 +27,7 @@ import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.Implicts._ ...@@ -31,6 +27,7 @@ import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.Implicts._
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb._ import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb._
import scala.collection.mutable import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.concurrent.{Await, Future} import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration import scala.concurrent.duration.Duration
...@@ -87,40 +84,30 @@ object FlexiprepReport extends ReportBuilder { ...@@ -87,40 +84,30 @@ object FlexiprepReport extends ReportBuilder {
name -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepFastQcPlot.ssp", name -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepFastQcPlot.ssp",
Map("plot" -> tag)) Map("plot" -> tag))
} }
/**
/** * Generates the lines for readSummaryPlot
* Generated a stacked bar plot for reads QC * @param read Must give "R1" or "R2"
* @param outputDir OutputDir for plot * @param summary Summary class
* @param prefix prefix for tsv and png file * @param sampleId Default selects all samples, when given plot is limits on given sample
* @param read Must give "R1" or "R2" */
* @param summary Summary class def summaryPlotLines(read: String,
* @param sampleId Default selects all samples, when given plot is limits on given sample summary: SummaryDb,
*/ sampleId: Option[Int] = None) : Seq[String] = {
def readSummaryPlot(outputDir: File,
prefix: String,
read: String,
summary: SummaryDb,
sampleId: Option[Int] = 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")
val seqstatPaths = Map("num_total" -> List("reads", "num_total")) val seqstatPaths = Map("num_total" -> List("reads", "num_total"))
val seqstatStats = val seqstatStats =
summary.getStatsForLibraries(runId, "flexiprep", "seqstat_" + read, keyValues = seqstatPaths) summary.getStatsForLibraries(runId, "flexiprep", "seqstat_" + read, keyValues = seqstatPaths)
val seqstatQcStats = summary.getStatsForLibraries(runId, val seqstatQcStats = summary.getStatsForLibraries(runId,
"flexiprep", "flexiprep",
"seqstat_" + read + "_qc", "seqstat_" + read + "_qc",
keyValues = seqstatPaths) keyValues = seqstatPaths)
val clippingPaths = Map( val clippingPaths = Map(
"num_reads_discarded_too_short" -> List("num_reads_discarded_too_short"), "num_reads_discarded_too_short" -> List("num_reads_discarded_too_short"),
"num_reads_discarded_too_long" -> List("num_reads_discarded_too_long")) "num_reads_discarded_too_long" -> List("num_reads_discarded_too_long"))
val clippingStats = summary.getStatsForLibraries(runId, val clippingStats = summary.getStatsForLibraries(runId,
"flexiprep", "flexiprep",
"clipping_" + read, "clipping_" + read,
keyValues = clippingPaths) keyValues = clippingPaths)
val trimmingPaths = Map("num_reads_discarded" -> List("num_reads_discarded_" + read)) val trimmingPaths = Map("num_reads_discarded" -> List("num_reads_discarded_" + read))
val trimmingStats = val trimmingStats =
...@@ -129,6 +116,8 @@ object FlexiprepReport extends ReportBuilder { ...@@ -129,6 +116,8 @@ object FlexiprepReport extends ReportBuilder {
val libraries = val libraries =
Await.result(summary.getLibraries(runId = runId, sampleId = sampleId), Duration.Inf) Await.result(summary.getLibraries(runId = runId, sampleId = sampleId), Duration.Inf)
val summaryPlotLines = ArrayBuffer[String]()
for (lib <- libraries) { for (lib <- libraries) {
val beforeTotal = val beforeTotal =
seqstatStats((lib.sampleId, lib.id))("num_total").getOrElse(0).toString.toLong seqstatStats((lib.sampleId, lib.id))("num_total").getOrElse(0).toString.toLong
...@@ -151,10 +140,30 @@ object FlexiprepReport extends ReportBuilder { ...@@ -151,10 +140,30 @@ object FlexiprepReport extends ReportBuilder {
sb.append(trimmingDiscarded + "\t") sb.append(trimmingDiscarded + "\t")
sb.append( sb.append(
beforeTotal - afterTotal - trimmingDiscarded - clippingDiscardedToShort - clippingDiscardedToLong) beforeTotal - afterTotal - trimmingDiscarded - clippingDiscardedToShort - clippingDiscardedToLong)
summaryPlotLines += sb.toString
tsvWriter.println(sb.toString)
} }
summaryPlotLines
}
/**
* 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 summaryPlotLines the lines for the tsv
*/
def readSummaryPlot(outputDir: File,
prefix: String,
read: String,
summaryPlotLines: Seq[String])
: 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")
for (line <- summaryPlotLines)
tsvWriter.println(line)
tsvWriter.close() tsvWriter.close()
val plot = new StackedBarPlot(null) val plot = new StackedBarPlot(null)
...@@ -263,15 +272,8 @@ object FlexiprepReadSummary { ...@@ -263,15 +272,8 @@ object FlexiprepReadSummary {
val clipCount = settings.count(_._2.getOrElse("skip_clip", None).contains(false)) val clipCount = settings.count(_._2.getOrElse("skip_clip", None).contains(false))
val librariesCount = libraries.size val librariesCount = libraries.size
if (showPlot) { val summaryPlotLinesR1 = if (showPlot) FlexiprepReport.summaryPlotLines("R1", summary, sampleId = sampleId)
FlexiprepReport.readSummaryPlot(outputDir, "QC_Reads_R1", "R1", summary, sampleId = sampleId) val summaryPlotlinesR2 = if (showPlot && paired) FlexiprepReport.summaryPlotLines("R2", summary, sampleId = sampleId)
if (paired)
FlexiprepReport.readSummaryPlot(outputDir,
"QC_Reads_R2",
"R2",
summary,
sampleId = sampleId)
}
val seqstatPaths = Map("num_total" -> List("reads", "num_total")) val seqstatPaths = Map("num_total" -> List("reads", "num_total"))
val clippingPaths = Map( val clippingPaths = Map(
...@@ -303,7 +305,9 @@ object FlexiprepReadSummary { ...@@ -303,7 +305,9 @@ object FlexiprepReadSummary {
"seqstatStats" -> seqstatStats, "seqstatStats" -> seqstatStats,
"seqstatQCStats" -> seqstatQCStats, "seqstatQCStats" -> seqstatQCStats,
"clippingStats" -> clippingStats, "clippingStats" -> clippingStats,
"trimmingStats" -> trimmingStats "trimmingStats" -> trimmingStats,
"summaryPlotLinesR1" -> summaryPlotLinesR1,
"summaryPlotLinesR2" -> summaryPlotlinesR2
) )
} }
} }
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