Commit 92e0976b authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge remote-tracking branch 'remotes/origin/fix-BIOPET-591' into fix-BIOPET-587

parents df4cf4cd c8bee878
......@@ -4,6 +4,8 @@
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(scalaz._)
#import(Scalaz._)
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
......@@ -87,7 +89,7 @@
"Duplicates" -> List("flagstats", "Duplicates"),
"NotPrimaryAlignment" -> List("flagstats", "NotPrimaryAlignment")
)
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("bamstats")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
val results = summary.getStatKeys(runId, "bammetrics".right, Some("bamstats".right), sample = Some(sample.id.left), library = libId.map(_.left), keyValues = statsPaths)
val total = results("All").getOrElse(0L).asInstanceOf[Long]
val mapped = results("Mapped").getOrElse(0L).asInstanceOf[Long]
val duplicates = results("Duplicates").getOrElse(0L).asInstanceOf[Long]
......
......@@ -4,6 +4,8 @@
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(scalaz._)
#import(Scalaz._)
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
......@@ -82,7 +84,7 @@
#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)
val results = summary.getStatKeys(runId, "bammetrics".right, Some("bamstats".right), sample = Some(sample.id.left), library = libId.map(_.left), keyValues = statsPaths)
}#
#for (field <- fields)
<td>${results(field)}</td>
......
......@@ -4,6 +4,8 @@
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(scalaz._)
#import(Scalaz._)
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
......@@ -84,7 +86,7 @@
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample.name}/Libraries/${libName}/index.html">${libName}</a></td> #end
#{
val statsPaths = fields.map(x => x -> List("metrics", x.toUpperCase)).toMap
val results = summary.getStatKeys(runId, Right("bammetrics"), Some(Right("CollectInsertSizeMetrics")), sample = Some(Left(sample.id)), library = libId.map(Left(_)), keyValues = statsPaths)
val results = summary.getStatKeys(runId, "bammetrics".right, Some("CollectInsertSizeMetrics".right), sample = Some(sample.id.left), library = libId.map(_.left), keyValues = statsPaths)
}#
#for (field <- fields)
<td>${results(field)}</td>
......
......@@ -4,6 +4,8 @@
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(scalaz._)
#import(Scalaz._)
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
......@@ -83,7 +85,7 @@
#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)
val results = summary.getStatKeys(runId, "bammetrics".right, Some("bamstats".right), sample = Some(sample.id.left), library = libId.map(_.left), keyValues = statsPaths)
}#
#for (field <- fields)
<td>${results(field)}</td>
......
......@@ -4,6 +4,8 @@
#import(scala.concurrent.duration.Duration)
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
#import(scalaz._)
#import(Scalaz._)
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
......@@ -73,7 +75,7 @@
#if (!sampleLevel) <td><a href="${rootPath}Samples/${sample.name}/Libraries/${libName}/index.html">${libName}</a></td> #end
#{
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)
val results = summary.getStatKeys(runId, "bammetrics".right, Some("wgs".right), sample = Some(sample.id.left), library = libId.map(_.left), keyValues = statsPaths)
}#
#for (field <- fields)
<td>${results(field)}</td>
......
......@@ -25,6 +25,8 @@ import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scalaz._
import Scalaz._
class BammetricsReport(val parent: Configurable) extends ReportBuilderExtension {
def builder = BammetricsReport
......@@ -64,14 +66,14 @@ object BammetricsReport extends ReportBuilder {
//val pipelineId: Int = summary.getPipelineId(runId, metricsTag).map(_.get)
val wgsExecuted = summary.getStatsSize(runId, Right(metricsTag), Some(Right("wgs")), sample = sampleId.map(Left(_)), library = libId.map(Left(_))) >= 1
val rnaExecuted = summary.getStatsSize(runId, Right(metricsTag), Some(Right("rna")), sample = sampleId.map(Left(_)), library = libId.map(Left(_))) >= 1
val wgsExecuted = summary.getStatsSize(runId, Some(metricsTag.right), Some(Some("wgs".right)), sample = sampleId.map(x => Some(x.left)), library = libId.map(x => Some(x.left))) >= 1
val rnaExecuted = summary.getStatsSize(runId, Some(metricsTag.right), Some(Some("rna".right)), sample = sampleId.map(x => Some(x.left)), library = libId.map(x => Some(x.left))) >= 1
val insertsizeMetrics = summary.getStatKeys(runId, Right(metricsTag), Some(Right("CollectInsertSizeMetrics")),
sample = sampleId.map(Left(_)), library = libId.map(Left(_)), Map("metrics" -> List("metrics")))
val insertsizeMetrics = summary.getStatKeys(runId, metricsTag.right, Some("CollectInsertSizeMetrics".right),
sample = sampleId.map(_.left), library = libId.map(_.left), Map("metrics" -> List("metrics")))
.exists(_._2.isDefined)
val targetSettings = summary.getSettingKeys(runId, Right(metricsTag), None, sample = sampleId.map(Left(_)), library = libId.map(Left(_)),
val targetSettings = summary.getSettingKeys(runId, metricsTag.right, None, sample = sampleId.map(_.left), library = libId.map(_.left),
Map("amplicon_name" -> List("amplicon_name"), "roi_name" -> List("roi_name")))
val targets = (
targetSettings("amplicon_name"),
......@@ -132,10 +134,10 @@ object BammetricsReport extends ReportBuilder {
)
val results: Map[(Int, Option[Int]), Map[String, Option[Any]]] = if (libraryLevel) {
summary.getStatsForLibraries(runId, Right("bammetrics"), Some(Right("bamstats")),
summary.getStatsForLibraries(runId, "bammetrics".right, Some("bamstats".right),
sampleId = sampleId, keyValues = statsPaths).map(x => (x._1._1, Some(x._1._2)) -> x._2)
} else summary.getStatsForSamples(runId, Right("bammetrics"), Some(Right("bamstats")),
sample = sampleId.map(Left(_)), keyValues = statsPaths).map(x => (x._1, None) -> x._2)
} else summary.getStatsForSamples(runId, "bammetrics".right, Some("bamstats".right),
sample = sampleId.map(_.left), keyValues = statsPaths).map(x => (x._1, None) -> x._2)
for (((s, l), result) <- results) {
val sampleName: String = summary.getSampleName(s).map(_.get)
......@@ -175,8 +177,8 @@ object BammetricsReport extends ReportBuilder {
statsPaths: Map[String, List[String]],
xKey: String,
yKey: String,
pipeline: Either[Int, String],
module: Option[Either[Int, String]],
pipeline: \/[Int, String],
module: Option[\/[Int, String]],
xlabel: Option[String] = None,
ylabel: Option[String] = None,
title: Option[String] = None,
......@@ -187,7 +189,7 @@ object BammetricsReport extends ReportBuilder {
val results: Map[(Int, Option[Int]), Map[String, Option[Array[Any]]]] = if (libraryLevel) {
summary.getStatsForLibraries(runId, pipeline, module, sampleId = sampleId, keyValues = statsPaths)
.map(x => (x._1._1, Some(x._1._2)) -> x._2.map(x => x._1 -> x._2.map(ConfigUtils.any2list(_).toArray)))
} else summary.getStatsForSamples(runId, pipeline, module, sample = sampleId.map(Left(_)), keyValues = statsPaths)
} else summary.getStatsForSamples(runId, pipeline, module, sample = sampleId.map(_.left), keyValues = statsPaths)
.map(x => (x._1, None) -> x._2.map(x => x._1 -> x._2.map(ConfigUtils.any2list(_).toArray)))
val tables: Array[Map[String, Array[Any]]] = results.map {
......@@ -231,7 +233,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"insert_size", "count", Right("bammetrics"), Some(Right("CollectInsertSizeMetrics")),
"insert_size", "count", "bammetrics".right, Some("CollectInsertSizeMetrics".right),
"Insert size", "Reads", "Insert size")
}
......@@ -247,7 +249,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"mapping_quality", "count", Right("bammetrics"), Some(Right("bamstats")),
"mapping_quality", "count", "bammetrics".right, Some("bamstats".right),
"Mapping quality", "Reads", "Mapping quality")
}
......@@ -263,7 +265,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"clipping", "count", Right("bammetrics"), Some(Right("bamstats")),
"clipping", "count", "bammetrics".right, Some("bamstats".right),
"Clipping", "Reads", "Clipping")
}
......@@ -288,7 +290,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"coverage", "count", Right("bammetrics"), Some(Right("wgs")),
"coverage", "count", "bammetrics".right, Some("wgs".right),
"Coverage", "Bases", "Whole genome coverage")
}
......@@ -313,7 +315,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"coverage", "count", Right("bammetrics"), Some(Right("rna")),
"coverage", "count", "bammetrics".right, Some("rna".right),
"Relative position", "Coverage", "Rna coverage")
}
......
......@@ -2,7 +2,8 @@
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
#import(scalaz._)
#import(Scalaz._)
<%@ var summary: SummaryDb %>
<%@ var rootPath: String %>
<%@ var pipeline: String %>
......@@ -10,7 +11,7 @@
#{
val settings = summary.getSettingKeys(runId, Right(pipeline),
val settings = summary.getSettingKeys(runId, pipeline.right,
keyValues = Map(
"contigs" -> List("reference", "contigs"),
"species" -> List("reference", "species"),
......@@ -18,7 +19,7 @@
))
val contigs = settings.getOrElse("contigs", Some(Map())).getOrElse(Map()).asInstanceOf[Map[String, Map[String, Any]]]
val referenceFile = Await.result(summary.getFile(runId, Right(pipeline), None, None, None, key = "referenceFasta"), Duration.Inf)
val referenceFile = Await.result(summary.getFile(runId, pipeline.right, None, None, None, key = "referenceFasta"), Duration.Inf)
}#
<table class="table">
......
......@@ -14,7 +14,7 @@
*/
package nl.lumc.sasc.biopet.core.extensions
import java.io.{File, FileOutputStream}
import java.io.{ File, FileOutputStream }
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.utils.Logging
......
......@@ -32,6 +32,8 @@ import org.testng.annotations.{ AfterClass, Test }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.util.matching.Regex
import scalaz._
import Scalaz._
/**
* Created by pjvanthof on 15/01/16.
......@@ -98,8 +100,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -119,8 +121,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -140,8 +142,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -161,8 +163,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), Some(Right("sampleName")), Some(Right("libName")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), Some(Right("sampleName")), Some(Right("libName")), key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), Some("sampleName".right), Some("libName".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), Some("sampleName".right), Some("libName".right), key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -202,8 +204,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@AfterClass
......
package nl.lumc.sasc.biopet.utils.implicits
/**
* Created by pjvanthof on 20/02/2017.
*/
object Either {
implicit def optionEitherLeft[T](x: Option[Either[T, _]]): Option[Option[T]] = {
x match {
case Some(i: Either[T, _]) if i.isLeft => Some(i.left.toOption)
case _ => None
}
}
implicit def optionEitherRight[T](x: Option[Either[_, T]]): Option[Option[T]] = {
x match {
case Some(i: Either[_, T]) if i.isRight => Some(i.right.toOption)
case _ => None
}
}
implicit def eitherLeft[T](x: Either[T, _]): Option[T] = {
x match {
case Left(x) => Some(x)
case _ => None
}
}
implicit def eitherRight[T](x: Either[_, T]): Option[T] = {
x match {
case Right(x) => Some(x)
case _ => None
}
}
implicit def left[T](x: T): Left[T, _] = Left(x)
implicit def right[T](x: T): Right[_, T] = Right(x)
implicit def left[T](x: Option[T]): Option[Left[T, _]] = x.map(Left(_))
implicit def right[T](x: Option[T]): Option[Right[_, T]] = x.map(Right(_))
}
package nl.lumc.sasc.biopet.utils.summary.db
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.utils.implicits.Either._
import nl.lumc.sasc.biopet.utils.summary.db.Schema._
import slick.driver.H2Driver.api._
......@@ -11,6 +10,10 @@ import scala.concurrent.{ Await, Future }
import java.io.{ Closeable, File }
import java.sql.Date
import scalaz._
import Scalaz._
import SummaryDb.Implicts._
/**
* This class interface wityh a summary database
*
......@@ -198,40 +201,40 @@ class SummaryDb(val db: Database) extends Closeable {
/** This create or update a stat */
def createOrUpdateStat(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None, content: String): Future[Int] = {
val filter = statsFilter(Some(runId), Some(Left(pipelineId)), Some(moduleId.map(Left(_))), Some(sampleId.map(Left(_))), Some(libId.map(Left(_))))
val filter = statsFilter(Some(runId), Some(pipelineId.left), Some(moduleId.map(_.left)), Some(sampleId.map(_.left)), Some(libId.map(_.left)))
val r = Await.result(db.run(filter.size.result), Duration.Inf)
if (r == 0) createStat(runId, pipelineId, moduleId, sampleId, libId, content)
else db.run(filter.map(_.content).update(content))
}
/** Return a Query for [[Stats]] */
def statsFilter(runId: Option[Int] = None, pipeline: Option[Either[Int, String]] = None, module: Option[Option[Either[Int, String]]] = None,
sample: Option[Option[Either[Int, String]]] = None, library: Option[Option[Either[Int, String]]] = None,
def statsFilter(runId: Option[Int] = None, pipeline: Option[\/[Int, String]] = None, module: Option[Option[\/[Int, String]]] = None,
sample: Option[Option[\/[Int, String]]] = None, library: Option[Option[\/[Int, String]]] = None,
mustHaveSample: Boolean = false, mustHaveLibrary: Boolean = false) = {
var f: Query[Stats, Stats#TableElementType, Seq] = stats
runId.foreach(r => f = f.filter(_.runId === r))
f = pipeline match {
case Some(Left(id)) => f.filter(_.pipelineId === id)
case Some(Right(name)) => f.join(pipelines).on(_.pipelineId === _.id).filter(_._2.name === name).map(_._1)
case _ => f
case Some(-\/(id)) => f.filter(_.pipelineId === id)
case Some(\/-(name)) => f.join(pipelines).on(_.pipelineId === _.id).filter(_._2.name === name).map(_._1)
case _ => f
}
f = module match {
case Some(Some(Left(id))) => f.filter(_.moduleId === id)
case Some(Some(Right(name))) => f.join(modules).on(_.moduleId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.moduleId.isEmpty)
case _ => f
case Some(Some(-\/(id))) => f.filter(_.moduleId === id)
case Some(Some(\/-(name))) => f.join(modules).on(_.moduleId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.moduleId.isEmpty)
case _ => f
}
f = sample match {
case Some(Some(Left(id))) => f.filter(_.sampleId === id)
case Some(Some(Right(name))) => f.join(samples).on(_.sampleId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.sampleId.isEmpty)
case _ => f
case Some(Some(-\/(id))) => f.filter(_.sampleId === id)
case Some(Some(\/-(name))) => f.join(samples).on(_.sampleId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.sampleId.isEmpty)
case _ => f
}
f = library match {
case Some(Some(Left(id))) => f.filter(_.libraryId === id)
case Some(Some(Right(name))) => f.join(libraries).on(_.libraryId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.libraryId.isEmpty)
case _ => f
case Some(Some(-\/(id))) => f.filter(_.libraryId === id)
case Some(Some(\/-(name))) => f.join(libraries).on(_.libraryId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.libraryId.isEmpty)
case _ => f
}
if (mustHaveSample) f = f.filter(_.sampleId.nonEmpty)
......@@ -240,28 +243,28 @@ class SummaryDb(val db: Database) extends Closeable {
}
/** Return all stats that match given criteria */
def getStats(runId: Option[Int] = None, pipeline: Option[Either[Int, String]] = None, module: Option[Option[Either[Int, String]]] = None,
sample: Option[Option[Either[Int, String]]] = None, lib: Option[Option[Either[Int, String]]] = None,
def getStats(runId: Option[Int] = None, pipeline: Option[\/[Int, String]] = None, module: Option[Option[\/[Int, String]]] = None,
sample: Option[Option[\/[Int, String]]] = None, lib: Option[Option[\/[Int, String]]] = None,
mustHaveSample: Boolean = false, mustHaveLibrary: Boolean = false): Future[Seq[Stat]] = {
db.run(statsFilter(runId, pipeline, module, sample, lib, mustHaveSample, mustHaveLibrary).result)
}
/** Return number of results */
def getStatsSize(runId: Option[Int] = None, pipeline: Option[Either[Int, String]] = None, module: Option[Option[Either[Int, String]]] = None,
sample: Option[Option[Either[Int, String]]] = None, library: Option[Option[Either[Int, String]]] = None,
def getStatsSize(runId: Option[Int] = None, pipeline: Option[\/[Int, String]] = None, module: Option[Option[\/[Int, String]]] = None,
sample: Option[Option[\/[Int, String]]] = None, library: Option[Option[\/[Int, String]]] = None,
mustHaveSample: Boolean = false, mustHaveLibrary: Boolean = false): Future[Int] = {
db.run(statsFilter(runId, pipeline, module, sample, library, mustHaveSample, mustHaveLibrary).size.result)
}
/** Get a single stat as [[Map[String, Any]] */
def getStat(runId: Int, pipeline: Either[Int, String], module: Option[Either[Int, String]] = None,
sample: Option[Either[Int, String]] = None, lib: Option[Either[Int, String]] = None): Future[Option[Map[String, Any]]] = {
def getStat(runId: Int, pipeline: \/[Int, String], module: Option[\/[Int, String]] = None,
sample: Option[\/[Int, String]] = None, lib: Option[\/[Int, String]] = None): Future[Option[Map[String, Any]]] = {
getStats(Some(runId), Some(pipeline), Some(module), Some(sample), Some(lib))
.map(_.headOption.map(x => ConfigUtils.jsonTextToMap(x.content)))
}
def getStatKeys(runId: Int, pipeline: Either[Int, String], module: Option[Either[Int, String]] = None,
sample: Option[Either[Int, String]] = None, library: Option[Either[Int, String]] = None,
def getStatKeys(runId: Int, pipeline: \/[Int, String], module: Option[\/[Int, String]] = None,
sample: Option[\/[Int, String]] = None, library: Option[\/[Int, String]] = None,
keyValues: Map[String, List[String]]): Map[String, Option[Any]] = {
val stats = Await.result(getStat(runId, pipeline, module, sample, library), Duration.Inf)
keyValues.map {
......@@ -273,19 +276,19 @@ class SummaryDb(val db: Database) extends Closeable {
}
}
def getStatsForSamples(runId: Int, pipeline: Either[Int, String], module: Option[Either[Int, String]] = None,
sample: Option[Either[Int, String]] = None, keyValues: Map[String, List[String]]) = {
val samples = Await.result(getSamples(runId = Some(runId), sampleId = sample.flatMap(_.left.toOption), name = sample.flatMap(_.right.toOption)), Duration.Inf)
def getStatsForSamples(runId: Int, pipeline: \/[Int, String], module: Option[\/[Int, String]] = None,
sample: Option[\/[Int, String]] = None, keyValues: Map[String, List[String]]) = {
val samples = Await.result(getSamples(runId = Some(runId), sampleId = sample.flatMap(_.left.toOption), name = sample.flatMap(_.toOption)), Duration.Inf)
(for (s <- samples) yield {
s.id -> getStatKeys(runId, pipeline, module, Option(Left(s.id)), None, keyValues = keyValues)
s.id -> getStatKeys(runId, pipeline, module, Option(s.id.left), None, keyValues = keyValues)
}).toMap
}
def getStatsForLibraries(runId: Int, pipeline: Either[Int, String], module: Option[Either[Int, String]] = None,
def getStatsForLibraries(runId: Int, pipeline: \/[Int, String], module: Option[\/[Int, String]] = None,
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, Some(Left(lib.sampleId)), Some(Left(lib.id)), keyValues = keyValues)
(lib.sampleId, lib.id) -> getStatKeys(runId, pipeline, module, Some(lib.sampleId.left), Some(lib.id.left), keyValues = keyValues)
}).toMap
}
......@@ -295,33 +298,33 @@ class SummaryDb(val db: Database) extends Closeable {
db.run(settings.forceInsert(Setting(runId, pipelineId, moduleId, sampleId, libId, content)))
}
def settingsFilter(runId: Option[Int] = None, pipeline: Option[Either[Int, String]] = None, module: Option[Option[Either[Int, String]]] = None,
sample: Option[Option[Either[Int, String]]] = None, library: Option[Option[Either[Int, String]]] = None,
def settingsFilter(runId: Option[Int] = None, pipeline: Option[\/[Int, String]] = None, module: Option[Option[\/[Int, String]]] = None,
sample: Option[Option[\/[Int, String]]] = None, library: Option[Option[\/[Int, String]]] = None,
mustHaveSample: Boolean = false, mustHaveLibrary: Boolean = false) = {
var f: Query[Settings, Settings#TableElementType, Seq] = settings
runId.foreach(r => f = f.filter(_.runId === r))
f = pipeline match {
case Some(Left(id)) => f.filter(_.pipelineId === id)
case Some(Right(name)) => f.join(pipelines).on(_.pipelineId === _.id).filter(_._2.name === name).map(_._1)
case _ => f
case Some(-\/(id)) => f.filter(_.pipelineId === id)
case Some(\/-(name)) => f.join(pipelines).on(_.pipelineId === _.id).filter(_._2.name === name).map(_._1)
case _ => f
}
f = module match {
case Some(Some(Left(id))) => f.filter(_.moduleId === id)
case Some(Some(Right(name))) => f.join(modules).on(_.moduleId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.moduleId.isEmpty)
case _ => f
case Some(Some(-\/(id))) => f.filter(_.moduleId === id)
case Some(Some(\/-(name))) => f.join(modules).on(_.moduleId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.moduleId.isEmpty)
case _ => f
}
f = sample match {
case Some(Some(Left(id))) => f.filter(_.sampleId === id)
case Some(Some(Right(name))) => f.join(samples).on(_.sampleId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.sampleId.isEmpty)
case _ => f
case Some(Some(-\/(id))) => f.filter(_.sampleId === id)
case Some(Some(\/-(name))) => f.join(samples).on(_.sampleId === _.id).filter(_._2.name === name).map(_.