Skip to content
Snippets Groups Projects
Commit 7d112c68 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Rscript usable without core now

parent c4c8292b
No related branches found
No related tags found
No related merge requests found
Showing
with 112 additions and 112 deletions
......@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter }
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.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 {
val builder = BammetricsReport
......
......@@ -15,7 +15,7 @@
*/
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 org.broadinstitute.gatk.utils.commandline.Input
......
......@@ -15,9 +15,10 @@
*/
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.utils.rscript.Rscript
import scala.sys.process._
......@@ -26,67 +27,13 @@ import scala.sys.process._
*
* Created by wyleung on 17-2-15.
*/
trait RscriptCommandLineFunction extends BiopetCommandLineFunction {
trait RscriptCommandLineFunction extends BiopetCommandLineFunction with Rscript {
protected var script: File
executable = config("exe", default = "Rscript", submodule = "Rscript")
executable = rscriptExecutable
override def beforeGraph(): Unit = {
checkScript()
}
/**
* 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
}
checkScript(Some(jobTempDir))
}
/**
* 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)
}
def cmdLine: String = repeat(cmd)
}
......@@ -19,7 +19,7 @@ import java.io.{ PrintWriter, InputStream, File }
import java.util
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 scala.collection.JavaConversions._
......
......@@ -9,7 +9,7 @@ import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite
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.
......
......@@ -13,26 +13,22 @@
* license; For commercial users or users who do not want to follow the AGPL
* 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 nl.lumc.sasc.biopet.core.extensions.RscriptCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/**
* Extension for en general line plot with R
*
* 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")
@Input
var input: File = _
@Output
var output: File = _
var width: Option[Int] = config("width")
......@@ -43,14 +39,14 @@ class LinePlot(val root: Configurable) extends RscriptCommandLineFunction {
var title: Option[String] = config("title")
var removeZero: Boolean = config("removeZero", default = false)
override def cmdLine: String = super.cmdLine +
required("--input", input) +
required("--output", output) +
optional("--width", width) +
optional("--height", height) +
optional("--xlabel", xlabel) +
required("--ylabel", ylabel) +
optional("--llabel", llabel) +
optional("--title", title) +
optional("--removeZero", removeZero)
override def cmd = super.cmd ++
Seq("--input", input.getAbsolutePath) ++
Seq("--output", output.getAbsolutePath) ++
width.map(x => Seq("--width", x.toString)).getOrElse(Seq()) ++
height.map(x => Seq("--height", x.toString)).getOrElse(Seq()) ++
xlabel.map(Seq("--xlabel", _)).getOrElse(Seq()) ++
ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
title.map(Seq("--title", _)).getOrElse(Seq()) ++
(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 @@
* license; For commercial users or users who do not want to follow the AGPL
* 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 nl.lumc.sasc.biopet.core.extensions.RscriptCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/**
* Extension for en general line plot with R
*
* 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")
@Input
var input: File = _
@Output
var output: File = _
var width: Option[Int] = config("width")
......@@ -43,14 +39,14 @@ class ScatterPlot(val root: Configurable) extends RscriptCommandLineFunction {
var title: Option[String] = config("title")
var removeZero: Boolean = config("removeZero", default = false)
override def cmdLine: String = super.cmdLine +
required("--input", input) +
required("--output", output) +
optional("--width", width) +
optional("--height", height) +
optional("--xlabel", xlabel) +
required("--ylabel", ylabel) +
optional("--llabel", llabel) +
optional("--title", title) +
optional("--removeZero", removeZero)
override def cmd = super.cmd ++
Seq("--input", input.getAbsolutePath) ++
Seq("--output", output.getAbsolutePath) ++
width.map(x => Seq("--width", x.toString)).getOrElse(Seq()) ++
height.map(x => Seq("--height", x.toString)).getOrElse(Seq()) ++
xlabel.map(Seq("--xlabel", _)).getOrElse(Seq()) ++
ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
title.map(Seq("--title", _)).getOrElse(Seq()) ++
(if (removeZero) Seq("--removeZero") else Seq())
}
......@@ -13,26 +13,22 @@
* license; For commercial users or users who do not want to follow the AGPL
* 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 nl.lumc.sasc.biopet.core.extensions.RscriptCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/**
* Extension for en general stackedbar plot with R
*
* 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")
@Input
var input: File = _
@Output
var output: File = _
var width: Option[Int] = config("width")
......@@ -42,13 +38,13 @@ class StackedBarPlot(val root: Configurable) extends RscriptCommandLineFunction
var llabel: Option[String] = config("llabel")
var title: Option[String] = config("title")
override def cmdLine: String = super.cmdLine +
required("--input", input) +
required("--output", output) +
optional("--width", width) +
optional("--height", height) +
optional("--xlabel", xlabel) +
required("--ylabel", ylabel) +
optional("--llabel", llabel) +
optional("--title", title)
override def cmd = super.cmd ++
Seq("--input", input.getAbsolutePath) ++
Seq("--output", output.getAbsolutePath) ++
width.map(x => Seq("--width", x.toString)).getOrElse(Seq()) ++
height.map(x => Seq("--height", x.toString)).getOrElse(Seq()) ++
xlabel.map(Seq("--xlabel", _)).getOrElse(Seq()) ++
ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
title.map(Seq("--title", _)).getOrElse(Seq())
}
......@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter }
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.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 {
val builder = FlexiprepReport
......
......@@ -20,7 +20,7 @@ import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.utils.config.Configurable
import nl.lumc.sasc.biopet.core.report._
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.flexiprep.FlexiprepReport
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment