MultiSampleQScript.scala 3.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * Biopet is built on top of GATK Queue for building bioinformatic
 * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
 * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
 * should also be able to execute Biopet tools and pipelines.
 *
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
 *
 * Contact us at: sasc@lumc.nl
 *
 * A dual licensing mode is applied. The source code within this project that are
 * not part of GATK Queue is freely available for non-commercial use under an AGPL
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
16
17
package nl.lumc.sasc.biopet.core

Peter van 't Hof's avatar
Peter van 't Hof committed
18
import nl.lumc.sasc.biopet.core.config.{ Config, Configurable }
19
import nl.lumc.sasc.biopet.utils.ConfigUtils._
20
21

trait MultiSampleQScript extends BiopetQScript {
Peter van 't Hof's avatar
Peter van 't Hof committed
22
  type LibraryOutput <: AbstractLibraryOutput
Peter van 't Hof's avatar
Peter van 't Hof committed
23
  type SampleOutput <: AbstractSampleOutput
Peter van 't Hof's avatar
Peter van 't Hof committed
24

Peter van 't Hof's avatar
Peter van 't Hof committed
25
  abstract class AbstractLibraryOutput
Peter van 't Hof's avatar
Peter van 't Hof committed
26
27
  abstract class AbstractSampleOutput {
    var libraries: Map[String, LibraryOutput] = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
28
    def getAllLibraries = libraries
Peter van 't Hof's avatar
Peter van 't Hof committed
29
    def getLibrary(key: String) = libraries(key)
Peter van 't Hof's avatar
Peter van 't Hof committed
30
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
31

32
  var samplesConfig: Map[String, Any] = config("samples")
Peter van 't Hof's avatar
Peter van 't Hof committed
33
  var samplesOutput: Map[String, SampleOutput] = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
34
  def globalSampleDir: String = outputDir + "samples/"
Peter van 't Hof's avatar
Peter van 't Hof committed
35

Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
  final def runSamplesJobs() {
    if (samplesConfig == null) samplesConfig = Map()
Peter van 't Hof's avatar
Peter van 't Hof committed
38
    if (Config.global.contains("samples")) for ((key, value) <- samplesConfig) {
39
      var sample = any2map(value)
40
41
      if (!sample.contains("ID")) sample += ("ID" -> key)
      if (sample("ID") == key) {
Peter van 't Hof's avatar
Peter van 't Hof committed
42
        samplesOutput += key -> runSingleSampleJobs(sample)
Peter van 't Hof's avatar
Peter van 't Hof committed
43
      } else logger.warn("Key is not the same as ID on value for sample")
bow's avatar
bow committed
44
45
    }
    else logger.warn("No Samples found in config")
46
  }
bow's avatar
bow committed
47

Peter van 't Hof's avatar
Peter van 't Hof committed
48
49
  def runSingleSampleJobs(sampleConfig: Map[String, Any]): SampleOutput
  def runSingleSampleJobs(sample: String): SampleOutput = {
50
    var map = any2map(samplesConfig(sample))
51
52
53
54
    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)
55
  }
bow's avatar
bow committed
56

Peter van 't Hof's avatar
Peter van 't Hof committed
57
58
  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
59
    val sampleID = sampleConfig("ID").toString
Peter van 't Hof's avatar
Peter van 't Hof committed
60
    if (sampleConfig.contains("libraries")) {
61
      val runs = any2map(sampleConfig("libraries"))
bow's avatar
bow committed
62
      for ((key, value) <- runs) {
63
        var library = any2map(value)
Peter van 't Hof's avatar
Peter van 't Hof committed
64
65
66
        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
67
        } else logger.warn("Key is not the same as ID on value for run of sample: " + sampleID)
68
69
70
71
      }
    } else logger.warn("No runs found in config for sample: " + sampleID)
    return output
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
72
  def runSingleLibraryJobs(runConfig: Map[String, Any], sampleConfig: Map[String, Any]): LibraryOutput
73
}