Changeset 1143 for plugins/base2
- Timestamp:
- Jul 28, 2009, 3:48:40 PM (14 years ago)
- Location:
- plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/AbstractNormalizationPlugin.java
r975 r1143 32 32 import net.sf.basedb.core.Item; 33 33 import net.sf.basedb.core.Permission; 34 import net.sf.basedb.core.PluginParameter; 34 35 import net.sf.basedb.core.Type; 35 36 import net.sf.basedb.core.VirtualColumn; … … 61 62 extends AbstractAnalysisPlugin 62 63 { 64 protected static final String arithmeticOption = "Arithmetic mean"; 65 protected static final String geometricOption = "Geometric mean"; 63 66 64 67 private static final Set<Permissions> permissions = new HashSet<Permissions>(); 65 68 69 protected PluginParameter<String> averageMethodParameter = new PluginParameter<String> 70 ( 71 "averageMethod", 72 "Average calculation method", 73 "Select which method to use when calculating the averages.\n" + 74 "Geometric mean is default for none-logged values and arithmetic " + 75 "is default for logged values.", 76 null 77 ); 66 78 67 79 /** … … 210 222 return data; 211 223 } 224 225 public class AverageCalculator 226 { 227 private double sum; 228 private int dataSize; 229 private final String avgMethod; 230 231 public AverageCalculator(String avgMethod) 232 { 233 this.avgMethod = avgMethod; 234 sum = 0; 235 dataSize = 0; 236 } 237 238 public void addNumber(float number) 239 { 240 if (arithmeticOption.equals(avgMethod)) 241 { 242 sum = sum + number; 243 } 244 else if (geometricOption.equals(avgMethod)) 245 { 246 sum = sum + Math.log(number); 247 } 248 dataSize++; 249 } 250 251 public Float getAverage() 252 { 253 Float average = null; 254 if (dataSize > 0) 255 { 256 if (arithmeticOption.equals(avgMethod)) 257 { 258 average = (float)sum/dataSize; 259 } 260 else if (geometricOption.equals(avgMethod)) 261 { 262 average = (float)Math.exp(sum/dataSize); 263 } 264 } 265 return average; 266 } 267 } 212 268 } -
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/AverageNormalization.java
r1060 r1143 32 32 import net.sf.basedb.core.DynamicSpotQuery; 33 33 import net.sf.basedb.core.FloatParameterType; 34 import net.sf.basedb.core.IntensityTransform;35 34 import net.sf.basedb.core.InvalidUseOfNullException; 36 35 import net.sf.basedb.core.Job; … … 89 88 { 90 89 private static final String yesOption = "yes"; 91 private static final String noOption = "no"; 92 private static final String geometricOption = "geometric"; 93 private static final String arithmeticOption = "arithmetic"; 90 private static final String noOption = "no"; 94 91 95 92 /* … … 127 124 new FloatParameterType(null, null, 100f, false) 128 125 ); 129 130 /* 131 Define which average method to use when calculating. 132 */ 133 private PluginParameter<String> averageMethodParameter = new PluginParameter<String> 134 ( 135 "averageMethod", 136 "Average calculation method", 137 "Select which method to use when calculating the averages.\n" + 138 "Geometric mean is default for none-logged values and arithmetic " + 139 "is default for logged values.", 140 null 141 ); 142 126 143 127 /* 144 128 Information about this plug-in … … 320 304 if (useGlobalAvgInt) 321 305 { 322 refValue = getGlobalGeometricMeanIntensity(dc, source, minIntensity );306 refValue = getGlobalGeometricMeanIntensity(dc, source, minIntensity, (String)job.getValue("averageMethod")); 323 307 } 324 308 else … … 389 373 parameters.add(getChildNameParameter(null, null, bas.getName())); 390 374 parameters.add(getChildDescriptionParameter(null, null, null)); 391 392 // Average normalization options 375 // Average normalization options 393 376 StringParameterType spt = new StringParameterType 394 377 ( 395 378 null, 396 bas.getIntensityTransform(). equals(IntensityTransform.NONE) ? geometricOption : arithmeticOption,379 bas.getIntensityTransform().getAverageMethod().toString(), 397 380 true, 1, 0, 0, 398 Arrays.asList( new String[] {geometricOption, arithmeticOption})381 Arrays.asList(arithmeticOption, geometricOption) 399 382 ); 400 383 averageMethodParameter = new PluginParameter<String> … … 437 420 long numSpots; 438 421 long normalizedSpots = 0; 439 440 boolean useGeometricMean = geometricOption.equals(job.getParameterValue("averageMethod"));441 422 442 423 // Create Transformation … … 515 496 if (dataSize == 0) continue; 516 497 517 // Calculatethe average intensity for the current assay.518 double sum = 0;519 float assayAverage;520 if (useGeometricMean)498 // Get the average intensity for the current assay. 499 String configuredAverageMethod = (String)job.getParameterValue("averageMethod"); 500 AverageCalculator avgCalc = new AverageCalculator(configuredAverageMethod); 501 for (Normalizable d : data) 521 502 { 522 for (Normalizable d : data) 523 { 524 sum = sum + Math.log(d.getNormalizableData()); 525 } 526 assayAverage = (float)Math.exp(sum/dataSize); 527 } 528 else 529 { 530 for (Normalizable d : data) 531 { 532 sum = sum + d.getNormalizableData(); 533 } 534 assayAverage = (float)sum/dataSize; 535 } 536 scaleFactor = refValue / assayAverage; 503 avgCalc.addNumber(d.getNormalizableData()); 504 } 505 Float assayAverage = avgCalc.getAverage(); 506 scaleFactor = assayAverage != null ? refValue / assayAverage : scaleFactor; 537 507 538 508 // Normalize data and put it into the child-bioassay set … … 560 530 either 1-channel or 2-channel data. 561 531 */ 562 private float getGlobalGeometricMeanIntensity(DbControl dc, BioAssaySet source, 563 float minIntensity) 532 private float getGlobalGeometricMeanIntensity(DbControl dc, BioAssaySet source, float minIntensity, String averageMethod) 564 533 throws SQLException, BaseException 565 534 { … … 574 543 { 575 544 case 1: 576 ratio = Expressions.ln(ch1);545 ratio = ch1; 577 546 break; 578 547 case 2: … … 582 551 throw new BaseException(noOfChannels + " channel-data is not supported by this plugin"); 583 552 } 584 mean = Aggregations.mean(ratio); 553 554 555 if (arithmeticOption.equals(averageMethod)) mean = Aggregations.mean(ratio); 556 else if (geometricOption.equals(averageMethod)) mean = Aggregations.geometricMean(ratio); 557 585 558 query.select(Selects.expression(mean, "mean")); 586 559 query.restrict(intensityRestriction); -
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/QuantileNormalization.java
r1051 r1143 34 34 import net.sf.basedb.core.RequestInformation; 35 35 import net.sf.basedb.core.SpotBatcher; 36 import net.sf.basedb.core.StringParameterType; 36 37 import net.sf.basedb.core.Transformation; 37 38 import net.sf.basedb.core.VirtualColumn; … … 223 224 storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION)); 224 225 226 storeValue(job, request, averageMethodParameter); 227 225 228 response.setDone("Job configuration completed", Job.ExecutionTime.MEDIUM); 226 229 } … … 273 276 parameters.add(getSourceBioAssaySetParameter(null, null)); 274 277 parameters.add(getChildNameParameter(null, null, bas.getName())); 275 parameters.add(getChildDescriptionParameter(null, null, null)); 278 parameters.add(getChildDescriptionParameter(null, null, null)); 279 280 // Average normalization options 281 StringParameterType spt = new StringParameterType 282 ( 283 null, 284 bas.getIntensityTransform().getAverageMethod().toString(), 285 true, 1, 0, 0, 286 Arrays.asList(arithmeticOption, geometricOption) 287 ); 288 averageMethodParameter = new PluginParameter<String> 289 ( 290 averageMethodParameter.getName(), 291 averageMethodParameter.getLabel(), 292 averageMethodParameter.getDescription(), 293 spt 294 ); 295 parameters.add(averageMethodParameter); 276 296 277 297 String description = "Set minimum intensity for each channel and properties for the child"; … … 300 320 Job job, ProgressReporter progress) 301 321 { 322 String averageMethod = (String)(job.getParameterValue("averageMethod")); 323 302 324 int noOfChannels = source.getRawDataType().getChannels(); 303 325 long normalizedSpots = 0; … … 320 342 normalizedSpots + " spots normalized"); 321 343 322 double[] rowSummaries = null;344 AverageCalculator[] rowCalculators = null; 323 345 324 346 List<BioAssay> assays = source.getBioAssays().list(dc); 325 347 Map<Integer, File> fileMap = new HashMap<Integer, File>(); 348 String configuredAverageMethod = (String)job.getParameterValue(averageMethodParameter.getName()); 326 349 int spotsPerAssay = -1; 327 350 … … 342 365 343 366 // Write spot data to file and calculate row summaries 344 if (row Summaries == null) rowSummaries = new double[data.size()];367 if (rowCalculators == null) rowCalculators = new AverageCalculator[data.size()]; 345 368 FileWriter fw = null; 346 369 try … … 351 374 for (int i=0; i<data.size(); i++) 352 375 { 353 AbstractSpotData spot = data.get(i); 354 rowSummaries[i] += spot.getNormalizableData(); 376 AbstractSpotData spot = data.get(i); 377 if (rowCalculators[i] == null) rowCalculators[i] = new AverageCalculator(configuredAverageMethod); 378 rowCalculators[i].addNumber(spot.getNormalizableData()); 355 379 356 380 if (i > 0)fw.write("\n"); … … 378 402 } 379 403 } 380 381 // Calculate the row averages. 382 float[] rowAverages = new float[rowSummaries.length]; 383 for (int i=0; i<rowSummaries.length; i++) 384 { 385 rowAverages[i] = (float)(rowSummaries[i]/assays.size()); 386 } 387 404 388 405 try 389 406 { … … 418 435 String[] lineInfo = line.split("\t"); 419 436 AbstractSpotData spot = getSpotDataFromString(lineInfo); 420 spot.setNormalizableData(row Averages[rowIndex]);437 spot.setNormalizableData(rowCalculators[rowIndex].getAverage()); 421 438 batcher.insert(columnNo, spot.getPosition(), spot.getChannelData()); 422 439 normalizedSpots++;
Note: See TracChangeset
for help on using the changeset viewer.