Sickle.scala 2.18 KB
Newer Older
1
package nl.lumc.sasc.biopet.function.fastq
Peter van 't Hof's avatar
Peter van 't Hof committed
2
3

import nl.lumc.sasc.biopet.core._
Peter van 't Hof's avatar
Peter van 't Hof committed
4
import nl.lumc.sasc.biopet.core.config._
Peter van 't Hof's avatar
Peter van 't Hof committed
5
import org.broadinstitute.gatk.utils.commandline.{Input, Output, Argument}
Peter van 't Hof's avatar
Peter van 't Hof committed
6
7
8
9
import java.io.File
import scala.io.Source._
import scala.sys.process._

Peter van 't Hof's avatar
Peter van 't Hof committed
10
class Sickle(val root:Configurable) extends BiopetCommandLineFunction {
11
12
  @Input(doc="R1 input")
  var input_R1: File = null
Peter van 't Hof's avatar
Peter van 't Hof committed
13
  
14
15
  @Input(doc="R2 input", required=false)
  var input_R2: File = null
16
  
17
18
  @Input(doc="qualityType file", required=false)
  var qualityTypeFile: File = _
19
  
20
21
22
23
24
25
26
27
28
29
30
31
  @Output(doc="R1 output")
  var output_R1: File = null
  
  @Output(doc="R2 output", required=false)
  var output_R2: File = null
  
  @Output(doc="singles output", required=false)
  var output_singles: File = null
  
  @Output(doc="stats output")
  var output_stats: File = null
  
Peter van 't Hof's avatar
Peter van 't Hof committed
32
  executable = config("exe", "sickle")
Peter van 't Hof's avatar
Peter van 't Hof committed
33
  var qualityType: String = config("qualitytype", null)
34
35
36
37
38
  
  var defaultQualityType: String = _
  override val versionRegex = """sickle version (.*)""".r
  
  override def afterGraph {
Peter van 't Hof's avatar
Peter van 't Hof committed
39
    if (defaultQualityType == null) defaultQualityType = config("defaultqualitytype", "sanger")
Peter van 't Hof's avatar
Peter van 't Hof committed
40
    if (qualityType == null && defaultQualityType != null) qualityType = defaultQualityType
41
42
  }
  
Peter van 't Hof's avatar
Peter van 't Hof committed
43
  override def versionCommand = executable + " --version"
44
  
45
46
47
48
49
  override def beforeCmd {
    qualityType = getQualityTypeFromFile
  }
  
  def cmdLine = {
Peter van 't Hof's avatar
Peter van 't Hof committed
50
    var cmd: String = required(executable)
Peter van 't Hof's avatar
Peter van 't Hof committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    if (input_R2 != null) {
      cmd += required("pe") +
      required("-r", input_R2) + 
      required("-p", output_R2) + 
      required("-s", output_singles)
    } else cmd += required("se")
    cmd + 
      required("-f", input_R1) + 
      required("-f", input_R1) + 
      required("-t", qualityType) + 
      required("-o", output_R1) +
      " > " + required(output_stats)
  }
  
65
  def getQualityTypeFromFile: String = {
Peter van 't Hof's avatar
Peter van 't Hof committed
66
67
68
69
    if (qualityType == null && qualityTypeFile != null) {
      if (qualityTypeFile.exists()) {
        for (line <- fromFile(qualityTypeFile).getLines) {
          var s: String = line.substring(0,line.lastIndexOf("\t"))
70
          return s
Peter van 't Hof's avatar
Peter van 't Hof committed
71
72
73
        }
      } else logger.warn("File : " + qualityTypeFile + " does not exist")
    }
74
    return null
Peter van 't Hof's avatar
Peter van 't Hof committed
75
76
  }
}