BcftoolsView.scala 5.53 KB
Newer Older
Sander Bollen's avatar
Sander Bollen committed
1
2
3
4
5
package nl.lumc.sasc.biopet.extensions.bcftools

import java.io.File

import nl.lumc.sasc.biopet.utils.config.Configurable
6
import org.broadinstitute.gatk.utils.commandline.{ Argument, Input, Output }
Sander Bollen's avatar
Sander Bollen committed
7
8
9
10
11
12
13
14
15
16
17
18

/**
 * Created by ahbbollen on 12-10-15.
 */
class BcftoolsView(val root: Configurable) extends Bcftools {

  @Input(doc = "Input VCF file")
  var input: File = _

  @Output(doc = "Output file")
  var output: File = _

19
  @Argument(doc = "drop individual genotypes", required = false)
Sander Bollen's avatar
Sander Bollen committed
20
  var dropGenotype: Boolean = config("drop_genotype", default = false)
Sander Bollen's avatar
Sander Bollen committed
21

22
  @Argument(doc = "header only", required = false)
Sander Bollen's avatar
Sander Bollen committed
23
  var headerOnly: Boolean = config("header_only", false)
Sander Bollen's avatar
Sander Bollen committed
24

25
  @Argument(doc = "Compression level", required = false)
Sander Bollen's avatar
Sander Bollen committed
26
  var compressionLevel: Int = config("compression_level", default = 9)
Sander Bollen's avatar
Sander Bollen committed
27

28
  @Argument(doc = "output type", required = false)
Sander Bollen's avatar
Sander Bollen committed
29
30
  var outputType: String = "z"

31
  @Argument(doc = "regions", required = false)
Sander Bollen's avatar
Sander Bollen committed
32
  var regions: Option[String] = config("r")
Sander Bollen's avatar
Sander Bollen committed
33

34
  @Argument(doc = "region file", required = false)
Sander Bollen's avatar
Sander Bollen committed
35
  var regionFile: Option[File] = config("R")
Sander Bollen's avatar
Sander Bollen committed
36

37
  @Argument(doc = "targets", required = false)
Sander Bollen's avatar
Sander Bollen committed
38
  var targets: Option[String] = config("t")
Sander Bollen's avatar
Sander Bollen committed
39

40
  @Argument(doc = "targets file", required = false)
Sander Bollen's avatar
Sander Bollen committed
41
  var targetFile: Option[File] = config("T")
Sander Bollen's avatar
Sander Bollen committed
42

43
  @Argument(doc = "trim alt alleles", required = false)
Sander Bollen's avatar
Sander Bollen committed
44
  var trimAltAlleles: Boolean = config("trim_alt_allele", default = false)
Sander Bollen's avatar
Sander Bollen committed
45

46
  @Argument(doc = "no update", required = false)
Sander Bollen's avatar
Sander Bollen committed
47
  var noUpdate: Boolean = config("no_update", default = false)
Sander Bollen's avatar
Sander Bollen committed
48

49
  @Argument(doc = "samples", required = false)
Sander Bollen's avatar
Sander Bollen committed
50
  var samples: List[String] = config("s", default = Nil)
Sander Bollen's avatar
Sander Bollen committed
51

52
  @Argument(doc = "samples file", required = false)
Sander Bollen's avatar
Sander Bollen committed
53
  var sampleFile: Option[File] = config("S")
Sander Bollen's avatar
Sander Bollen committed
54

55
  @Argument(doc = "minimum allele count", required = false)
Sander Bollen's avatar
Sander Bollen committed
56
  var minAC: Option[Int] = config("c")
Sander Bollen's avatar
Sander Bollen committed
57

58
  @Argument(doc = "max allele count", required = false)
Sander Bollen's avatar
Sander Bollen committed
59
  var maxAC: Option[Int] = config("C")
Sander Bollen's avatar
Sander Bollen committed
60

61
  @Argument(doc = "exclude (expression)", required = false)
Sander Bollen's avatar
Sander Bollen committed
62
  var exclude: Option[String] = config("e")
Sander Bollen's avatar
Sander Bollen committed
63

64
  @Argument(doc = "apply filters", required = false)
Sander Bollen's avatar
Sander Bollen committed
65
  var applyFilters: List[String] = config("F", default = Nil)
Sander Bollen's avatar
Sander Bollen committed
66

67
  @Argument(doc = "genotype", required = false)
Sander Bollen's avatar
Sander Bollen committed
68
  var genotype: Option[String] = config("g")
Sander Bollen's avatar
Sander Bollen committed
69

70
  @Argument(doc = "include (expression)", required = false)
Sander Bollen's avatar
Sander Bollen committed
71
  var include: Option[String] = config("i")
Sander Bollen's avatar
Sander Bollen committed
72

73
  @Argument(doc = "Known (ID field is not .) only", required = false)
Sander Bollen's avatar
Sander Bollen committed
74
  var known: Boolean = config("k", default = false)
Sander Bollen's avatar
Sander Bollen committed
75

76
  @Argument(doc = "min alleles", required = false)
Sander Bollen's avatar
Sander Bollen committed
77
  var minAlleles: Option[Int] = config("m")
Sander Bollen's avatar
Sander Bollen committed
78

79
  @Argument(doc = "max alleles", required = false)
Sander Bollen's avatar
Sander Bollen committed
80
  var maxAlleles: Option[Int] = config("M")
Sander Bollen's avatar
Sander Bollen committed
81

82
  @Argument(doc = "novel (ID field is .) only", required = false)
Sander Bollen's avatar
Sander Bollen committed
83
  var novel: Boolean = config("n", false)
Sander Bollen's avatar
Sander Bollen committed
84

85
  @Argument(doc = "phased only", required = false)
Sander Bollen's avatar
Sander Bollen committed
86
  var phased: Boolean = config("p", false)
Sander Bollen's avatar
Sander Bollen committed
87

88
  @Argument(doc = "exclude phased (only)", required = false)
Sander Bollen's avatar
Sander Bollen committed
89
  var excludePhased: Boolean = config("P", false)
Sander Bollen's avatar
Sander Bollen committed
90

91
  @Argument(doc = "min allele frequency", required = false)
Sander Bollen's avatar
Sander Bollen committed
92
  var minAF: Option[Int] = config("q")
Sander Bollen's avatar
Sander Bollen committed
93

94
  @Argument(doc = "max allele frequency", required = false)
Sander Bollen's avatar
Sander Bollen committed
95
  var maxAF: Option[Int] = config("Q")
Sander Bollen's avatar
Sander Bollen committed
96

97
  @Argument(doc = "uncalled only", required = false)
Sander Bollen's avatar
Sander Bollen committed
98
  var uncalled: Boolean = config("u", default = false)
Sander Bollen's avatar
Sander Bollen committed
99

100
  @Argument(doc = "exclude uncalled (only)", required = false)
Sander Bollen's avatar
Sander Bollen committed
101
  var excludeUncalled: Boolean = config("U", default = false)
Sander Bollen's avatar
Sander Bollen committed
102

103
  @Argument(doc = "types", required = false)
Sander Bollen's avatar
Sander Bollen committed
104
  var types: Option[String] = config("v")
Sander Bollen's avatar
Sander Bollen committed
105

106
  @Argument(doc = "exclude types", required = false)
Sander Bollen's avatar
Sander Bollen committed
107
  var excludeTypes: Option[String] = config("V")
Sander Bollen's avatar
Sander Bollen committed
108

109
  @Argument(doc = "private (requires samples)", required = false)
Sander Bollen's avatar
Sander Bollen committed
110
  var onlyPrivate: Boolean = config("x", default = false)
Sander Bollen's avatar
Sander Bollen committed
111

112
  @Argument(doc = "Exclude privates", required = false)
Sander Bollen's avatar
Sander Bollen committed
113
  var excludePrivate: Boolean = config("X", default = false)
Sander Bollen's avatar
Sander Bollen committed
114
115
116
117
118
119
120
121
122
123
124
125

