Commit 098e447a authored by Peter van 't Hof's avatar Peter van 't Hof

Fixing small issues in the report

parent 5cf65727
......@@ -75,10 +75,11 @@
case _ => Await.result(summary.getLibraries(sampleId = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample.name}/index.html">${sample.name}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${libId}/index.html">${libId}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample.name}/Libraries/${libName}/index.html">${libName}</a></td> #end
#{
val statsPaths = Map(
"All" -> List("flagstats", "All"),
......
......@@ -75,10 +75,11 @@
case _ => Await.result(summary.getLibraries(sampleId = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample.name}/index.html">${sample.name}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${libId}/index.html">${libId}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample.name}/Libraries/${libName}/index.html">${libName}</a></td> #end
#{
val statsPaths = fields.map(x => x -> List("clipping", "general", x)).toMap
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("bamstats")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
......
......@@ -76,10 +76,11 @@
case _ => Await.result(summary.getLibraries(sampleId = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample.name}/index.html">${sample.name}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${libId}/index.html">${libId}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample.name}/Libraries/${libName}/index.html">${libName}</a></td> #end
#{
val statsPaths = fields.map(x => x -> List("mapping_quality", "general", x)).toMap
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("bamstats")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
......
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(org.apache.commons.io.FileUtils)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
<%@ var rootPath: String %>
<%@ var metricsTag: String = "bammetrics" %>
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var fields: List[String] = List("mean_coverage", "pct_5x", "pct_10x", "pct_15x", "pct_20x", "pct_25x", "pct_30x", "pct_40x", "pct_50x", "pct_60x", "pct_70x", "pct_80x", "pct_90x", "pct_100x")%>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
<%@ var showIntro: Boolean = true%>
<%@ var runId: Int %>
<%@ var fields: List[String] = List("mean_coverage", "pct_5x", "pct_10x", "pct_15x", "pct_20x", "pct_25x", "pct_30x", "pct_40x", "pct_50x", "pct_60x", "pct_70x", "pct_80x", "pct_90x", "pct_100x")%>
#{
val samples = sampleId match {
case Some(sample) => {
List(sample.toString)
}
case _ => summary.samples.toList
}
val samples = Await.result(summary.getSamples(runId = Some(runId)), Duration.Inf)
}#
#if (showIntro)
......@@ -36,7 +32,7 @@
#end
#if (showPlot)
#{ BammetricsReport.wgsHistogramPlot(outputDir, "wgs", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
#{ BammetricsReport.wgsHistogramPlot(outputDir, "wgs", summary, !sampleLevel, sampleId = sampleId, libraryId = libId) }#
<div class="panel-body">
<img src="wgs.png" class="img-responsive" />
......@@ -62,27 +58,25 @@
#end
</tr></thead>
<tbody>
#for (sample <- samples.toList.sorted)
#for (sample <- samples.sortBy(_.name))
#{
val libs = (libId, sampleLevel) match {
case (_, true) => List("")
case (Some(libId), _) => List(libId.toString)
case _ => summary.libraries(sample).toList
val libs: List[Option[Int]] = (libId, sampleLevel) match {
case (_, true) => List(None)
case (Some(_), _) => List(libId)
case _ => Await.result(summary.getLibraries(sampleId = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)).toList
}
}#
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample}/index.html">${sample}</a></td>
<tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample.name}/index.html">${sample.name}</a></td>
#for (libId <- libs)
#{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
#if (libs.head != libId) <tr> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample}/Libraries/${libId}/index.html">${libId}</a></td> #end
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample.name}/Libraries/${libName}/index.html">${libName}</a></td> #end
#{
val prefixPath = List("samples", sample) ::: (if (libId.isEmpty) Nil else List("libraries", libId)) ::: List("bammetrics", "stats")
val fieldValues = for (field <- fields) yield {
summary.getValue((prefixPath ::: List("wgs", "metrics", field.toUpperCase)):_*).getOrElse(prefixPath ::: metricsTag :: Nil)
}
val statsPaths = fields.map(x => x -> List("metrics", x)).toMap
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("wgs")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
}#
#for (value <- fieldValues)
<td>${value}</td>
#for (field <- fields)
<td>${results(field)}</td>
#end
</tr>
#end
......
......@@ -244,6 +244,12 @@ object ConfigUtils extends Logging {
case i: String =>
logger.warn("Value '" + any + "' is a string insteadof int in json file, trying auto convert")
i.toInt
case Some(i: Int) => i
case Some(i: Double) => i.toInt
case Some(i: Long) => i.toInt
case Some(i: String) =>
logger.warn("Value '" + any + "' is a string insteadof int in json file, trying auto convert")
i.toInt
case _ => throw new IllegalStateException("Value '" + any + "' is not an int")
}
}
......@@ -257,6 +263,12 @@ object ConfigUtils extends Logging {
case l: String =>
logger.warn("Value '" + any + "' is a string insteadof int in json file, trying auto convert")
l.toLong
case Some(l: Double) => l.toLong
case Some(l: Int) => l.toLong
case Some(l: Long) => l
case Some(l: String) =>
logger.warn("Value '" + any + "' is a string insteadof int in json file, trying auto convert")
l.toLong
case _ => throw new IllegalStateException("Value '" + any + "' is not an int")
}
}
......
......@@ -285,7 +285,7 @@ class SummaryDb(val db: Database) extends Closeable {
sampleId: Option[Int] = None, keyValues: Map[String, List[String]]) = {
val libraries = Await.result(getLibraries(runId = Some(runId), sampleId = sampleId), Duration.Inf)
(for (lib <- libraries) yield {
(lib.sampleId, lib.id) -> getStatKeys(runId, pipeline, module, Left(lib.sampleId), Left(lib.id), keyValues = keyValues)
(lib.sampleId, lib.id) -> getStatKeys(runId, pipeline, module, Some(Left(lib.sampleId)), Some(Left(lib.id)), keyValues = keyValues)
}).toMap
}
......
......@@ -55,6 +55,80 @@ class SummaryDbTest extends TestNGSuite with Matchers {
db.close()
}
@Test
def testStatKeys: Unit = {
val dbFile = File.createTempFile("summary.", ".db")
dbFile.deleteOnExit()
val db = SummaryDb.openSqliteSummary(dbFile)
db.createTables()
Await.result(db.createOrUpdateStat(0, 0, Some(0), Some(0), Some(0),
"""
|{
|"content": "test",
|"content2": {
| "key": "value"
|}
| }""".stripMargin), Duration.Inf)
db.getStatKeys(0,Left(0),Some(Left(0)),Some(Left(0)),Some(Left(0)), keyValues = Map()) shouldBe Map()
db.getStatKeys(0,Left(0),Some(Left(0)),Some(Left(0)),Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map("content" -> Some("test"))
db.getStatKeys(0,Left(0),Some(Left(0)),Some(Left(0)),Some(Left(0)), keyValues = Map("content" -> List("content2", "key"))) shouldBe Map("content" -> Some("value"))
db.close()
}
@Test
def testStatsForSamples: Unit = {
val dbFile = File.createTempFile("summary.", ".db")
dbFile.deleteOnExit()
val db = SummaryDb.openSqliteSummary(dbFile)
db.createTables()
val sampleId = Await.result(db.createSample("test_sample", 0), Duration.Inf)
val libraryId = Await.result(db.createLibrary("test_library", 0, sampleId), Duration.Inf)
Await.result(db.createOrUpdateStat(0, 0, Some(0), Some(sampleId), None,
"""
|{
|"content": "test",
|"content2": {
| "key": "value"
|}
| }""".stripMargin), Duration.Inf)
db.getStatsForSamples(0, Left(0),Some(Left(0)), keyValues = Map()) shouldBe Map(0 -> Map())
db.getStatsForSamples(0, Left(0),Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map(0 -> Map("content" -> Some("test")))
db.close()
}
@Test
def testStatsForLibraries: Unit = {
val dbFile = File.createTempFile("summary.", ".db")
dbFile.deleteOnExit()
val db = SummaryDb.openSqliteSummary(dbFile)
db.createTables()
val sampleId = Await.result(db.createSample("test_sample", 0), Duration.Inf)
val libraryId = Await.result(db.createLibrary("test_library", 0, sampleId), Duration.Inf)
Await.result(db.createOrUpdateStat(0, 0, Some(0), Some(sampleId), Some(libraryId),
"""
|{
|"content": "test",
|"content2": {
| "key": "value"
|}
| }""".stripMargin), Duration.Inf)
db.getStatsForLibraries(0, Left(0),Some(Left(0)), keyValues = Map()) shouldBe Map((0,0) -> Map())
db.getStatsForLibraries(0, Left(0),Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map((0,0) -> Map("content" -> Some("test")))
db.close()
}
@Test
def testExecutable: Unit = {
val dbFile = File.createTempFile("summary.", ".db")
......
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
<%@ var summary: Summary %>
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
<%@ var summary: SummaryDb %>
<%@ var runId: Int %>
#{
val run = Await.result(summary.getRuns(runId = Some(runId)), Duration.Inf).head
}#
<table class="table">
<tbody>
<tr><th>Pipeline</th><td>Carp</td></tr>
<tr><th>Version</th><td>${summary.getValue("meta", "pipeline_version")}</td></tr>
<tr><th>Last commit hash</th><td>${summary.getValue("meta", "last_commit_hash")}</td></tr>
<tr><th>Output directory</th><td>${summary.getValue("meta", "output_dir")}</td></tr>
<tr><th>Version</th><td>${run.version}</td></tr>
<tr><th>Last commit hash</th><td>${run.commitHash}</td></tr>
<tr><th>Output directory</th><td>${run.outputDir}</td></tr>
</tbody>
</table>
<br/>
......
......@@ -19,7 +19,7 @@ import nl.lumc.sasc.biopet.pipelines.mapping.MultisampleMappingReportTrait
import nl.lumc.sasc.biopet.utils.config.Configurable
/**
* Class for report for CArp
* Class for report for Carp
*
* Created by pjvanthof on 25/06/15.
*/
......
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#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 summary: SummaryDb %>
<%@ var runId: Int %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
......@@ -12,13 +16,18 @@
<%@ var showIntro: Boolean = true %>
<%@ var multisample: Boolean = true %>
#{
val samples = sampleId match {
case Some(sample) => List(sample.toString)
case _ => summary.samples.toList
}
val trimCount = summary.getLibraryValues("flexiprep", "settings", "skip_trim").count(_._2 == Some(false))
val clipCount = summary.getLibraryValues("flexiprep", "settings", "skip_clip").count(_._2 == Some(false))
val librariesCount = summary.samples.foldLeft(0)(_ + summary.libraries(_).size)
val samples = Await.result(summary.getSamples(runId = Some(runId), sampleId = sampleId), Duration.Inf)
val libraries = Await.result(summary.getLibraries(runId = Some(runId), sampleId = sampleId), Duration.Inf)
val settings = summary.getSettingsForLibraries(runId, Right("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(true))
val clipCount = settings.count(_._2.getOrElse("skip_clip", None) == Some(true))
val librariesCount = libraries.size
val paired: Boolean = if (sampleId.isDefined && libId.isDefined)
summary.getSettingKeys(runId, Right("flexiprep"), None, sampleId.map(Left(_)), libId.map(Left(_)), keyValues = Map("paired" -> List("paired"))).getOrElse("paired", None) == Some(true)
else settings.count(_._2.getOrElse("skip_clip", None) == Some(true)) >= 1
}#
#if (showIntro)
<br/>
......@@ -56,9 +65,6 @@
#end
#if (showPlot)
#{
val paired: Boolean = if (sampleId.isDefined && libId.isDefined)
summary.getLibraryValue(sampleId.get, libId.get, "flexiprep", "settings", "paired").get.asInstanceOf[Boolean]
else summary.getLibraryValues("flexiprep", "settings", "paired").values.exists(_ == Some(true))
FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R1","R1", summary, sampleId = sampleId)
if (paired) FlexiprepReport.baseSummaryPlot(outputDir, "QC_Bases_R2","R2", summary, sampleId = sampleId)
}#
......@@ -103,41 +109,40 @@
<th>After QC</th>
</tr></thead>
<tbody>
#for (sample <- samples.toList.sorted)
#for (sample <- samples.sortBy(_.name))
#{
val libs = libId match {
case Some(libId) => List(libId.toString).sorted
case _ => summary.libraries(sample).toList.sorted
}
val sampleRowspan = {
libs.size +
libs.count(summary.getLibraryValue(sample, _, "flexiprep", "settings", "paired").getOrElse(false) == true)
libraries.size +
settings.count(_._2("paired").getOrElse(false) == true)
}
}#
<tr><td rowspan="${sampleRowspan}">
#if (multisample)
<a href="${rootPath}Samples/${sample}/index.html">${sample}</a>
<a href="${rootPath}Samples/${sample.name}/index.html">${sample.name}</a>
#else
${sample}
#end
</td>
#for (libId <- libs)
#if (libs.head != libId) <tr> #end
#{ val paired = summary.getLibraryValue(sample, libId, "flexiprep", "settings", "paired").getOrElse(false) }#
#for (lib <- libraries.filter(_.sampleId == sample.id))
#if (Some(lib.id) != libId) <tr> #end
#{ val paired = settings.filter(_._1._1 == sample.id).filter(_._1._2 == lib.id).head._2("paired") == Some(true) }#
<td #if (paired == true) rowspan="2" #end>
#if (multisample)
<a href="${rootPath}Samples/${sample}/Libraries/${libId}/index.html">${libId}</a>
<a href="${rootPath}Samples/${sample.name}/Libraries/${lib.name}/index.html">${lib.name}</a>
#else
${libId}
${lib.name}
#end
</td>
#{ val reads = if (paired == true) List("R1", "R2") else List("R1") }#
#for (read <- reads)
#if (read == "R2") </tr><tr> #end
#{
val beforeTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read, "bases", "num_total").getOrElse(0).toString.toLong
val afterTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read + "_qc", "bases", "num_total").getOrElse(0).toString.toLong
val statsPaths = Map("num_total" -> List("bases", "num_total"))
val seqstatStats = summary.getStatKeys(runId, Right("flexiprep"), Some(Right("seqstat_" + read)), sample = Some(Left(sample.id)), library = Some(Left(lib.id)), keyValues = statsPaths)
val seqstatQcStats = summary.getStatKeys(runId, Right("flexiprep"), Some(Right("seqstat_" + read + "_qc")), sample = Some(Left(sample.id)), library = Some(Left(lib.id)), keyValues = statsPaths)
val beforeTotal = seqstatStats("num_total").getOrElse(0).toString.toLong
val afterTotal = seqstatQcStats("num_total").getOrElse(0).toString.toLong
}#
<td>${read}</td>
<td>${beforeTotal}</td>
......
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(org.apache.commons.io.FileUtils)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] %>
<%@ var libId: Option[String] %>
<%@ var summary: SummaryDb %>
<%@ var runId: Int %>
<%@ var sampleId: Option[Int] %>
<%@ var libId: Option[Int] %>
<%@ var plot: String %>
<%@ var outputDir: File %>
#{
val paired: Boolean = summary.getLibraryValue(sampleId.get, libId.get, "flexiprep", "settings", "paired").get.asInstanceOf[Boolean]
val skipClip: Boolean = summary.getLibraryValue(sampleId.get, libId.get, "flexiprep", "settings", "skip_clip").get.asInstanceOf[Boolean]
val skipTrim: Boolean = summary.getLibraryValue(sampleId.get, libId.get, "flexiprep", "settings", "skip_trim").get.asInstanceOf[Boolean]
val settings = summary.getSettingKeys(runId, Right("flexiprep"), keyValues = Map(
"skip_trim" -> List("skip_trim"), "skip_clip" -> List("skip_clip"), "paired" -> List("paired")))
val paired: Boolean = settings("paired") == Some(true)
val skipClip: Boolean = settings("skip_clip") == Some(true)
val skipTrim: Boolean = settings("skip_trim") == Some(true)
def getPlot(read:String) = {
summary.getLibraryValue(sampleId.get, libId.get, "flexiprep", "files", read, plot, "path").collect {
val file = Await.result(summary.getFile(runId, Right("flexiprep"), Some(Right(read)), sampleId.map(Left(_)), libId.map(Left(_)), plot), Duration.Inf)
file.collect {
case path => {
val file = new File(path.toString)
val file = new File(path.path.toString)
val newFile = new File(outputDir, read + "_" + file.getName)
if (file.exists()) FileUtils.copyFile(file, newFile)
newFile.getName
......@@ -24,7 +32,8 @@
}
def plotAvailable(read:String) = {
new File(summary.getLibraryValue(sampleId.get, libId.get, "flexiprep", "files", read, plot, "path").get.toString).exists()
val file = Await.result(summary.getFile(runId, Right("flexiprep"), Some(Right(read)), sampleId.map(Left(_)), libId.map(Left(_)), plot), Duration.Inf)
file.map(x => new File(x.path).exists()).getOrElse(false)
}
}#
......
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
<%@ var libId: Option[String] = None %>
#import(nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport)
<%@ var summary: SummaryDb %>
<%@ var runId: Int %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
<%@ var rootPath: String %>
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
......@@ -12,17 +15,18 @@
<%@ var showIntro: Boolean = true %>
<%@ var multisample: Boolean = true %>
#{
val samples = sampleId match {
case Some(sample) => List(sample.toString)
case _ => summary.samples.toList
}
val trimCount = summary.getLibraryValues("flexiprep", "settings", "skip_trim").count(_._2 == Some(false))
val clipCount = summary.getLibraryValues("flexiprep", "settings", "skip_clip").count(_._2 == Some(false))
val librariesCount = summary.samples.foldLeft(0)(_ + summary.libraries(_).size)
val samples = Await.result(summary.getSamples(runId = Some(runId), sampleId = sampleId), Duration.Inf)
val libraries = Await.result(summary.getLibraries(runId = Some(runId), sampleId = sampleId), Duration.Inf)
val settings = summary.getSettingsForLibraries(runId, Right("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(true))
val clipCount = settings.count(_._2.getOrElse("skip_clip", None) == Some(true))
val librariesCount = libraries.size
val paired: Boolean = if (sampleId.isDefined && libId.isDefined)
summary.getLibraryValue(sampleId.get, libId.get, "flexiprep", "settings", "paired").get.asInstanceOf[Boolean]
else summary.getLibraryValues("flexiprep", "settings", "paired").values.exists(_ == Some(true))
summary.getSettingKeys(runId, Right("flexiprep"), None, sampleId.map(Left(_)), libId.map(Left(_)), keyValues = Map("paired" -> List("paired"))).getOrElse("paired", None) == Some(true)
else settings.count(_._2.getOrElse("skip_clip", None) == Some(true)) >= 1
}#
#if (showIntro)
......@@ -110,30 +114,26 @@
<th>After QC</th>
</tr></thead>
<tbody>
#for (sample <- samples.toList.sorted)
#for (sample <- samples.sortBy(_.name))
#{
val libs = libId match {
case Some(libId) => List(libId.toString).sorted
case _ => summary.libraries(sample).toList.sorted
}
val sampleRowspan = {
libs.size +
libs.count(summary.getLibraryValue(sample, _, "flexiprep", "settings", "paired").getOrElse(false) == true)
libraries.size +
settings.count(_._2("paired").getOrElse(false) == true)
}
}#
<tr><td rowspan="${sampleRowspan}">
#if (multisample)
<a href="${rootPath}Samples/${sample}/index.html">${sample}</a>
<a href="${rootPath}Samples/${sample.name}/index.html">${sample.name}</a>
#else
${sample}
#end
</td>
#for (libId <- libs)
#if (libs.head != libId) <tr> #end
#{ val paired = summary.getLibraryValue(sample, libId, "flexiprep", "settings", "paired").getOrElse(false) }#
#for (lib <- libraries.filter(_.sampleId == sample.id))
#if (Some(libraries.head.id) != libId) <tr> #end
#{ val paired = settings.filter(_._1._1 == sample.id).filter(_._1._2 == lib.id).head._2("paired") == Some(true) }#
<td #if (paired == true) rowspan="2" #end>
#if (multisample)
<a href="${rootPath}Samples/${sample}/Libraries/${libId}/index.html">${libId}</a>
<a href="${rootPath}Samples/${sample.name}/Libraries/${lib.name}/index.html">${lib.name}</a>
#else
${libId}
#end
......@@ -142,11 +142,22 @@
#for (read <- reads)
#if (read == "R2") </tr><tr> #end
#{
val beforeTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read, "reads", "num_total").getOrElse(0).toString.toLong
val afterTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read + "_qc", "reads", "num_total").getOrElse(0).toString.toLong
val clippingDiscardedToShort = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "clipping_" + read, "num_reads_discarded_too_short").getOrElse(0).toString.toLong
val clippingDiscardedToLong = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "clipping_" + read, "num_reads_discarded_too_long").getOrElse(0).toString.toLong
var trimmingDiscarded = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "trimming_" + read, "num_reads_discarded_total").getOrElse(0).toString.toLong
val seqstatPaths = Map("num_total" -> List("reads", "num_total"))
val seqstatStats = summary.getStatKeys(runId, Right("flexiprep"), Some(Right("seqstat_" + read)), sample = Some(Left(sample.id)), library = Some(Left(lib.id)), keyValues = seqstatPaths)
val seqstatQcStats = summary.getStatKeys(runId, Right("flexiprep"), Some(Right("seqstat_" + read + "_qc")), sample = Some(Left(sample.id)), library = Some(Left(lib.id)), keyValues = seqstatPaths)
val clippingPaths = Map("num_reads_discarded_too_short" -> List("num_reads_discarded_too_short"),
"num_reads_discarded_too_long" -> List("num_reads_discarded_too_long"))
val clippingStats = summary.getStatKeys(runId, Right("flexiprep"), Some(Right("clipping_" + read)), sample = Some(Left(sample.id)), library = Some(Left(lib.id)), keyValues = clippingPaths)
val trimmingPaths = Map("num_reads_discarded" -> List("num_reads_discarded_" + read))
val trimmingStats = summary.getStatKeys(runId, Right("flexiprep"), Some(Right("trimming")), sample = Some(Left(sample.id)), library = Some(Left(lib.id)), keyValues = trimmingPaths)
val beforeTotal = seqstatStats("num_total").getOrElse(0).toString.toLong
val afterTotal = seqstatQcStats("num_total").getOrElse(0).toString.toLong
val clippingDiscardedToShort = clippingStats("num_reads_discarded_too_short").getOrElse(0).toString.toLong
val clippingDiscardedToLong = clippingStats("num_reads_discarded_too_long").getOrElse(0).toString.toLong
val trimmingDiscarded = trimmingStats("num_reads_discarded").getOrElse(0).toString.toLong
}#
<td>${read}</td>
<td>${beforeTotal}</td>
......
......@@ -14,12 +14,15 @@
*/
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.core.report.{ ReportBuilderExtension, ReportBuilder, ReportPage, ReportSection }
import nl.lumc.sasc.biopet.core.report.{ReportBuilder, ReportBuilderExtension, ReportPage, ReportSection}
import nl.lumc.sasc.biopet.utils.rscript.StackedBarPlot
import nl.lumc.sasc.biopet.utils.summary.{ Summary, SummaryValue }
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import scala.concurrent.Await
import scala.concurrent.duration.Duration
class FlexiprepReport(val parent: Configurable) extends ReportBuilderExtension {
def builder = FlexiprepReport
......@@ -84,39 +87,41 @@ object FlexiprepReport extends ReportBuilder {
def readSummaryPlot(outputDir: File,
prefix: String,
read: String,
summary: Summary,
sampleId: Option[String] = None): Unit = {
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")
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 + "_qc", "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 seqstatPaths = Map("num_total" -> List("reads", "num_total"))
val seqstatStats = summary.getStatsForLibraries(runId, Right("flexiprep"), Right("seqstat_" + read), keyValues = seqstatPaths)
val seqstatQcStats = summary.getStatsForLibraries(runId, Right("flexiprep"), Right("seqstat_" + read + "_qc"), keyValues = seqstatPaths)
val clippingPaths = Map("num_reads_discarded_too_short" -> List("num_reads_discarded_too_short"),
"num_reads_discarded_too_long" -> List("num_reads_discarded_too_long"))
val clippingStats = summary.getStatsForLibraries(runId, Right("flexiprep"), Right("clipping_" + read), keyValues = clippingPaths)
val trimmingPaths = Map("num_reads_discarded" -> List("num_reads_discarded_" + read))
val trimmingStats = summary.getStatsForLibraries(runId, Right("flexiprep"), Right("trimming"), keyValues = trimmingPaths)
val libraries = Await.result(summary.getLibraries(runId = runId, sampleId = sampleId), Duration.Inf)
for (lib <- libraries) {
val beforeTotal = seqstatStats((lib.sampleId, lib.id))("num_total").getOrElse(0).toString.toLong
val afterTotal = seqstatQcStats((lib.sampleId, lib.id))("num_total").getOrElse(0).toString.toLong
val clippingDiscardedToShort = clippingStats((lib.sampleId, lib.id))("num_reads_discarded_too_short").getOrElse(0).toString.toLong
val clippingDiscardedToLong = clippingStats((lib.sampleId, lib.id))("num_reads_discarded_too_long").getOrElse(0).toString.toLong
val trimmingDiscarded = trimmingStats((lib.sampleId, lib.id))("num_reads_discarded").getOrElse(0).toString.toLong
val sb = new StringBuffer()
sb.append(sample + "-" + lib + "\t")
sb.append(Await.result(summary.getSampleName(lib.sampleId), Duration.Inf) + "-" + lib.name + "\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.println(sb.toString)
}
tsvWriter.close()
......@@ -125,7 +130,7 @@ object FlexiprepReport extends ReportBuilder {
plot.input = tsvFile
plot.output = pngFile
plot.ylabel = Some("Reads")
plot.width = Some(200 + (summary.libraries.filter(s => sampleId.getOrElse(s._1) == s._1).foldLeft(0)(_ + _._2.size) * 10))
plot.width = Some(200 + (libraries.filter(s => sampleId.getOrElse(s.id) == s.id).size * 10))
plot.title = Some("QC summary on " + read + " reads")
plot.runLocal()
}
......@@ -141,31 +146,29 @@ object FlexiprepReport extends ReportBuilder {
def baseSummaryPlot(outputDir: File,
prefix: String,
read: String,
summary: Summary,
sampleId: Option[String] = None): Unit = {
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 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 + "_qc", "bases", "num_total"),
summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
val statsPaths = Map("num_total" -> List("bases", "num_total"))
val seqstatStats = summary.getStatsForLibraries(runId, Right("flexiprep"), Right("seqstat_" + read), keyValues = statsPaths)
val seqstatQcStats = summary.getStatsForLibraries(runId, Right("flexiprep"), Right("seqstat_" + read + "_qc"), keyValues = statsPaths)
val libraries = Await.result(summary.getLibraries(runId = runId, sampleId = sampleId), Duration.Inf)