SamtoolsView.scala 2.34 KB
Newer Older
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
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.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
15
16
package nl.lumc.sasc.biopet.extensions.samtools

Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
import java.io.File

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
21
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }

Peter van 't Hof's avatar
Peter van 't Hof committed
22
/** Extension for samtools view */
Peter van 't Hof's avatar
Peter van 't Hof committed
23
24
class SamtoolsView(val root: Configurable) extends Samtools {
  @Input(doc = "Bam File")
25
  var input: File = null
Peter van 't Hof's avatar
Peter van 't Hof committed
26
27

  @Output(doc = "output File")
28
  var output: File = null
Peter van 't Hof's avatar
Peter van 't Hof committed
29

30
  var q: Option[Int] = config("q")
31
32
33
34
  var b: Boolean = config("b", default = false)
  var h: Boolean = config("h", default = false)
  var f: List[String] = config("f", default = List.empty[String])
  var F: List[String] = config("F", default = List.empty[String])
Peter van 't Hof's avatar
Peter van 't Hof committed
35
36
37

  def cmdBase = required(executable) +
    required("view") +
38
    optional("-q", q) +
39
40
    repeat("-f", f) +
    repeat("-F", F) +
Peter van 't Hof's avatar
Peter van 't Hof committed
41
42
    conditional(b, "-b") +
    conditional(h, "-h")
Peter van 't Hof's avatar
Peter van 't Hof committed
43
44
  def cmdPipeInput = cmdBase + "-"
  def cmdPipe = cmdBase + required(input)
Peter van 't Hof's avatar
Peter van 't Hof committed
45
46

  /** Returns command to execute */
Peter van 't Hof's avatar
Peter van 't Hof committed
47
48
49
50
51
52
53
54
  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
Peter van 't Hof's avatar
Peter van 't Hof committed
55
    view
Peter van 't Hof's avatar
Peter van 't Hof committed
56
57
58
59
60
  }

  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))
Peter van 't Hof's avatar
Peter van 't Hof committed
61
    apply(root, input, outputFile)
Peter van 't Hof's avatar
Peter van 't Hof committed
62
63
64
  }

  def apply(root: Configurable, input: File): SamtoolsView = {
Peter van 't Hof's avatar
Peter van 't Hof committed
65
    apply(root, input, new File(swapExtension(input.getAbsolutePath)))
Peter van 't Hof's avatar
Peter van 't Hof committed
66
67
68
69
  }

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