MergeSamFiles.scala 3 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.
 */
16
17
18
package nl.lumc.sasc.biopet.extensions.picard

import java.io.File
Peter van 't Hof's avatar
Peter van 't Hof committed
19

Peter van 't Hof's avatar
Peter van 't Hof 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.{ Argument, Input, Output }
22

Peter van 't Hof's avatar
Peter van 't Hof committed
23
/** Extension for picard MergeSamFiles */
24
class MergeSamFiles(val root: Configurable) extends Picard {
25
  javaMainClass = new picard.sam.MergeSamFiles().getClass.getName
26
27
28
29
30
31
32
33
34
35
36
37

  @Input(doc = "The input SAM or BAM files to analyze.", required = true)
  var input: List[File] = Nil

  @Output(doc = "The output file to bam file to", required = true)
  var output: File = _

  @Argument(doc = "Sort order of output file Required. Possible values: {unsorted, queryname, coordinate} ", required = true)
  var sortOrder: String = _

  @Argument(doc = "ASSUME_SORTED", required = false)
  var assumeSorted: Boolean = config("assumesorted", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
38

39
40
  @Argument(doc = "MERGE_SEQUENCE_DICTIONARIES", required = false)
  var mergeSequenceDictionaries: Boolean = config("merge_sequence_dictionaries", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
41

42
43
  @Argument(doc = "USE_THREADING", required = false)
  var useThreading: Boolean = config("use_threading", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
44

45
  @Argument(doc = "COMMENT", required = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
46
  var comment: Option[String] = config("comment")
Peter van 't Hof's avatar
Peter van 't Hof committed
47

48
49
50
51
52
53
54
55
  @Output(doc = "Bam Index", required = true)
  private var outputIndex: File = _

  override def beforeGraph() {
    super.beforeGraph()
    if (createIndex) outputIndex = new File(output.getAbsolutePath.stripSuffix(".bam") + ".bai")
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
56
  /** Returns command to execute */
57
  override def cmdLine = super.cmdLine +
Peter van 't Hof's avatar
Peter van 't Hof committed
58
    repeat("INPUT=", input, spaceSeparated = false) +
59
60
61
62
63
64
65
66
    required("OUTPUT=", output, spaceSeparated = false) +
    required("SORT_ORDER=", sortOrder, spaceSeparated = false) +
    conditional(assumeSorted, "ASSUME_SORTED=TRUE") +
    conditional(mergeSequenceDictionaries, "MERGE_SEQUENCE_DICTIONARIES=TRUE") +
    optional("COMMENT=", comment, spaceSeparated = false)
}

object MergeSamFiles {
Peter van 't Hof's avatar
Peter van 't Hof committed
67
  /** Returns default MergeSamFiles */
Peter van 't Hof's avatar
Peter van 't Hof committed
68
  def apply(root: Configurable, input: List[File], outputFile: File, sortOrder: String = null): MergeSamFiles = {
69
70
    val mergeSamFiles = new MergeSamFiles(root)
    mergeSamFiles.input = input
Peter van 't Hof's avatar
Peter van 't Hof committed
71
    mergeSamFiles.output = outputFile
72
73
    if (sortOrder == null) mergeSamFiles.sortOrder = "coordinate"
    else mergeSamFiles.sortOrder = sortOrder
Peter van 't Hof's avatar
Peter van 't Hof committed
74
    mergeSamFiles
75
76
  }
}