SortVcf.scala 2.48 KB
Newer Older
Wai Yi Leung's avatar
Wai Yi Leung committed
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
Wai Yi Leung's avatar
Wai Yi Leung committed
12
13
14
15
16
17
18
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
package nl.lumc.sasc.biopet.extensions.picard

import java.io.File

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

/** Extension for picard SortVcf */
24
class SortVcf(val root: Configurable) extends Picard with Reference {
Wai Yi Leung's avatar
Wai Yi Leung committed
25
26
27
28
29
30
31
32
  javaMainClass = new picard.vcf.SortVcf().getClass.getName

  @Input(doc = "Input VCF(s) to be sorted. Multiple inputs must have the same sample names (in order)", required = true)
  var input: File = _

  @Output(doc = "Output VCF to be written.", required = true)
  var output: File = _

Wai Yi Leung's avatar
Wai Yi Leung committed
33
  @Input(doc = "Sequence dictionary to use", required = true)
34
  var sequenceDictionary: File = _
Wai Yi Leung's avatar
Wai Yi Leung committed
35

Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
38
  @Output
  private var outputIndex: File = _

39
40
  override val dictRequired = true

41
42
  override def beforeGraph(): Unit = {
    super.beforeGraph()
Peter van 't Hof's avatar
Peter van 't Hof committed
43
44
    if (output.getName.endsWith(".vcf.gz")) outputIndex = new File(output.getAbsolutePath + ".tbi")
    if (output.getName.endsWith(".vcf")) outputIndex = new File(output.getAbsolutePath + ".idx")
Peter van 't Hof's avatar
Peter van 't Hof committed
45
    if (sequenceDictionary == null) sequenceDictionary = referenceDictFile
46
47
  }

Wai Yi Leung's avatar
Wai Yi Leung committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  /** Returns command to execute */
  override def cmdLine = super.cmdLine +
    (if (inputAsStdin) required("INPUT=", new File("/dev/stdin"), spaceSeparated = false)
    else required("INPUT=", input, spaceSeparated = false)) +
    (if (outputAsStsout) required("OUTPUT=", new File("/dev/stdout"), spaceSeparated = false)
    else required("OUTPUT=", output, spaceSeparated = false)) +
    required("SEQUENCE_DICTIONARY=", sequenceDictionary, spaceSeparated = false)
}

object SortVcf {
  /** Returns default SortSam */
  def apply(root: Configurable, input: File, output: File): SortVcf = {
    val sortVcf = new SortVcf(root)
    sortVcf.input = input
    sortVcf.output = output
    sortVcf
  }
}