* Converts a workflow into a loni pipeline.
* @param workflow The workflow to be converted.
*/
public Object visit(Workflow workflow) {
Pipeline pipeline = new Pipeline();
ModuleGroup moduleGroup = new ModuleGroup();
LoniEnvironment le = new LoniEnvironment();
/*
* Create a modulegroup
*/
moduleGroup.setDescription(workflow.getAnnotation());
moduleGroup.setPosX(0);
moduleGroup.setPosY(0);
moduleGroup.setName(workflow.getName());
moduleGroup.setRotation(0);
//set module group as root module group in pipeline.
pipeline.setPipelineModuleGroup(moduleGroup);
/*
* INITIALIZE THE SETUP, RUN MODULES
*
*/
/*
* Create the setupModule.
*
*/
setupModule = new Module();
setupContext = new LoniContext();
setupModule.setId("Setup");
setupModule.setRotation(4);
setupModule.setName("Setup");
setupModule.setLocation(ConverterConstants.LOCALHOST_PATH + ConverterConfig.PYTHON_BIN);
//create the String parameter containing the script name for the
//setup module.
LONI.tree.module.Parameter setupScript = new LONI.tree.module.Parameter();
setupScript.setEnabled(true);
setupScript.setFileFormat(new Format());
setupScript.getFileFormat().setCardinality(1);
setupScript.getFileFormat().setType("String");
setupScript.setOrder(0);
setupScript.setName("setupScript");
Value scriptValue = new Value();
scriptValue.setValue("{"+SCRIPT_DIR+"}setup_workflow.py");
setupScript.getValues().addValue(scriptValue);
setupModule.getInputs().add(setupScript);
//Create the String Parameter that contains the Galaxy API Key
//for the setupScript Module.
LONI.tree.module.Parameter setupAPI = new LONI.tree.module.Parameter();
setupAPI.setEnabled(true);
setupAPI.setFileFormat(new Format());
setupAPI.getFileFormat().setCardinality(1);
setupAPI.getFileFormat().setType("String");
setupAPI.setOrder(1);
setupAPI.setName("Galaxy API Key");
setupAPI.setPrefix("-api-key");
setupAPI.setPrefixSpaced(true);
Value apiValue = new Value();
apiValue.setValue("{"+API_KEY+"}");
setupAPI.getValues().addValue(apiValue);
setupModule.getInputs().add(setupAPI);
/*
* Initialize and add the String parameter that contains the Galaxy Root Directory
* to the setup Module. This directory is used to call python scripts inside Galaxy.
*/
LONI.tree.module.Parameter setupGalRootDir = new LONI.tree.module.Parameter();
setupGalRootDir.setEnabled(true);
setupGalRootDir.setFileFormat(new Format());
setupGalRootDir.getFileFormat().setCardinality(1);
setupGalRootDir.getFileFormat().setType("String");
setupGalRootDir.setOrder(1);
setupGalRootDir.setName("Galaxy Root Dir");
setupGalRootDir.setPrefix("-galaxy-root-dir");
setupGalRootDir.setPrefixSpaced(true);
Value setupGalRootDirValue = new Value();
setupGalRootDirValue.setValue("{"+GALAXY_DIR+"}");
setupGalRootDir.getValues().addValue(setupGalRootDirValue);
setupModule.getInputs().add(setupGalRootDir);
/*
* Initialize and add String parameter containing Galaxy server url to setup module.
*/
LONI.tree.module.Parameter setupGalURLDir = new LONI.tree.module.Parameter();
setupGalURLDir.setEnabled(true);
setupGalURLDir.setFileFormat(new Format());
setupGalURLDir.getFileFormat().setCardinality(1);
setupGalURLDir.getFileFormat().setType("String");
setupGalURLDir.setOrder(2);
setupGalURLDir.setPrefixSpaced(true);
setupGalURLDir.setName("Galaxy URL");
setupGalURLDir.setPrefix("-galaxy-url");
Value setupGalaxyURLValue = new Value();
setupGalaxyURLValue.setValue("{"+GALAXY_URL+"}");
setupGalURLDir.getValues().addValue(setupGalaxyURLValue);
setupModule.getInputs().add(setupGalURLDir);
/*
* Initialize and add String cookie parameter containing cookie for website
* to setup module.
*/
LONI.tree.module.Parameter setupCookie = new LONI.tree.module.Parameter();
setupCookie.setEnabled(true);
setupCookie.setFileFormat(new Format());
setupCookie.getFileFormat().setCardinality(1);
setupCookie.getFileFormat().setType("String");
setupCookie.setOrder(2);
setupCookie.setName("Cookie for galaxy site");
setupCookie.setPrefix("-cookie");
setupCookie.setPrefixSpaced(true);
Value setupCookieValue = new Value();
setupCookieValue.setValue("{"+COOKIE+"}");
setupCookie.getValues().addValue(setupCookieValue);
setupModule.getInputs().add(setupCookie);
/*
* Initialize and fill in the run module.
*
*/
runModule = new Module();
runModule.setRotation(4);
runContext = new LoniContext();
runModule.setId("Run");
runModule.setLocation(ConverterConstants.LOCALHOST_PATH + ConverterConfig.PYTHON_BIN);
//Add the String script parameter containing the name of the script to run.
LONI.tree.module.Parameter runScript = new LONI.tree.module.Parameter();
runScript.setEnabled(true);
runScript.setFileFormat(new Format());
runScript.getFileFormat().setCardinality(1);
runScript.getFileFormat().setType("String");
runScript.setOrder(0);
runScript.setName("runScript");
scriptValue = new Value();
scriptValue.setValue("{"+SCRIPT_DIR+"}run_workflow.py");
runScript.getValues().addValue(scriptValue);
runModule.getInputs().add(runScript);
//Create the workflow output to the run module. This output contains
//a functional galaxy workflow that was generated from the loni pipeline
//modules.
LONI.tree.module.Output runWorkflow = new LONI.tree.module.Output();
runWorkflow.setEnabled(true);
runWorkflow.setFormat(new Format());
runWorkflow.getFormat().setCardinality(1);
runWorkflow.getFormat().setType("File");
FileType runFileType = new FileType();
runFileType.setName(GENERIC_DICT_TYPE);
runFileType.setDescription("");
runFileType.setExtension("");
runWorkflow.getFormat().getFileTypes().addFileType(runFileType);
runWorkflow.setOrder(0);
runWorkflow.setPrefix("-workflow");
runWorkflow.setPrefixSpaced(true);
runWorkflow.setName("Workflow Data");
runModule.getOutputs().add(runWorkflow);
//Add the setup and run modules to the setup and run contexts respectively.
setupContext.getPathContext().addContext("Setup");
runContext.getPathContext().addContext("Run");
/*
*VISIT THE STEPS IN THE WORKFLOW
*/
//used to place run, setup modules
int totalY=0; // running sum of y values.
int leftX = -1; //furthest left x position
int rightX = 0; //furthest right y position
int spacing = 200; //spacing between modules.
// TODO Auto-generated method stub
for(Step s : workflow.getSteps()){
//visit each step in the workflow
Pair<GraphObject,LoniEnvironment> step = stepVisitor.visit(s, new LoniContext());
//add the returned environment to the pipeline environment.
le.addEnvironment(step.getElem2());
//add the returned graphobject to the pipeline modulegroup
moduleGroup.getModules().add(step.getElem1());
//add the step's y value to the running sum of y values.
totalY += s.getPosition().getFromTop();
//update furthest left position
if(leftX < 0 || leftX > s.getPosition().getFromLeft())
leftX =s.getPosition().getFromLeft();
//update furthest right position
if(rightX < s.getPosition().getFromLeft())
rightX=s.getPosition().getFromLeft();
}
//calculate the average y value from the total.
int avgY = totalY;
if(workflow.getSteps().size() > 0)
avgY = totalY / workflow.getSteps().size();
//place the setup module futhest to the left, at the
//average y value.
setupModule.setPosX(leftX);
setupModule.setPosY(avgY + spacing);
//Place the run module furthest to the right, at the
//average y value.
runModule.setPosX(rightX+ spacing);
runModule.setPosY(avgY);
//add the run, setupmodule
moduleGroup.getModules().add(setupModule);
moduleGroup.getModules().add(runModule);
/*
* Connect module outputs that are not connected to anything to the
* run module.
*/
int conncount=1;
/*
* For each module output
*/
for(String id : le.getOutputAliases().keySet()){
boolean isConnected = false;
//check if any connections link the output of that module
//to the input of some other module.
for(Connection c : le.getConnections()){
if(c.getSource().equals(id))
isConnected = true;
}
//If the output is not connected to any other modules.
if(isConnected == false){
Connection runConn; //connection to the run module
//Create a new parameter for the runmodule that is connected
//to the connectionless output.
LONI.tree.module.Parameter runInput = new LONI.tree.module.Parameter();
runInput.setId(runContext.getPathContext().getAbsoluteContext("conn"+conncount));
runInput.setFileFormat(new Format());
runInput.getFormat().setCardinality(1);
runInput.getFormat().setType("File");
runFileType = new FileType();
runFileType.setName(GENERIC_DICT_TYPE);
runFileType.setDescription("");
runFileType.setExtension("");
runInput.getFormat().getFileTypes().addFileType(runFileType);
runInput.setOrder(conncount);
runInput.setPrefix("-input");
runInput.setPrefixSpaced(true);
runInput.setEnabled(true);
runInput.setName("input"+ conncount);
//add the created input to the runmodule.
runModule.addInput(runInput);
//create a new connection from the connectionless output to the new run module input.
runConn = new Connection(id, runInput.getId());
le.addConnection(runConn);
conncount++;
}
}
//add all the connections in the environment being maintained to
//the pipeline
pipeline.getConnections().addConnections(le.getConnections());
//set the moduleGroup to the pipeline moduelGroup.
pipeline.setPipelineModuleGroup(moduleGroup);
/**
* Create Pipeline Variables
*/
//location of galaxy web service scripts
Variable scriptVar = new Variable();
scriptVar.setName(SCRIPT_DIR);
scriptVar.setValue(ConverterConfig.GALAXY_SCRIPT_DIR);
scriptVar.setDescription("Where the galaxy wrapper scripts are");
moduleGroup.getVariables().addVariable(scriptVar);
//api key for the galaxy server
Variable apikeyVal = new Variable();
apikeyVal.setName(API_KEY);
apikeyVal.setValue(ConverterConfig.GALAXY_API_KEY);
apikeyVal.setDescription("api key for server");
moduleGroup.getVariables().addVariable(apikeyVal);
//location of the galaxy root. scripts are used from the galaxy root.
Variable dirVal = new Variable();
dirVal.setName(GALAXY_DIR);
dirVal.setValue(ConverterConfig.GALAXY_INPUT_DIR);
dirVal.setDescription("Galaxy distribution sirectory Here");
moduleGroup.getVariables().addVariable(dirVal);
//url of galaxy server.
Variable urlVal = new Variable();
urlVal.setName(GALAXY_URL);
urlVal.setValue(ConverterConfig.GALAXY_URL);
urlVal.setDescription("server address");
moduleGroup.getVariables().addVariable(urlVal);
/*Temporary : Until everything migrates to api*/
//value of cookie from website. This will be phased out
//when galaxy migrates completely to web api.
Variable cookieVal = new Variable();
cookieVal.setName(COOKIE);
cookieVal.setValue(ConverterConfig.GALAXY_COOKIE);
cookieVal.setDescription("login cookie for size");
moduleGroup.getVariables().addVariable(cookieVal);
return pipeline;
}