Raxml.scala 3.95 KB
Newer Older
1
/**
2
3
4
5
6
7
8
9
10
11
12
13
14
  * 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 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
15
16
package nl.lumc.sasc.biopet.extensions

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

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

23
import scala.util.matching.Regex
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
class Raxml(val parent: Configurable) extends BiopetCommandLineFunction with Version {
Peter van 't Hof's avatar
Peter van 't Hof committed
31

Peter van 't Hof's avatar
Peter van 't Hof committed
32
  override def defaultThreads = 1
33
34
  def versionCommand: String = executable + " -v"
  def versionRegex: Regex = """.*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)
58
  var w: File = _
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)
77
78
79
    executable =
      if (threads > 1 && executableThreads.isDefined) executableThreads.get
      else executableNonThreads
Peter van 't Hof's avatar
Peter van 't Hof committed
80
    super.beforeGraph()
81
    out :::= List(Some(getInfoFile), getBestTreeFile, getBootstrapFile, getBipartitionsFile).flatten
Peter van 't Hof's avatar
Peter van 't Hof committed
82
    f match {
83
84
85
86
87
88
      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)
        }
89
      case "b" => out +:= new File(w, "RAxML_bipartitionsBranchLabels." + n)
90
      case _ =>
Peter van 't Hof's avatar
Peter van 't Hof committed
91
92
    }
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
93

94
  /** Returns bestTree file */
Peter van 't Hof's avatar
Peter van 't Hof committed
95
96
  def getBestTreeFile: Option[File] =
    option(f == "d" && b.isEmpty, new File(w, "RAxML_bestTree." + n))
97
98

  /** Returns bootstrap file */
Peter van 't Hof's avatar
Peter van 't Hof committed
99
100
  def getBootstrapFile: Option[File] =
    option(f == "d" && b.isDefined, new File(w, "RAxML_bootstrap." + n))
101
102

  /** Returns bipartitions file */
103
  def getBipartitionsFile: Option[File] = option(f == "b", new File(w, "RAxML_bipartitions." + n))
104
105
106

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

108
  /** return commandline to execute */
109
  def cmdLine: String =
110
111
112
113
114
115
116
117
118
119
120
121
122
    required(executable) +
      required("-m", m) +
      required("-s", input) +
      optional("-p", p) +
      optional("-b", b) +
      optional("-N", N) +
      optional("-n", n) +
      optional("-w", w) +
      optional("-f", f) +
      optional("-t", t) +
      optional("-z", z) +
      conditional(noBfgs, "--no-bfgs") +
      required("-T", threads)
123
}