Grep.scala 1.33 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package nl.lumc.sasc.biopet.extensions

import java.io.File

import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }

/**
  * Created by pjvanthof on 30/03/16.
  */
class Grep(val root: Configurable) extends BiopetCommandLineFunction {
  @Input(doc = "Input file", required = true)
  var input: File = _

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

  executable = config("exe", default = "grep")

  var grepFor: String = null

  var invertMatch: Boolean = false
  var regex: Boolean = false
  var perlRegexp: Boolean = false

  /** return commandline to execute */
  def cmdLine = required(executable) +
    conditional(invertMatch, "-v") +
    conditional(regex, "-e") +
    conditional(perlRegexp, "-P") +
    required(grepFor) +
    (if (inputAsStdin) "" else required(input)) +
    (if (outputAsStsout) "" else " > " + required(output))
}

object Grep {
  def apply(root: Configurable,
            grepFor: String,
            regex: Boolean = false,
            invertMatch: Boolean = false,
            perlRegexp: Boolean = false): Grep = {
    val grep = new Grep(root)
    grep.grepFor = grepFor
    grep.regex = regex
    grep.perlRegexp = perlRegexp
    grep.invertMatch = invertMatch
    grep
  }
}