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

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

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

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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
31
  var quality: Option[Int] = config("quality")
32
33
34
35
  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
36
37
38
39

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

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

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

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

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