SamtoolsView.scala 2.4 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

Peter van 't Hof's avatar
Peter van 't Hof committed
36 37 38
  @Input(required = false)
  var L: Option[File] = None

Peter van 't Hof's avatar
Peter van 't Hof committed
39
  /** Returns command to execute */
Peter van 't Hof's avatar
Peter van 't Hof committed
40
  def cmdLine = required(executable) +
Peter van 't Hof's avatar
Peter van 't Hof committed
41
    required("view") +
42
    optional("-q", q) +
Peter van 't Hof's avatar
Peter van 't Hof committed
43
    optional("-L", L) +
44 45
    repeat("-f", f) +
    repeat("-F", F) +
Peter van 't Hof's avatar
Peter van 't Hof committed
46
    conditional(b, "-b") +
Peter van 't Hof's avatar
Peter van 't Hof committed
47 48 49
    conditional(h, "-h") +
    (if (inputAsStdin) "-" else required(input)) +
    (if (outputAsStsout) "" else " > " + required(output))
Peter van 't Hof's avatar
Peter van 't Hof committed
50 51 52 53 54 55 56
}

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
57
    view
Peter van 't Hof's avatar
Peter van 't Hof committed
58 59 60 61 62
  }

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

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

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