Changeset 729
- Timestamp:
- Jul 21, 2008, 4:42:06 PM (15 years ago)
- Location:
- plugins/base2/net.sf.basedb.normalizations/trunk/src/net/sf/basedb/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.normalizations/trunk/src/net/sf/basedb/plugins/AbstractNormalizationPlugin.java
r728 r729 49 49 { 50 50 51 pr ivatestatic final String REFERENCE_GROUP = "reference_group";51 protected static final String REFERENCE_GROUP = "reference_group"; 52 52 53 53 private static final Set<Permissions> permissions = new HashSet<Permissions>(); … … 73 73 } 74 74 75 /** 76 Gets the plug-in parameter that holds the reference group. 77 @param label 78 @param description 79 @return PluginParameter for a BioAssay 80 */ 75 81 protected PluginParameter<BioAssay> getReferenceGroupParameter(String label, String description) 76 82 { … … 80 86 if (description == null) 81 87 { 82 description = "Select bio assays to be used as a reference group. " +88 description = "Select one or several bio assays to be used as a reference group. " + 83 89 "The reference group is used to calculate a virtual array. "; 84 90 } -
plugins/base2/net.sf.basedb.normalizations/trunk/src/net/sf/basedb/plugins/AverageNormalization.java
r728 r729 30 30 import net.sf.basedb.core.BioAssaySet; 31 31 import net.sf.basedb.core.DbControl; 32 import net.sf.basedb.core.DynamicQuery; 33 import net.sf.basedb.core.DynamicResultIterator; 34 import net.sf.basedb.core.DynamicSpotQuery; 35 import net.sf.basedb.core.Job; 32 36 import net.sf.basedb.core.PluginParameter; 33 37 import net.sf.basedb.core.ProgressReporter; 34 38 import net.sf.basedb.core.RequestInformation; 39 import net.sf.basedb.core.SpotBatcher; 40 import net.sf.basedb.core.Transformation; 41 import net.sf.basedb.core.Type; 42 import net.sf.basedb.core.VirtualColumn; 35 43 import net.sf.basedb.core.plugin.About; 36 44 import net.sf.basedb.core.plugin.AboutImpl; … … 39 47 import net.sf.basedb.core.plugin.Request; 40 48 import net.sf.basedb.core.plugin.Response; 49 import net.sf.basedb.core.query.Aggregations; 50 import net.sf.basedb.core.query.Dynamic; 51 import net.sf.basedb.core.query.Expression; 52 import net.sf.basedb.core.query.Expressions; 53 import net.sf.basedb.core.query.Orders; 54 import net.sf.basedb.core.query.Restriction; 55 import net.sf.basedb.core.query.Restrictions; 56 import net.sf.basedb.core.query.Selects; 57 import net.sf.basedb.core.query.SqlResult; 41 58 import net.sf.basedb.core.signal.SignalHandler; 42 59 import net.sf.basedb.core.signal.SignalReceivedException; … … 46 63 import net.sf.basedb.util.Values; 47 64 65 import java.sql.SQLException; 48 66 import java.util.ArrayList; 49 67 import java.util.Arrays; … … 72 90 private RequestInformation configureJob = null; 73 91 92 /** 93 Expressions used to get data 94 */ 95 private Expression ch1 = Dynamic.column(VirtualColumn.channel(1)); 96 97 /** 98 Create restriction: column = :bioAssayColumn 99 */ 100 Restriction bioAssayRestriction = Restrictions.eq( 101 Dynamic.column(VirtualColumn.COLUMN), 102 Expressions.parameter("bioAssayColumn") 103 ); 74 104 75 105 private final About about = new AboutImpl … … 124 154 // Child name, description and transformation 125 155 storeValue(job, request, ri.getParameter(CHILD_NAME)); 126 storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION)); 127 128 //TODO Store Average Normalization specific parameters 156 storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION)); 157 storeValue(job, request, ri.getParameter(REFERENCE_GROUP)); 158 //TODO More normalization specific parameters?? 159 160 response.setDone("Job configuration completed", Job.ExecutionTime.MEDIUM); 129 161 } 130 162 catch (SignalReceivedException signalException) … … 181 213 String childName = Values.getString((String)job.getValue(CHILD_NAME), source.getName()); 182 214 String childDescription = (String)job.getValue(CHILD_DESCRIPTION); 183 184 List<BioAssay> referenceGroup = getReferenceGroup(dc); 185 //TODO Implement things specific for the algortihm. 215 Job thisJob = getCurrentJob(dc); 216 217 List<BioAssay> refGroup = getReferenceGroup(dc); 218 219 //Normalize the data 220 BioAssaySet child = normalize(dc, source, thisJob, refGroup, progress); 221 222 //Finish up 223 child.setName(childName); 224 child.setDescription(childDescription); 225 dc.commit(); 226 int normalizedSpots = child.getNumSpots(); 227 if (progress != null) progress.display(100, normalizedSpots + " spots normalized\n"); 228 response.setDone(normalizedSpots + " spots normalized, " + (source.getNumSpots() - normalizedSpots) + " spots removed"); 186 229 } 187 230 catch (Throwable ex) … … 198 241 --------------------------------------------------------- 199 242 */ 243 244 public BioAssaySet normalize(DbControl dc, BioAssaySet source, Job job, List<BioAssay> refGroup, ProgressReporter progress) 245 { 246 if (progress != null) progress.display(0, "Preparing normalization..."); 247 248 // Create transformation and prepare for the normalization 249 Transformation t = source.newTransformation(job); 250 t.setName(about.getName()); 251 dc.saveItem(t); 252 253 BioAssaySet child = t.newProduct(null, "new", true); 254 dc.saveItem(child); 255 256 SpotBatcher spotBatcher = child.getSpotBatcher(); 257 258 float scaleFactor = getScaleFactor(dc, refGroup, source, progress); 259 // Get the number of spots to be normalized 260 DynamicSpotQuery query = source.getSpotData(); 261 long totalNumSpots = query.count(dc); 262 query.reset(); 263 long normalizedSpots = 0; 264 265 // Restrictions for the ch1's value 266 query.select(Dynamic.select(VirtualColumn.POSITION)); 267 query.select(Selects.expression(ch1, "ch1")); 268 query.restrict(bioAssayRestriction); 269 270 if (progress != null) 271 progress.display((int)(normalizedSpots / totalNumSpots * 100), 272 normalizedSpots + " spots normalized"); 273 274 // Normalize data 275 List<BioAssay> assays = source.getBioAssays().list(dc); 276 try 277 { 278 for (BioAssay ba : assays) 279 { 280 checkInterrupted(); 281 282 short bioAssayColumn = ba.getDataCubeColumnNo(); 283 query.setParameter("bioAssayColumn", (int)bioAssayColumn, Type.INT); 284 DynamicResultIterator it = query.iterate(dc); 285 int positionIndex = it.getIndex(VirtualColumn.POSITION.getName()); 286 int ch1Index = it.getIndex("ch1"); 287 288 while (it.hasNext()) 289 { 290 SqlResult r = it.next(); 291 float intensity = r.getFloat(ch1Index); 292 int position = r.getInt(positionIndex); 293 294 spotBatcher.insert(bioAssayColumn, position, (intensity * scaleFactor)); 295 ++normalizedSpots; 296 } 297 it.close(); 298 spotBatcher.flush(); 299 if (progress != null) 300 progress.display((int)((normalizedSpots * 100L) / totalNumSpots), 301 normalizedSpots + " spots normalized"); 302 } 303 } 304 catch (SQLException ex) 305 { 306 throw new BaseException(ex); 307 } 308 return child; 309 } 310 200 311 201 312 private RequestInformation getConfiguredJobParameters() … … 217 328 //Reference group 218 329 parameters.add(getReferenceGroupParameter(null, null)); 219 //TODO Configure Average Normalization specific parameters.330 //TODO More normalization specific parameters??? 220 331 } 221 332 } … … 227 338 return configureJob; 228 339 } 340 341 private float getScaleFactor(DbControl dc, List<BioAssay> refGroup, BioAssaySet source, ProgressReporter progress) 342 { 343 float averageVirtualArray; 344 float averageWholeGroup; 345 346 DynamicSpotQuery query = source.getSpotData(); 347 query.selectPermanent(Selects.expression(Aggregations.sum(ch1), "sumCh1")); 348 query.restrictPermanent(bioAssayRestriction); 349 350 //Get average intensity for the bio assays in reference group. 351 float totSum = 0; 352 long numOfSpots = 0; 353 try 354 { 355 for (BioAssay ba : refGroup) 356 { 357 numOfSpots = numOfSpots + ba.getNumSpots(); 358 short bioAssayColumn = ba.getDataCubeColumnNo(); 359 query.setParameter("bioAssayColumn", (int)bioAssayColumn, Type.INT); 360 DynamicResultIterator it = query.iterate(dc); 361 int sumCh1Index = it.getIndex("sumCh1"); 362 SqlResult result = it.next(); 363 totSum = totSum + result.getFloat(sumCh1Index); 364 it.close(); 365 } 366 } 367 catch (SQLException e) 368 { 369 throw new BaseException(e); 370 } 371 averageVirtualArray = totSum / numOfSpots; 372 query.reset(); 373 374 // Get average intensity for the whole group 375 List<BioAssay> assays = source.getBioAssays().list(dc); 376 totSum = 0; 377 numOfSpots = 0; 378 try 379 { 380 for (BioAssay ba : assays) 381 { 382 numOfSpots = numOfSpots + ba.getNumSpots(); 383 short bioAssayColumn = ba.getDataCubeColumnNo(); 384 query.setParameter("bioAssayColumn", (int)bioAssayColumn, Type.INT); 385 DynamicResultIterator it = query.iterate(dc); 386 int sumCh1Index = it.getIndex("sumCh1"); 387 SqlResult result = it.next(); 388 totSum = totSum + result.getFloat(sumCh1Index); 389 it.close(); 390 } 391 } 392 catch (SQLException e) 393 { 394 throw new BaseException(e); 395 } 396 averageWholeGroup = totSum / numOfSpots; 397 398 399 float scaleFactor = averageVirtualArray / averageWholeGroup; 400 401 return scaleFactor; 402 } 229 403 }
Note: See TracChangeset
for help on using the changeset viewer.