Commit 7d112c68 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Rscript usable without core now

parent c4c8292b
...@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter } ...@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportBuilder, ReportPage, ReportSection } import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportBuilder, ReportPage, ReportSection }
import nl.lumc.sasc.biopet.core.summary.{ Summary, SummaryValue } import nl.lumc.sasc.biopet.core.summary.{ Summary, SummaryValue }
import nl.lumc.sasc.biopet.extensions.rscript.{ StackedBarPlot, LinePlot } import nl.lumc.sasc.biopet.utils.rscript.{ StackedBarPlot, LinePlot }
class BammetricsReport(val root: Configurable) extends ReportBuilderExtension { class BammetricsReport(val root: Configurable) extends ReportBuilderExtension {
val builder = BammetricsReport val builder = BammetricsReport
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package nl.lumc.sasc.biopet.core.extensions package nl.lumc.sasc.biopet.core.extensions
import java.io.{File, FileOutputStream} import java.io.{ File, FileOutputStream }
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import org.broadinstitute.gatk.utils.commandline.Input import org.broadinstitute.gatk.utils.commandline.Input
......
...@@ -15,9 +15,10 @@ ...@@ -15,9 +15,10 @@
*/ */
package nl.lumc.sasc.biopet.core.extensions package nl.lumc.sasc.biopet.core.extensions
import java.io.{File, FileOutputStream} import java.io.{ File, FileOutputStream }
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.utils.rscript.Rscript
import scala.sys.process._ import scala.sys.process._
...@@ -26,67 +27,13 @@ import scala.sys.process._ ...@@ -26,67 +27,13 @@ import scala.sys.process._
* *
* Created by wyleung on 17-2-15. * Created by wyleung on 17-2-15.
*/ */
trait RscriptCommandLineFunction extends BiopetCommandLineFunction { trait RscriptCommandLineFunction extends BiopetCommandLineFunction with Rscript {
protected var script: File executable = rscriptExecutable
executable = config("exe", default = "Rscript", submodule = "Rscript")
override def beforeGraph(): Unit = { override def beforeGraph(): Unit = {
checkScript() checkScript(Some(jobTempDir))
}
/**
* 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/"
*/
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)
}
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
}
} }
/** def cmdLine: String = repeat(cmd)
* Execute rscript on local system
* @param logger How to handle stdout and stderr
*/
def runLocal(logger: ProcessLogger): Unit = {
checkScript(local = true)
this.logger.info(cmdLine)
val cmd = cmdLine.stripPrefix(" '").stripSuffix("' ").split("' *'")
this.logger.info(cmd.mkString(" "))
val process = Process(cmd.toSeq).run(logger)
this.logger.info(process.exitValue())
}
/**
* Execute rscript on local system
* Stdout and stderr will go to biopet logger
*/
def runLocal(): Unit = {
runLocal(ProcessLogger(logger.info(_)))
}
def cmdLine: String = {
required(executable) +
required(script)
}
} }
...@@ -19,7 +19,7 @@ import java.io.{ PrintWriter, InputStream, File } ...@@ -19,7 +19,7 @@ import java.io.{ PrintWriter, InputStream, File }
import java.util import java.util
import htsjdk.variant.vcf.VCFFileReader import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.extensions.rscript.ScatterPlot import nl.lumc.sasc.biopet.utils.rscript.ScatterPlot
import nl.lumc.sasc.biopet.utils.intervals.{ BedRecord, BedRecordList } import nl.lumc.sasc.biopet.utils.intervals.{ BedRecord, BedRecordList }
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
......
...@@ -9,7 +9,7 @@ import org.scalatest.mock.MockitoSugar ...@@ -9,7 +9,7 @@ import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test import org.testng.annotations.Test
import nl.lumc.sasc.biopet.core.summary.Summary import nl.lumc.sasc.biopet.utils.summary.Summary
/** /**
* Created by ahbbollen on 31-8-15. * Created by ahbbollen on 31-8-15.
......
...@@ -13,26 +13,22 @@ ...@@ -13,26 +13,22 @@
* license; For commercial users or users who do not want to follow the AGPL * license; For commercial users or users who do not want to follow the AGPL
* license, please contact us to obtain a separate license. * license, please contact us to obtain a separate license.
*/ */
package nl.lumc.sasc.biopet.extensions.rscript package nl.lumc.sasc.biopet.utils.rscript
import java.io.File import java.io.File
import nl.lumc.sasc.biopet.core.extensions.RscriptCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/** /**
* Extension for en general line plot with R * Extension for en general line plot with R
* *
* Created by pjvan_thof on 4/29/15. * Created by pjvan_thof on 4/29/15.
*/ */
class LinePlot(val root: Configurable) extends RscriptCommandLineFunction { class LinePlot(val root: Configurable) extends Rscript {
protected var script: File = config("script", default = "plotXY.R") protected var script: File = config("script", default = "plotXY.R")
@Input
var input: File = _ var input: File = _
@Output
var output: File = _ var output: File = _
var width: Option[Int] = config("width") var width: Option[Int] = config("width")
...@@ -43,14 +39,14 @@ class LinePlot(val root: Configurable) extends RscriptCommandLineFunction { ...@@ -43,14 +39,14 @@ class LinePlot(val root: Configurable) extends RscriptCommandLineFunction {
var title: Option[String] = config("title") var title: Option[String] = config("title")
var removeZero: Boolean = config("removeZero", default = false) var removeZero: Boolean = config("removeZero", default = false)
override def cmdLine: String = super.cmdLine + override def cmd = super.cmd ++
required("--input", input) + Seq("--input", input.getAbsolutePath) ++
required("--output", output) + Seq("--output", output.getAbsolutePath) ++
optional("--width", width) + width.map(x => Seq("--width", x.toString)).getOrElse(Seq()) ++
optional("--height", height) + height.map(x => Seq("--height", x.toString)).getOrElse(Seq()) ++
optional("--xlabel", xlabel) + xlabel.map(Seq("--xlabel", _)).getOrElse(Seq()) ++
required("--ylabel", ylabel) + ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
optional("--llabel", llabel) + llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
optional("--title", title) + title.map(Seq("--title", _)).getOrElse(Seq()) ++
optional("--removeZero", removeZero) (if (removeZero) Seq("--removeZero") else Seq())
} }
package nl.lumc.sasc.biopet.utils.rscript
import java.io.{ File, FileOutputStream }
import nl.lumc.sasc.biopet.utils.Logging
import nl.lumc.sasc.biopet.utils.config.Configurable
import scala.sys.process.{ Process, ProcessLogger }
/**
* Created by pjvanthof on 13/09/15.
*/
trait Rscript extends Configurable {
protected var script: File
def rscriptExecutable: String = config("exe", default = "Rscript", submodule = "Rscript")
/** This is the defaul implementation, to add arguments override this */
def cmd: Seq[String] = Seq(rscriptExecutable, script.getAbsolutePath)
/**
* If script not exist in file system it try to copy it from the jar
* @param dir Directory to store temp script, if None or not given File.createTempFile is called
*/
protected def checkScript(dir: Option[File] = None): Unit = {
if (script.exists()) {
script = script.getAbsoluteFile
} else {
val rScript: File = dir match {
case Some(dir) => new File(dir, script.getName)
case _ => File.createTempFile(script.getName, ".R")
}
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
}
}
/**
* Execute rscript on local system
* @param logger How to handle stdout and stderr
*/
def runLocal(logger: ProcessLogger): Unit = {
checkScript()
Logging.logger.info("Running: " + cmd.mkString(" "))
val process = Process(cmd).run(logger)
Logging.logger.info(process.exitValue())
}
/**
* Execute rscript on local system
* Stdout and stderr will go to biopet logger
*/
def runLocal(): Unit = {
runLocal(ProcessLogger(Logging.logger.info(_)))
}
}
...@@ -13,26 +13,22 @@ ...@@ -13,26 +13,22 @@
* license; For commercial users or users who do not want to follow the AGPL * license; For commercial users or users who do not want to follow the AGPL
* license, please contact us to obtain a separate license. * license, please contact us to obtain a separate license.
*/ */
package nl.lumc.sasc.biopet.extensions.rscript package nl.lumc.sasc.biopet.utils.rscript
import java.io.File import java.io.File
import nl.lumc.sasc.biopet.core.extensions.RscriptCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/** /**
* Extension for en general line plot with R * Extension for en general line plot with R
* *
* Created by pjvan_thof on 4/29/15. * Created by pjvan_thof on 4/29/15.
*/ */
class ScatterPlot(val root: Configurable) extends RscriptCommandLineFunction { class ScatterPlot(val root: Configurable) extends Rscript {
protected var script: File = config("script", default = "plotScatter.R") protected var script: File = config("script", default = "plotScatter.R")
@Input
var input: File = _ var input: File = _
@Output
var output: File = _ var output: File = _
var width: Option[Int] = config("width") var width: Option[Int] = config("width")
...@@ -43,14 +39,14 @@ class ScatterPlot(val root: Configurable) extends RscriptCommandLineFunction { ...@@ -43,14 +39,14 @@ class ScatterPlot(val root: Configurable) extends RscriptCommandLineFunction {
var title: Option[String] = config("title") var title: Option[String] = config("title")
var removeZero: Boolean = config("removeZero", default = false) var removeZero: Boolean = config("removeZero", default = false)
override def cmdLine: String = super.cmdLine + override def cmd = super.cmd ++
required("--input", input) + Seq("--input", input.getAbsolutePath) ++
required("--output", output) + Seq("--output", output.getAbsolutePath) ++
optional("--width", width) + width.map(x => Seq("--width", x.toString)).getOrElse(Seq()) ++
optional("--height", height) + height.map(x => Seq("--height", x.toString)).getOrElse(Seq()) ++
optional("--xlabel", xlabel) + xlabel.map(Seq("--xlabel", _)).getOrElse(Seq()) ++
required("--ylabel", ylabel) + ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
optional("--llabel", llabel) + llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
optional("--title", title) + title.map(Seq("--title", _)).getOrElse(Seq()) ++
optional("--removeZero", removeZero) (if (removeZero) Seq("--removeZero") else Seq())
} }
...@@ -13,26 +13,22 @@ ...@@ -13,26 +13,22 @@
* license; For commercial users or users who do not want to follow the AGPL * license; For commercial users or users who do not want to follow the AGPL
* license, please contact us to obtain a separate license. * license, please contact us to obtain a separate license.
*/ */
package nl.lumc.sasc.biopet.extensions.rscript package nl.lumc.sasc.biopet.utils.rscript
import java.io.File import java.io.File
import nl.lumc.sasc.biopet.core.extensions.RscriptCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/** /**
* Extension for en general stackedbar plot with R * Extension for en general stackedbar plot with R
* *
* Created by pjvan_thof on 4/29/15. * Created by pjvan_thof on 4/29/15.
*/ */
class StackedBarPlot(val root: Configurable) extends RscriptCommandLineFunction { class StackedBarPlot(val root: Configurable) extends Rscript {
protected var script: File = config("script", default = "stackedBar.R") protected var script: File = config("script", default = "stackedBar.R")
@Input
var input: File = _ var input: File = _
@Output
var output: File = _ var output: File = _
var width: Option[Int] = config("width") var width: Option[Int] = config("width")
...@@ -42,13 +38,13 @@ class StackedBarPlot(val root: Configurable) extends RscriptCommandLineFunction ...@@ -42,13 +38,13 @@ class StackedBarPlot(val root: Configurable) extends RscriptCommandLineFunction
var llabel: Option[String] = config("llabel") var llabel: Option[String] = config("llabel")
var title: Option[String] = config("title") var title: Option[String] = config("title")
override def cmdLine: String = super.cmdLine + override def cmd = super.cmd ++
required("--input", input) + Seq("--input", input.getAbsolutePath) ++
required("--output", output) + Seq("--output", output.getAbsolutePath) ++
optional("--width", width) + width.map(x => Seq("--width", x.toString)).getOrElse(Seq()) ++
optional("--height", height) + height.map(x => Seq("--height", x.toString)).getOrElse(Seq()) ++
optional("--xlabel", xlabel) + xlabel.map(Seq("--xlabel", _)).getOrElse(Seq()) ++
required("--ylabel", ylabel) + ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
optional("--llabel", llabel) + llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
optional("--title", title) title.map(Seq("--title", _)).getOrElse(Seq())
} }
...@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter } ...@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportBuilder, ReportPage, ReportSection } import nl.lumc.sasc.biopet.core.report.{ ReportBuilderExtension, ReportBuilder, ReportPage, ReportSection }
import nl.lumc.sasc.biopet.core.summary.{ Summary, SummaryValue } import nl.lumc.sasc.biopet.core.summary.{ Summary, SummaryValue }
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot import nl.lumc.sasc.biopet.utils.rscript.StackedBarPlot
class FlexiprepReport(val root: Configurable) extends ReportBuilderExtension { class FlexiprepReport(val root: Configurable) extends ReportBuilderExtension {
val builder = FlexiprepReport val builder = FlexiprepReport
......
...@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter } ...@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.core.report._ import nl.lumc.sasc.biopet.core.report._
import nl.lumc.sasc.biopet.core.summary.{ Summary, SummaryValue } import nl.lumc.sasc.biopet.core.summary.{ Summary, SummaryValue }
import nl.lumc.sasc.biopet.extensions.rscript.StackedBarPlot import nl.lumc.sasc.biopet.utils.rscript.StackedBarPlot
import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport
import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport import nl.lumc.sasc.biopet.pipelines.flexiprep.FlexiprepReport
......
Markdown is supported
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