Package LONI.tree.GraphObject

Examples of LONI.tree.GraphObject.ModuleGroup


  /**
   * Convert a Pipeline to a Galaxy Workflow
   */
  public Object visit(Pipeline pipeline) {
    Workflow workflow;
    ModuleGroup mgroup = pipeline.getPipelineModuleGroup();
    Connections conns = pipeline.getConnections();
    GalaxyContext context=  new GalaxyContext();
    context.getDatabase().clear();
    NODE_COUNT = 0;
   
    //convert the module group
    Pair<List<Step>, Object> mystp = moduleVisitor.visit(mgroup, context);
   
    /* Visit connections */
    List<Pair<Pair<Integer,String>, InputConnection>> connlist;
    connlist = (List<Pair<Pair<Integer,String>, InputConnection>>) visit(conns, context).getElem1();
   
    /* Add resulting connections */
    for(Pair<Pair<Integer,String>, InputConnection> myconn : connlist){
      for(Step mystep : mystp.getElem1()){
        if(mystep.getId() == myconn.getElem1().getElem1().intValue()){
          mystep.getConnections().put(
              myconn.getElem1().getElem2(), myconn.getElem2());
        }
      }
    }
    //create workflow from modulegroup, connections
    workflow = new Workflow(mgroup.getName(),
        mgroup.getDescription(),
        pipeline.getVersion(),
        true);
    //add steps retrieved from visiting modulegroup.
    for(Step s : mystp.getElem1())
      workflow.addStep(s.getId(), s);
View Full Code Here



  public Object visit(Workflow workflow)
  {
    Pipeline pipeline;
    ModuleGroup mgroup;
    LoniEnvironment stepEnv;
    LoniContext context = new LoniContext();
   
    String annotation = workflow.getAnnotation();
    String version = workflow.getFormatVersion();
    String name = workflow.getName();
    mgroup = new ModuleGroup();
    mgroup.setName(name);
    mgroup.setVersion("version");
    mgroup.setDescription(annotation);
    mgroup.setPosX(0);
    mgroup.setPosY(0);
    /* Add the Galaxy directory global to the loni file*/
    String varName="GALAXY_DIR";
    String varDescription="directory of galaxy installation. Used to find galaxy scripts.";
    boolean secret = false;
    int order = 0;
    boolean required=true;
    mgroup.getVariables().addVariable(new Variable(varName, varDescription, required,
        secret, order, ConverterConfig.GALAXY_INPUT_DIR) );
   
    varName="OUTPUT_FILE_DIR";
    varDescription="directory of galaxy installation. Used to find galaxy scripts.";
    mgroup.getVariables().addVariable(new Variable(varName, varDescription, required,
        secret, order, ConverterConfig.GALAXY_OUTPUT_DIR) );
   
    /* Record environmental variable in context for future use*/
    /*TODO: Migrate these globals to some sort of configuration file*/
   
    Connections connections = new Connections();
   
    for(Step s : workflow.getSteps()){
      Pair<GraphObject, LoniEnvironment> dat;
      dat = (Pair<GraphObject, LoniEnvironment>) stepVisitor.visit(s, context);
      connections.addConnections(dat.getElem2().getConnections());
      mgroup.getModules().addAll(dat.getElem2().getModules());
      if(dat.getElem1() != null)
        mgroup.getModules().add(dat.getElem1());
     
    }
   
    pipeline = new Pipeline(version, mgroup, connections);
   
View Full Code Here

 
  //TO Johnny
  public Pipeline(){
    this.version = ".1";
    connections = new Connections();
    pipelineModuleGroup = new ModuleGroup();
  }
View Full Code Here

   * 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;
  }
View Full Code Here

   */
  public Object visit(Workflow workflow){
    Pipeline pipeline;
    String version  = workflow.getVersion();
   
    ModuleGroup moduleGroup;
    Connections connections = getConnections(workflow.getDataflow());
    moduleGroup = (ModuleGroup) visit(workflow.getDataflow());


    pipeline = new Pipeline(version, moduleGroup, connections);
View Full Code Here

 
  /* (non-Javadoc)
   * @see Taverna.Visitor.DFSVisitor#visit(Taverna.Tree.DataFlowImpl.Dataflow)
   */
  public Object visit(Dataflow dataflow){
    ModuleGroup myModuleGroup = null;
    String id = "workflow_1";
    String name = "workflow";
    final String myPackage = "";
    final String version = "0.1";
    String description = "";
    Authors authors = null;
    final String icon = "";
    final int rotation = 0;
    final int posX = 0;
    final int posY = 0;
    final boolean needsProvenance = false;
   
    //Annotation assignment
    try{
      AnnotationContent annotationContent=new AnnotationContent();
      annotationContent=(AnnotationContent) annotationVisitor.visit(dataflow.getAnnotations());
     
      if (annotationContent.name!=null){
        name=annotationContent.name;
     
      if (annotationContent.iD!=null){
        id=annotationContent.iD;
      }
      if (annotationContent.description!=null){
        description=annotationContent.description;
      }     
     
    }catch (Exception e) {
      Printer.log("No Annotation");
    }   
   
    myModuleGroup = new ModuleGroup( id,  name,  myPackage,
         version,  description,  icon,  rotation,
         posX,  posY,  needsProvenance, authors);
   
    //This is used to create the input and output modules if there are---important
    try{
      List<DataModule> inputDataModules = (List<DataModule>)dataFlowImplVisitor.visit(dataflow.getInputPorts());
      if(inputDataModules.size() > 0){
        for(DataModule d : inputDataModules){
          myModuleGroup.getModules().add(d);
        }
      }
    } catch (Exception e){
      Printer.log("No InputPorts");
    }
   
    try{
      List<DataModule> outputDataModules = (List<DataModule>)dataFlowImplVisitor.visit(dataflow.getOutputPorts());
      if(outputDataModules.size() > 0){
        for(DataModule d : outputDataModules){
          myModuleGroup.getModules().add(d);
        }
      }
    } catch (Exception e){
      Printer.log("No OutputPorts");
    }
   
    List<GraphObject> procs = (List<GraphObject>) dataFlowImplVisitor.visit(dataflow.getProcessors());
    if(procs != null
      myModuleGroup.getModules().addAll(procs);
    return myModuleGroup;
  }
View Full Code Here

 
  /* (non-Javadoc)
   * @see Taverna.Visitor.DataFlowImplVisitor#visit(Taverna.Tree.Processor.Processor)
   */
  public Object visit(Processor p){
    ModuleGroup newgrp = new ModuleGroup();
    List<DataModule> inputs =  (List<DataModule>) visit(p.getInputPorts());
    List<DataModule> outputs =  (List<DataModule>) visit(p.getOutputPorts());
    if(outputs != null)
      newgrp.getModules().addAll(outputs);
    if(inputs != null)
      newgrp.getModules().addAll(inputs);
   
    newgrp.setName(p.getProcessorName());
    List<GraphObject> grActivities= (List<GraphObject>) visit(p.getActivities());
    newgrp.getModules().addAll(grActivities);
   
    return newgrp;
}
View Full Code Here

TOP

Related Classes of LONI.tree.GraphObject.ModuleGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.