Yamsvp.scala 4.13 KB
Newer Older
wyleung's avatar
wyleung committed
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * Structural variation calling
 */

package nl.lumc.sasc.biopet.pipelines.yamsvp

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

import nl.lumc.sasc.biopet.extensions.Cat
import nl.lumc.sasc.biopet.extensions.picard.MergeSamFiles
13
import nl.lumc.sasc.biopet.extensions.svcallers.Clever
wyleung's avatar
wyleung committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

import nl.lumc.sasc.biopet.pipelines.mapping.Mapping

import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.queue.function._



class Yamsvp(val root: Configurable) extends QScript with MultiSampleQScript {
  def this() = this(null)

  var reference: File = _
  var finalBamFiles: List[File] = Nil
  
  def init() {
    for (file <- configfiles) globalConfig.loadConfigFile(file)
    reference = config("reference", required = true)
    if (outputDir == null)
      throw new IllegalStateException("Output directory is not specified in the config / argument")
    else if (!outputDir.endsWith("/"))
      outputDir += "/"
  }

  def biopetScript() {
    // write the pipeline here
    // start with QC, alignment, call sambamba, call sv callers, reporting

    // read config and set all parameters for the pipeline
42
    logger.info("Starting YAM SV Pipeline")
wyleung's avatar
wyleung committed
43
    runSamplesJobs
44
    // 
wyleung's avatar
wyleung committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

  }
  
  def runSingleSampleJobs(sampleConfig: Map[String, Any]): Map[String, List[File]] = {
    var outputFiles: Map[String, List[File]] = Map()
    var libraryBamfiles: List[File] = List()
    var libraryFastqFiles: List[File] = List()
    val sampleID: String = sampleConfig("ID").toString
    val sampleDir: String = outputDir + sampleID + "/" 
    for ((library, libraryFiles) <- runLibraryJobs(sampleConfig)) {
      libraryBamfiles +:= libraryFiles("FinalBam")
    }
    
    val bamFile: File = if (libraryBamfiles.size == 1) libraryBamfiles.head
                  else if (libraryBamfiles.size > 1) {
                    val mergeSamFiles = MergeSamFiles(this, libraryBamfiles, sampleDir)
                    add(mergeSamFiles)
                    mergeSamFiles.output
                  } else null
    val fastqFile: File = if (libraryFastqFiles.size == 1) libraryFastqFiles.head
                  else if (libraryFastqFiles.size > 1) {
                    val cat = Cat.apply(this, libraryFastqFiles, sampleDir + sampleID + ".fastq")
                    add(cat)
                    cat.output
                  } else null
70
71
72
73
74
75
76

    /// bamfile will be used as input for the SV callers. First run Clever
//    val cleverVCF : File = sampleDir + "/" + sampleID + ".clever.vcf"
//    
//    val clever = Clever(this, bamFile, this.reference, sampleDir )
//    outputFiles += ("CleverVCF" -> List(clever.outputvcf) )
//    add(clever)
wyleung's avatar
wyleung committed
77
78
79
80
81
82
83
84
85
86
    return outputFiles
  }
  
  // Called for each run from a sample
  def runSingleLibraryJobs(runConfig: Map[String, Any], sampleConfig: Map[String, Any]): Map[String, File] = {
    var outputFiles: Map[String, File] = Map()
    val runID: String = runConfig("ID").toString
    val sampleID: String = sampleConfig("ID").toString
    val runDir: String = outputDir + sampleID + "/run_" + runID + "/"
    if (runConfig.contains("R1")) {
87
88
      val mapping = Mapping.loadFromLibraryConfig(this, runConfig, sampleConfig, runDir)
      mapping.skipFlexiprep = false
wyleung's avatar
wyleung committed
89
90
      mapping.skipMarkduplicates = true
      mapping.defaultAligner = "bwa"
91
92
      mapping.chunking = true
      mapping.numberChunks = 4
wyleung's avatar
wyleung committed
93
94
95
96
97
98
99
100
101
      mapping.RGLB = runConfig("ID").toString
      mapping.RGSM = sampleConfig("ID").toString
      if (runConfig.contains("PL")) mapping.RGPL = runConfig("PL").toString
      if (runConfig.contains("PU")) mapping.RGPU = runConfig("PU").toString
      if (runConfig.contains("CN")) mapping.RGCN = runConfig("CN").toString
      mapping.outputDir = runDir
      mapping.init
      mapping.biopetScript
      addAll(mapping.functions)
102

wyleung's avatar
wyleung committed
103
104
      outputFiles += ("FinalBam" -> mapping.outputFiles("finalBamFile"))
    } else this.logger.error("Sample: " + sampleID + ": No R1 found for run: " + runConfig)
105
    logger.debug( outputFiles )
wyleung's avatar
wyleung committed
106
107
108
109
110
111
112
    return outputFiles
  }
}

object Yamsvp extends PipelineCommand {
  override val pipeline = "/nl/lumc/sasc/biopet/pipelines/yamsvp/Yamsvp.class"
}