MultiSampleQScript.scala 2.4 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
7
8
9
10
11
12
13
14
15
16
17
  type LibraryOutput <: AbstractLibraryOutput
  type SampleOutput[LibraryOutput] <: AbstractSampleOutput[LibraryOutput]
  
  abstract class AbstractLibraryOutput
  abstract class AbstractSampleOutput[LibraryOutput] {
    protected[MultiSampleQScript] var libraries: Map[String, LibraryOutput] = Map()
    def getAllLibraries = libraries
    def getLibrary(key:String) = libraries(key)
  }
  
  var samplesConfig: Map[String, Any] = Map()
  var samplesOutput: Map[String, SampleOutput[LibraryOutput]] = 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
28
29
30
31
        val output = runSingleSampleJobs(sample)
        if (samplesOutput.contains(key)) output.libraries = samplesOutput(key).libraries
        samplesOutput += key -> output
      }
      else logger.warn("Key is not the same as ID on value for sample")
bow's avatar
bow committed
32
33
    }
    else logger.warn("No Samples found in config")
34
  }
bow's avatar
bow committed
35

Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
38
  def runSingleSampleJobs(sampleConfig: Map[String, Any]): SampleOutput[LibraryOutput]
  def runSingleSampleJobs(sample: String): SampleOutput[LibraryOutput] = {
    return runSingleSampleJobs(Configurable.any2map(samplesConfig(sample)))
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()
43
    val sampleID = sampleConfig("ID")
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
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
}