Commit b2475ba7 authored by Peter van 't Hof's avatar Peter van 't Hof

Fix format

parent 4228881c
......@@ -17,9 +17,9 @@ package nl.lumc.sasc.biopet.core
import java.io.File
import nl.lumc.sasc.biopet.core.MultiSampleQScript.Gender
import nl.lumc.sasc.biopet.core.summary.{Summarizable, SummaryQScript}
import nl.lumc.sasc.biopet.core.summary.{ Summarizable, SummaryQScript }
import nl.lumc.sasc.biopet.utils.summary.SummaryDb
import nl.lumc.sasc.biopet.utils.{ConfigUtils, Logging}
import nl.lumc.sasc.biopet.utils.{ ConfigUtils, Logging }
import org.broadinstitute.gatk.queue.QScript
import scala.concurrent.Await
......
......@@ -112,9 +112,9 @@ object WriteDependencies extends Logging with Configurable {
case cmd: CommandLineFunction => cmd.commandLine
case _ => None
}), "main_job" -> (f match {
case cmd: BiopetCommandLineFunction => cmd.mainFunction
case cmd: BiopetCommandLineFunction => cmd.mainFunction
case s: WriteSummary if s.qscript.parent == null => true
case _ => false
case _ => false
}), "intermediate" -> f.isIntermediate,
"depends_on_intermediate" -> BiopetQScript.safeInputs(f).getOrElse(Seq()).exists(files(_).isIntermediate),
"depends_on_jobs" -> BiopetQScript.safeInputs(f).getOrElse(Seq()).toList.flatMap(files(_).outputJobNames).distinct,
......
......@@ -14,10 +14,10 @@
*/
package nl.lumc.sasc.biopet.core.summary
import java.io.{File, PrintWriter}
import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.core.extensions.{CheckChecksum, Md5sum}
import nl.lumc.sasc.biopet.core.extensions.{ CheckChecksum, Md5sum }
import nl.lumc.sasc.biopet.utils.summary.SummaryDb
import org.broadinstitute.gatk.queue.QScript
......@@ -52,8 +52,8 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript =>
def summaryFile: File
def summaryDbFile: File = root match {
case s:SummaryQScript => new File(s.outputDir, s"${s.summaryName}.summary.db")
case _ => throw new IllegalStateException("Root should be a SummaryQScript")
case s: SummaryQScript => new File(s.outputDir, s"${s.summaryName}.summary.db")
case _ => throw new IllegalStateException("Root should be a SummaryQScript")
}
/**
......@@ -113,10 +113,9 @@ trait SummaryQScript extends BiopetQScript { qscript: QScript =>
private def runIdFile = root match {
case s: SummaryQScript => new File(s.outputDir, s".log/summary.runid")
case _ => throw new IllegalStateException("Root should be a SummaryQscript")
case _ => throw new IllegalStateException("Root should be a SummaryQscript")
}
private def createRun(): Int = {
val db = SummaryDb.openSqliteSummary(summaryDbFile)
val id = Await.result(db.createRun(summaryName, outputDir), Duration.Inf)
......
......@@ -14,15 +14,15 @@
*/
package nl.lumc.sasc.biopet.core.summary
import java.io.{File, PrintWriter}
import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.LastCommitHash
import nl.lumc.sasc.biopet.utils.summary.SummaryDb
import org.broadinstitute.gatk.queue.function.{InProcessFunction, QFunction}
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
import org.broadinstitute.gatk.queue.function.{ InProcessFunction, QFunction }
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import scala.collection.mutable
import scala.io.Source
......@@ -59,7 +59,7 @@ class WriteSummary(val parent: SummaryQScript) extends InProcessFunction with Co
if (qscript == root) { // This initialize the database
qscript match {
case s: MultiSampleQScript => s.initSummaryDb
case _ => qscript.summaryRunId
case _ => qscript.summaryRunId
}
}
val db = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
......@@ -89,12 +89,12 @@ class WriteSummary(val parent: SummaryQScript) extends InProcessFunction with Co
val pipelineId = Await.result(db.getPipelines(name = Some(qscript.summaryName), runId = Some(qscript.summaryRunId)).map(_.head.id), Duration.Inf)
for (((name, sampleName, libName), summarizables) <-qscript.summarizables) {
for (((name, sampleName, libName), summarizables) <- qscript.summarizables) {
require(summarizables.nonEmpty)
val stats = ConfigUtils.anyToJson(if (summarizables.size == 1) summarizables.head.summaryStats
else {
val s = summarizables.map(_.summaryStats)
s.tail.foldLeft(Map("stats" -> s.head))((a,b) =>
s.tail.foldLeft(Map("stats" -> s.head))((a, b) =>
ConfigUtils.mergeMaps(a, Map("stats" -> b), summarizables.head.resolveSummaryConflict))("stats")
})
val moduleId = db.getModules(name = Some(name), runId = Some(qscript.summaryRunId), pipelineId = Some(pipelineId))
......
......@@ -10,8 +10,8 @@ import scala.concurrent.Await
import scala.concurrent.duration.Duration
/**
* Created by pjvanthof on 26/01/2017.
*/
* Created by pjvanthof on 26/01/2017.
*/
object SummaryToSqlite extends ToolCommand {
case class Args(inputJson: File = null,
......@@ -70,7 +70,7 @@ object SummaryToSqlite extends ToolCommand {
println(Await.result(summary.getStats(runId = Some(runId), pipelineId = Some(pipelineId), sampleId = Option(None)), Duration.Inf))
println(Await.result(summary.getStat(0,0), Duration.Inf))
println(Await.result(summary.getStat(0, 0), Duration.Inf))
db.close()
......
package nl.lumc.sasc.biopet.utils.summary
import java.io.{Closeable, File}
import java.io.{ Closeable, File }
import nl.lumc.sasc.biopet.utils.ConfigUtils
import slick.driver.H2Driver.api._
import scala.concurrent.{Await, Future}
import scala.concurrent.{ Await, Future }
import scala.concurrent.duration.Duration
import nl.lumc.sasc.biopet.utils.summary.db.Schema._
import scala.concurrent.ExecutionContext.Implicits.global
/**
* Created by pjvanthof on 05/02/2017.
*/
* Created by pjvanthof on 05/02/2017.
*/
class SummaryDb(db: Database) extends Closeable {
def close(): Unit = db.close()
......@@ -98,9 +98,10 @@ class SummaryDb(db: Database) extends Closeable {
def createPipeline(name: String, runId: Int): Future[Int] = {
getPipelines(name = Some(name), runId = Some(runId))
.flatMap{ case m =>
if (m.isEmpty) forceCreatePipeline(name, runId)
else Future(m.head.id)
.flatMap {
case m =>
if (m.isEmpty) forceCreatePipeline(name, runId)
else Future(m.head.id)
}
}
......@@ -122,9 +123,10 @@ class SummaryDb(db: Database) extends Closeable {
def createModule(name: String, runId: Int, pipelineId: Int): Future[Int] = {
getModules(name = Some(name), runId = Some(runId), pipelineId = Some(pipelineId))
.flatMap{ case m =>
if (m.isEmpty) forceCreateModule(name, runId, pipelineId)
else Future(m.head.id)
.flatMap {
case m =>
if (m.isEmpty) forceCreateModule(name, runId, pipelineId)
else Future(m.head.id)
}
}
......@@ -154,7 +156,7 @@ class SummaryDb(db: Database) extends Closeable {
}
private def statsFilter(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None,
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
val l: List[Option[Query[Stats, Stats#TableElementType, Seq] => Query[Stats, Stats#TableElementType, Seq]]] = List(
runId.map(x => y => y.filter(_.runId === x)),
pipelineId.map(x => y => y.filter(_.pipelineId === x)),
......@@ -162,7 +164,7 @@ class SummaryDb(db: Database) extends Closeable {
sampleId.map(x => y => (if (x.isDefined) y.filter(_.sampleId === x) else y.filter(_.sampleId.isEmpty))),
libId.map(x => y => (if (x.isDefined) y.filter(_.libraryId === x) else y.filter(_.libraryId.isEmpty)))
)
l.flatten.foldLeft(stats.subquery)((a,b) => b(a))
l.flatten.foldLeft(stats.subquery)((a, b) => b(a))
}
def getStats(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None,
......@@ -179,18 +181,18 @@ class SummaryDb(db: Database) extends Closeable {
y => (if (sampleId.isDefined) y.filter(_.sampleId === sampleId) else y.filter(_.sampleId.isEmpty)),
y => (if (libId.isDefined) y.filter(_.libraryId === libId) else y.filter(_.libraryId.isEmpty))
)
val q = l.foldLeft(stats.subquery)((a,b) => b(a))
val q = l.foldLeft(stats.subquery)((a, b) => b(a))
db.run(q.map(_.content).result).map(_.headOption.map(ConfigUtils.jsonTextToMap))
}
def createSetting(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None, content: String) = {
sampleId: Option[Int] = None, libId: Option[Int] = None, content: String) = {
db.run(settings.forceInsert(Setting(runId, pipelineId, moduleId, sampleId, libId, content)))
}
def getSettings(runId: Option[Int] = None, pipelineId: Option[Int] = None, moduleId: Option[Option[Int]] = None,
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
sampleId: Option[Option[Int]] = None, libId: Option[Option[Int]] = None) = {
val l: List[Option[Query[Settings, Settings#TableElementType, Seq] => Query[Settings, Settings#TableElementType, Seq]]] = List(
runId.map(x => y => y.filter(_.runId === x)),
pipelineId.map(x => y => y.filter(_.pipelineId === x)),
......@@ -198,13 +200,13 @@ class SummaryDb(db: Database) extends Closeable {
sampleId.map(x => y => (if (x.isDefined) y.filter(_.sampleId === x) else y.filter(_.sampleId.isEmpty))),
libId.map(x => y => (if (x.isDefined) y.filter(_.libraryId === x) else y.filter(_.libraryId.isEmpty)))
)
val q = l.flatten.foldLeft(settings.subquery)((a,b) => b(a))
val q = l.flatten.foldLeft(settings.subquery)((a, b) => b(a))
db.run(q.result)
}
def getSetting(runId: Int, pipelineId: Int, moduleId: Option[Int] = None,
sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = {
sampleId: Option[Int] = None, libId: Option[Int] = None): Future[Option[Map[String, Any]]] = {
val l: List[Query[Settings, Settings#TableElementType, Seq] => Query[Settings, Settings#TableElementType, Seq]] = List(
_.filter(_.runId === runId),
_.filter(_.pipelineId === pipelineId),
......@@ -213,7 +215,7 @@ class SummaryDb(db: Database) extends Closeable {
y => (if (libId.isDefined) y.filter(_.libraryId === libId) else y.filter(_.libraryId.isEmpty))
)
val q = l.foldLeft(settings.subquery)((a,b) => b(a))
val q = l.foldLeft(settings.subquery)((a, b) => b(a))
db.run(q.map(_.content).result).map(_.headOption.map(ConfigUtils.jsonTextToMap))
}
}
......
......@@ -3,8 +3,8 @@ package nl.lumc.sasc.biopet.utils.summary.db
import slick.driver.H2Driver.api._
/**
* Created by pjvan_thof on 27-1-17.
*/
* Created by pjvan_thof on 27-1-17.
*/
object Schema {
case class Run(id: Int, name: String, outputDir: String)
......@@ -118,7 +118,7 @@ object Schema {
}
val files = TableQuery[Files]
case class Executable(runId: Int, toolName: String, version : Option[String], javaVersion: Option[String], exeMd5: Option[String], javaMd5: Option[String])
case class Executable(runId: Int, toolName: String, version: Option[String], javaVersion: Option[String], exeMd5: Option[String], javaMd5: Option[String])
class Executables(tag: Tag) extends Table[Executable](tag, "Executables") {
def runId = column[Int]("runId")
def toolName = column[String]("toolName")
......
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