Changeset 2126


Ignore:
Timestamp:
Mar 29, 2006, 2:56:43 PM (17 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #166 and #167:

Location:
trunk
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/plugins/IntensityCalculatorPlugin.java

    r1972 r2126  
    2727import net.sf.basedb.core.ProgressReporter;
    2828
     29import net.sf.basedb.core.BaseException;
     30import net.sf.basedb.core.Formula;
     31import net.sf.basedb.core.Include;
     32import net.sf.basedb.core.InvalidDataException;
     33import net.sf.basedb.core.Item;
     34import net.sf.basedb.core.ItemParameterType;
     35import net.sf.basedb.core.ItemQuery;
     36import net.sf.basedb.core.PluginParameter;
     37import net.sf.basedb.core.RequestInformation;
     38import net.sf.basedb.core.StringParameterType;
    2939import net.sf.basedb.core.Transformation;
    3040import net.sf.basedb.core.BioAssaySet;
     
    3747import net.sf.basedb.core.plugin.AboutImpl;
    3848import net.sf.basedb.core.plugin.AbstractPlugin;
     49import net.sf.basedb.core.plugin.GuiContext;
    3950import net.sf.basedb.core.plugin.Plugin;
     51import net.sf.basedb.core.plugin.InteractivePlugin;
    4052import net.sf.basedb.core.plugin.Request;
    4153import net.sf.basedb.core.plugin.Response;
    42 import net.sf.basedb.core.IntensityFormula;
     54import net.sf.basedb.core.query.Hql;
     55import net.sf.basedb.core.query.Orders;
    4356import net.sf.basedb.util.IntensityCalculator;
    4457import net.sf.basedb.util.IntensityCalculatorUtil;
    4558
     59import java.util.ArrayList;
     60import java.util.Arrays;
     61import java.util.Collections;
    4662import java.util.List;
     63import java.util.Set;
    4764
    4865/**
    49    This plugin provides methods to calculate the intensity for a root bioassayset using different formulas.
    50    It needs the following parameters
     66   This plugin provides methods to calculate the intensity for a root bioassayset
     67   using different formulas. It needs the following parameters:
    5168
    5269   <pre>
    53    String              : name
    54    Experiment          : experiment
    55    List<RawBioAssay>   : rawBioAssays 
    56    String              : formula
     70   String              : name; The name of the new bioassayset
     71   Experiment          : experiment; The experiment we are working on
     72   List&gt;RawBioAssay&lt;   : rawBioAssays; The raw bioassays to create bioassays for
     73     (must be part of the experiment)
     74   Formula             : formula; The formula to use to for calculating intesities
    5775   </pre>
    5876
    59    @author Gregory
     77   @author Gregory, Nicklas
     78   @version 2.0
     79   @base.modified $Date$
    6080*/
    6181public class IntensityCalculatorPlugin
    6282  extends AbstractPlugin
    63   implements Plugin
     83  implements InteractivePlugin
    6484{
    6585
     
    7090          new AboutImpl
    7191    (
    72       "Intensity calculator",
    73       "This plugin is used to calculate intensities from raw data creating an initial raw bioassay.",
    74       "1.0",
     92      "Formula intensity calculator",
     93      "This plugin is used to calculate intensities from raw data creating an initial root bioassay set. "+
     94      "The intensities are calculated using Formula objects registered for the experiment's raw data type. " +
     95      "Thus, the functionality of this plugin can be extended by adding more formula objects to the database.",
     96      "2.0",
    7597      "2006, Department of Theoretical Physics, Lund University",
    7698      null,
     
    79101    );
    80102
    81 
     103  private static final Set<GuiContext> guiContexts =
     104    Collections.singleton(new GuiContext(Item.BIOASSAYSET, GuiContext.Type.LIST));
     105
     106  private static final RequestInformation configurePlugin = new RequestInformation
     107  (
     108    Request.COMMAND_CONFIGURE_PLUGIN,
     109    "Configure intensity calculator",
     110    "This plugin has no configuration options.",
     111    null
     112  );
     113
     114  private static final StringParameterType nameType =
     115    new StringParameterType(BioAssaySet.MAX_NAME_LENGTH, "New bioassayset", true);
     116  private static final PluginParameter<String> nameParameter = new PluginParameter<String>(
     117    "name", "Bioassay set name", "The name of the root bioassayset", nameType);
     118
     119  private ItemParameterType<Experiment> experimentType;
     120  private PluginParameter<Experiment> experimentParameter;
     121
     122  private ItemParameterType<RawBioAssay> rawBioAssaysType;
     123  private PluginParameter<RawBioAssay> rawBioAssaysParameter;
     124
     125  private ItemParameterType<Formula> formulaType;
     126  private PluginParameter<Formula> formulaParameter;
     127
     128  private RequestInformation configureJob;
     129 
    82130  /**
    83131     Constructor should be empty.
     
    86134  {}
    87135 
    88 
    89   /*
    90     Plugin interface implementation
    91     -------------------------------
     136  /*
     137    From the Plugin interface
     138    -------------------------------------------
    92139  */
    93140  public About getAbout()
     
    95142    return about;
    96143  }
    97 
    98 
    99144  /**
    100145     Returns the main plugin type this plugin belongs to.
     
    106151  }
    107152
    108 
    109   /**
    110      @param request
    111      @param response
    112      @param progress
    113   */
    114153  @SuppressWarnings("unchecked")
    115154  public void run(Request request, Response response, ProgressReporter progress)
     
    118157    try
    119158    {
    120       /* name parameter */
     159      // name parameter
    121160      String name = (String)job.getValue("name");
    122161 
    123       /* experiment parameter*/
    124  
    125       Integer experimentId = (Integer)job.getValue("experiment_id");
    126       if(experimentId != null)
    127       {
    128         Experiment experiment = Experiment.getById(dc, experimentId.intValue());
    129  
    130         /* rawBioAssays parameter*/
    131         List<RawBioAssay> sources = (List<RawBioAssay>)job.getValues("rawBioAssays");
    132         for (RawBioAssay rba : sources)
    133         {
    134           dc.reattachItem(rba);
    135         }
    136  
    137         /* formula parameter */
    138         String formula = (String)job.getValue("formula");
    139  
    140         /* intensity calculation */
    141         RawDataType rdt = experiment.getRawDataType();
    142         IntensityFormula intensityFormula = rdt.getIntensityFormula( formula );
    143         IntensityCalculator iCalc = IntensityCalculatorUtil.createJepIntensityCalculator(dc, rdt, intensityFormula.getExpressions());
    144         int jobId = job.getId();
    145         Job thisJob = Job.getById(dc, jobId);
    146         BioAssaySet rootBas = IntensityCalculatorUtil.createRootBioAssaySet(dc, experiment, sources, thisJob, iCalc, progress);
    147         rootBas.setName(name);
    148         Transformation t = rootBas.getTransformation();
    149         t.setName(intensityFormula.getTitle());
    150         dc.commit();
    151         response.setDone("Done");
     162      // experiment parameter
     163      Experiment experiment = (Experiment)job.getValue("experiment");
     164     
     165      // To avoid disconnection/reconnection issues
     166      experiment = Experiment.getById(dc, experiment.getId());
     167 
     168      // rawBioAssays parameter
     169      List<RawBioAssay> sources = (List<RawBioAssay>)job.getValues("rawBioAssays");
     170      for (RawBioAssay rba : sources)
     171      {
     172        dc.reattachItem(rba);
    152173      }
    153       else
    154       {
    155         response.setError("Experiment id is null", null);
     174
     175      // Formula parameter
     176      Formula formula = (Formula)job.getValue("formula");
     177      formula = Formula.getById(dc, formula.getId());
     178 
     179      // intensity calculation
     180      RawDataType rdt = experiment.getRawDataType();
     181
     182      // IntensityFormula intensityFormula = rdt.getIntensityFormula( formula );
     183      IntensityCalculator iCalc =
     184        IntensityCalculatorUtil.createJepIntensityCalculator(dc, rdt,
     185        formula.getFormulas().toArray(new String[formula.getNumFormulas()]));
     186      int jobId = job.getId();
     187      Job thisJob = Job.getById(dc, jobId);
     188
     189      BioAssaySet rootBas = IntensityCalculatorUtil.createRootBioAssaySet(dc, experiment, sources, thisJob, iCalc, progress);
     190      rootBas.setName(name);
     191      Transformation t = rootBas.getTransformation();
     192      t.setName(formula.getName());
     193      dc.commit();
     194      response.setDone("Done");
     195    }
     196    finally
     197    {
     198      if (dc != null) dc.close();
     199    }
     200  }
     201  // -------------------------------------------
     202
     203  /*
     204    From the InteractivePlugin interface
     205    -------------------------------------------
     206  */
     207  public Set<GuiContext> getGuiContexts()
     208  {
     209    return guiContexts;
     210  }
     211  /**
     212    Always false, since plugin doesn't operate on individual items.
     213  */
     214  public boolean isInContext(GuiContext context, Object item)
     215  {
     216    return false;
     217  }
     218  /**
     219    The {@link Request#COMMAND_CONFIGURE_PLUGIN} command will not ask for
     220    any parameters.
     221    The {@link Request#COMMAND_CONFIGURE_JOB} command will ask for
     222    the parameters mentioned in the class documentation.
     223  */
     224  public RequestInformation getRequestInformation(GuiContext context, String command)
     225    throws BaseException
     226  {
     227    RequestInformation requestInformation = null;
     228    if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN))
     229    {
     230      requestInformation = configurePlugin;
     231    }
     232    else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
     233    {
     234      requestInformation = getConfigureJobParameters();
     235    }
     236    return requestInformation;
     237  }
     238  /**
     239    Store configuration settings for {@link Request#COMMAND_CONFIGURE_PLUGIN},
     240    and {@link Request#COMMAND_CONFIGURE_JOB}.
     241  */
     242  @SuppressWarnings("unchecked")
     243  public void configure(GuiContext context, Request request, Response response)
     244  {
     245    String command = request.getCommand();
     246   
     247    try
     248    {
     249      if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN))
     250      {
     251        response.setDone("No configuration needed.");
    156252      }
    157     }
    158     finally
    159     {
    160       if (dc != null) dc.close();
    161     }
    162   }
     253      else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
     254      {
     255        List<Throwable> errors = validateRequestParameters(configureJob.getParameters(), request);
     256        if (errors != null)
     257        {
     258          response.setError(errors.size()+" invalid parameter(s) were found in the request", errors);
     259          return;
     260        }
     261       
     262        Experiment experiment = (Experiment)request.getParameterValue("experiment");
     263        DbControl dc = sc.newDbControl();
     264        int numSpots = 0;
     265        try
     266        {
     267          experiment = Experiment.getById(dc, experiment.getId());
     268          List<RawBioAssay> rawBioAssays = (List<RawBioAssay>)request.getParameterValues("rawBioAssays");
     269          for (RawBioAssay rba : rawBioAssays)
     270          {
     271            if (!experiment.isUsing(rba))
     272            {
     273              throw new InvalidDataException("Raw bioassay '" + rba.getName() +
     274                "' is not part of the experiment '" + experiment.getName()+"'");
     275            }
     276            numSpots += rba.getSpots();
     277          }
     278        }
     279        finally
     280        {
     281          if (dc != null) dc.close();
     282        }
     283       
     284        Formula formula = (Formula)request.getParameterValue("formula");
     285        if (formula.getFormulaType() != Formula.Type.INTENSITY_EXPRESSION)
     286        {
     287          throw new InvalidDataException("The selected formula is not an intensity expression formula: " +
     288            formula.getName());
     289        }
     290        if (formula.getRawDataType() != experiment.getRawDataType())
     291        {
     292          throw new InvalidDataException("The selected formula '"+formula.getName()+
     293            "' uses a different raw data type than the experiment '" + experiment.getName()+"'");
     294        }
     295       
     296        storeValue(job, request, nameParameter);
     297        storeValue(job, request, experimentParameter);
     298        storeValues(job, request, rawBioAssaysParameter);
     299        storeValue(job, request, formulaParameter);
     300       
     301        Job.ExecutionTime execTime = Job.ExecutionTime.SHORT;
     302        // TODO - this should be configurable in some way
     303        if (numSpots > 1000000 && numSpots < 10000000)
     304        {
     305          execTime = Job.ExecutionTime.MEDIUM;
     306        }
     307        else
     308        {
     309          execTime = Job.ExecutionTime.LONG;
     310        }
     311       
     312        response.setDone("Job configuration complete", execTime);
     313      }
     314    }
     315    catch (Throwable ex)
     316    {
     317      response.setError(ex.getMessage(), Arrays.asList(ex));
     318      ex.printStackTrace();
     319    }
     320  }
     321
     322 
     323  private RequestInformation getConfigureJobParameters()
     324  {
     325    if (configureJob == null)
     326    {
     327      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
     328     
     329      experimentType = new ItemParameterType<Experiment>(Experiment.class, null, true, 1, null);
     330      experimentParameter = new PluginParameter<Experiment>(
     331        "experiment", "Experiment", "The experiment we are working with", experimentType);
     332     
     333      parameters.add(experimentParameter);
     334      parameters.add(nameParameter);
     335     
     336      DbControl dc = sc.newDbControl();
     337      try
     338      {
     339        int experimentId = sc.getCurrentContext(Item.EXPERIMENT).getId();
     340        Experiment experiment = Experiment.getById(dc, experimentId);
     341       
     342        ItemQuery<RawBioAssay> rawBioAssayQuery = experiment.getRawBioAssays();
     343        rawBioAssayQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
     344        rawBioAssayQuery.order(Orders.asc(Hql.property("name")));
     345        List<RawBioAssay> rawBioAssays = new ArrayList<RawBioAssay>(rawBioAssayQuery.list(dc));
     346        rawBioAssaysType = new ItemParameterType<RawBioAssay>(RawBioAssay.class, null, true, 0, rawBioAssays);
     347        rawBioAssaysParameter = new PluginParameter<RawBioAssay>(
     348          "rawBioAssays", "Raw bioassays", "Select the raw bioassays to use when creating the root bioassay set",
     349          rawBioAssaysType);
     350       
     351        parameters.add(rawBioAssaysParameter);
     352       
     353        ItemQuery<Formula> formulaQuery = Formula.getQuery(Formula.Type.INTENSITY_EXPRESSION,
     354            experiment.getRawDataType());
     355        formulaQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
     356        formulaQuery.order(Orders.asc(Hql.property("name")));
     357        List<Formula> formulas = new ArrayList<Formula>(formulaQuery.list(dc));
     358        formulaType = new ItemParameterType<Formula>(Formula.class, null, true, 1, formulas);
     359        formulaParameter = new PluginParameter<Formula>(
     360          "formula", "Formula", "Select the expression to use for calculating the intensities",
     361          formulaType);
     362        parameters.add(formulaParameter);
     363      }
     364      finally
     365      {
     366        if (dc != null) dc.close();
     367      }     
     368      configureJob = new RequestInformation
     369      (
     370        Request.COMMAND_CONFIGURE_JOB,
     371        "Intensity calculation options",
     372        "Select which raw bioassays to use and a formula for the calculations",
     373        parameters
     374      );
     375    }
     376    return configureJob;
     377  }
     378
    163379}
  • trunk/www/common/plugin/configure.jsp

    r2073 r2126  
    129129            }
    130130            // Finally we use the parameters default value
    131             if (values == null || values.size() == 0)
     131            if ((values == null || values.size() == 0) && pType.getDefaultValue() != null)
    132132            {
    133133              values = Collections.singletonList(pType.getDefaultValue());
     
    579579                  {
    580580                    %>
    581                     <select name="<%=inputName%>" multiple size="10"
     581                    <select name="<%=inputName%>" multiple size="10" style="width: 30em;"
    582582                      onchange="setEnumValues('<%=inputName%>')">
    583583                    <%
     
    587587                    String listValue = "";
    588588                    String listText = "";
     589                    String listTitle = "";
    589590                    if (value instanceof Date)
    590591                    {
     
    596597                      BasicItem item = (BasicItem)value;
    597598                      listValue = Integer.toString(item.getId());
    598                       listText = HTML.encodeTags(item instanceof Nameable ? ((Nameable)item).getName() : item.toString());
     599                      if (item instanceof Nameable)
     600                      {
     601                        Nameable nameable = (Nameable)item;
     602                        listText = HTML.encodeTags(nameable.getName());
     603                        listTitle = HTML.encodeTags(nameable.getDescription());
     604                      }
     605                      else
     606                      {
     607                        listText = item.toString();
     608                      }
    599609                    }
    600610                    else
     
    604614                    }
    605615                    %>
    606                     <option value="<%=listValue%>"><%=listText%>
     616                    <option value="<%=listValue%>" title="<%=listTitle%>"><%=listText%>
    607617                    <%
    608618                  }
     
    786796                  if (cc.getId() != 0)
    787797                  {
     798                    BasicItem item = parameterItemType.getById(dc, cc.getId());
     799                    String display = "";
     800                    if (item instanceof Nameable)
     801                    {
     802                      Nameable nameable = (Nameable)item;
     803                      display = nameable.getName();
     804                    }
     805                    else
     806                    {
     807                      display = item.toString();
     808                    }
    788809                    %>
    789                     <%=parameterItemType.getById(dc, cc.getId()).toString()%>
     810                    <b><%=HTML.encodeTags(param.getLabel())%></b><br>
     811                    <input class="text disabled" size="50" type="text" disabled value="<%=HTML.encodeTags(display)%>">
    790812                    <%
    791813                  }
  • trunk/www/views/experiments/bioassaysets/index.jsp

    r2125 r2126  
    8383final String viewPage = "view_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId;
    8484final String editPage = "edit_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId;
    85 final String newPage = "create_root_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId;
     85
     86final String newPage = "../../../common/plugin/index.jsp?ID="+ID
     87  +"&cmd=SelectPlugin&main_type=INTENSITY&item_type=BIOASSAYSET&context_type=LIST&title=Create+root+bioassay+set";
     88
    8689sc.getCurrentContext(Item.EXPERIMENT).setId(experimentId);
    8790
  • trunk/www/views/experiments/bioassaysets/list_bioassaysets.jsp

    r2102 r2126  
    166166    function newItem()
    167167    {
    168       Main.openPopup('index.jsp?ID=<%=ID%>&cmd=NewItem&experiment_id=<%=experimentId%>', 'NewBioAssaySet', 600, 400);
     168      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=NewItem&experiment_id=<%=experimentId%>', 'NewBioAssaySet', 740, 540);
    169169    }
    170170    function editItem(itemId)
     
    210210    function runPlugin(cmd)
    211211    {
    212       Table.submitToPopup(formId, cmd, 540, 460);
     212      Table.submitToPopup(formId, cmd, 740, 540);
    213213    }
    214214    function returnSelected()
     
    455455          title="New root bioassay set&hellip;"
    456456          tooltip="<%=createPermission ? "Create new event" : "You do not have permission to create events"%>"
     457          visible="<%=pluginCount.containsKey(Plugin.MainType.INTENSITY)%>"
    457458        />
    458459        <tbl:button
Note: See TracChangeset for help on using the changeset viewer.