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

import java.io.File
import nl.lumc.sasc.biopet.core.config.Configurable

trait MultiSampleQScript extends BiopetQScript {
bow's avatar
bow committed
7
  var samples: Map[String, Any] = Map()
8
  var globalSampleDir: String = _
bow's avatar
bow committed
9

10
11
12
13
  def init {
    globalSampleDir = outputDir + "samples/"
  }
  
bow's avatar
bow committed
14
15
  final def runSamplesJobs: Map[String, Map[String, File]] = {
    var output: Map[String, Map[String, File]] = Map()
16
    samples = config("samples")
Peter van 't Hof's avatar
Peter van 't Hof committed
17
    if (samples == null) samples = Map()
bow's avatar
bow committed
18
    if (globalConfig.contains("samples")) for ((key, value) <- samples) {
19
20
21
      var sample = Configurable.any2map(value)
      if (!sample.contains("ID")) sample += ("ID" -> key)
      if (sample("ID") == key) {
bow's avatar
bow committed
22
        var files: Map[String, List[File]] = runSingleSampleJobs(sample)
23
      } else logger.warn("Key is not the same as ID on value for sample")
bow's avatar
bow committed
24
25
    }
    else logger.warn("No Samples found in config")
26
27
    return output
  }
bow's avatar
bow committed
28
29
30

  def runSingleSampleJobs(sampleConfig: Map[String, Any]): Map[String, List[File]]
  def runSingleSampleJobs(sample: String): Map[String, List[File]] = {
31
32
    return runSingleSampleJobs(Configurable.any2map(samples(sample)))
  }
bow's avatar
bow committed
33

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