Commit 14c6c116 authored by Wai Yi Leung's avatar Wai Yi Leung
Browse files

Merge branch 'patch-rscript' into 'develop'

Patch rscript

See merge request !156
parents 61232d12 ca601520
......@@ -18,82 +18,65 @@ package nl.lumc.sasc.biopet.extensions
import java.io.{ FileOutputStream, File }
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import org.broadinstitute.gatk.utils.commandline.Input
import scala.collection.mutable.ListBuffer
import scala.sys.process._
/**
* Created by wyleung on 17-2-15.
*/
trait RscriptCommandLineFunction extends BiopetCommandLineFunction {
/**
* Will initially handle Cluster supported commands
*
*/
// TODO: write support for running with InProcesFunction
@Input(doc = "R script", required = false)
protected var script: File = _
protected var scriptName: String = _
protected var arguments: ListBuffer[String] = ListBuffer()
override val defaultCoreMemory = 2.0
protected var script: File
executable = config("exe", default = "Rscript", submodule = "R")
executable = config("exe", default = "Rscript", submodule = "Rscript")
/**
* Adding arguments in order
*
* @param argName
* @param argValue
* @param dash , is the dashsign a - or -- ?
* @param sep using a space or "=" to specify the "connector" between argName and argValue
*/
def addArgument(argName: String, argValue: String, dash: String = "-", sep: String = " ") = {
arguments += "%s%s%s%s".format(dash, argName, sep, argValue)
}
def addPositionalArgument(argValue: String, dash: String = "-", sep: String = " ") = {
arguments += "%s".format(argValue)
override def beforeGraph: Unit = {
checkScript()
}
/**
* Set the Rscript to run
*
* @param filename RScript file location
* If script not exist in file system it try to copy it from the jar
* @param local if true it use File.createTempFile instead of ".queue/tmp/"
*/
def setScript(filename: String): Unit = {
val f: File = new File(filename)
f.getAbsoluteFile.exists() match {
case true => {
script = f
scriptName = f.getName
protected def checkScript(local: Boolean = false): Unit = {
if (script.exists()) {
script = script.getAbsoluteFile
} else {
val rScript: File = {
if (local) File.createTempFile(script.getName, ".R")
else new File(".queue/tmp/" + script)
}
case false => setScript(f, "")
}
if (!rScript.getParentFile.exists) rScript.getParentFile.mkdirs
val is = getClass.getResourceAsStream(script.getPath)
val os = new FileOutputStream(rScript)
org.apache.commons.io.IOUtils.copy(is, os)
os.close()
script = rScript
}
}
/**
* Gets the R-script from within Biopet
*
* throws ResourceNotFound if script doesn't exist
* Execute rscript on local system
* @param logger How to handle stdout and stderr
*/
def setScript(filename: File, subpackage: String): Unit = {
val RScript: File = new File(".queue/tmp/" + subpackage + filename)
if (!RScript.getParentFile.exists) RScript.getParentFile.mkdirs
val is = getClass.getResourceAsStream(subpackage + RScript.getName)
val os = new FileOutputStream(RScript)
def runLocal(logger: ProcessLogger): Unit = {
checkScript(local = true)
org.apache.commons.io.IOUtils.copy(is, os)
os.close()
Process(cmdLine).run(logger)
}
script = RScript
scriptName = RScript.getName
/**
* Execute rscript on local system
* Stdout and stderr will go to biopet logger
*/
def runLocal(): Unit = {
runLocal(ProcessLogger(logger.info(_)))
}
override def cmdLine: String = {
def cmdLine: String = {
required(executable) +
required(script) +
arguments.mkString(" ")
required(script)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment