Raxml.scala 3.85 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
package nl.lumc.sasc.biopet.extensions

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

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

24
import scalaz.std.boolean.option
Peter van 't Hof's avatar
Peter van 't Hof committed
25

26 27 28 29
/**
 * extension for raxml
 * based on version 8.1.3
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
30 31
class Raxml(val root: Configurable) extends BiopetCommandLineFunction {

Peter van 't Hof's avatar
Peter van 't Hof committed
32
  override def defaultThreads = 1
Peter van 't Hof's avatar
Peter van 't Hof committed
33
  override def versionCommand = executable + " -v"
Peter van 't Hof's avatar
Peter van 't Hof committed
34
  override def versionRegex = """.*version ([\w\.]*) .*""".r
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  @Input(doc = "Input phy/fasta file", required = true)
  var input: File = _

  @Argument(doc = "Model", required = true)
  var m: String = _

  @Argument(doc = "Parsimony seed", required = false)
  var p: Option[Int] = config("p")

  @Argument(doc = "Bootstrapping seed", required = false)
  var b: Option[Int] = config("b")

  @Argument(doc = "Number of runs", required = false)
  var N: Option[Int] = config("N")

  @Argument(doc = "Name of output files", required = true)
  var n: String = _
Peter van 't Hof's avatar
Peter van 't Hof committed
53

Peter van 't Hof's avatar
Peter van 't Hof committed
54 55 56
  @Argument(doc = "Name of output files", required = true)
  var f: String = "d"

Peter van 't Hof's avatar
Peter van 't Hof committed
57
  @Argument(doc = "Output directory", required = true)
Peter van 't Hof's avatar
Peter van 't Hof committed
58
  var w: File = null
Peter van 't Hof's avatar
Peter van 't Hof committed
59

Peter van 't Hof's avatar
Peter van 't Hof committed
60
  @Input(required = false)
61
  var t: Option[File] = _
Peter van 't Hof's avatar
Peter van 't Hof committed
62

Peter van 't Hof's avatar
Peter van 't Hof committed
63
  @Input(required = false)
64
  var z: Option[File] = _
Peter van 't Hof's avatar
Peter van 't Hof committed
65

Peter van 't Hof's avatar
Peter van 't Hof committed
66 67
  @Output(doc = "Output files", required = false)
  private var out: List[File] = Nil
Peter van 't Hof's avatar
Peter van 't Hof committed
68

69 70
  var noBfgs: Boolean = config("no_bfgs", default = false)

Peter van 't Hof's avatar
Peter van 't Hof committed
71
  var executableNonThreads: String = config("exe", default = "raxmlHPC")
Peter van 't Hof's avatar
Peter van 't Hof committed
72
  var executableThreads: Option[String] = config("exe_pthreads")
Peter van 't Hof's avatar
Peter van 't Hof committed
73

74
  /** Sets correct output files to job */
Peter van 't Hof's avatar
Peter van 't Hof committed
75
  override def beforeGraph() {
Peter van 't Hof's avatar
Peter van 't Hof committed
76
    require(w != null)
Peter van 't Hof's avatar
Peter van 't Hof committed
77
    if (threads == 0) threads = getThreads
Peter van 't Hof's avatar
Peter van 't Hof committed
78
    executable = if (threads > 1 && executableThreads.isDefined) executableThreads.get else executableNonThreads
Peter van 't Hof's avatar
Peter van 't Hof committed
79
    super.beforeGraph()
80
    out :::= List(Some(getInfoFile), getBestTreeFile, getBootstrapFile, getBipartitionsFile).flatten
Peter van 't Hof's avatar
Peter van 't Hof committed
81
    f match {
82 83 84 85
      case "d" if b.isEmpty => for (t <- 0 until N.getOrElse(1)) {
        out +:= new File(w, "RAxML_log." + n + ".RUN." + t)
        out +:= new File(w, "RAxML_parsimonyTree." + n + ".RUN." + t)
        out +:= new File(w, "RAxML_result." + n + ".RUN." + t)
Peter van 't Hof's avatar
Peter van 't Hof committed
86
      }
87 88
      case "b" => out +:= new File(w, "RAxML_bipartitionsBranchLabels." + n)
      case _   =>
Peter van 't Hof's avatar
Peter van 't Hof committed
89 90
    }
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
91

92 93 94 95 96 97 98 99 100 101 102
  /** Returns bestTree file */
  def getBestTreeFile = option(f == "d" && b.isEmpty, new File(w, "RAxML_bestTree." + n))

  /** Returns bootstrap file */
  def getBootstrapFile = option(f == "d" && b.isDefined, new File(w, "RAxML_bootstrap." + n))

  /** Returns bipartitions file */
  def getBipartitionsFile = option(f == "b", new File(w, "RAxML_bipartitions." + n))

  /** Returns info file */
  def getInfoFile = new File(w, "RAxML_info." + n)
Peter van 't Hof's avatar
Peter van 't Hof committed
103

104
  /** return commandline to execute */
Peter van 't Hof's avatar
Peter van 't Hof committed
105 106 107 108 109 110
  def cmdLine = required(executable) +
    required("-m", m) +
    required("-s", input) +
    optional("-p", p) +
    optional("-b", b) +
    optional("-N", N) +
Peter van 't Hof's avatar
Peter van 't Hof committed
111
    optional("-n", n) +
Peter van 't Hof's avatar
Peter van 't Hof committed
112 113 114 115
    optional("-w", w) +
    optional("-f", f) +
    optional("-t", t) +
    optional("-z", z) +
Peter van 't Hof's avatar
Peter van 't Hof committed
116
    conditional(noBfgs, "--no-bfgs") +
Peter van 't Hof's avatar
Peter van 't Hof committed
117
    required("-T", threads)
118
}