FreeC.scala 10.8 KB
Newer Older
Wai Yi Leung's avatar
Wai Yi Leung committed
1
/**
Wai Yi Leung's avatar
Wai Yi Leung committed
2
3
4
5
6
7
8
9
10
 * 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
 *
11
 * A dual licensing mode is applied. The source code within this project is freely available for non-commercial use under an AGPL
Wai Yi Leung's avatar
Wai Yi Leung committed
12
13
14
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
Wai Yi Leung's avatar
Wai Yi Leung committed
15
package nl.lumc.sasc.biopet.extensions.freec
Wai Yi Leung's avatar
Wai Yi Leung committed
16

Peter van 't Hof's avatar
Peter van 't Hof committed
17
import java.io.{ File, PrintWriter }
Wai Yi Leung's avatar
Wai Yi Leung committed
18

Peter van 't Hof's avatar
Peter van 't Hof committed
19
import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, Reference, Version }
20
import nl.lumc.sasc.biopet.utils.config.Configurable
21
22
import org.broadinstitute.gatk.utils.commandline._

23
class FreeC(val root: Configurable) extends BiopetCommandLineFunction with Reference with Version {
Wai Yi Leung's avatar
Wai Yi Leung committed
24

25
26
  override def defaults = Map("max_walltime_limit" -> 7200)

27
28
29
30
  @Input(doc = "BAMfile", required = true)
  var input: File = _

  var inputFormat: Option[String] = config("inputFormat")
Wai Yi Leung's avatar
Wai Yi Leung committed
31

32
  var outputPath: File = _
33

Wai Yi Leung's avatar
Wai Yi Leung committed
34
35
36
  @Output(doc = "Output", shortName = "out")
  protected var output: File = _

Wai Yi Leung's avatar
Wai Yi Leung committed
37
  @Output(doc = "FreeC GC_profile")
Peter van 't Hof's avatar
Peter van 't Hof committed
38
  private var _gcProfile: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
39
  def gcProfile = new File(outputPath, "GC_profile.cnp")
Wai Yi Leung's avatar
Wai Yi Leung committed
40
41

  @Output(doc = "FreeC Read numbers per bin")
Peter van 't Hof's avatar
Peter van 't Hof committed
42
  private var _sampleBins: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
43
  def sampleBins = new File(outputPath, input.getName + "_sample.cpn")
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45

  @Output
Peter van 't Hof's avatar
Peter van 't Hof committed
46
  private var _cnvOutput: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
47
  def cnvOutput = new File(outputPath, input.getName + "_CNVs")
Wai Yi Leung's avatar
Wai Yi Leung committed
48

Peter van 't Hof's avatar
Peter van 't Hof committed
49
  @Output
Peter van 't Hof's avatar
Peter van 't Hof committed
50
  private var _bafOutput: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
51
  def bafOutput = new File(outputPath, input.getName + "_BAF.txt")
Peter van 't Hof's avatar
Peter van 't Hof committed
52
53

  @Output
Peter van 't Hof's avatar
Peter van 't Hof committed
54
  private var _ratioOutput: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
55
  def ratioOutput = new File(outputPath, input.getName + "_ratio.txt")
Peter van 't Hof's avatar
Peter van 't Hof committed
56
57

  @Output
Peter van 't Hof's avatar
Peter van 't Hof committed
58
  private var _ratioBedGraph: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
59
  def ratioBedGraph = new File(outputPath, input.getName + "_ratio.BedGraph")
Peter van 't Hof's avatar
Peter van 't Hof committed
60

Wai Yi Leung's avatar
Wai Yi Leung committed
61
  executable = config("exe", default = "freec")
Wai Yi Leung's avatar
Wai Yi Leung committed
62
  var bedGraphOutput: Boolean = config("BedGraphOutput", default = false)
63
  var _bedtools: File = config("exe", default = "bedtools", namespace = "bedtools")
64
  var bedtools: Option[String] = config("bedtools", default = _bedtools, freeVar = false)
65
66
67
68
69
70
71
72
  var breakPointThreshold: Option[Double] = config("breakPointThreshold")
  var breakPointType: Option[Int] = config("breakPointType")

  var chrFiles: File = config("chrFiles")
  var chrLenFile: File = config("chrLenFile")

  var coefficientOfVariation: Option[Double] = config("coefficientOfVariation")
  var contamination: Option[Double] = config("contamination")
Wai Yi Leung's avatar
Wai Yi Leung committed
73
  var contaminationAdjustment: Boolean = config("contaminationAdjustment", default = false)
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

  var degree: Option[String] = config("degree")
  var forceGCcontentNormalization: Option[Int] = config("forceGCcontentNormalization")

  var gcContentProfile: Option[File] = config("GCcontentProfile")
  var gemMappabilityFile: Option[String] = config("gemMappabilityFile")

  var intercept: Option[Int] = config("intercept")
  var minCNAlength: Option[Int] = config("minCNAlength")
  var minMappabilityPerWindow: Option[Double] = config("minMappabilityPerWindow")
  var minExpectedGC: Option[Double] = config("minExpectedGC")
  var maxExpectedGC: Option[Double] = config("maxExpectedGC")
  var minimalSubclonePresence: Option[Int] = config("minimalSubclonePresence")
  var maxThreads: Int = getThreads

Wai Yi Leung's avatar
Wai Yi Leung committed
89
  var noisyData: Boolean = config("noisyData", default = false)
90
91
  //var outputDir: File
  var ploidy: Option[String] = config("ploidy")
Wai Yi Leung's avatar
Wai Yi Leung committed
92
  var printNA: Boolean = config("printNA", default = false)
93
94
  var readCountThreshold: Option[Int] = config("readCountThreshold")

95
  var _sambamba: File = config("exe", namespace = "sambamba", default = "sambamba")
96
  var sambamba: File = config("sambamba", default = _sambamba, freeVar = false)
97
  var sambambaThreads: Option[Int] = config("SambambaThreads")
Wai Yi Leung's avatar
Wai Yi Leung committed
98

99
  var _samtools: File = config("exe", namespace = "samtools", default = "samtools")
100
  var samtools: File = config("samtools", default = _samtools, freeVar = false)
101
102
103
104
105

  var sex: Option[String] = config("sex")
  var step: Option[Int] = config("step")
  var telocentromeric: Option[Int] = config("telocentromeric")

Wai Yi Leung's avatar
Wai Yi Leung committed
106
  var uniqueMatch: Boolean = config("uniqueMatch", default = false)
107
108
109
110
111
  var window: Option[Int] = config("window")

  /** [sample] options */
  //  var mateFile: File = input
  var mateCopyNumberFile: Option[File] = config("mateCopyNumberFile")
