MultiSampleQScript.scala 2.32 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
import nl.lumc.sasc.biopet.utils.ConfigUtils._
5
6

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

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
21
22
  final def runSamplesJobs() {
    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
      var sample = any2map(value)
25
26
      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 = {
35
    var map = any2map(samplesConfig(sample))
36
37
38
39
    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)
40
  }
bow's avatar
bow committed
41

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