Star.scala 2.14 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
package nl.lumc.sasc.biopet.wrappers

import nl.lumc.sasc.biopet.core._
import org.broadinstitute.sting.queue.function.CommandLineFunction
import org.broadinstitute.sting.commandline._
import java.io.File
import scala.sys.process._

class Star(private var globalConfig: Config) extends CommandLineFunction {
  def this() = this(new Config(Map()))
  this.analysisName = "STAR"
Peter van 't Hof's avatar
Peter van 't Hof committed
12
  var config: Config = Config.mergeConfigs(globalConfig.getAsConfig("star"), globalConfig)
Peter van 't Hof's avatar
Peter van 't Hof committed
13

Peter van 't Hof's avatar
Peter van 't Hof committed
14
15
16
  @Argument(doc="STAR executeble", shortName="star_exe", required=false)
  var star_exe: String = config.getAsString("exe", "/usr/local/bin/STAR")
  @Input(doc="The reference file for the bam files.", shortName="R") var referenceFile: File = new File(config.getAsString("referenceFile"))
Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
19
20
  @Input(doc="Fastq file R1", shortName="R1") var R1: File = _
  @Input(doc="Fastq file R2", shortName="R2", required=false) var R2: File = _
  @Argument(doc="Output Directory", shortName="outputDir") var outputDir: String = _
  @Argument(doc="GenomeDir", required=false) var genomeDir: String = _
Peter van 't Hof's avatar
Peter van 't Hof committed
21
  if (genomeDir == null) genomeDir = config.getAsString("genomeDir", referenceFile.getParent + "/star")
Peter van 't Hof's avatar
Peter van 't Hof committed
22
23
24
  
  @Argument(doc="STAR runmode", shortName="runmode", required=false) var runmode: String = _
  
Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
27
28
29
30
31
32
  this.addJobReportBinding("version", "NA")

  jobResourceRequests :+= "h_vmem=" + config.getAsString("vmem", "6G")
  var threads: Int = config.getAsInt("threads", 8)
  var maxThreads: Int = config.getAsInt("maxthreads", 24)
  if (threads > maxThreads) threads = maxThreads
  nCoresRequest = Option(threads)

Peter van 't Hof's avatar
Peter van 't Hof committed
33
  @Output var outputSam: File = new File(outputDir + "/Aligned.out.sam")
Peter van 't Hof's avatar
Peter van 't Hof committed
34
35
  
  def commandLine : String= {
Peter van 't Hof's avatar
Peter van 't Hof committed
36
    //init()
Peter van 't Hof's avatar
Peter van 't Hof committed
37
38
39
40
41
42
43
44
45
    var cmd: String = required("cd",outputDir) + "&&" + required(star_exe)
    if (runmode != null && runmode == "genomeGenerate") { // Create index
      cmd += required("--runmode", runmode) +
        required("--genomeDir", genomeDir) +
        required("--genomeFastaFiles", referenceFile)
    } else { // Aligner
      cmd += required("--genomeDir", genomeDir) +
        required("--readFilesIn", R1) + optional(R2)
    }
46
    cmd += optional("--runThreadN", nCoresRequest)
Peter van 't Hof's avatar
Peter van 't Hof committed
47
48
49
50
    
    return cmd
  }
}