-
Notifications
You must be signed in to change notification settings - Fork 0
JRubyScripting
##Scripting analysis with JRuby
In version 5.0, the library can now accept jruby scripts as well as XML files to set up and run analysis. This allows creation of more complex methods than XML files without having to add java code and recompile the library. Additionally, it makes it easier to share methods with others, as only a single file has to be passed around.
###Usage
Create a script file for your analysis using the standard ruby language, according to the guidelines in the section below on creating the scripts. You can access any java classes that are on the classpath using standard jruby syntax (see for instance the jruby wiki page on this subject). When running analysis, select the ruby script (must end in .rb to be recognized as such) instead of an XML parameter file and run normally. The output files will be tagged with "ScriptMethod".
###Creating jruby analysis scripts
There are no restrictions on the ruby code that can be used for the analysis. It is recommended, however, to organize a script into two sections: parameter definitions and method code, using the following syntax:
include IATScripting #this loads extra functions for declaring parameters and methods,
#as well as some convenience methods
#(note that this must be include and not require)
parameter_definitions(parameters) do #the argument should literally be the variable called "parameters"
#code to define parameters goes here
end
method_definition do
#code to do the analysis goes here
end
Each script is actually read twice: once when parameters are loaded initially, and another time when the method is being run. This organization makes sure parameters are only set once and the method is only run once; parameter_definitions
and method_definition
are functions defined such that each section will only be run at the appropriate time. Any code outsize these blocks will be run both when parameters are being initialized and when the method is being run.
The interpreter will have the following local variables defined when the script runs; these can be used to interact with the analysis:
-
parameters
: the ParameterDictionary object associated with the analysis (defined both at parameter initialization and method running time) -
imageset
: the ImageSet object containing the Images to be processed (defined only at method running time) -
method
: the Method object for the analysis (defined only at method running time)
There are also a number of convenience methods defined to make some java interaction tasks easier. See the API documentation here for more details.