Wai Yi Leung's avatar
Wai Yi Leung committed
112
  //  var inputFormat: Option[String] = config("inputFormat")
113
114
115
  var mateOrientation: Option[String] = config("mateOrientation")

  /** [BAF] options */
116
  var snpFile: Option[File] = config("snpFile")
117
118
119
120
121
122
123
124
  var minimalCoveragePerPosition: Option[Int] = config("minimalCoveragePerPosition")
  var makePileup: Option[File] = config("makePileup")
  var fastaFile: Option[File] = config("fastaFile")
  var minimalQualityPerPosition: Option[Int] = config("minimalQualityPerPosition")
  var shiftInQuality: Option[Int] = config("shiftInQuality")

  /** [target] */
  var captureRegions: Option[File] = config("captureRegions")
Wai Yi Leung's avatar
Wai Yi Leung committed
125

126
  // Control-FREEC v8.7 : calling copy number alterations and LOH regions using deep-sequencing data
127
  override def versionCommand = executable
128
  override def versionRegex = """Control-FREEC v([0-9\.]+) : .*""".r
Peter van 't Hof's avatar
Peter van 't Hof committed
129
  override def defaultThreads = 4
Sander Bollen's avatar
Sander Bollen committed
130
  override def defaultCoreMemory = 50
Peter van 't Hof's avatar
Peter van 't Hof committed
131

Peter van 't Hof's avatar
Peter van 't Hof committed
132
  private var configFile: File = _
133

