MultiSampleQScript.scala 2.33 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

16
  var samplesConfig: Map[String, Any] = config("samples")
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
  final def runSamplesJobs() {
    if (samplesConfig == null) samplesConfig = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
22
    if (Config.global.contains("samples")) for ((key, value) <- samplesConfig) {
23
24
25
      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
26
        samplesOutput += key -> runSingleSampleJobs(sample)
Peter van 't Hof's avatar
Peter van 't Hof committed
27
      } else logger.warn("Key is not the same as ID on value for sample")
bow's avatar
bow committed
28
29
    }
    else logger.warn("No Samples found in config")
30
  }
bow's avatar
bow committed
31

Peter van 't Hof's avatar
Peter van 't Hof committed
32
33
  def runSingleSampleJobs(sampleConfig: Map[String, Any]): SampleOutput
  def runSingleSampleJobs(sample: String): SampleOutput = {
34
35
36
37
38
    var map = Configurable.any2map(samplesConfig(sample))
    if (map.contains("ID") && map("ID") != sample)
      throw new IllegalStateException("ID in config not the same as the key")
    else map += ("ID" -> sample)
    return runSingleSampleJobs(map)
39
  }
bow's avatar
bow committed
40

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