SamtoolsView.scala 2.41 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
18
19
20
21
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

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

Peter van 't Hof's avatar
Peter van 't Hof committed
30
  var quality: Option[Int] = config("quality")
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
38

  def cmdBase = required(executable) +
    required("view") +
    optional("-q", quality) +
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  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"
}