Centrifuge.scala 1.77 KB
Newer Older
1
2
3
4
5
6
package nl.lumc.sasc.biopet.extensions.centrifuge

import java.io.File

import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, Version }
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
7
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
8
9
10
11

import scala.util.matching.Regex

/**
12
13
 * Created by pjvanthof on 19/09/16.
 */
14
15
16
17
18
19
20
class Centrifuge(val root: Configurable) extends BiopetCommandLineFunction with Version {
  @Input(doc = "Input: FastQ or FastA", required = true)
  var inputR1: File = _

  @Input(doc = "Input: FastQ or FastA", required = false)
  var inputR2: Option[File] = None

21
  var index: File = config("centrifuge_index")
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

  @Output(doc = "Output with hits per sequence")
  var output: File = _

  @Output(doc = "Output with hits per sequence")
  var report: Option[File] = None

  override def defaultThreads = 8

  executable = config("exe", default = "centrifuge", freeVar = false)

  /** Command to get version of executable */
  def versionCommand: String = s"$executable --version"

  /** Regex to get version from version command output */
  def versionRegex: Regex = ".* version (.*)".r

Peter van 't Hof's avatar
Peter van 't Hof committed
39
40
  override def beforeGraph(): Unit = {
    super.beforeGraph()
Peter van 't Hof's avatar
Peter van 't Hof committed
41
42
43
    deps :+= new File(index + ".1.cf")
    deps :+= new File(index + ".2.cf")
    deps :+= new File(index + ".3.cf")
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
  }

46
  /**
47
48
49
50
   * This function needs to be implemented to define the command that is executed
   *
   * @return Command to run
   */
51
  def cmdLine: String = executable +
52
    //TODO: Options
Peter van 't Hof's avatar
Peter van 't Hof committed
53
54
    optional("--threads", threads) +
    required("-x", index) +
55
56
57
58
59
60
61
    (inputR2 match {
      case Some(r2) => required("-1", inputR1) + required("-2", r2)
      case _        => required("-U", inputR1)
    }) +
    (if (outputAsStsout) "" else required("-S", output)) +
    optional("--report-file", report)
}