Changeset 2126
- Timestamp:
- Mar 29, 2006, 2:56:43 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/plugins/IntensityCalculatorPlugin.java
r1972 r2126 27 27 import net.sf.basedb.core.ProgressReporter; 28 28 29 import net.sf.basedb.core.BaseException; 30 import net.sf.basedb.core.Formula; 31 import net.sf.basedb.core.Include; 32 import net.sf.basedb.core.InvalidDataException; 33 import net.sf.basedb.core.Item; 34 import net.sf.basedb.core.ItemParameterType; 35 import net.sf.basedb.core.ItemQuery; 36 import net.sf.basedb.core.PluginParameter; 37 import net.sf.basedb.core.RequestInformation; 38 import net.sf.basedb.core.StringParameterType; 29 39 import net.sf.basedb.core.Transformation; 30 40 import net.sf.basedb.core.BioAssaySet; … … 37 47 import net.sf.basedb.core.plugin.AboutImpl; 38 48 import net.sf.basedb.core.plugin.AbstractPlugin; 49 import net.sf.basedb.core.plugin.GuiContext; 39 50 import net.sf.basedb.core.plugin.Plugin; 51 import net.sf.basedb.core.plugin.InteractivePlugin; 40 52 import net.sf.basedb.core.plugin.Request; 41 53 import net.sf.basedb.core.plugin.Response; 42 import net.sf.basedb.core.IntensityFormula; 54 import net.sf.basedb.core.query.Hql; 55 import net.sf.basedb.core.query.Orders; 43 56 import net.sf.basedb.util.IntensityCalculator; 44 57 import net.sf.basedb.util.IntensityCalculatorUtil; 45 58 59 import java.util.ArrayList; 60 import java.util.Arrays; 61 import java.util.Collections; 46 62 import java.util.List; 63 import java.util.Set; 47 64 48 65 /** 49 This plugin provides methods to calculate the intensity for a root bioassayset using different formulas.50 It needs the following parameters66 This plugin provides methods to calculate the intensity for a root bioassayset 67 using different formulas. It needs the following parameters: 51 68 52 69 <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>RawBioAssay< : 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 57 75 </pre> 58 76 59 @author Gregory 77 @author Gregory, Nicklas 78 @version 2.0 79 @base.modified $Date$ 60 80 */ 61 81 public class IntensityCalculatorPlugin 62 82 extends AbstractPlugin 63 implements Plugin83 implements InteractivePlugin 64 84 { 65 85 … … 70 90 new AboutImpl 71 91 ( 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", 75 97 "2006, Department of Theoretical Physics, Lund University", 76 98 null, … … 79 101 ); 80 102 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 82 130 /** 83 131 Constructor should be empty. … … 86 134 {} 87 135 88 89 /* 90 Plugin interface implementation 91 ------------------------------- 136 /* 137 From the Plugin interface 138 ------------------------------------------- 92 139 */ 93 140 public About getAbout() … … 95 142 return about; 96 143 } 97 98 99 144 /** 100 145 Returns the main plugin type this plugin belongs to. … … 106 151 } 107 152 108 109 /**110 @param request111 @param response112 @param progress113 */114 153 @SuppressWarnings("unchecked") 115 154 public void run(Request request, Response response, ProgressReporter progress) … … 118 157 try 119 158 { 120 / * name parameter */159 // name parameter 121 160 String name = (String)job.getValue("name"); 122 161 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); 152 173 } 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."); 156 252 } 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 163 379 } -
trunk/www/common/plugin/configure.jsp
r2073 r2126 129 129 } 130 130 // Finally we use the parameters default value 131 if ( values == null || values.size() == 0)131 if ((values == null || values.size() == 0) && pType.getDefaultValue() != null) 132 132 { 133 133 values = Collections.singletonList(pType.getDefaultValue()); … … 579 579 { 580 580 %> 581 <select name="<%=inputName%>" multiple size="10" 581 <select name="<%=inputName%>" multiple size="10" style="width: 30em;" 582 582 onchange="setEnumValues('<%=inputName%>')"> 583 583 <% … … 587 587 String listValue = ""; 588 588 String listText = ""; 589 String listTitle = ""; 589 590 if (value instanceof Date) 590 591 { … … 596 597 BasicItem item = (BasicItem)value; 597 598 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 } 599 609 } 600 610 else … … 604 614 } 605 615 %> 606 <option value="<%=listValue%>" ><%=listText%>616 <option value="<%=listValue%>" title="<%=listTitle%>"><%=listText%> 607 617 <% 608 618 } … … 786 796 if (cc.getId() != 0) 787 797 { 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 } 788 809 %> 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)%>"> 790 812 <% 791 813 } -
trunk/www/views/experiments/bioassaysets/index.jsp
r2125 r2126 83 83 final String viewPage = "view_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId; 84 84 final String editPage = "edit_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId; 85 final String newPage = "create_root_bioassayset.jsp?ID="+ID+"&experiment_id="+experimentId; 85 86 final 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 86 89 sc.getCurrentContext(Item.EXPERIMENT).setId(experimentId); 87 90 -
trunk/www/views/experiments/bioassaysets/list_bioassaysets.jsp
r2102 r2126 166 166 function newItem() 167 167 { 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); 169 169 } 170 170 function editItem(itemId) … … 210 210 function runPlugin(cmd) 211 211 { 212 Table.submitToPopup(formId, cmd, 540, 460);212 Table.submitToPopup(formId, cmd, 740, 540); 213 213 } 214 214 function returnSelected() … … 455 455 title="New root bioassay set…" 456 456 tooltip="<%=createPermission ? "Create new event" : "You do not have permission to create events"%>" 457 visible="<%=pluginCount.containsKey(Plugin.MainType.INTENSITY)%>" 457 458 /> 458 459 <tbl:button
Note: See TracChangeset
for help on using the changeset viewer.