Changeset 4068
- Timestamp:
- Dec 17, 2007, 9:02:44 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/LowessNormalization.java
r4062 r4068 33 33 import net.sf.basedb.core.DynamicSpotQuery; 34 34 import net.sf.basedb.core.FloatParameterType; 35 import net.sf.basedb.core.Include; 35 36 import net.sf.basedb.core.IntegerParameterType; 36 37 import net.sf.basedb.core.Item; 38 import net.sf.basedb.core.ItemParameterType; 39 import net.sf.basedb.core.ItemQuery; 37 40 import net.sf.basedb.core.Job; 38 41 import net.sf.basedb.core.Permission; 39 42 import net.sf.basedb.core.PluginParameter; 40 43 import net.sf.basedb.core.ProgressReporter; 44 import net.sf.basedb.core.ReporterList; 41 45 import net.sf.basedb.core.RequestInformation; 42 46 import net.sf.basedb.core.SpotBatcher; … … 55 59 import net.sf.basedb.core.query.Expression; 56 60 import net.sf.basedb.core.query.Expressions; 61 import net.sf.basedb.core.query.Hql; 62 import net.sf.basedb.core.query.JoinType; 57 63 import net.sf.basedb.core.query.Orders; 58 64 import net.sf.basedb.core.query.Restriction; … … 60 66 import net.sf.basedb.core.query.Selects; 61 67 import net.sf.basedb.core.query.SqlResult; 68 import net.sf.basedb.core.query.WhenStatement; 62 69 import net.sf.basedb.util.Values; 63 70 … … 103 110 "method addressing single and multiple slide systematic " + 104 111 "variation. Nucleic Acids Res 2002, 30:e15.", 105 "2. 5",112 "2.6", 106 113 "2006, Base 2 development team", 107 114 null, … … 184 191 permissions.add(new Permissions(Item.EXPERIMENT, null, EnumSet.of(Permission.USE))); 185 192 permissions.add(new Permissions(Item.JOB, null, EnumSet.of(Permission.READ))); 193 permissions.add(new Permissions(Item.REPORTERLIST, null, EnumSet.of(Permission.READ))); 186 194 } 187 195 return permissions; … … 204 212 float fitFraction = (Float) job.getValue(fitFractionParameter.getName()); 205 213 int iterations = (Integer) job.getValue(iterParameter.getName()); 214 ReporterList excludeReporters = (ReporterList)job.getValue("excludeReporters"); 206 215 Job thisJob = getCurrentJob(dc); 207 216 208 BioAssaySet child = normalize(dc, source, thisJob, fitFraction, delta, iterations, blockGroupSize, progress); 217 BioAssaySet child = normalize(dc, source, thisJob, fitFraction, delta, iterations, 218 blockGroupSize, excludeReporters, progress); 209 219 child.setName(childName); 210 220 child.setDescription(childDescription); … … 291 301 storeValue(job, request, iterParameter); 292 302 storeValue(job, request, blockGroupParameter); 303 storeValue(job, request, ri.getParameter("excludeReporters")); 293 304 response.setDone("Job configuration complete", Job.ExecutionTime.SHORT); 294 305 } … … 301 312 // ------------------------------------------- 302 313 314 /** 315 Normalise the source bioassay set using LOWESS normalization. 316 All reporters are included. 317 @since 2.5 318 @see #normalize(DbControl, BioAssaySet, Job, float, float, int, int, ReporterList, ProgressReporter) 319 */ 320 public BioAssaySet normalize(DbControl dc, BioAssaySet source, Job job, float fitFraction, float delta, int iterations, int blockGroupSize, ProgressReporter progress) 321 { 322 return normalize(dc, source, job, fitFraction, delta, iterations, blockGroupSize, null, progress); 323 } 324 325 303 326 /** 304 327 Normalise the source bioassay set using LOWESS normalization. … … 311 334 @param blockGroupSize The number of blocks to group and normalise at the same time, 312 335 if <=0, all blocks on a bioassay are grouped to a single dataset 336 @param excludeReporters A reporter list containing reporters that should not be 337 used in when normalizing, or null to use all spots 313 338 @param progress Progress reporter used by the caller to keep track of the progress. Null is allowed 314 339 @return The normalized bioassayset 315 340 @since 2.5 316 341 */ 317 public BioAssaySet normalize(DbControl dc, BioAssaySet source, Job job, float fitFraction, float delta, int iterations, int blockGroupSize, ProgressReporter progress)342 public BioAssaySet normalize(DbControl dc, BioAssaySet source, Job job, float fitFraction, float delta, int iterations, int blockGroupSize, ReporterList excludeReporters, ProgressReporter progress) 318 343 { 319 344 if (progress != null) progress.display(0, "Preparing to normalize..."); … … 355 380 if (progress != null) progress.display((int)(normalizedSpots / numSpots * 100), normalizedSpots + " spots normalized"); 356 381 357 // Create query to retrieve spot data: COLUMN, POSITION, ch1, ch2, block 382 // If some reporters should be excluded, create an expression that: 383 // = 0 if spot's reporter is not present in list, = 1 if it is 384 Expression isPresent = Expressions.integer(0); 385 if (excludeReporters != null) 386 { 387 query.joinReporterList(excludeReporters, JoinType.LEFT); 388 isPresent = Expressions.caseWhen(isPresent, 389 new WhenStatement(Dynamic.isPartOf(excludeReporters), Expressions.integer(1))); 390 } 391 392 // Create query to retrieve spot data: COLUMN, POSITION, ch1, ch2, block, present 358 393 // We use a parameter to restrict the query to return data for one bioassay at a time 394 // The 'exclude' value is 0 to not exclude and 1 to exclude a spot 359 395 query.select(Dynamic.select(VirtualColumn.POSITION)); 360 396 query.select(Selects.expression(ch1, "ch1")); 361 397 query.select(Selects.expression(ch2, "ch2")); 362 398 query.select(Selects.expression(block, "block")); 399 query.select(Selects.expression(isPresent, "present")); 363 400 query.restrict(bioAssayRestriction); 364 401 query.order(Orders.asc(block)); … … 384 421 int ch2Index = it.getIndex("ch2"); 385 422 int blockIndex = it.getIndex("block"); 423 int presentIndex = it.getIndex("present"); 386 424 387 425 // Copy bioassay data to SpotData objects … … 390 428 SqlResult r = it.next(); 391 429 SpotData spot = new SpotData(r.getInt(positionIndex), 392 r.getFloat(ch1Index), r.getFloat(ch2Index), r.getInt(blockIndex)); 430 r.getFloat(ch1Index), r.getFloat(ch2Index), r.getInt(blockIndex), 431 r.getInt(presentIndex) == 1); 393 432 data.add(spot); 394 433 } … … 471 510 parameters.add(iterParameter); 472 511 parameters.add(blockGroupParameter); 512 PluginParameter<ReporterList> excludeReporters = 513 getExcludeReportersParameters(dc); 514 if (excludeReporters != null) parameters.add(excludeReporters); 473 515 474 516 configureJob = new RequestInformation … … 488 530 } 489 531 532 private PluginParameter<ReporterList> getExcludeReportersParameters(DbControl dc) 533 { 534 // Load reporter types and initialise the reporterTypeParameter 535 ItemQuery<ReporterList> query = ReporterList.getQuery(); 536 query.order(Orders.asc(Hql.property("name"))); 537 query.include(Include.MINE, Include.SHARED, Include.IN_PROJECT); 538 List<ReporterList> reporterLists = new ArrayList<ReporterList>(query.list(dc)); 539 if (reporterLists.size() == 0) return null; 540 541 ItemParameterType<ReporterList> reporterListType = 542 new ItemParameterType<ReporterList>(ReporterList.class, null, false, 1, reporterLists); 543 PluginParameter<ReporterList> reporterListParameter = new PluginParameter<ReporterList>( 544 "excludeReporters", 545 "Exclude reporters", 546 "Spots with reporters in the selected list will not be used in the lowess calculations. " + 547 "If no list is selected all spots are used.", 548 reporterListType); 549 return reporterListParameter; 550 } 551 490 552 private static List<Double> lowess(List<SpotData> data, double f, int iter, double delta) 491 553 { … … 591 653 for (int j = 0; j < data.size(); j++) 592 654 { 593 double localW = w.get(j); 594 double localA = data.get(j).A; 595 double localM = data.get(j).M; 596 sumA += localA * localW; 597 sumM += localM * localW; 598 sumAA += localA * localA * localW; 599 sumAM += localA * localM * localW; 600 sumW += localW; 655 SpotData spot = data.get(j); 656 if (!spot.exclude) 657 { 658 double localW = w.get(j); 659 double localA = spot.A; 660 double localM = spot.M; 661 sumA += localA * localW; 662 sumM += localM * localW; 663 sumAA += localA * localA * localW; 664 sumAM += localA * localM * localW; 665 sumW += localW; 666 } 601 667 } 602 668 if (sumW <= 0) … … 634 700 for (int i = 0; i < data.size(); i++) 635 701 { 636 double A2 = data.get(i).A; 637 double distance = Math.abs(A1 - A2) * invRadius; 638 w.add((distance < 1 ? Math.pow(1D - Math.pow(Math.abs(distance), 3), 3) : 0) * wFit.get(i)); 702 if (!data.get(i).exclude) 703 { 704 double A2 = data.get(i).A; 705 double distance = Math.abs(A1 - A2) * invRadius; 706 w.add((distance < 1 ? Math.pow(1D - Math.pow(Math.abs(distance), 3), 3) : 0) * wFit.get(i)); 707 } 708 else 709 { 710 w.add(0.0); 711 } 639 712 } 640 713 return w; … … 650 723 final double A; 651 724 final int block; 725 final boolean exclude; 652 726 static final double INV_LN2 = 1 / Math.log(2); 653 727 654 public SpotData(int position, float ch1, float ch2, int block )728 public SpotData(int position, float ch1, float ch2, int block, boolean exclude) 655 729 { 656 730 this.position = position; … … 658 732 this.ch2 = ch2; 659 733 this.block = block; 734 this.exclude = exclude; 660 735 this.M = Math.log(ch1 / ch2) * INV_LN2; 661 736 this.A = Math.log10(Math.sqrt(ch1 * ch2));
Note: See TracChangeset
for help on using the changeset viewer.