Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
b04b3390
Commit
b04b3390
authored
Apr 29, 2015
by
Peter van 't Hof
Browse files
Refactor Rscript extension
parent
61232d12
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/RscriptCommandLineFunction.scala
View file @
b04b3390
...
...
@@ -18,82 +18,49 @@ 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
=
"R
script
"
)
/**
* 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
*/
def
setScript
(
filename
:
String
)
:
Unit
=
{
val
f
:
File
=
new
File
(
filename
)
f
.
getAbsoluteFile
.
exists
()
match
{
case
true
=>
{
script
=
f
scriptName
=
f
.
getName
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
)
/**
* 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
org
.
apache
.
commons
.
io
.
IOUtils
.
copy
(
is
,
os
)
os
.
close
()
val
is
=
getClass
.
getResourceAsStream
(
subpackage
+
RScript
.
getName
)
val
os
=
new
FileOutputStream
(
RScript
)
script
=
rScript
}
}
org
.
apache
.
commons
.
io
.
IOUtils
.
copy
(
is
,
os
)
os
.
close
(
)
def
runLocal
(
logger
:
ProcessLogger
)
:
Unit
=
{
checkScript
(
local
=
true
)
script
=
RScript
scriptName
=
RScript
.
getName
Process
(
cmdLine
).
run
(
logger
)
}
override
def
cmdLine
:
String
=
{
def
cmdLine
:
String
=
{
required
(
executable
)
+
required
(
script
)
+
arguments
.
mkString
(
" "
)
required
(
script
)
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment