SamtoolsView.scala 1.42 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
5
6
7
8
9
10
11
12
package nl.lumc.sasc.biopet.extensions.samtools

import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import java.io.File

class SamtoolsView(val root: Configurable) extends Samtools {
  @Input(doc = "Bam File")
  var input: File = _

  @Output(doc = "output File")
  var output: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
13

Peter van 't Hof's avatar
Peter van 't Hof committed
14
15
16
  var quality: Option[Int] = config("quality")
  var b: Boolean = config("b")
  var h: Boolean = config("h")
Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
19
20
21
22

  def cmdBase = required(executable) +
    required("view") +
    optional("-q", quality) +
    conditional(b, "-b") +
    conditional(h, "-h")
Peter van 't Hof's avatar
Peter van 't Hof committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  def cmdPipeInput = cmdBase + "-"
  def cmdPipe = cmdBase + required(input)
  def cmdLine = cmdPipe + " > " + required(output)
}

object SamtoolsView {
  def apply(root: Configurable, input: File, output: File): SamtoolsView = {
    val view = new SamtoolsView(root)
    view.input = input
    view.output = output
    return view
  }

  def apply(root: Configurable, input: File, outputDir: String): SamtoolsView = {
    val dir = if (outputDir.endsWith("/")) outputDir else outputDir + "/"
    val outputFile = new File(dir + swapExtension(input.getName))
    return apply(root, input, outputFile)
  }

  def apply(root: Configurable, input: File): SamtoolsView = {
    return apply(root, input, new File(swapExtension(input.getAbsolutePath)))
  }

  private def swapExtension(inputFile: String) = inputFile.stripSuffix(".bam") + ".mpileup"
}