FreeC.scala 10.5 KB
Newer Older
Wai Yi Leung's avatar
Wai Yi Leung committed
1
/**
Peter van 't Hof's avatar
Peter van 't Hof committed
2
3
4
5
6
7
8
9
10
11
12
13
14
  * 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 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.
  */
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

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

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
24
import scala.util.matching.Regex

Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
27
28
class FreeC(val parent: Configurable)
    extends BiopetCommandLineFunction
    with Reference
    with Version {
Wai Yi Leung's avatar
Wai Yi Leung committed
29

30
31
  override def defaults = Map("max_walltime_limit" -> 7200)

32
33
34
35
  @Input(doc = "BAMfile", required = true)
  var input: File = _

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

37
  var outputPath: File = _
38

Wai Yi Leung's avatar
Wai Yi Leung committed
39
40
41
  @Output(doc = "Output", shortName = "out")
  protected var output: File = _

Wai Yi Leung's avatar
Wai Yi Leung committed
42
  @Output(doc = "FreeC GC_profile")
Peter van 't Hof's avatar
Peter van 't Hof committed
43
  private var _gcProfile: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
44
  def gcProfile = new File(outputPath, "GC_profile.cnp")
Wai Yi Leung's avatar
Wai Yi Leung committed
45
46

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

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

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

  @Output
Peter van 't Hof's avatar
Peter van 't Hof committed
59
  private var _ratioOutput: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
60
  def ratioOutput = new File(outputPath, input.getName + "_ratio.txt")
Peter van 't Hof's avatar
Peter van 't Hof committed
61
62

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

Peter van 't Hof's avatar
Peter van 't Hof committed
66
  executable = config("exe", default = "freec", freeVar = false)
Wai Yi Leung's avatar
Wai Yi Leung committed
67
  var bedGraphOutput: Boolean = config("BedGraphOutput", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
68
69
  var bedtools: Option[File] =
    config("exe", default = "bedtools", namespace = "bedtools", freeVar = false)
70
71
72
73
74
75
76
77
  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
78
  var contaminationAdjustment: Boolean = config("contaminationAdjustment", default = false)
79
80
81
82
83
84
85
86
87
88
89
90
91
92

  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")

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

Peter van 't Hof's avatar
Peter van 't Hof committed
99
  var sambamba: File = config("exe", namespace = "sambamba", default = "sambamba", freeVar = false)
100
  var sambambaThreads: Option[Int] = config("SambambaThreads")
Wai Yi Leung's avatar
Wai Yi Leung committed
101

pjvan_thof's avatar
pjvan_thof committed
102
  var samtools: File = config("exe", namespace = "samtools", default = "samtools", freeVar = false)
103
104
105
106
107

  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
108
  var uniqueMatch: Boolean = config("uniqueMatch", default = false)
109
110
111
112
113
  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
114
  //  var inputFormat: Option[String] = config("inputFormat")
115
116
117
  var mateOrientation: Option[String] = config("mateOrientation")

  /** [BAF] options */
118
  var snpFile: Option[File] = config("snpFile")
119
120
121
122
123
124
125
126
  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
127

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

Peter van 't Hof's avatar
Peter van 't Hof committed
134
  private var configFile: File = _
135

136
137
  override def beforeGraph() {
    super.beforeGraph()
Peter van 't Hof's avatar
Peter van 't Hof committed
138

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

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

150
151
  override def beforeCmd(): Unit = {
    super.beforeCmd()
152

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

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

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

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

    writer.write(conf)
Wai Yi Leung's avatar
Wai Yi Leung committed
230
231
232
    writer.close()
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
233
234
235
  def cmdLine: String =
    required(executable) +
      required("--conf", configFile)
Wai Yi Leung's avatar
Wai Yi Leung committed
236
}