PindelConfig.scala 3.65 KB
Newer Older
1
2
3
4
5
/**
 * 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.
6
 *
7
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
8
 *
9
 * Contact us at: sasc@lumc.nl
10
 *
11
12
13
14
 * 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.
15
 */
16
package nl.lumc.sasc.biopet.extensions.pindel
Wai Yi Leung's avatar
Wai Yi Leung committed
17
18
import collection.JavaConversions._
import java.io.{ PrintWriter, File }
19

Wai Yi Leung's avatar
Wai Yi Leung committed
20
import htsjdk.samtools.SamReaderFactory
21
22
import nl.lumc.sasc.biopet.core.BiopetJavaCommandLineFunction
import nl.lumc.sasc.biopet.utils.ToolCommand
Peter van 't Hof's avatar
Peter van 't Hof committed
23
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
24
25
import org.broadinstitute.gatk.utils.commandline.{ Argument, Input, Output }

26
27
28
29
30
31
32
class PindelConfig(val root: Configurable) extends BiopetJavaCommandLineFunction {
  javaMainClass = getClass.getName
  @Input(doc = "Bam File")
  var input: File = _

  @Output(doc = "Output Config file")
  var output: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
33
34

  @Argument(doc = "Insertsize")
Wai Yi Leung's avatar
Wai Yi Leung committed
35
36
37
  var insertsize: Int = _

  var sampleName: String = _
Peter van 't Hof's avatar
Peter van 't Hof committed
38

39
  override def cmdLine = super.cmdLine +
Peter van 't Hof's avatar
Peter van 't Hof committed
40
    "-i" + required(input) +
Wai Yi Leung's avatar
Wai Yi Leung committed
41
    "-l" + required(sampleName) +
Peter van 't Hof's avatar
Peter van 't Hof committed
42
    "-s" + required(insertsize) +
43
44
45
46
    "-o" + required(output)
}

object PindelConfig extends ToolCommand {
Wai Yi Leung's avatar
Wai Yi Leung committed
47
48
  case class Args(inputbam: File = null, samplelabel: Option[String] = None,
                  insertsize: Option[Int] = None, output: Option[File] = None) extends AbstractArgs
49
50

  class OptParser extends AbstractOptParser {
Peter van 't Hof's avatar
Peter van 't Hof committed
51
    opt[File]('i', "inputbam") required () valueName "<bamfile/path>" action { (x, c) =>
Peter van 't Hof's avatar
Peter van 't Hof committed
52
      c.copy(inputbam = x)
Peter van 't Hof's avatar
Peter van 't Hof committed
53
54
    } text "Please specify the input bam file"
    opt[String]('l', "samplelabel") valueName "<sample label>" action { (x, c) =>
Peter van 't Hof's avatar
Peter van 't Hof committed
55
      c.copy(samplelabel = Some(x))
Peter van 't Hof's avatar
Peter van 't Hof committed
56
57
    } text "Sample label is missing"
    opt[Int]('s', "insertsize") valueName "<insertsize>" action { (x, c) =>
Peter van 't Hof's avatar
Peter van 't Hof committed
58
      c.copy(insertsize = Some(x))
Peter van 't Hof's avatar
Peter van 't Hof committed
59
    } text "Insertsize is missing"
Wai Yi Leung's avatar
Wai Yi Leung committed
60
61
62
    opt[Int]('o', "output") valueName "<output>" action { (x, c) =>
      c.copy(insertsize = Some(x))
    } text "Output path is missing"
63
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
64

65
66
67
68
69
70
  /**
   * @param args the command line arguments
   */
  def main(args: Array[String]): Unit = {
    val argsParser = new OptParser
    val commandArgs: Args = argsParser.parse(args, Args()) getOrElse sys.exit(1)
Peter van 't Hof's avatar
Peter van 't Hof committed
71

72
    val input: File = commandArgs.inputbam
Wai Yi Leung's avatar
Wai Yi Leung committed
73
    val output: File = commandArgs.output.getOrElse(new File(input.getAbsoluteFile + ".pindel.cfg"))
Wai Yi Leung's avatar
Wai Yi Leung committed
74
75
76
77
    val insertsize: Int = commandArgs.insertsize.getOrElse(0)

    val bamReader = SamReaderFactory.makeDefault().open(input)
    val writer = new PrintWriter(output)
Wai Yi Leung's avatar
Wai Yi Leung committed
78
79
    for (readgroup <- bamReader.getFileHeader.getReadGroups().toList) {
      writer.write(s"${input.getAbsoluteFile}\t${insertsize}\t${readgroup.getSample}\n")
Wai Yi Leung's avatar
Wai Yi Leung committed
80
81
82
    }
    bamReader.close()
    writer.close()
83

84
85
86
    // the logic here is to pull the libraries stored in the bam file and output this to a pindel config file.
    // see: http://gmt.genome.wustl.edu/packages/pindel/quick-start.html
    // this is called bam-configuration file
Wai Yi Leung's avatar
Wai Yi Leung committed
87
88
89

    // sampleLabel can be given from the commandline or read from the bam header

90
91
92
93
94
95
    /**
     * filename<tab>avg insert size<tab>sample_label or name for reporting
     * tumor_sample_1222.bam<tab>250<tab>TUMOR_1222
     * somatic_sample_1222.bam<tab>250<tab>HEALTHY_1222
     */

96
97
98
  }
}