134
135
  override def beforeGraph {
    super.beforeGraph
Peter van 't Hof's avatar
Peter van 't Hof committed
136

Peter van 't Hof's avatar
Peter van 't Hof committed
137
138
139
140
141
142
    _gcProfile = gcProfile
    _sampleBins = sampleBins
    _cnvOutput = cnvOutput
    _bafOutput = bafOutput
    _ratioOutput = ratioOutput
    _ratioBedGraph = ratioBedGraph
Peter van 't Hof's avatar
Peter van 't Hof committed
143

Peter van 't Hof's avatar
Peter van 't Hof committed
144
145
    configFile = new File(outputPath, input.getName + ".freec_config.txt")
    output = cnvOutput
146
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
147

Peter van 't Hof's avatar
Peter van 't Hof committed
148
149
  override def beforeCmd: Unit = {
    super.beforeCmd
150

Wai Yi Leung's avatar
Wai Yi Leung committed
151
    outputPath.mkdirs()
Peter van 't Hof's avatar
Peter van 't Hof committed
152
153

    logger.info("Creating FREEC config file: " + configFile.getAbsolutePath)
Wai Yi Leung's avatar
Wai Yi Leung committed
154
155
    createConfigFile
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
156

Peter van 't Hof's avatar
Peter van 't Hof committed
157
158
  protected def createConfigFile = {
    val writer = new PrintWriter(configFile)
Wai Yi Leung's avatar
Wai Yi Leung committed
159

160
    val conf: String = "[general]" + "\n" +
Wai Yi Leung's avatar
Wai Yi Leung committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
      conditional(bedGraphOutput, "BedGraphOutput=TRUE", escape = false) + "\n" +
      required("bedtools=", bedtools, spaceSeparated = false, escape = false) + "\n" +
      optional("breakPointThreshold=", breakPointThreshold, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("breakPointType=", breakPointType, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      required("chrFiles=", chrFiles, spaceSeparated = false, escape = false) + "\n" +
      required("chrLenFile=", chrLenFile, spaceSeparated = false, escape = false) + "\n" +
      optional("coefficientOfVariation=", coefficientOfVariation, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("contamination=", contamination, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      conditional(contaminationAdjustment, "contaminationAdjustment=TRUE", escape = false) + "\n" +
      optional("degree=", degree, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("forceGCcontentNormalization=", forceGCcontentNormalization, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("GCcontentProfile=", gcContentProfile, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("gemMappabilityFile=", gemMappabilityFile, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("intercept=", intercept, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("minCNAlength=", minCNAlength, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("minMappabilityPerWindow=", minMappabilityPerWindow, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("minExpectedGC=", minExpectedGC, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("maxExpectedGC=", maxExpectedGC, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("minimalSubclonePresence=", minimalSubclonePresence, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("maxThreads=", getThreads, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      conditional(noisyData, "noisyData=TRUE", escape = false) + "\n" +
      required("outputDir=", outputPath, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("ploidy=", ploidy, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      conditional(printNA, "printNA=TRUE", escape = false) + "\n" +
      optional("readCountThreshold=", readCountThreshold, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      required("sambamba=", sambamba, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("SambambaThreads=", sambambaThreads, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      required("samtools=", samtools, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("sex=", sex, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("step=", step, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("telocentromeric=", telocentromeric, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      conditional(uniqueMatch, "uniqueMatch=TRUE", escape = false) + "\n" +
      optional("window=", window, suffix = "", spaceSeparated = false, escape = false) + "\n" +
194
      "[sample]" + "\n" +
Wai Yi Leung's avatar
Wai Yi Leung committed
195
196
197
198
      required("mateFile=", input, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("mateCopyNumberFile=", mateCopyNumberFile, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      required("inputFormat=", inputFormat, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      required("mateOrientation=", mateOrientation, suffix = "", spaceSeparated = false, escape = false) + "\n" +
199
      "[BAF]" + "\n" +
Wai Yi Leung's avatar
Wai Yi Leung committed
200
201
202
203
204
205
      optional("SNPfile=", snpFile, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("minimalCoveragePerPosition=", minimalCoveragePerPosition, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("makePileup=", makePileup, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("fastaFile=", fastaFile, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("minimalQualityPerPosition=", minimalQualityPerPosition, suffix = "", spaceSeparated = false, escape = false) + "\n" +
      optional("shiftInQuality=", shiftInQuality, suffix = "", spaceSeparated = false, escape = false) + "\n" +
206
      "[target]" + "\n" +
Wai Yi Leung's avatar
Wai Yi Leung committed
207
      optional("captureRegions=", captureRegions, suffix = "", spaceSeparated = false, escape = false) + "\n"
208
209

    writer.write(conf)
Wai Yi Leung's avatar
Wai Yi Leung committed
210
211
212
213
    writer.close()
  }

  def cmdLine = required(executable) +
Peter van 't Hof's avatar
Peter van 't Hof committed
214
    required("--conf", configFile)
Wai Yi Leung's avatar
Wai Yi Leung committed
215
}