MultiSampleQScript.scala 2.18 KB
Newer Older
1
2
package nl.lumc.sasc.biopet.core

Peter van 't Hof's avatar
Peter van 't Hof committed
3
import nl.lumc.sasc.biopet.core.config.{ Config, Configurable }
4
5

trait MultiSampleQScript extends BiopetQScript {
Peter van 't Hof's avatar
Peter van 't Hof committed
6
  type LibraryOutput <: AbstractLibraryOutput
Peter van 't Hof's avatar
Peter van 't Hof committed
7
  type SampleOutput <: AbstractSampleOutput
Peter van 't Hof's avatar
Peter van 't Hof committed
8

Peter van 't Hof's avatar
Peter van 't Hof committed
9
  abstract class AbstractLibraryOutput
Peter van 't Hof's avatar
Peter van 't Hof committed
10
11
  abstract class AbstractSampleOutput {
    var libraries: Map[String, LibraryOutput] = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
12
    def getAllLibraries = libraries
Peter van 't Hof's avatar
Peter van 't Hof committed
13
    def getLibrary(key: String) = libraries(key)
Peter van 't Hof's avatar
Peter van 't Hof committed
14
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
15

Peter van 't Hof's avatar
Peter van 't Hof committed
16
  var samplesConfig: Map[String, Any] = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
17
  var samplesOutput: Map[String, SampleOutput] = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
18
  def globalSampleDir: String = outputDir + "samples/"
Peter van 't Hof's avatar
Peter van 't Hof committed
19

Peter van 't Hof's avatar
Peter van 't Hof committed
20
21
22
  final def runSamplesJobs() {
    samplesConfig = config("samples")
    if (samplesConfig == null) samplesConfig = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
23
    if (Config.global.contains("samples")) for ((key, value) <- samplesConfig) {
24
25
26
      var sample = Configurable.any2map(value)
      if (!sample.contains("ID")) sample += ("ID" -> key)
      if (sample("ID") == key) {
Peter van 't Hof's avatar
Peter van 't Hof committed
27
        samplesOutput += key -> runSingleSampleJobs(sample)
Peter van 't Hof's avatar
Peter van 't Hof committed
28
      } else logger.warn("Key is not the same as ID on value for sample")
bow's avatar
bow committed
29
30
    }
    else logger.warn("No Samples found in config")
31
  }
bow's avatar
bow committed
32

Peter van 't Hof's avatar
Peter van 't Hof committed
33
34
  def runSingleSampleJobs(sampleConfig: Map[String, Any]): SampleOutput
  def runSingleSampleJobs(sample: String): SampleOutput = {
Peter van 't Hof's avatar
Peter van 't Hof committed
35
    return runSingleSampleJobs(Configurable.any2map(samplesConfig(sample)))
36
  }
bow's avatar
bow committed
37

Peter van 't Hof's avatar
Peter van 't Hof committed
38
39
  final def runLibraryJobs(sampleConfig: Map[String, Any]): Map[String, LibraryOutput] = {
    var output: Map[String, LibraryOutput] = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
40
    val sampleID = sampleConfig("ID").toString
Peter van 't Hof's avatar
Peter van 't Hof committed
41
42
    if (sampleConfig.contains("libraries")) {
      val runs = Configurable.any2map(sampleConfig("libraries"))
bow's avatar
bow committed
43
      for ((key, value) <- runs) {
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
46
47
        var library = Configurable.any2map(value)
        if (!library.contains("ID")) library += ("ID" -> key)
        if (library("ID") == key) {
          output += key -> runSingleLibraryJobs(library, sampleConfig)
Peter van 't Hof's avatar
Peter van 't Hof committed
48
        } else logger.warn("Key is not the same as ID on value for run of sample: " + sampleID)
49
50
51
52
      }
    } else logger.warn("No runs found in config for sample: " + sampleID)
    return output
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
53
  def runSingleLibraryJobs(runConfig: Map[String, Any], sampleConfig: Map[String, Any]): LibraryOutput
54
}