Commit 97661f8f authored by rhpvorderman's avatar rhpvorderman

defutured flexiprepBaseSummary.ssp

parent dd62378d
......@@ -21,20 +21,19 @@
<%@ var multisample: Boolean = true %>
<%@ var allSamples: Seq[Sample] %>
<%@ var allLibraries: Seq[Library] %>
#{
val samples = sampleId.map(id => allSamples.filter(_.id == id)).getOrElse(allSamples)
val libraries = libId.map(id => allLibraries.filter(_.id == id)).getOrElse(allLibraries)
val settings = summary.getSettingsForLibraries(runId, "flexiprep", keyValues = Map(
"skip_trim" -> List("skip_trim"), "skip_clip" -> List("skip_clip"), "paired" -> List("paired")))
settings.count(_._2.getOrElse("skip_trim", None) == Some(true))
val trimCount = settings.count(_._2.getOrElse("skip_trim", None) == Some(false))
val clipCount = settings.count(_._2.getOrElse("skip_clip", None) == Some(false))
val librariesCount = libraries.size
val paired: Boolean = if (sampleId.isDefined && libId.isDefined)
summary.getSettingKeys(runId, "flexiprep", NoModule, SampleId(sampleId.get), LibraryId(libId.get), keyValues = Map("paired" -> List("paired"))).getOrElse("paired", None) == Some(true)
else settings.count(_._2.getOrElse("paired", None) == Some(true)) >= 1
}#
<%@ var trimCount: Int %>
<%@ var librariesCount: Int %>
<%@ var clipCount: Int %>
<%@ var paired: Boolean %>
<%@ var summaryPlotLinesR1: Seq[String] %>
<%@ var summaryPlotLinesR2: Seq[String] %>
<%@ var samples: Seq[Sample] %>
<%@ var libraries: Seq[Library] %>
<%@ var settings: Map[(Int, Int), Map[String, Option[Any]]]%>
<%@ var seqstatStats: Map[(Int, Int), Map[String, Option[Any]]] %>
<%@ var seqstatQCStats: Map[(Int, Int), Map[String, Option[Any]]] %>
#if (showIntro)
<br/>
<div class="row">
......@@ -71,8 +70,8 @@
#end
#if (showPlot)
#{
FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R1","R1", summary, sampleId = sampleId)
if (paired) FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R2","R2", summary, sampleId = sampleId)
FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R1","R1", summaryPlotLinesR1)
if (paired) FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R2","R2", summaryPlotLinesR2)
}#
<div class="panel-body">
<div class="row">
......@@ -142,12 +141,8 @@
#for (read <- reads)
#if (read == "R2") </tr><tr> #end
#{
val statsPaths = Map("num_total" -> List("bases", "num_total"))
val seqstatStats = summary.getStatKeys(runId, "flexiprep", "seqstat_" + read, sample = sample.id, library = lib.id, keyValues = statsPaths)
val seqstatQcStats = summary.getStatKeys(runId, "flexiprep", "seqstat_" + read + "_qc", sample = sample.id, library = lib.id, keyValues = statsPaths)
val beforeTotal = seqstatStats("num_total").getOrElse(0).toString.toLong
val afterTotal = seqstatQcStats("num_total").getOrElse(0).toString.toLong
val beforeTotal = seqstatStats(sample.id,lib.id)("num_total").getOrElse(0).toString.toLong
val afterTotal = seqstatQCStats(sample.id,lib.id)("num_total").getOrElse(0).toString.toLong
}#
<td>${read}</td>
<td>${beforeTotal}</td>
......
......@@ -90,7 +90,7 @@ object FlexiprepReport extends ReportBuilder {
* @param summary Summary class
* @param sampleId Default selects all samples, when given plot is limits on given sample
*/
def summaryPlotLines(read: String,
def readSummaryPlotLines(read: String,
summary: SummaryDb,
sampleId: Option[Int] = None) : Seq[String] = {
......@@ -150,7 +150,7 @@ object FlexiprepReport extends ReportBuilder {
* @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
* @param summaryPlotLines A sequence of strings written to the summary tsv
*/
def readSummaryPlot(outputDir: File,
prefix: String,
......@@ -176,34 +176,29 @@ object FlexiprepReport extends ReportBuilder {
}
/**
* Generated a stacked bar plot for bases QC
* @param outputDir OutputDir for plot
* @param prefix prefix for tsv and png file
* Generates the lines for baseSummaryPlotLines
* @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,
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\tDiscarded")
def baseSummaryPlotLines (read: String,
summary: SummaryDb,
sampleId: Option[Int] = None): Seq[String] = {
val statsPaths = Map("num_total" -> List("bases", "num_total"))
val seqstatStats =
summary.getStatsForLibraries(runId, "flexiprep", "seqstat_" + read, keyValues = statsPaths)
val seqstatQcStats = summary.getStatsForLibraries(runId,
"flexiprep",
"seqstat_" + read + "_qc",
keyValues = statsPaths)
"flexiprep",
"seqstat_" + read + "_qc",
keyValues = statsPaths)
val libraries =
Await.result(summary.getLibraries(runId = runId, sampleId = sampleId), Duration.Inf)
val summaryPlotLines = ArrayBuffer[String]()
for (lib <- libraries) {
val beforeTotal =
seqstatStats((lib.sampleId, lib.id))("num_total").getOrElse(0).toString.toLong
......@@ -218,7 +213,29 @@ object FlexiprepReport extends ReportBuilder {
sb.append(afterTotal + "\t")
sb.append(beforeTotal - afterTotal)
tsvWriter.println(sb.toString)
summaryPlotLines += sb.toString
}
summaryPlotLines
}
/**
* 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 summaryPlotLines A sequence of strings written to the summary tsv
*/
def baseSummaryPlot(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\tDiscarded")
for (line <- summaryPlotLines){
tsvWriter.println(line)
}
tsvWriter.close()
......@@ -235,7 +252,6 @@ object FlexiprepReport extends ReportBuilder {
object FlexiprepReadSummary {
def values(summary: SummaryDb,
outputDir: File,
runId: Int,
allSamples: Seq[Sample],
allLibraries: Seq[Library],
......@@ -272,8 +288,8 @@ object FlexiprepReadSummary {
val clipCount = settings.count(_._2.getOrElse("skip_clip", None).contains(false))
val librariesCount = libraries.size
val summaryPlotLinesR1 = if (showPlot) FlexiprepReport.summaryPlotLines("R1", summary, sampleId = sampleId)
val summaryPlotlinesR2 = if (showPlot && paired) FlexiprepReport.summaryPlotLines("R2", summary, sampleId = sampleId)
val summaryPlotLinesR1 = if (showPlot) FlexiprepReport.readSummaryPlotLines("R1", summary, sampleId = sampleId)
val summaryPlotlinesR2 = if (showPlot && paired) FlexiprepReport.readSummaryPlotLines("R2", summary, sampleId = sampleId)
val seqstatPaths = Map("num_total" -> List("reads", "num_total"))
val clippingPaths = Map(
......@@ -291,7 +307,6 @@ object FlexiprepReadSummary {
Map(
"summary" -> summary,
"outputDir" -> outputDir,
"runId" -> runId,
"sampleId" -> sampleId,
"libId" -> libId,
......@@ -311,3 +326,51 @@ object FlexiprepReadSummary {
)
}
}
object FlexiprepBaseSummary {
def values(summary: SummaryDb,
runId: Int,
allSamples: Seq[Sample],
allLibraries: Seq[Library],
sampleId: Option[Int] = None,
libId: Option[Int] = None,
showPlot: Boolean = false,
showTable: Boolean = true,
showIntro: Boolean = true,
multisample: Boolean = true): Map[String,Any] = {
val samples = sampleId.map(id => allSamples.filter(_.id == id)).getOrElse(allSamples)
val libraries = libId.map(id => allLibraries.filter(_.id == id)).getOrElse(allLibraries)
val librariesCount = libraries.size
val settings = summary.getSettingsForLibraries(runId, "flexiprep", keyValues = Map(
"skip_trim" -> List("skip_trim"), "skip_clip" -> List("skip_clip"), "paired" -> List("paired")))
settings.count(_._2.getOrElse("skip_trim", None) == Some(true))
val trimCount = settings.count(_._2.getOrElse("skip_trim", None) == Some(false))
val clipCount = settings.count(_._2.getOrElse("skip_clip", None) == Some(false))
val paired: Boolean = if (sampleId.isDefined && libId.isDefined)
summary.getSettingKeys(runId, "flexiprep", NoModule, SampleId(sampleId.get), LibraryId(libId.get), keyValues = Map("paired" -> List("paired"))).getOrElse("paired", None) == Some(true)
else settings.count(_._2.getOrElse("paired", None) == Some(true)) >= 1
val summaryPlotLinesR1 = if (showPlot) FlexiprepReport.readSummaryPlotLines("R1", summary, sampleId = sampleId)
val summaryPlotlinesR2 = if (showPlot && paired) FlexiprepReport.readSummaryPlotLines("R2", summary, sampleId = sampleId)
val statsPaths = Map("num_total" -> List("bases", "num_total"))
val seqstatStats =
summary.getStatsForLibraries(runId, "flexiprep", "seqstat_R1", sampleId, statsPaths)
val seqstatQCStats =
summary.getStatsForLibraries(runId, "flexiprep", "seqstat_R1_QC", sampleId, statsPaths)
Map(
"trimCount" -> trimCount,
"librariesCount" -> librariesCount,
"clipCount" -> clipCount,
"paired" -> paired,
"summaryPlotLinesR1" -> summaryPlotLinesR1,
"summaryPlotLinesR2" -> summaryPlotlinesR2
)
}
}
\ No newline at end of file
......@@ -141,7 +141,7 @@ object GearsReport extends MultisampleReportBuilder {
)))
else None
val flexiprepReadSummary = FlexiprepReadSummary.values(summary,,runId,samples,libraries,sampleId,libId, true, false)
val flexiprepReadSummary = FlexiprepReadSummary.values(summary,runId,samples,libraries,sampleId,libId, true, false)
Future {
ReportPage(
List(centrifugePage, krakenPage, qiimeClosedPage, qiimeOpenPage).flatten ::: List(
......
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