Changeset 2132
- Timestamp:
- Mar 30, 2006, 1:26:37 PM (17 years ago)
- Location:
- trunk/src/core/net/sf/basedb/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/plugins/LowessNormalization.java
r2062 r2132 52 52 import net.sf.basedb.core.plugin.Request; 53 53 import net.sf.basedb.core.plugin.Response; 54 import net.sf.basedb.core.query.Aggregations; 54 55 import net.sf.basedb.core.query.Dynamic; 55 56 import net.sf.basedb.core.query.Expressions; 57 import net.sf.basedb.core.query.JoinType; 56 58 import net.sf.basedb.core.query.Orders; 57 59 import net.sf.basedb.core.query.Restriction; … … 130 132 new ItemParameterType<BioAssaySet>(BioAssaySet.class, null, true, 1, null) 131 133 ); 134 135 private static final PluginParameter<Integer> blockGroupParameter = new PluginParameter<Integer> 136 ( 137 "blockGroup", 138 "Blockgroup size", 139 "The number of arraydesign blocks in each group", 140 new IntegerParameterType(1, null, 1, true) 141 ); 132 142 133 143 private static double ywRangeFactor = 6; … … 163 173 parameters.add(iterParameter); 164 174 parameters.add(bioAssaySetParameter); 175 parameters.add(blockGroupParameter); 165 176 configureJob = new RequestInformation 166 177 ( … … 181 192 public void run(Request request, Response response, ProgressReporter progress) 182 193 { 194 DbControl dc = sc.newDbControl(); 183 195 String command = request.getCommand(); 184 196 if (command.equals(Request.COMMAND_EXECUTE)) 185 197 { 186 198 SpotBatcher batcher = null; 187 DbControl dc = null;188 199 try 189 200 { 190 dc = sc.newDbControl();201 int blockGroupSize = (Integer) job.getValue(blockGroupParameter.getName()); 191 202 BioAssaySet bioAssaySet = (BioAssaySet) job.getValue(bioAssaySetParameter.getName()); 192 203 bioAssaySet = BioAssaySet.getById(dc, bioAssaySet.getId()); … … 218 229 "a" 219 230 ); 220 Restriction restriction = Restrictions.and231 Restriction intensityRestriction = Restrictions.and 221 232 ( 222 233 Restrictions.gt(Dynamic.column(VirtualColumn.channel(1)), Expressions.aFloat(0)), … … 224 235 ); 225 236 237 DynamicSpotQuery query; 238 DynamicResultIterator resultIter; 226 239 List<BioAssay> assays = bioAssaySet.getBioAssays().list(dc); 227 240 for (BioAssay assay : assays) 228 241 { 229 BioAssay childBioAssay = childBioAssaySet.newBioAssay(assay); 230 childBioAssay.setName(assay.getName()); 231 dc.saveItem(childBioAssay); 232 233 DynamicSpotQuery query = assay.getSpotData(); 234 query.restrictPermanent(restriction); 235 query.select(M); 236 query.select(A); 237 query.orderPermanent(Orders.asc(Expressions.selected(A))); 238 239 int count = query.count(dc); 240 numSpots -= assay.getNumSpots() - count; 241 progress.display((normalizedSpots * 100) / numSpots, (assay.getNumSpots() - count)+ " spots removed from assay " + assay.getName()); 242 243 ArrayList<Double> mValues = new ArrayList<Double>(); 244 ArrayList<Double> aValues = new ArrayList<Double>(); 245 DynamicResultIterator it = query.iterate(dc); 246 247 while (it.hasNext()) 242 dc.saveItem(childBioAssaySet.newBioAssay(assay)); 243 244 query = assay.getSpotData(); 245 query = assay.getSpotData(); 246 query.restrict(intensityRestriction); 247 query.joinRawData(JoinType.LEFT); 248 query.select(Selects.expression(Aggregations.max(Expressions.selected(Dynamic.selectRawData("block"))), "max")); 249 resultIter = query.iterate(dc); 250 int maxBlock = resultIter.next().getInt(resultIter.getIndex("max")); 251 252 for (int i = 0; i < maxBlock; i += blockGroupSize) 248 253 { 249 SqlResult r = it.next(); 250 aValues.add((double) r.getFloat(it.getIndex(A.getAlias()))); 251 mValues.add((double) r.getFloat(it.getIndex(M.getAlias()))); 254 Restriction blockRestriction = Restrictions.between 255 ( 256 Expressions.selected(Dynamic.selectRawData("block")), 257 Expressions.integer(i), 258 Expressions.integer(i+blockGroupSize) 259 ); 260 261 query = assay.getSpotData(); 262 query.select(M); 263 query.select(A); 264 query.select(Dynamic.selectRawData("block")); 265 query.joinRawData(JoinType.LEFT); 266 query.restrictPermanent(intensityRestriction); 267 query.restrictPermanent(blockRestriction); 268 query.orderPermanent(Orders.asc(Expressions.selected(A))); 269 270 if (query.count(dc) <= 0) continue; 271 272 ArrayList<Double> mValues = new ArrayList<Double>(); 273 ArrayList<Double> aValues = new ArrayList<Double>(); 274 DynamicResultIterator it = query.iterate(dc); 275 276 while (it.hasNext()) 277 { 278 SqlResult r = it.next(); 279 aValues.add((double) r.getFloat(it.getIndex(A.getAlias()))); 280 mValues.add((double) r.getFloat(it.getIndex(M.getAlias()))); 281 } 282 283 List<Double> smoothCurve = lowess(aValues, mValues, fitFraction, iter, delta); 284 285 query.reset(); 286 query.select(Dynamic.select(VirtualColumn.COLUMN)); 287 query.select(Dynamic.select(VirtualColumn.POSITION)); 288 query.select(Dynamic.select(VirtualColumn.channel(1))); 289 query.select(Dynamic.select(VirtualColumn.channel(2))); 290 query.select(A); 291 query.joinRawData(JoinType.LEFT); 292 293 it = query.iterate(dc); 294 int column = it.getIndex(VirtualColumn.COLUMN.getName()); 295 int position = it.getIndex(VirtualColumn.POSITION.getName()); 296 int ch1Col = it.getIndex(VirtualColumn.channel(1).getName()); 297 int ch2Col = it.getIndex(VirtualColumn.channel(2).getName()); 298 299 for (int j = 0; j < smoothCurve.size() && it.hasNext(); j++) 300 { 301 SqlResult r = it.next(); 302 303 double factor = Math.exp(smoothCurve.get(j) * 0.5); 304 double ch1 = r.getFloat(ch1Col)/factor; 305 double ch2 = r.getFloat(ch2Col)*factor; 306 batcher.insert(r.getShort(column), r.getInt(position), (float) ch1, (float) ch2); 307 } 308 309 normalizedSpots += smoothCurve.size(); 310 progress.display((normalizedSpots * 100) / numSpots, normalizedSpots + " spots normalized"); 252 311 } 253 254 List<Double> smoothCurve = lowess(aValues, mValues, fitFraction, iter, delta);255 256 query.reset();257 query.select(Dynamic.select(VirtualColumn.COLUMN));258 query.select(Dynamic.select(VirtualColumn.POSITION));259 query.select(Dynamic.select(VirtualColumn.channel(1)));260 query.select(Dynamic.select(VirtualColumn.channel(2)));261 query.select(A);262 263 it = query.iterate(dc);264 int column = it.getIndex(VirtualColumn.COLUMN.getName());265 int position = it.getIndex(VirtualColumn.POSITION.getName());266 int ch1Col = it.getIndex(VirtualColumn.channel(1).getName());267 int ch2Col = it.getIndex(VirtualColumn.channel(2).getName());268 269 for (int i = 0; i < smoothCurve.size() && it.hasNext(); i++)270 {271 SqlResult r = it.next();272 273 double factor = Math.exp(smoothCurve.get(i) * 0.5);274 double ch1 = r.getFloat(ch1Col)/factor;275 double ch2 = r.getFloat(ch2Col)*factor;276 batcher.insert(r.getShort(column), r.getInt(position), (float) ch1, (float) ch2);277 }278 279 normalizedSpots += smoothCurve.size();280 progress.display((normalizedSpots * 100) / numSpots, normalizedSpots + " spots normalized");281 312 } 282 313 batcher.close(); … … 354 385 storeValue(job, request, iterParameter); 355 386 storeValue(job, request, bioAssaySetParameter); 387 storeValue(job, request, blockGroupParameter); 356 388 response.setDone("Job configuration complete", Job.ExecutionTime.SHORT); 357 389 } -
trunk/src/core/net/sf/basedb/plugins/MedianRatioNormalization.java
r2120 r2132 216 216 for (BioAssay assay : assays) 217 217 { 218 //TODO use block numbers to create subgroups219 218 dc.saveItem(child.newBioAssay(assay)); 220 219
Note: See TracChangeset
for help on using the changeset viewer.