From 62cc447adae8d17100ec0cd0101b6c9792c3be51 Mon Sep 17 00:00:00 2001 From: Wai Yi Leung <w.y.leung@lumc.nl> Date: Mon, 9 Mar 2015 14:23:44 +0100 Subject: [PATCH] RCommandlineFunction Trait Conflicts: public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/RscriptCommandLineFunction.scala --- .../RscriptCommandLineFunction.scala | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/RscriptCommandLineFunction.scala diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/RscriptCommandLineFunction.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/RscriptCommandLineFunction.scala new file mode 100644 index 000000000..26ddc7d2e --- /dev/null +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/RscriptCommandLineFunction.scala @@ -0,0 +1,84 @@ +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 + +/** + * 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 defaultVmem: String = "4G" + + executable = config("exe", default = "Rscript", submodule = "R") + + /** + * 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) + } + + /** + * Set the Rscript to run + * + * @param filename RScript file location + */ + def setScript(filename: String): Unit = { + val f: File = new File(filename) + f.getAbsoluteFile.exists() match { + case true => { + script = f + scriptName = f.getName + } + case false => setScript(f, "") + } + + } + + /** + * Gets the R-script from within Biopet + * + * throws ResourceNotFound if script doesn't exist + */ + 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) + + org.apache.commons.io.IOUtils.copy(is, os) + os.close() + + script = RScript + scriptName = RScript.getName + } + + override def cmdLine: String = { + required(executable) + + required(script) + + arguments.mkString(" ") + } +} -- GitLab