Cnmops.scala 3.78 KB
Newer Older
Wai Yi Leung's avatar
Wai Yi Leung committed
1
2
3
4
5
6
/**
 * 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.
 *
7
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
Wai Yi Leung's avatar
Wai Yi Leung committed
8
9
10
 *
 * 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
15
16
17
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
package nl.lumc.sasc.biopet.extensions

import java.io.File
18

Sander Bollen's avatar
Sander Bollen committed
19
import nl.lumc.sasc.biopet.core.Version
20
21
import nl.lumc.sasc.biopet.core.extensions.RscriptCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable
22
import org.broadinstitute.gatk.utils.commandline._
Wai Yi Leung's avatar
Wai Yi Leung committed
23

Sander Bollen's avatar
Sander Bollen committed
24
25
import nl.lumc.sasc.biopet.utils.getSemanticVersion

Wai Yi Leung's avatar
Wai Yi Leung committed
26
27
28
29
/**
 * Wrapper for the Cnmops command line tool.
 * Written based on Cnmops version v2.2.1.
 */
Sander Bollen's avatar
Sander Bollen committed
30
class Cnmops(val root: Configurable) extends RscriptCommandLineFunction with Version {
Wai Yi Leung's avatar
Wai Yi Leung committed
31

32
33
34
  override def defaultThreads = 4
  override def defaultCoreMemory: Double = 4.0

Peter van 't Hof's avatar
Peter van 't Hof committed
35
  protected var script: File = new File("/nl/lumc/sasc/biopet/extensions/cnmops.R")
36

37
38
39
40
41
  def versionCommand = {
    val v = super.cmdLine + "--version"
    v.trim.replace("'", "")
  }
  def versionRegex = "(\\d+\\.\\d+\\.\\d+)".r
Sander Bollen's avatar
Sander Bollen committed
42
43
44
45
46
47
48
49
50
51

  private def stringToInt(s: String): Option[Int] = {
    try {
      Some(s.toInt)
    } catch {
      case e: Exception => None
    }
  }

  /**
Sander Bollen's avatar
Sander Bollen committed
52
53
54
55
   * Check whether version of cn mops is at least 1.18.0
   *
   * @return
   */
Sander Bollen's avatar
Sander Bollen committed
56
  def versionCheck: Boolean = {
Sander Bollen's avatar
Sander Bollen committed
57
    getVersion.flatMap(getSemanticVersion(_)) match {
58
59
      case Some(version) => (version.major == 1 && version.minor >= 18) || version.major >= 2
      case _             => false
Sander Bollen's avatar
Sander Bollen committed
60
61
62
    }
  }

Wai Yi Leung's avatar
Wai Yi Leung committed
63
64
65
  @Input(doc = "Input file BAM", required = true)
  var input: List[File] = List()

66
67
68
  @Argument(doc = "Chromsomosome to query", required = true)
  var chromosome: String = _

69
70
71
  @Argument(doc = "Window length", required = false)
  var windowLength: Int = config("window_length", namespace = "kopisu", default = 1000)

Peter van 't Hof's avatar
Peter van 't Hof committed
72
  // output files, computed automatically from output directory
Wai Yi Leung's avatar
Wai Yi Leung committed
73
  @Output(doc = "Output CNV file")
74
  lazy val outputCnv: File = {
75
    outputDir match {
76
      case Some(dir) => new File(dir, "cnv.txt")
77
      case _         => throw new IllegalArgumentException("Unexpected error when trying to set cn.MOPS CNV output")
78
    }
Wai Yi Leung's avatar
Wai Yi Leung committed
79
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
80

Wai Yi Leung's avatar
Wai Yi Leung committed
81
  @Output(doc = "Output CNR file")
82
  lazy val outputCnr: File = {
83
    outputDir match {
84
      case Some(dir) => new File(dir, "cnr.txt")
85
      case _         => throw new IllegalArgumentException("Unexpected error when trying to set cn.MOPS CNR output")
86
    }
Wai Yi Leung's avatar
Wai Yi Leung committed
87
88
  }

89
  @Output(doc = "Raw output")
90
  lazy val rawOutput: File = {
91
    outputDir match {
92
93
      case Some(dir) => new File(dir, "rawoutput.txt")
      case _         => throw new IllegalArgumentException("Unexpected error when trying to set cn.MOPS raw output")
94
    }
95
96
  }

Wai Yi Leung's avatar
Wai Yi Leung committed
97
  /** write all output files to this directory [./] */
98
  var outputDir: Option[File] = None
Wai Yi Leung's avatar
Wai Yi Leung committed
99
100
101

  override def beforeGraph = {
    super.beforeGraph
102
    require(outputDir.isDefined, "Outputdir for cn.MOPS should not be empty")
Peter van 't Hof's avatar
Peter van 't Hof committed
103
    require(input.length >= 2, "Please supply at least 2 BAM files for cn.MOPS")
Sander Bollen's avatar
Sander Bollen committed
104
105
106
    if (!versionCheck) {
      logger.warn("cn.mops version is below 1.18.0. Contigs containing little to no reads WILL fail")
    }
Wai Yi Leung's avatar
Wai Yi Leung committed
107
  }
Wai Yi Leung's avatar
Wai Yi Leung committed
108

Peter van 't Hof's avatar
Peter van 't Hof committed
109
  override def cmdLine = super.cmdLine +
110
111
112
    required("--cnr", outputCnr) +
    required("--cnv", outputCnv) +
    required("--chr", chromosome) +
113
    required("--rawoutput", rawOutput) +
114
    required("--threads", threads) +
115
    optional("--wl", windowLength) +
116
    repeat(input)
Wai Yi Leung's avatar
Wai Yi Leung committed
117
}