Changeset 1292


Ignore:
Timestamp:
Feb 24, 2011, 9:52:28 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #281: Plug-in should suggest better job names

Also removed calls to deprecated methods and tagger methods with @Override.

Location:
plugins/base2/net.sf.basedb.examples/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.examples/trunk/META-INF/base-plugins.xml

    r647 r1292  
    33<plugins jarname="%%plugins.jar%%">
    44  <pluginclass classname="net.sf.basedb.exampleplugins.ExampleAnalyzer">
    5     <minbaseversion>2.6</minbaseversion>
     5    <minbaseversion>2.17</minbaseversion>
    66    <hasconfigurations/>
    77    </pluginclass>
    88  <pluginclass classname="net.sf.basedb.exampleplugins.ExampleImporter">
    9     <minbaseversion>2.6</minbaseversion>
     9    <minbaseversion>2.17</minbaseversion>
    1010    <hasconfigurations/>
    1111  </pluginclass>
  • plugins/base2/net.sf.basedb.examples/trunk/README

    r1291 r1292  
    11== Requirements ==
    22
    3  1. BASE 2.6.0 or later.
     3 1. BASE 2.17.0 or later.
    44 
    55== Introduction ==
  • plugins/base2/net.sf.basedb.examples/trunk/build.xml

    r1291 r1292  
    2121  <property name="javac.target" value="1.6" />
    2222  <property name="javac.encoding" value="UTF-8" />
    23   <property name="depend.jars" value="http://base2.thep.lu.se/base/jars/2.6.0" />
     23  <property name="depend.jars" value="http://base2.thep.lu.se/base/jars/2.17.0" />
    2424
    2525  <!-- set up classpath for compiling -->
  • plugins/base2/net.sf.basedb.examples/trunk/src/net/sf/basedb/exampleplugins/ExampleAnalyzer.java

    r647 r1292  
    2626import net.sf.basedb.core.DbControl;
    2727import net.sf.basedb.core.DynamicSpotQuery;
    28 import net.sf.basedb.core.Experiment;
    2928import net.sf.basedb.core.Item;
    30 import net.sf.basedb.core.ItemParameterType;
    3129import net.sf.basedb.core.Job;
    3230import net.sf.basedb.core.FloatParameterType;
    33 import net.sf.basedb.core.Permission;
    3431import net.sf.basedb.core.PluginParameter;
    3532import net.sf.basedb.core.ProgressReporter;
     
    5047import net.sf.basedb.core.plugin.About;
    5148import net.sf.basedb.core.plugin.AboutImpl;
    52 import net.sf.basedb.core.plugin.AbstractPlugin;
     49import net.sf.basedb.core.plugin.AbstractAnalysisPlugin;
    5350import net.sf.basedb.core.plugin.InteractivePlugin;
    5451import net.sf.basedb.core.plugin.GuiContext;
    55 import net.sf.basedb.core.plugin.Plugin;
    5652import net.sf.basedb.core.plugin.Request;
    5753import net.sf.basedb.core.plugin.Response;
     
    7470*/
    7571public class ExampleAnalyzer
    76   extends AbstractPlugin
     72  extends AbstractAnalysisPlugin
    7773  implements InteractivePlugin, SignalTarget
    7874{
     
    8581      "by multiplying each intensitity value with the same factor, filtering " +
    8682      "out intensities below a cutoff value.",
    87       "2.6",
     83      "2.17",
    8884      "2006, Base 2 development team",
    8985      null,
     
    9995  private RequestInformation configureJob;
    10096 
    101   // The selected source bioassay set
    102   private PluginParameter<BioAssaySet> bioAssaySetParameter;
    103 
    10497  // Intensities below this value will be filtered out
    10598  private PluginParameter<Float> cutoffParameter;
     
    121114    -------------------------------------------
    122115  */
     116  @Override
    123117  public About getAbout()
    124118  {
    125119    return about;
    126120  }
    127   public Plugin.MainType getMainType()
    128   {
    129     return Plugin.MainType.ANALYZE;
    130   }
     121  @Override
    131122  public boolean supportsConfigurations()
    132123  {
    133124    return false;
    134125  }
     126  @Override
    135127  public boolean requiresConfiguration()
    136128  {
    137129    return false;
    138130  }
     131  @Override
    139132  public void run(Request request, Response response, ProgressReporter progress)
    140133  {
     
    150143      float cutoff = (Float)job.getValue("cutoff");
    151144      float factor = (Float)job.getValue("factor");
    152       BioAssaySet source = (BioAssaySet)job.getValue("bioAssaySet");
    153 
    154       // Reload with current DbControl
    155       source = BioAssaySet.getById(dc, source.getId());
     145      BioAssaySet source = getSourceBioAssaySet(dc);
    156146      int channels = source.getRawDataType().getChannels();
    157147       
     
    177167      for (int ch = 1; ch <= channels; ch++)
    178168      {
    179         Expression chExpression = Dynamic.column(VirtualColumn.channel(ch));
     169        Expression chExpression = Dynamic.column(VirtualColumn.channelRaw(ch));
    180170        // Selects: ch * factor for each channel
    181171        query.select(
     
    189179      SpotBatcher batcher = result.getSpotBatcher();
    190180      // Check for the ABORT signal before a lengthy operation
    191       checkInterrupted();
     181      ThreadSignalHandler.checkInterrupted();
    192182      int spotsCopied = batcher.insert(query);
    193183      batcher.close();
     
    220210    Return a set containing the context [BIOASSAYSET, ITEM].
    221211  */
     212  @Override
    222213  public Set<GuiContext> getGuiContexts()
    223214  {
     
    226217  /**
    227218    Check if the item is a {@link BioAssaySet} and the logged in
    228     user has USE permission to the experiment.
    229   */
     219    user has USE permission to the experiment. Also verify that
     220    the bioassay set has data stored in the database.
     221  */
     222  @Override
    230223  public String isInContext(GuiContext context, Object item)
    231224  {
    232     String message = null; 
    233     if (item == null)
    234     {
    235       message = "The item is null";
    236     }
    237     else if (!(item instanceof BioAssaySet))
    238     {
    239       message = "The item is not a BioAssaySet: " + item;
    240     }
    241     else
    242     {
    243       // Without USE permission we will not be able
    244       // to create new bioassay sets
    245       Experiment e = ((BioAssaySet)item).getExperiment();
    246       e.checkPermission(Permission.USE);
     225    String message = super.isInContext(context, item);
     226    if (message == null)
     227    {
     228      BioAssaySet bas = (BioAssaySet)item;
     229      if (bas.getNumSpots() <= 0)
     230      {
     231        message = "This plug-in requires spot data in the database";
     232      }
    247233    }
    248234    return message;
     
    255241    a bioassay set, a multiplcation factor and a cutoff value.
    256242  */
     243  @Override
    257244  public RequestInformation getRequestInformation(GuiContext context, String command)
    258245    throws BaseException
     
    269256    {@link Request#COMMAND_CONFIGURE_JOB}.
    270257  */
     258  @Override
    271259  public void configure(GuiContext context, Request request, Response response)
    272260  {
     
    276264      if (command.equals(Request.COMMAND_CONFIGURE_JOB))
    277265      {
     266        RequestInformation ri = getConfigureJob(context);
    278267        List<Throwable> errors =
    279           validateRequestParameters(getConfigureJob(context).getParameters(), request);
     268          validateRequestParameters(ri.getParameters(), request);
    280269        if (errors != null)
    281270        {
     
    284273        }
    285274
    286         storeValue(job, request, bioAssaySetParameter);
     275        // Source bioassay set
     276        storeValue(job, request, ri.getParameter(SOURCE_BIOASSAYSET));
     277               
     278        // Other options
    287279        storeValue(job, request, factorParameter);
    288280        storeValue(job, request, cutoffParameter);
     281        BioAssaySet bioAssaySet = (BioAssaySet)job.getValue(SOURCE_BIOASSAYSET);
     282        response.setSuggestedJobName("Example analysis on bioassay set '" +
     283            bioAssaySet.getName() + "'");
    289284        response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
    290285        // TODO - maybe check file size to make a better estimate
     
    301296    -------------------------------------------
    302297  */
     298  @Override
    303299  public SignalHandler getSignalHandler()
    304300  {
     
    311307  private RequestInformation getConfigureJob(GuiContext context)
    312308  {
    313     if (configureJob == null)
    314     {
    315       // Create bioassay set parameter
    316       // A value is automatically assigned by the web client
    317       bioAssaySetParameter = new PluginParameter<BioAssaySet>(
    318         "bioAssaySet",
    319         "Bioassay set",
    320         "The bioassay set used as the source for this plugin",
    321         new ItemParameterType<BioAssaySet>(BioAssaySet.class, null, true, 1, null)
    322       );
    323 
    324       // Create multiplication factor parameter
    325       factorParameter = new PluginParameter<Float>(
    326         "factor",
    327         "Multiplication factor",
    328         "The factor to multiply each spot intensity with.",
    329         new FloatParameterType(0.0f, 100.0f, 1.0f, true)
    330       );
    331 
    332       // Create cutoff parameter
    333       cutoffParameter = new PluginParameter<Float>(
    334         "cutoff",
    335         "Cut-off value",
    336         "Original intensities falling below this value are filtered out.",
    337         new FloatParameterType(null, null, 0.0f, true)
    338       );
    339      
    340       // Create parameter list and request informaion
    341       List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    342       parameters.add(bioAssaySetParameter);
    343       parameters.add(factorParameter);
    344       parameters.add(cutoffParameter);
    345      
    346       configureJob = new RequestInformation
    347       (
    348         Request.COMMAND_CONFIGURE_JOB,
    349         "Specify multiplication factor and cutoff",
    350         about.getDescription(),
    351         parameters
    352       );
     309    DbControl dc = null;
     310    try
     311    {
     312      if (configureJob == null)
     313      {
     314        dc = sc.newDbControl();
     315        BioAssaySet bas = getCurrentBioAssaySet(dc);
     316        // Create parameter list and request informaion
     317        List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
     318       
     319        // Source bioassay set parameter
     320        parameters.add(getSourceBioAssaySetParameter(null, null));   
     321 
     322        // Other parameters
     323        // Create multiplication factor parameter
     324        factorParameter = new PluginParameter<Float>(
     325          "factor",
     326          "Multiplication factor",
     327          "The factor to multiply each spot intensity with.",
     328          new FloatParameterType(0.0f, 100.0f, 1.0f, true)
     329        );
     330 
     331        // Create cutoff parameter
     332        cutoffParameter = new PluginParameter<Float>(
     333          "cutoff",
     334          "Cut-off value",
     335          "Original intensities falling below this value are filtered out.",
     336          new FloatParameterType(null, null, 0.0f, true)
     337        );
     338        parameters.add(factorParameter);
     339        parameters.add(cutoffParameter);
     340       
     341        configureJob = new RequestInformation
     342        (
     343          Request.COMMAND_CONFIGURE_JOB,
     344          "Specify multiplication factor and cutoff",
     345          about.getDescription(),
     346          parameters
     347        );
     348      }
     349    }
     350    finally
     351    {
     352      if (dc != null) dc.close();
    353353    }
    354354    return configureJob;
  • plugins/base2/net.sf.basedb.examples/trunk/src/net/sf/basedb/exampleplugins/ExampleImporter.java

    r647 r1292  
    7878      "or not. It won't actually import any samples, but will report that a few samples " +
    7979      "has been imported.",
    80       "2.6",
     80      "2.17",
    8181      "2006, Base 2 development team",
    8282      null,
     
    114114    -------------------------------------------
    115115  */
     116  @Override
    116117  public About getAbout()
    117118  {
    118119    return about;
    119120  }
     121  @Override
    120122  public Plugin.MainType getMainType()
    121123  {
    122124    return Plugin.MainType.IMPORT;
    123125  }
     126  @Override
    124127  public boolean supportsConfigurations()
    125128  {
    126129    return false;
    127130  }
     131  @Override
    128132  public boolean requiresConfiguration()
    129133  {
    130134    return false;
    131135  }
     136  @Override
    132137  public void run(Request request, Response response, ProgressReporter progress)
    133138  {
     
    175180    Return a set containing the context [SAMPLE, LIST].
    176181  */
     182  @Override
    177183  public Set<GuiContext> getGuiContexts()
    178184  {
     
    182188    Always null, we are not dealing with individual items.
    183189  */
     190  @Override
    184191  public String isInContext(GuiContext context, Object item)
    185192  {
     
    193200    a file and if existing samples should be updated or ignored.
    194201  */
     202  @Override
    195203  public RequestInformation getRequestInformation(GuiContext context, String command)
    196204    throws BaseException
     
    207215    {@link Request#COMMAND_CONFIGURE_JOB}.
    208216  */
     217  @Override
    209218  public void configure(GuiContext context, Request request, Response response)
    210219  {
     
    224233        storeValue(job, request, fileParameter);
    225234        storeValue(job, request, updateExistingParameter);
     235        File importFile = (File)job.getValue(fileParameter.getName());
     236        response.setSuggestedJobName("Import samples from '" + importFile.getName() + "'");
    226237        response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
    227238        // TODO - maybe check file size to make a better estimate
     
    243254    Always true, since we accept all files.
    244255  */
     256  @Override
    245257  public boolean isImportable(InputStream in)
    246258    throws BaseException
     
    251263    We don't do anything in this method.
    252264  */
     265  @Override
    253266  public void doImport(InputStream in, ProgressReporter progress)
    254267    throws BaseException
    255268  {
    256269    // Check if the ABORT signal has been sent
    257     checkInterrupted();
     270    ThreadSignalHandler.checkInterrupted();
    258271    /*
    259272      Pseudo code:
    260273      Parse input stream, for each found sample:
    261       checkInterrupted();  // Do this as the first thing in a loop
     274      ThreadSignalHandler.checkInterrupted();  // Do this as the first thing in a loop
    262275      String name = ...
    263276      String externalId = ...
     
    267280      {
    268281        s = Sample.getNew(dc);
     282        s.setName(name) // and other properites
    269283        dc.saveItem(s);
    270284        isNew = true;
     
    283297    -------------------------------------------
    284298  */
     299  @Override
    285300  public SignalHandler getSignalHandler()
    286301  {
Note: See TracChangeset for help on using the changeset viewer.