IGVToolsCount.scala 4.3 KB
Newer Older
bow's avatar
bow committed
1
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
bow's avatar
bow 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
16
package nl.lumc.sasc.biopet.extensions.igvtools

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

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

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

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

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

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

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

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  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)
60

Peter van 't Hof's avatar
Peter van 't Hof committed
61
  override def defaultCoreMemory = 4.0
62

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
72
73
74
75
    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"))
76
77
  }

78
  /** Returns command to execute */
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  override def cmdLine = super.cmdLine +
    required("count") +
    optional("--maxZoom", maxZoom) +
    optional("--windowSize", windowSize) +
    optional("--extFactor", extFactor) +
    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") +
    required(input) +
    required(outputArg) +
    required(genomeChromSizes)
96

97
  /** This part should never fail, these values are set within this wrapper */
98
  private def outputArg: String = {
99
100
101
102
103
    (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;
104
    }
105
  }
Wai Yi Leung's avatar
Wai Yi Leung committed
106
107
108
}

object IGVToolsCount {
109
110
111
112
113
114
  /**
   * 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
115
116
   * @throws FileNotFoundException bam File is not found
   * @throws IllegalArgumentException tdf or wig not supplied
117
   */
118
  def apply(root: Configurable, input: File, genomeChromSizes: File): IGVToolsCount = {
Wai Yi Leung's avatar
Wai Yi Leung committed
119
120
    val counting = new IGVToolsCount(root)
    counting.input = input
121
    counting.genomeChromSizes = genomeChromSizes
Peter van 't Hof's avatar
Peter van 't Hof committed
122
    counting
Wai Yi Leung's avatar
Wai Yi Leung committed
123
  }
124
}