  override def beforeGraph() = {
    super.beforeGraph()

    require((compressionLevel <= 9) && (compressionLevel >= 0))
    require(
      (outputType.length == 1) &&
        (outputType == "z" || outputType == "b" || outputType == "u" || outputType == "v")
    )
  }

  def baseCmd = {
Sander Bollen's avatar
Sander Bollen committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    executable +
      required("view") +
      conditional(dropGenotype, "-G") +
      conditional(headerOnly, "-h") +
      required("-l", compressionLevel) +
      required("-O", outputType) +
      optional("-r", regions) +
      optional("-R", regionFile) +
      optional("-t", targets) +
      optional("-T", targetFile) +
      conditional(trimAltAlleles, "-a") +
      conditional(noUpdate, "-I") +
      repeat("-s", samples) +
      optional("-S", sampleFile) +
      optional("-c", minAC) +
      optional("-C", maxAC) +
      optional("-e", exclude) +
      optional("-f", applyFilters) +
      optional("-g", genotype) +
      optional("-i", include) +
      conditional(known, "-k") +
      optional("-m", minAlleles) +
      optional("-M", maxAlleles) +
      conditional(novel, "-n") +
      conditional(phased, "-p") +
      conditional(excludePhased, "-P") +
      optional("-q", minAF) +
      optional("-Q", maxAF) +
      conditional(uncalled, "-u") +
      conditional(excludeUncalled, "-U") +
      optional("-v", types) +
      optional("-V", excludeTypes) +
      conditional(onlyPrivate, "-x") +
159
      conditional(excludePrivate, "-X")
Sander Bollen's avatar
Sander Bollen committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  }

  def cmdPipeInput = {
    baseCmd + "-"
  }

  def cmdPipe = {
    baseCmd + required(input)
  }

  def cmdLine = {
    baseCmd + required("-o", output) + required(input)
  }

174
175
176
177
178
179
180
181
182
183
  /**
   * Convert cmdLine into line without quotes and double spaces
   * primarily for testing
   * @return
   */
  final def cmd = {
    val a = cmdLine
    a.replace("'", "").replace("  ", " ").trim
  }

Sander Bollen's avatar
Sander Bollen committed
184
}