Changeset 2155


Ignore:
Timestamp:
Apr 7, 2006, 2:56:14 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #139: Write documentation: 5d) Analysis plug-ins
Added another example plugin: ExampleAnalyzer?

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r2154 r2155  
    638638      srcdir="${exampledir}/src"
    639639      destdir="${exampledir}/bin"
     640      debug="true"
    640641      >
    641642      <classpath>
     
    660661      />
    661662    </tar>
     663    <delete file="${exampledir}/ExamplePlugins.jar" />
     664    <delete includeemptydirs="true">
     665      <fileset dir="${exampledir}/bin" includes="**/*"/>
     666    </delete>
    662667  </target>
    663668 
  • trunk/doc/development/index.html

    r2154 r2155  
    300300      and if existing samples should be updated or not, but doesn't
    301301      actually import anything.
     302
     303    <li>ExampleAnalyzer: Asks for a multiplication factor and a cut-off value.
     304      It will create a child bioassay set by multiplying the original intensities
     305      with the given factor and filter out those with original intensities less than
     306      the cut-off. It works for any number of channels.
     307   
    302308    </ul>
    303309    <br>
  • trunk/doc/development/plugins/analysis/index.html

    r734 r2155  
    33  $Id$
    44
    5   BioArray Software Environment (BASE) - http://base.thep.lu.se/
    6   Copyright (C) 2002-2004 Lao Saal, Carl Troein,
    7   Johan Vallon-Christersson, Jari Häkkinen, Nicklas Nordborg
    8 
    9   This file is part of BASE.
     5  Copyright (C) 2006 Nicklas Nordborg
     6
     7  This file is part of BASE - BioArray Software Environment.
     8  Available at http://base.thep.lu.se/
    109
    1110  BASE is free software; you can redistribute it and/or
     
    4443  <div class="abstract">
    4544 
    46     TODO
     45    <p>
     46    This document contains information specific for writing analysis plugins.
     47    </p>
    4748 
    4849    <p>
     
    5051    </p>
    5152    <ol>
    52       <li>
    53 
     53      <li><a href="#analysis">Analysis plugins</a>
    5454    </ol>
     55   
    5556    <p>
    5657    <b>See also</b>
     58    </p>
     59   
    5760    <ul>
    58     <li>
     61    <li><a href="../index.html">How to write plug-ins</a>
     62    <li><a href="../../overview/dynamic/index.html">Dynamic API for experiments and analysis</a>
    5963    </ul>
    60     </p>
    6164   
    6265    <p class="authors">
    63     <b>Last updated:</b> $Date$
     66    <b>Last updated:</b> $Date$<br>
     67    <b>Copyright &copy;</b> 2006 The respective authors. All rights reserved.
    6468    </p>
    6569  </div>
    66 
     70 
     71  <a name="analysis"></a>
     72  <h2>1. Analysis plugins</h2>
     73 
     74  <p>
     75  A plugin becoms an analysis plugin simply by returning <code>Plugin.MainType.ANALYSIS</code>
     76  from the <code>Plugin.getMainType()</code> method.
     77  </p>
     78
     79  <p>
     80  The information return from <code>InteractivePlugin.getGuiContexts()</code>
     81  must include: <code>GuiContext = [Item.BIOASSAYSET, Type.ITEM]</code>
     82  since this is the only place where the web client looks for analysis plugins.
     83  </p>
     84 
     85  <pre class="code">
     86private static final Set&lt;GuiContext&gt; guiContexts =
     87   Collections.singleton(new GuiContext(Item.BIOASSAYSET, GuiContext.Type.ITEM));
     88
     89public Set&lt;GuiContext&gt; getGuiContexts()
     90{
     91   return guiContexts;
     92}
     93</pre>
     94 
     95  <p>
     96  If the plugin depends on a specific raw data type or on the number of
     97  channels, it should check that the current bioassayset is of the
     98  correct type in the <code>InteractivePlugin.isInContext()</code> method:
     99  </p>
     100 
     101  <pre class="code">
     102/**
     103   Check if the item is a bioassay set with a 2-channel raw data type
     104*/
     105public boolean isInContext(GuiContext context, Object item)
     106{
     107   if (item instanceof BioAssaySet)
     108   {
     109      BioAssaySet bas = (BioAssaySet)item;
     110      RawDataType rdt = bas.getRawDataType();
     111      int channels = rdt.getChannels();
     112      return channels == 2;
     113   }
     114   return false;
     115}
     116</pre>
     117
     118  <p>
     119  The plugin should always include a parameter asking for the current
     120  bioassay set when the <code>InteractivePlugin.getRequestInformation()</code>
     121  is called with the <code>command = Request.COMMAND_CONFIGURE_JOB</code>.
     122  </p> 
     123
     124  <pre class="code">
     125private static final RequestInformation configurePlugin;
     126private RequestInformation configureJob;
     127private PluginParameter&lt;BioAssaySet&gt; bioAssaySetParameter;
     128
     129public RequestInformation getRequestInformation(GuiContext context, String command)
     130   throws BaseException
     131{
     132   RequestInformation requestInformation = null;
     133   if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN))
     134   {
     135      requestInformation = getConfigurePlugin(guiContext);
     136   }
     137   else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
     138   {
     139      requestInformation = getConfigureJob(guiContext);
     140   }
     141   return requestInformation;
     142}
     143
     144private RequestInformation getConfigureJob(GuiContext context)
     145{
     146   if (configureJob == null)
     147   {
     148      bioAssaySetParameter; = new PluginParameter&lt;BioAssaySet&gt;(
     149         "bioAssaySet",
     150         "Bioassay set",
     151         "The bioassay set used as the source for this analysis plugin",
     152         new ItemParameterType&lt;BioAssaySet&gt;(BioAssaySet.class, null, true, 1, null)
     153      );
     154
     155      List&lt;PluginParameter&lt;?&gt;&gt; parameters = new ArrayList&lt;PluginParameter&lt;?&gt;&gt;();
     156      parameters.add(bioAssaySetParameter);
     157      // Add more plugin-specific parameters...
     158   
     159      configureJob = new RequestInformation(
     160         Request.COMMAND_CONFIGURE_JOB,
     161         "Configure job",
     162         "TODO - description",
     163         parameters
     164      );
     165   }
     166   return configureJob;
     167}
     168private RequestInformation getConfigurePlugin(GuiContext context)
     169{
     170   if (configurePlugin == null)
     171   {
     172      // TODO - Add plugin-specific parameters
     173      configurePlugin = new RequestInformation(
     174         Request.COMMAND_CONFIGURE_PLUGIN,
     175         "Configure plugin",
     176         "This plugin has no configuration options.",
     177         null
     178      );
     179   }
     180}
     181</pre>
     182
     183  <p>
     184  Of course, the <code>configure</code> method needs to validate and store
     185  the bioassay set parameter as well:
     186  </p>
     187 
     188  <pre class="code">
     189public void configure(GuiContext context, Request request, Response response)
     190{
     191   String command = request.getCommand();
     192   try
     193   {
     194      if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN))
     195      {
     196         // Validate and store configuration parameters
     197         response.setDone("Plugin configuration complete");
     198      }
     199      else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
     200      {
     201         List&lt;Throwable&gt; errors =
     202            validateRequestParameters(configureJob.getParameters(), request);
     203         if (errors != null)
     204         {
     205            response.setError(errors.size() +
     206               " invalid parameter(s) were found in the request", errors);
     207            return;
     208         }
     209         storeValue(job, request, bioAssaySetParameter);
     210         // Store other plugin-specific parameters
     211     
     212         response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
     213         // TODO - better estimate of execution time!!
     214      }
     215   }
     216   catch (Throwable ex)
     217   {
     218      // Never throw exception, always set response!
     219      response.setError(ex.getMessage(), Arrays.asList(ex));
     220   }
     221}
     222</pre>
     223
     224  <p>
     225  Now, the typical <code>run()</code> method loads the specfied bioassay set
     226  and it's spot data. It may do some filtering and recalculation of the spot
     227  intensity value(s). In most cases it will store the result as a child bioassay
     228  set with one bioassay for each bioassay in the parent bioassay set.
     229  Here is an example, which just copies the intensity values, while
     230  removing those with a negative value in either channel.
     231  </p>
     232 
     233  <pre class="code">
     234public void run(Request request, Response response, ProgressReporter progress)
     235{
     236   DbControl dc = sc.newDbControl();
     237   try
     238   {
     239      BioAssaySet source = (BioAssaySet)job.getParameter("bioAssaySet");
     240      // Reload with current DbControl
     241      source = BioAssaySet.getById(dc, source.getId());
     242      int channels = source.getRawDataType().getChannels();
     243     
     244      // Create transformation and new bioassay set
     245      Job j = Job.getById(dc, job.getId());
     246      Transformation t = source.newTransformation(j);
     247      t.setName("Copy spot intensities &gt;= 0");
     248      BioAssaySet result = t.newProduct(null, "new");
     249      result.setName("After: Copying spot intensities");
     250      dc.saveItem(t);
     251      dc.saveItem(result);
     252     
     253      // Create child bioassays for each source bioassay
     254      for (BioAssay ba : source.getBioAssays.list(dc))
     255      {
     256         dc.saveItem(result.newBioAssay(ba));
     257      }
     258
     259      // Get query for source data
     260      DynamicSpotQuery query = source.getSpotData();
     261     
     262      // Do not return spots with intensities &lt; 0
     263      for (int ch = 1; ch &lt;= channels; ++ch)
     264      {
     265         query.restrict(
     266            Restrictions.gteq(
     267               Dynamic.column(VirtualColumn.channel(ch)),
     268               Expressions.integer(0)
     269            )
     270         );
     271      }
     272     
     273      // Create batcher and copy data
     274      SpotBatcher batcher = result.getSpotBatcher();
     275      int spotsCopied = batcher.insert(query);
     276      batcher.close();
     277     
     278      // Commit and return
     279      dc.commit();
     280      response.setDone("Copied " + spotsCopied + " spots.");
     281   }
     282   catch (Throwable t)
     283   {
     284      response.setError(t.getMessage(), Arrays.asList(t));
     285   }
     286   finally
     287   {
     288      if (dc != null) dc.close();
     289   }
     290}
     291</pre>
     292
     293  <p>
     294  See the <a href="../../overview/dynamic/index.html">Dynamic API for experiments and analysis</a>
     295  for more examples of using the analysis API.
     296  </p>
     297 
    67298</body>
    68299</html>
  • trunk/src/examples/plugins/build.xml

    r2154 r2155  
    2727         srcdir="${src}"
    2828         destdir="${bin}"
     29         debug="true"
    2930         classpathref="classpath">
    3031      </javac>
Note: See TracChangeset for help on using the changeset viewer.