Analysis plugins

NOTE! This document is outdated and has been replaced with newer documentation. See Plug-in developer: Analysis plug-ins

This document contains information specific for writing analysis plugins.

Contents

  1. Analysis plugins

See also

Last updated: $Date: 2009-04-06 14:52:39 +0200 (må, 06 apr 2009) $
Copyright © 2006 The respective authors. All rights reserved.

1. Analysis plugins

A plugin becomes an analysis plugin simply by returning Plugin.MainType.ANALYSIS from the Plugin.getMainType() method.

The information returned from InteractivePlugin.getGuiContexts() must include: GuiContext = [Item.BIOASSAYSET, Type.ITEM] since this is the only place where the web client looks for analysis plugins.

private static final Set<GuiContext> guiContexts = 
   Collections.singleton(new GuiContext(Item.BIOASSAYSET, GuiContext.Type.ITEM));

public Set<GuiContext> getGuiContexts()
{
   return guiContexts;
}

If the plugin depends on a specific raw data type or on the number of channels, it should check that the current bioassayset is of the correct type in the InteractivePlugin.isInContext() method:

/**
   Check if the item is a bioassay set with a 2-channel raw data type
*/
public boolean isInContext(GuiContext context, Object item)
{
   if (item instanceof BioAssaySet)
   {
      BioAssaySet bas = (BioAssaySet)item;
      RawDataType rdt = bas.getRawDataType();
      int channels = rdt.getChannels();
      return channels == 2;
   }
   return false;
}

The plugin should always include a parameter asking for the current bioassay set when the InteractivePlugin.getRequestInformation() is called with the command = Request.COMMAND_CONFIGURE_JOB.

private static final RequestInformation configurePlugin;
private RequestInformation configureJob;
private PluginParameter<BioAssaySet> bioAssaySetParameter;

public RequestInformation getRequestInformation(GuiContext context, String command) 
   throws BaseException
{
   RequestInformation requestInformation = null;
   if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN))
   {
      requestInformation = getConfigurePlugin(guiContext);
   }
   else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
   {
      requestInformation = getConfigureJob(guiContext);
   }
   return requestInformation;
}

private RequestInformation getConfigureJob(GuiContext context)
{
   if (configureJob == null)
   {
      bioAssaySetParameter; = new PluginParameter<BioAssaySet>(
         "bioAssaySet",
         "Bioassay set",
         "The bioassay set used as the source for this analysis plugin",
         new ItemParameterType<BioAssaySet>(BioAssaySet.class, null, true, 1, null)
      );

      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
      parameters.add(bioAssaySetParameter);
      // Add more plugin-specific parameters...
		
      configureJob = new RequestInformation(
         Request.COMMAND_CONFIGURE_JOB,
         "Configure job",
         "TODO - description",
         parameters
      );
   }
   return configureJob;
}
private RequestInformation getConfigurePlugin(GuiContext context)
{
   if (configurePlugin == null)
   {
      // TODO - Add plugin-specific parameters
      configurePlugin = new RequestInformation(
         Request.COMMAND_CONFIGURE_PLUGIN,
         "Configure plugin",
         "This plugin has no configuration options.",
         null
      );
   }
}

Of course, the configure method needs to validate and store the bioassay set parameter as well:

public void configure(GuiContext context, Request request, Response response)
{
   String command = request.getCommand();
   try
   {
      if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN))
      {
         // Validate and store configuration parameters
         response.setDone("Plugin configuration complete");
      }
      else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
      {
         List<Throwable> errors = 
            validateRequestParameters(configureJob.getParameters(), request);
         if (errors != null)
         {
            response.setError(errors.size() +
               " invalid parameter(s) were found in the request", errors);
            return;
         }
         storeValue(job, request, bioAssaySetParameter);
         // Store other plugin-specific parameters
			
         response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
         // TODO - better estimate of execution time!!
      }
   }
   catch (Throwable ex)
   {
      // Never throw exception, always set response!
      response.setError(ex.getMessage(), Arrays.asList(ex));
   }
}

Now, the typical run() method loads the specfied bioassay set and it's spot data. It may do some filtering and recalculation of the spot intensity value(s). In most cases it will store the result as a child bioassay set with one bioassay for each bioassay in the parent bioassay set. Here is an example, which just copies the intensity values, while removing those with a negative value in either channel.

public void run(Request request, Response response, ProgressReporter progress)
{
   DbControl dc = sc.newDbControl();
   try
   {
      BioAssaySet source = (BioAssaySet)job.getParameter("bioAssaySet");
      // Reload with current DbControl
      source = BioAssaySet.getById(dc, source.getId());
      int channels = source.getRawDataType().getChannels();
      
      // Create transformation and new bioassay set
      Job j = Job.getById(dc, job.getId());
      Transformation t = source.newTransformation(j);
      t.setName("Copy spot intensities >= 0");
      dc.saveItem(t);

      BioAssaySet result = t.newProduct(null, "new", true);
      result.setName("After: Copying spot intensities");
      dc.saveItem(result);

      // Get query for source data
      DynamicSpotQuery query = source.getSpotData();
      
      // Do not return spots with intensities < 0
      for (int ch = 1; ch <= channels; ++ch)
      {
         query.restrict(
      	    Restrictions.gteq(
      	       Dynamic.column(VirtualColumn.channel(ch)),
      	       Expressions.integer(0)
      	    )
      	 );
      }
      
      // Create batcher and copy data
      SpotBatcher batcher = result.getSpotBatcher();
      int spotsCopied = batcher.insert(query);
      batcher.close();
      
      // Commit and return
      dc.commit();
      response.setDone("Copied " + spotsCopied + " spots.");
   }
   catch (Throwable t)
   {
      response.setError(t.getMessage(), Arrays.asList(t));
   }
   finally
   {
      if (dc != null) dc.close();
   }
}

See the Dynamic API for experiments and analysis for more examples of using the analysis API.