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

import nl.lumc.sasc.biopet.core.config.Configurable

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
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
13
14
15
16
    def getAllLibraries = libraries
    def getLibrary(key:String) = libraries(key)
  }
  
  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
20
21
22
23
  
  final def runSamplesJobs() {
    samplesConfig = config("samples")
    if (samplesConfig == null) samplesConfig = Map()
    if (globalConfig.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
29
      }
      else logger.warn("Key is not the same as ID on value for sample")
bow's avatar
bow committed
30
31
    }
    else logger.warn("No Samples found in config")
32
  }
bow's avatar
bow committed
33

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

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