Ignore:
Timestamp:
Jun 10, 2009, 1:36:40 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

References #218: Proof-of-concept: run a selected GenePattern? module from BASE

Now uses a custom JSP page with some more interaction. Uses the new wrapper classes.

Location:
extensions/net.sf.basedb.genepattern/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.genepattern/trunk/src/net/sf/basedb/genepattern/GenePattern.java

    r1091 r1119  
    11package net.sf.basedb.genepattern;
     2
     3import net.sf.basedb.clients.web.extensions.ExtensionsControl;
     4import net.sf.basedb.core.Presets;
     5import net.sf.basedb.core.SessionControl;
    26
    37/**
     
    3640  public static final String GCT_FILE = "genepattern.gct";
    3741
     42  /**
     43    Get the home directory URL for the GenePattern extension.
     44  */
     45  public static final String getHomeUrl()
     46  {
     47    return ExtensionsControl.getHomeUrl("net.sf.basedb.genepattern.options");
     48  }
     49   
    3850}
  • extensions/net.sf.basedb.genepattern/trunk/src/net/sf/basedb/genepattern/plugin/GenePatternAnalysisPlugin.java

    r1110 r1119  
    11package net.sf.basedb.genepattern.plugin;
    22
    3 import java.net.URL;
    43import java.util.ArrayList;
    54import java.util.Arrays;
    65import java.util.Date;
    76import java.util.List;
    8 import java.util.Map;
    9 
    10 import org.genepattern.client.GPClient;
    11 import org.genepattern.webservice.JobResult;
     7
    128import org.genepattern.webservice.Parameter;
    13 import org.genepattern.webservice.ParameterInfo;
    149import org.genepattern.webservice.WebServiceException;
    1510
     
    2520import net.sf.basedb.core.Experiment;
    2621import net.sf.basedb.core.File;
    27 import net.sf.basedb.core.FileParameterType;
    28 import net.sf.basedb.core.FloatParameterType;
    29 import net.sf.basedb.core.IntegerParameterType;
    3022import net.sf.basedb.core.Item;
    3123import net.sf.basedb.core.ItemQuery;
     
    5446import net.sf.basedb.core.signal.SignalTarget;
    5547import net.sf.basedb.core.signal.ThreadSignalHandler;
     48import net.sf.basedb.genepattern.GPServer;
    5649import net.sf.basedb.genepattern.GenePattern;
    5750import net.sf.basedb.genepattern.file.BaseFileProxy;
    5851import net.sf.basedb.genepattern.file.FileTransferGateway;
    59 import net.sf.basedb.util.Enumeration;
    60 import net.sf.basedb.util.Values;
     52import net.sf.basedb.genepattern.wrapper.GPClient;
     53import net.sf.basedb.genepattern.wrapper.JobResult;
     54import net.sf.basedb.genepattern.wrapper.ParameterInfo;
    6155
    6256public class GenePatternAnalysisPlugin
     
    122116      checkInterrupted();
    123117      String gpModule = (String)configuration.getValue("gpModule");
    124       Presets.Preset gpServer = getSelectedGpServer((String)job.getValue("gpServer"));
    125      
    126       GPClient gp = new GPClient(gpServer.getName(),
    127           gpServer.getSetting("server.login"),
    128           gpServer.getSetting("server.password"));
    129       ParameterInfo[] info = gp.getParameters(gpModule);     
     118      GPServer gpServer = GPServer.get(sc, (String)job.getValue("gpServer"));
     119     
     120      GPClient gp = new GPClient(gpServer);
     121      ParameterInfo[] info = gp.getParameters(gpModule, null);     
    130122      Parameter[] parameters = new Parameter[info.length];
    131123      int index = 0;
     
    163155      if (progress != null)
    164156      {
    165         progress.display(25, "Running analysis on GenePattern server: " + gpServer.getName());
     157        progress.display(25, "Running analysis on GenePattern server: " + gpServer.getUrl());
    166158      }
    167159      checkInterrupted();
    168160      int jobId = gp.runAnalysisNoWait(gpModule, parameters);
    169161      JobResult result = null;
    170       while (true)
    171       {
    172         if (gp.isComplete(jobId))
    173         {
    174           result = gp.createJobResult(jobId);
    175           break;
    176         }
    177         try
    178         {
    179           Thread.sleep(5000);
    180         }
    181         catch (InterruptedException ex)
    182         {
    183           throw new SignalException("Aborted by user");
    184         }
    185       }
    186      
     162      try
     163      {
     164        result = gp.waitFor(jobId, 5000);
     165      }
     166      catch (InterruptedException ex)
     167      {
     168        throw new SignalException("Aborted by user");
     169      }
    187170      checkInterrupted();
    188171     
     
    235218      {
    236219        checkInterrupted();
    237         URL url = result.getURLForFileName(f);
    238220        File baseFile = File.getFile(dc, dir, f, true);
    239221        if (!baseFile.isInDatabase()) dc.saveItem(baseFile);
     
    488470    parameters.add(new PluginParameter<String>(
    489471      "gpModule",
    490       "GenePattern module/pipeline",
     472      "Module/pipeline",
    491473      "Enter the name or LSID of a GenePattern module or pipeline",
    492474      new StringParameterType(255, null, true)
     
    502484    configurePlugin = new RequestInformation(
    503485      Request.COMMAND_CONFIGURE_PLUGIN,
    504       "GenePattern module/pipeline",
     486      "Configure GenePattern module/pipeline",
    505487      "Select a GenePattern module or pipeline to run " +
    506488      "when this configuration is selected.",
    507       parameters
     489      parameters,
     490      GenePattern.getHomeUrl() + "/configure_plugin.jsp"
    508491    );
    509492   
    510    
    511493    return configurePlugin;
    512494  }
     
    517499    if (configureGpParameters != null) return configureGpParameters;
    518500    String gpModule = (String)configuration.getValue("gpModule");
    519     Presets.Preset gpServer = getSelectedGpServer(
     501    GPServer gpServer = GPServer.get(sc,
    520502        context == null ? (String)configuration.getValue("gpServer") : (String)job.getValue("gpServer"));
    521503   
    522504    try
    523505    {
    524       GPClient gp =  new GPClient(gpServer.getName(),
    525         gpServer.getSetting("server.login"), gpServer.getSetting("server.password"));
    526      
    527       ParameterInfo[] info = gp.getParameters(gpModule);
     506      GPClient gp =  new GPClient(gpServer);
     507     
     508      ParameterInfo[] info = gp.getParameters(gpModule, null);
    528509      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(info.length);
    529510     
    530511      for (ParameterInfo pi : info)
    531512      {
    532         PluginParameter<?> pp = convertToPluginParameter(pi, context != null);
    533         if (pp != null) parameters.add(pp);
     513        if (context != null || !pi.isInputFile())
     514        {
     515          PluginParameter<?> pp = pi.createPluginParameter("gp.");
     516          if (pp != null) parameters.add(pp);
     517        }
    534518      }
    535519     
     
    569553  }
    570554 
    571   protected Presets.Preset getSelectedGpServer(String server)
    572   {
    573     String presetsXml = sc.getUserDefaultSetting("net.sf.basedb.genepattern.options");
    574     System.out.println("xml=" + presetsXml);
    575     Presets presets = new Presets();
    576     if (presetsXml != null) presets.loadFrom(presetsXml);
    577     return presets.getPreset(server);
    578   }
    579  
    580  
    581   protected PluginParameter<?> convertToPluginParameter(ParameterInfo pi, boolean forJob)
    582   {
    583     String name = pi.getName();
    584     String type = (String)pi.getAttributes().get("type");
    585     Map<String, String> choices = pi.getChoices();
    586     PluginParameter<?> parameter = null;
    587     if (pi.isInputFile())
    588     {
    589       if (forJob)
    590       {
    591         parameter = new PluginParameter<File>(
    592           "gp." + name,
    593           name,
    594           pi.getDescription(),
    595           new FileParameterType(null, !pi.isOptional(), 1)
    596         );
    597       }
    598     }
    599     else if (choices != null && !choices.isEmpty())
    600     {
    601       Enumeration<String, String> options = convertChoicesToEnumeration(choices);
    602       parameter = new PluginParameter<String>(
    603         "gp." + name,
    604         name,
    605         pi.getDescription(),
    606         new StringParameterType(255, pi.getDefaultValue(), !pi.isOptional(), 1, 0, 0, options)
    607       );
    608     }
    609     else if (type.equals("java.lang.String"))
    610     {
    611       parameter = new PluginParameter<String>(
    612           "gp." + name,
    613           name,
    614           pi.getDescription(),
    615           new StringParameterType(255, Values.getStringOrNull(pi.getDefaultValue()), !pi.isOptional())
    616       );
    617     }
    618     else if (type.equals("java.lang.Integer"))
    619     {
    620       parameter = new PluginParameter<Integer>(
    621         "gp." + name,
    622         name,
    623         pi.getDescription(),
    624         new IntegerParameterType(null, null,
    625           Values.getInteger(pi.getDefaultValue(), null), !pi.isOptional())
    626       );
    627     }
    628     else if (type.equals("java.lang.Float"))
    629     {
    630       parameter = new PluginParameter<Float>(
    631         "gp." + name,
    632         name,
    633         pi.getDescription(),
    634         new FloatParameterType(null, null,
    635           Values.getFloat(pi.getDefaultValue(), null), !pi.isOptional())
    636       );
    637     }
    638     return parameter;
    639   }
    640  
    641   protected Enumeration<String, String> convertChoicesToEnumeration(Map<String, String> choices)
    642   {
    643     if (choices == null || choices.isEmpty()) return null;
    644     Enumeration<String, String> options = new Enumeration<String, String>();
    645     for (Map.Entry<String, String> entry : choices.entrySet())
    646     {
    647       options.add(entry.getValue(), entry.getKey());
    648     }
    649     return options;
    650   }
     555 
    651556}
Note: See TracChangeset for help on using the changeset viewer.