Changeset 862
- Timestamp:
- Dec 2, 2008, 11:22:29 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.pluginutilities/trunk/src/net/sf/basedb/plugins/AbstractRunBinaryPlugin.java
r818 r862 4 4 Copyright (C) 2008 Jari Hakkinen 5 5 6 This file is part of the net.sf.basedb.pluginutilities package, a 7 utility package that simplifies creation of BASE plug-ins. The 8 package is available at http://baseplugins.thep.lu.se/ and BASE web 9 site is http://base.thep.lu.se 6 This file is part of the PluginUtilities 7 (net.sf.basedb.pluginutilities) package, a utility package that 8 simplifies creation of BASE plug-ins. The package is available at 9 http://baseplugins.thep.lu.se/ and BASE web site is 10 http://base.thep.lu.se 10 11 11 12 This is free software; you can redistribute it and/or modify it … … 28 29 import net.sf.basedb.core.BioAssaySet; 29 30 import net.sf.basedb.core.DbControl; 30 import net.sf.basedb.core.Experiment; 31 import net.sf.basedb.core.File; 32 import net.sf.basedb.core.Include; 33 import net.sf.basedb.core.InvalidDataException; 34 import net.sf.basedb.core.InvalidUseOfNullException; 35 import net.sf.basedb.core.Item; 36 import net.sf.basedb.core.ItemParameterType; 37 import net.sf.basedb.core.ItemQuery; 31 import net.sf.basedb.core.Experiment; // Jari, remove this? 32 import net.sf.basedb.core.InvalidUseOfNullException; // Jari, remove this? 38 33 import net.sf.basedb.core.Job; 39 import net.sf.basedb.core.Platform;40 34 import net.sf.basedb.core.PluginDefinition; 41 35 import net.sf.basedb.core.PluginParameter; 42 36 import net.sf.basedb.core.ProgressReporter; 43 import net.sf.basedb.core.RawBioAssay; 37 import net.sf.basedb.core.RawBioAssay; // Jari, remove this? 44 38 import net.sf.basedb.core.RequestInformation; 45 import net.sf.basedb.core.StringParameterType;46 39 47 40 import net.sf.basedb.core.plugin.About; 48 import net.sf.basedb.core.plugin.Abstract Plugin;41 import net.sf.basedb.core.plugin.AbstractAnalysisPlugin; 49 42 import net.sf.basedb.core.plugin.GuiContext; 50 43 import net.sf.basedb.core.plugin.InteractivePlugin; 44 import net.sf.basedb.core.plugin.Permissions; 51 45 import net.sf.basedb.core.plugin.Plugin; 52 46 import net.sf.basedb.core.plugin.Request; 53 47 import net.sf.basedb.core.plugin.Response; 54 48 55 import net.sf.basedb.core.query.Hql;56 import net.sf.basedb.core.query.Orders;57 58 49 import java.io.IOException; 59 50 60 51 import java.util.ArrayList; 61 52 import java.util.Arrays; 62 import java.util.Collections; 53 import java.util.Collection; 54 import java.util.HashSet; 63 55 import java.util.List; 64 56 import java.util.Set; 65 57 66 58 /** 67 This is an abstract base class useful for developing plugins. 68 <pre> 69 String : name; The name of the new bioassayset. 70 Experiment : experiment; The experiment we are working on. 71 List>RawBioAssay< : rawBioAssays; The raw bioassays to create bioassays for 72 (must be part of the experiment). 73 </pre> 74 75 @author Peter 59 This is an abstract base class useful for developing plugins that 60 call external binaries. 61 62 Two methods must be defined by the derived class runBinary and 63 storeResult 64 65 The derived class constructor should set the protected member 66 variables about, defaultChildName, permissions, and 67 plugin_maintype. 68 69 @author Jari Hakkinen 76 70 @version MAKESUBSTOFVERSIONNUMBER 71 @since BASE 2.9 77 72 @base.modified $Date$ 78 73 */ 79 74 80 75 abstract public class AbstractRunBinaryPlugin 81 extends Abstract Plugin76 extends AbstractAnalysisPlugin 82 77 implements InteractivePlugin 83 78 { … … 88 83 public void configure(GuiContext context, Request request, Response response) 89 84 { 90 try { 91 if (request.getCommand().equals(Request.COMMAND_CONFIGURE_JOB)) { 92 List<Throwable> errors = validateRequestParameters 93 (getConfigureJobParameters().getParameters(), request); 94 if (errors != null) { 85 try 86 { 87 if (request.getCommand().equals(Request.COMMAND_CONFIGURE_JOB)) 88 { 89 RequestInformation ri = getConfigureJobParameters(); 90 List<Throwable> errors = validateRequestParameters(ri.getParameters(), 91 request); 92 if (errors != null) 93 { 95 94 response.setError(errors.size() + 96 95 " invalid parameter(s) were found in the request", … … 98 97 return; 99 98 } 100 Experiment experiment = 101 (Experiment)request.getParameterValue("experiment"); 99 100 storeValue(job, request, ri.getParameter(SOURCE_BIOASSAYSET)); 101 storeValue(job, request, ri.getParameter(CHILD_NAME)); 102 storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION)); 103 104 Job.ExecutionTime execTime = Job.ExecutionTime.SHORT; 102 105 DbControl dc = sc.newDbControl(); 103 int numCels=0;104 106 try { 105 experiment = Experiment.getById(dc, experiment.getId()); 106 if (!experiment.getRawDataType().getPlatform(dc).equals(Platform.AFFYMETRIX)) 107 throw new BaseException("Raw data type '" + 108 experiment.getRawDataType() + 109 "' is not supoorted by this plug-in."); 110 List<RawBioAssay> rawBioAssays = 111 (List<RawBioAssay>)request.getParameterValues("rawBioAssays"); 112 for (RawBioAssay rba : rawBioAssays) 113 if (!experiment.isUsing(rba)) 114 throw new InvalidDataException 115 ("Raw bioassay '" + rba.getName() + 116 "' is not part of the experiment '" + experiment.getName()+"'"); 117 numCels=rawBioAssays.size(); 107 BioAssaySet source = getSourceBioAssaySet(dc); 108 int nofAssays = source.getBioAssays().list(dc).size(); 109 if (nofAssays>10 && nofAssays<30) 110 execTime = Job.ExecutionTime.MEDIUM; 111 else if (nofAssays>=30) 112 execTime = Job.ExecutionTime.LONG; 118 113 } 119 114 finally { … … 121 116 dc.close(); 122 117 } 123 storeValue(job, request, nameParameter);124 storeValue(job, request, experimentParameter);125 storeValues(job, request, rawBioAssaysParameter);126 Job.ExecutionTime execTime = Job.ExecutionTime.SHORT;127 if (numCels>10 && numCels<30)128 execTime = Job.ExecutionTime.MEDIUM;129 else if (numCels>=30)130 execTime = Job.ExecutionTime.LONG;131 118 response.setDone("Job configuration complete", execTime); 132 119 } … … 138 125 139 126 140 protected void download(File file) 141 throws IOException 142 { 143 java.io.FileOutputStream os = new java.io.FileOutputStream 144 (new java.io.File(getExecDirectory(),file.getName())); 145 file.download(os,0); 146 } 147 148 149 abstract public About getAbout(); 150 151 152 protected String getBinaryPath(String binary) 153 { 154 DbControl dc = sc.newDbControl(); 155 String jarpath=PluginDefinition.getByClassName(dc,binary).getJarPath(); 156 int pos = jarpath.length(); 157 while ((pos>0) && (jarpath.charAt(pos-1)!=java.io.File.separatorChar)) 158 --pos; 159 return jarpath.substring(0,pos); 160 } 161 162 163 private RequestInformation getConfigureJobParameters() 164 { 165 if (configureJob == null) { 166 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 167 168 experimentType = new ItemParameterType<Experiment>(Experiment.class, null, 169 true, 1, null); 170 experimentParameter = new PluginParameter<Experiment>( 171 "experiment", "Experiment", "The experiment we are working with", 172 experimentType); 173 parameters.add(experimentParameter); 174 parameters.add(nameParameter); 127 protected void execute(String[] cmd, ProgressReporter progress) 128 throws InterruptedException, IOException 129 { 130 percentDone+=1; 131 progress.display(percentDone,"Running " + about.getName()); 132 Process p = Runtime.getRuntime().exec(cmd, null, getExecDirectory()); 133 p.waitFor(); 134 int status=p.exitValue(); 135 if (status>0) 136 throw new IOException("Unexpected exit of " + about.getName() + 137 "WeNNI sub-process. Return value: " + status); 138 } 139 140 141 public About getAbout() 142 { 143 return about; 144 } 145 146 147 protected String getBinaryPath(Class cls, String binaryname) 148 { 149 if (BinaryPath == null) { 175 150 DbControl dc = sc.newDbControl(); 176 151 try { 177 int experimentId = sc.getCurrentContext(Item.EXPERIMENT).getId(); 178 Experiment experiment = Experiment.getById(dc, experimentId); 179 ItemQuery<RawBioAssay> rawBioAssayQuery = experiment.getRawBioAssays(); 180 rawBioAssayQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, 181 Include.IN_PROJECT); 182 rawBioAssayQuery.order(Orders.asc(Hql.property("name"))); 183 List<RawBioAssay> rawBioAssays = new ArrayList<RawBioAssay>( 184 rawBioAssayQuery.list(dc)); 185 rawBioAssaysType = new ItemParameterType<RawBioAssay>(RawBioAssay.class, 186 null, true, 0, 187 rawBioAssays); 188 rawBioAssaysParameter = new PluginParameter<RawBioAssay>( 189 "rawBioAssays", "Raw bioassays", 190 "Select the raw bioassays to use when creating the root bioassay set", 191 rawBioAssaysType); 192 parameters.add(rawBioAssaysParameter); 152 String jarpath= 153 PluginDefinition.getByClassName(dc, cls.getName()).getJarPath(); 154 int pos = jarpath.length(); 155 while ((pos>0) && (jarpath.charAt(pos-1)!=java.io.File.separatorChar)) 156 --pos; 157 BinaryPath=jarpath.substring(0, pos) + binaryname; 193 158 } 194 159 finally { … … 196 161 dc.close(); 197 162 } 163 } 164 return BinaryPath; 165 } 166 167 168 private RequestInformation getConfigureJobParameters() 169 { 170 if (configureJob == null) 171 { 172 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 173 174 // Source and child bioassay set parameters 175 parameters.add(getSourceBioAssaySetParameter(null, null)); 176 parameters.add(getChildNameParameter(null, null, defaultChildName)); 177 parameters.add(getChildDescriptionParameter(null, null, null)); 178 198 179 configureJob = new RequestInformation( 199 Request.COMMAND_CONFIGURE_JOB, "Intensity calculation options", 200 "Select which raw bioassays to use and a formula for the calculations", 201 parameters); 180 Request.COMMAND_CONFIGURE_JOB, about.getName() + " options", 181 "Select ...", parameters); 202 182 } 203 183 return configureJob; … … 217 197 218 198 219 public Set<GuiContext> getGuiContexts() { return guiContexts; } 220 221 222 public Plugin.MainType getMainType() { return Plugin.MainType.INTENSITY; } 223 224 225 public RequestInformation getRequestInformation(GuiContext context, 226 String command) 199 public Plugin.MainType getMainType() 200 { 201 return plugin_maintype; 202 } 203 204 205 public Collection<Permissions> getPermissions() 206 { 207 return permissions; 208 } 209 210 211 public RequestInformation 212 getRequestInformation(GuiContext context, String command) 227 213 throws BaseException 228 214 { … … 233 219 234 220 235 /* 236 public String getRMAExpressConsolePath() 237 { 238 if (RMAExpressConsolePath == null) { 239 DbControl dc = sc.newDbControl(); 240 String jarpath=PluginDefinition.getByClassName(dc, 241 "se.lu.thep.affymetrix.RMAExpress").getJarPath(); 242 int pos = jarpath.length(); 243 while ((pos>0) && (jarpath.charAt(pos-1)!=java.io.File.separatorChar)) 244 --pos; 245 RMAExpressConsolePath=jarpath.substring(0,pos); 246 // Hard coded file name and the binary must reside in the same 247 // directory as the plug-in jar. The idea behind this is that 248 // only the BASE administrator is allowed to change files in the 249 // BASE application direcotry structure. 250 RMAExpressConsolePath+="RMAExpressConsole"; 251 } 252 return RMAExpressConsolePath; 253 } 254 */ 255 256 public String isInContext(GuiContext context, Object item) 257 { 258 DbControl dc = sc.newDbControl(); 259 try { 260 Experiment e=Experiment.getById 261 (dc, sc.getCurrentContext(Item.EXPERIMENT).getId()); 262 if (!e.getRawDataType().getPlatform(dc).equals(Platform.AFFYMETRIX)) 263 return ("Raw data type '" + e.getRawDataType() + 264 "' is not supoorted by this plug-in."); 265 } 266 catch (Throwable e) { 267 } 268 finally { 269 if (dc != null) 270 dc.close(); 271 } 272 return null; 273 } 274 275 276 public boolean requiresConfiguration() { return false; } 221 public boolean requiresConfiguration() 222 { 223 return false; 224 } 277 225 278 226 … … 296 244 runBinary(sources,progress); 297 245 storeResult(dc,experiment,sources,name,progress); 298 dc.commit();246 // dc.commit(); 299 247 response.setDone("Plug-in ended successfully"); 300 248 } … … 324 272 325 273 326 public boolean supportsConfigurations() { return false; } 327 328 274 public boolean supportsConfigurations() 275 { 276 return false; 277 } 278 279 280 protected About about=null; 281 protected String defaultChildName = "New bioassayset"; 282 protected Set<Permissions> permissions = new HashSet<Permissions>(); 283 protected Plugin.MainType plugin_maintype=null; 284 285 private String BinaryPath=null; 329 286 private RequestInformation configureJob = null; 330 private RequestInformation configurePlugin = null;331 private ItemParameterType<Experiment> experimentType;332 /**333 This is the directory where the plug-in will generate its output.334 */335 287 private java.io.File execDirectory; 336 private PluginParameter<Experiment> experimentParameter;337 private static final Set<GuiContext> guiContexts = Collections.singleton338 (new GuiContext(Item.BIOASSAYSET,GuiContext.Type.LIST));339 private static final StringParameterType nameType =340 new StringParameterType(BioAssaySet.MAX_NAME_LENGTH, "New bioassayset",341 true);342 private static final PluginParameter<String> nameParameter =343 new PluginParameter<String>("name", "Bioassay set name",344 "The name of the root bioassayset", nameType);345 288 private int percentDone=0; 346 private ItemParameterType<RawBioAssay> rawBioAssaysType;347 private PluginParameter<RawBioAssay> rawBioAssaysParameter;348 289 }
Note: See TracChangeset
for help on using the changeset viewer.