SamtoolsMpileup.scala 2.87 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 mpileup */
Peter van 't Hof's avatar
Peter van 't Hof committed
23
24
class SamtoolsMpileup(val root: Configurable) extends Samtools {
  @Input(doc = "Bam File")
Peter van 't Hof's avatar
Peter van 't Hof committed
25
  var input: List[File] = Nil
Peter van 't Hof's avatar
Peter van 't Hof committed
26
27
28
29
30
31

  @Output(doc = "output File")
  var output: File = _

  @Input(doc = "Reference fasta")
  var reference: File = config("reference")
Peter van 't Hof's avatar
Peter van 't Hof committed
32

Peter van 't Hof's avatar
Peter van 't Hof committed
33
  @Input(doc = "Interval bed", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
34
  var intervalBed: Option[File] = config("interval_bed")
Peter van 't Hof's avatar
Peter van 't Hof committed
35

36
  var disableBaq: Boolean = config("disable_baq", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
37
  var u: Boolean = config("u", default = false)
38
39
  var minMapQuality: Option[Int] = config("min_map_quality")
  var minBaseQuality: Option[Int] = config("min_base_quality")
bow's avatar
bow committed
40
41
  var depth: Option[Int] = config("depth")
  var outputMappingQuality: Boolean = config("output_mapping_quality", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
42
43
44
45
46
47
48

  def cmdBase = required(executable) +
    required("mpileup") +
    optional("-f", reference) +
    optional("-l", intervalBed) +
    optional("-q", minMapQuality) +
    optional("-Q", minBaseQuality) +
bow's avatar
bow committed
49
50
    optional("-d", depth) +
    conditional(outputMappingQuality, "-s") +
Peter van 't Hof's avatar
Peter van 't Hof committed
51
52
    conditional(disableBaq, "-B") +
    conditional(u, "-u")
Peter van 't Hof's avatar
Peter van 't Hof committed
53
  def cmdPipeInput = cmdBase + "-"
Peter van 't Hof's avatar
Peter van 't Hof committed
54
  def cmdPipe = cmdBase + repeat(input)
Peter van 't Hof's avatar
Peter van 't Hof committed
55
56

  /** Returns command to execute */
Peter van 't Hof's avatar
Peter van 't Hof committed
57
58
59
60
61
62
  def cmdLine = cmdPipe + " > " + required(output)
}

object SamtoolsMpileup {
  def apply(root: Configurable, input: File, output: File): SamtoolsMpileup = {
    val mpileup = new SamtoolsMpileup(root)
Peter van 't Hof's avatar
Peter van 't Hof committed
63
    mpileup.input = List(input)
Peter van 't Hof's avatar
Peter van 't Hof committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    mpileup.output = output
    return mpileup
  }

  def apply(root: Configurable, input: File, outputDir: String): SamtoolsMpileup = {
    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): SamtoolsMpileup = {
    return apply(root, input, new File(swapExtension(input.getAbsolutePath)))
  }

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