Changeset 975
- Timestamp:
- Feb 26, 2009, 12:13:51 PM (15 years ago)
- Location:
- plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/AbstractNormalizationPlugin.java
r950 r975 165 165 // Load spot data for this bioassay 166 166 short bioassayColumn = assay.getDataCubeColumnNo(); 167 if (!query.getParameterNames().contains("bioAssayColumn")) 168 { 169 // Create restriction: column = :bioAssayColumn 170 Restriction bioAssayRestriction = Restrictions.eq( 171 Dynamic.column(VirtualColumn.COLUMN), 172 Expressions.parameter("bioAssayColumn") 173 ); 174 query.restrict(bioAssayRestriction); 175 } 167 176 query.setParameter("bioAssayColumn", (int)bioassayColumn, Type.INT); 168 177 DynamicResultIterator it = query.iterate(dc); -
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/RankInvariantNormalization.java
r967 r975 39 39 import net.sf.basedb.core.Transformation; 40 40 import net.sf.basedb.core.Type; 41 import net.sf.basedb.core.VirtualColumn; 41 42 import net.sf.basedb.core.plugin.About; 42 43 import net.sf.basedb.core.plugin.AboutImpl; … … 45 46 import net.sf.basedb.core.plugin.Request; 46 47 import net.sf.basedb.core.plugin.Response; 48 import net.sf.basedb.core.query.Dynamic; 49 import net.sf.basedb.core.query.Expressions; 50 import net.sf.basedb.core.query.Restriction; 51 import net.sf.basedb.core.query.Restrictions; 47 52 import net.sf.basedb.core.query.SqlResult; 48 53 import net.sf.basedb.core.signal.SignalHandler; … … 130 135 storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION)); 131 136 132 storeValue (job, request, ri.getParameter("masterSample"));137 storeValues(job, request, ri.getParameter("masterSample")); 133 138 storeValue(job, request, ri.getParameter("numIterations")); 134 139 … … 286 291 ); 287 292 parameters.add(masterSampleParameter); 288 // TODO Add parameter to set the number of iterations to get the least square fit? 289 290 //TODO More parameters? 293 291 294 String description = "TODO"; 292 295 … … 334 337 query.reset(); 335 338 339 340 // Create restriction: column = :bioAssayColumn 341 Restriction bioAssayRestriction = Restrictions.eq( 342 Dynamic.column(VirtualColumn.COLUMN), 343 Expressions.parameter("bioAssayColumn") 344 ); 345 query.restrictPermanent(bioAssayRestriction); 346 336 347 // Get spot data for the master sample 337 348 if (progress != null) progress.display(0, "Calculate master sample"); … … 343 354 for (BioAssay assay : assays) 344 355 { 356 // Update progress reporter 357 if(progress != null) progress.display( 358 (int)((100L * normalizedSpots)/numSpots), 359 normalizedSpots + " spots normalized"); 360 345 361 short bioassayColumn = assay.getDataCubeColumnNo(); 346 362 List<AbstractSpotData> data = getSpots(dc, assay, query, assay.getRawDataType().getChannels()); … … 349 365 350 366 // Pick out rank invariant genes from the highRank(90th percentile) and lowRank(50th-25th percentile). 351 float rankQuot =0;352 int highRankIndex = Math.round(((data.size() / 100 )*highRank)+0.5f);367 double rankQuot = 0.0; 368 int highRankIndex = Math.round(((data.size() / 100f)*highRank)+0.5f); 353 369 int lowRankIndex; 354 370 int decrLowRank = 0; 355 List<SpotData1Ch> rankInvSampleGenes ;356 List<Double> rankInvMasterGenes ;371 List<SpotData1Ch> rankInvSampleGenes = new ArrayList<SpotData1Ch>(); 372 List<Double> rankInvMasterGenes = new ArrayList<Double>(); 357 373 // Iterate until at least 2% of the genes are considered to be rank invariant. 358 374 // LowRank is decreased with 5 steps each time. 359 do 360 { 361 rankInvSampleGenes = new ArrayList<SpotData1Ch>(); 375 while (rankQuot < 0.02f && ((lowRank-decrLowRank) >= 25)) 376 { 377 lowRankIndex = Math.round(((data.size() / 100)*(lowRank-decrLowRank))+0.5f); 378 379 rankInvSampleGenes = new ArrayList<SpotData1Ch>(); 362 380 rankInvMasterGenes = new ArrayList<Double>(); 363 364 lowRankIndex = Math.round(((data.size() / 100)*(lowRank-decrLowRank))+0.5f); 365 366 // Map<position, rank> 367 Map<Integer, Integer> sampleRankMap = getRankedPositions(data, highRankIndex, lowRankIndex); 368 Map<Integer, Integer> masterRankMap = getRankedPositions(masterSample, highRankIndex, lowRankIndex); 369 370 for (int i=0; i < dataSize ; i++) 371 { 372 AbstractSpotData d = data.get(i); 373 // Gets the gene's ranking in master and current sample 374 Integer masterRank = masterRankMap.get(d.getPosition()); 375 Integer sampleRank = sampleRankMap.get(d.getPosition()); 381 //Map<position, rank> 382 Map<Integer, Integer> sampleRanks = new HashMap<Integer, Integer>(); 383 Map<Integer, Integer> masterRanks = new HashMap<Integer, Integer>(); 384 385 for (int i=lowRankIndex; i<=highRankIndex; i++) 386 { 387 sampleRanks.put(data.get(i).getPosition(), i); 388 masterRanks.put(masterSample.get(i).getPosition(), i); 376 389 377 // Check the relative rank between master and sample if 378 //the position exists in both of them 379 if (masterRank != null && sampleRank != null) 390 } 391 for (Integer pos : sampleRanks.keySet()) 392 { 393 Integer sRank = sampleRanks.get(pos); 394 Integer mRank = masterRanks.get(pos); 395 float distance = (sRank != null && mRank != null) ? Math.abs((sRank - mRank) / mRank) : 1f; 396 if (distance < 0.05) 380 397 { 381 float div = (Math.abs(sampleRank-masterRank) / masterRank); 382 if (div < 0.05) 383 { 384 rankInvSampleGenes.add((SpotData1Ch)d); 385 rankInvMasterGenes.add((double)masterSample.get(masterRank).getNormalizableData()); 386 } 398 rankInvSampleGenes.add((SpotData1Ch)data.get(sRank)); 399 rankInvMasterGenes.add((double)masterSample.get(mRank).getNormalizableData()); 387 400 } 388 } 389 rankQuot = rankInvSampleGenes.size() / data.size(); 401 } 402 float numRankedGenes = rankInvSampleGenes.size(); 403 rankQuot = numRankedGenes / new Float(highRankIndex-lowRankIndex+1); 390 404 decrLowRank += 5; 391 } while (rankQuot < 0.02 || (lowRank-decrLowRank) >= 25);405 } 392 406 393 407 for (SpotData1Ch spot : rankInvSampleGenes) … … 395 409 List<Double> weights = getBiSquareWeights(rankInvSampleGenes, spot.getNormalizableData()); 396 410 double[] km = getNormCoeffs(rankInvMasterGenes, rankInvSampleGenes, weights); 397 float newCh1 = new Float((spot.getNormalizableData()-km[1]) / km[0]); 398 399 batcher.insert(bioassayColumn, spot.getPosition(), newCh1); 400 } 401 normalizedSpots += rankInvSampleGenes.size(); 402 403 // Update progress reporter 404 if(progress != null) progress.display( 405 (int)((100L * normalizedSpots)/numSpots), 406 normalizedSpots + " spots normalized"); 411 float newIntensity = new Float((spot.getNormalizableData()-km[1]) / km[0]); 412 413 batcher.insert(bioassayColumn, spot.getPosition(), newIntensity); 414 } 415 normalizedSpots += rankInvSampleGenes.size(); 407 416 } 408 417 batcher.flush(); … … 410 419 411 420 return child; 412 }413 414 /*415 Gets positions of those genes that are ranked between two values.416 The data-parameter must be list sorted asc.417 */418 @SuppressWarnings("unchecked")419 private Map<Integer, Integer> getRankedPositions(List<? extends AbstractSpotData> data, int highRankIndex, int lowRankIndex)420 {421 Map<Integer, Integer> rankedPos = new HashMap<Integer, Integer>();422 for (AbstractSpotData spd : data)423 {424 int dataIndex = data.indexOf(spd);425 if (dataIndex <= highRankIndex && dataIndex >= lowRankIndex)426 {427 rankedPos.put(spd.getPosition(), data.indexOf(spd));428 }429 }430 return rankedPos;431 421 } 432 422 … … 440 430 { 441 431 BioAssay assay = (BioAssay)obj; 432 assay = BioAssay.getById(dc, assay.getId()); 442 433 try 443 434 {
Note: See TracChangeset
for help on using the changeset viewer.