IGVToolsCount.scala 4.38 KB
Newer Older
bow's avatar
bow committed
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.
 */
Wai Yi Leung's avatar
Wai Yi Leung committed
16
17
18

package nl.lumc.sasc.biopet.extensions.igvtools

Peter van 't Hof's avatar
Peter van 't Hof committed
19
20
import java.io.{ File, FileNotFoundException }

Peter van 't Hof's avatar
Peter van 't Hof committed
21
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
23
24
25
26
27
28
29

/**
 * IGVTools `count` wrapper
 *
 * @constructor create a new IGVTools instance from a `.bam` file
 *
 */
Wai Yi Leung's avatar
Wai Yi Leung committed
30
31
32
33
class IGVToolsCount(val root: Configurable) extends IGVTools {
  @Input(doc = "Bam File")
  var input: File = _

34
  @Input(doc = "<genome>.chrom.sizes File", required = true)
35
  var genomeChromSizes: File = _
36

37
  @Output
Peter van 't Hof's avatar
Peter van 't Hof committed
38
  var tdf: Option[File] = None
Wai Yi Leung's avatar
Wai Yi Leung committed
39

40
  @Output
Peter van 't Hof's avatar
Peter van 't Hof committed
41
  var wig: Option[File] = None
42

43
44
45
  @Output
  def logFile = new File(jobLocalDir, "igv.log")

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  var maxZoom: Option[Int] = config("maxZoom")
  var windowSize: Option[Int] = config("windowSize")
  var extFactor: Option[Int] = config("extFactor")

  var preExtFactor: Option[Int] = config("preExtFactor")
  var postExtFactor: Option[Int] = config("postExtFactor")

  var windowFunctions: Option[String] = config("windowFunctions")
  var strands: Option[String] = config("strands")
  var bases: Boolean = config("bases", default = false)

  var query: Option[String] = config("query")
  var minMapQuality: Option[Int] = config("minMapQuality")
  var includeDuplicates: Boolean = config("includeDuplicates", default = false)

  var pairs: Boolean = config("pairs", default = false)
62

Peter van 't Hof's avatar
Peter van 't Hof committed
63
  override def defaultCoreMemory = 4.0
64

Peter van 't Hof's avatar
Peter van 't Hof committed
65
66
  override def beforeGraph() {
    super.beforeGraph()
67

68
    (tdf, wig) match {
Peter van 't Hof's avatar
Peter van 't Hof committed
69
70
71
      case (Some(t), _) => jobLocalDir = t.getParentFile
      case (_, Some(w)) => jobLocalDir = w.getParentFile
      case _            => throw new IllegalArgumentException("Must have a wig or tdf file")
72
73
    }

Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
76
77
    wig.foreach(x => if (!x.getAbsolutePath.endsWith(".wig"))
      throw new IllegalArgumentException("WIG file should have a .wig file-extension"))
    tdf.foreach(x => if (!x.getAbsolutePath.endsWith(".tdf"))
      throw new IllegalArgumentException("TDF file should have a .tdf file-extension"))
78
79
  }

80
  /** Returns command to execute */
81
82
83
  def cmdLine = {
    required(executable) +
      required("count") +
84
85
86
      optional("--maxZoom", maxZoom) +
      optional("--windowSize", windowSize) +
      optional("--extFactor", extFactor) +
87
88
89
90
91
92
93
94
95
      optional("--preExtFactor", preExtFactor) +
      optional("--postExtFactor", postExtFactor) +
      optional("--windowFunctions", windowFunctions) +
      optional("--strands", strands) +
      conditional(bases, "--bases") +
      optional("--query", query) +
      optional("--minMapQuality", minMapQuality) +
      conditional(includeDuplicates, "--includeDuplicates") +
      conditional(pairs, "--pairs") +
96
      required(input) +
97
      required(outputArg) +
98
      required(genomeChromSizes)
99
  }
100

101
  /** This part should never fail, these values are set within this wrapper */
102
  private def outputArg: String = {
103
104
105
106
107
    (tdf, wig) match {
      case (None, None)       => throw new IllegalArgumentException("Either TDF or WIG should be supplied");
      case (Some(a), None)    => a.getAbsolutePath;
      case (None, Some(b))    => b.getAbsolutePath;
      case (Some(a), Some(b)) => a.getAbsolutePath + "," + b.getAbsolutePath;
108
    }
109
  }
Wai Yi Leung's avatar
Wai Yi Leung committed
110
111
112
}

object IGVToolsCount {
113
114
115
116
117
118
  /**
   * Create an object by specifying the `input` (.bam),
   * and the `genomename` (hg18,hg19,mm10)
   *
   * @param input Bamfile to count reads from
   * @return a new IGVToolsCount instance
119
120
   * @throws FileNotFoundException bam File is not found
   * @throws IllegalArgumentException tdf or wig not supplied
121
   */
122
  def apply(root: Configurable, input: File, genomeChromSizes: File): IGVToolsCount = {
Wai Yi Leung's avatar
Wai Yi Leung committed
123
124
    val counting = new IGVToolsCount(root)
    counting.input = input
125
    counting.genomeChromSizes = genomeChromSizes
Peter van 't Hof's avatar
Peter van 't Hof committed
126
    counting
Wai Yi Leung's avatar
Wai Yi Leung committed
127
  }
128
}