SamtoolsView.scala 2.34 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
22
23
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")
24
  var input: File = null
Peter van 't Hof's avatar
Peter van 't Hof committed
25
26

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

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

  def cmdBase = required(executable) +
    required("view") +
    optional("-q", quality) +
38
39
    optional("-f", f) +
    optional("-F", F) +
Peter van 't Hof's avatar
Peter van 't Hof committed
40
41
    conditional(b, "-b") +
    conditional(h, "-h")
Peter van 't Hof's avatar
Peter van 't Hof committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  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"
}