Changeset 2132


Ignore:
Timestamp:
Mar 30, 2006, 1:26:37 PM (17 years ago)
Author:
Johan Enell
Message:

Lowess is pinbased

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  
    5252import net.sf.basedb.core.plugin.Request;
    5353import net.sf.basedb.core.plugin.Response;
     54import net.sf.basedb.core.query.Aggregations;
    5455import net.sf.basedb.core.query.Dynamic;
    5556import net.sf.basedb.core.query.Expressions;
     57import net.sf.basedb.core.query.JoinType;
    5658import net.sf.basedb.core.query.Orders;
    5759import net.sf.basedb.core.query.Restriction;
     
    130132    new ItemParameterType<BioAssaySet>(BioAssaySet.class, null, true, 1, null)
    131133  );
     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  );
    132142
    133143  private static double ywRangeFactor = 6;
     
    163173    parameters.add(iterParameter);
    164174    parameters.add(bioAssaySetParameter);
     175    parameters.add(blockGroupParameter);
    165176    configureJob = new RequestInformation
    166177    (
     
    181192  public void run(Request request, Response response, ProgressReporter progress)
    182193  {
     194    DbControl dc = sc.newDbControl();
    183195    String command = request.getCommand();
    184196    if (command.equals(Request.COMMAND_EXECUTE))
    185197    {
    186198      SpotBatcher batcher = null;
    187       DbControl dc = null;
    188199      try
    189200      {
    190         dc = sc.newDbControl();
     201        int blockGroupSize = (Integer) job.getValue(blockGroupParameter.getName());
    191202        BioAssaySet bioAssaySet = (BioAssaySet) job.getValue(bioAssaySetParameter.getName());
    192203        bioAssaySet = BioAssaySet.getById(dc, bioAssaySet.getId());
     
    218229          "a"
    219230        );
    220         Restriction restriction = Restrictions.and
     231        Restriction intensityRestriction = Restrictions.and
    221232        (
    222233          Restrictions.gt(Dynamic.column(VirtualColumn.channel(1)), Expressions.aFloat(0)),
     
    224235        );
    225236
     237        DynamicSpotQuery query;
     238        DynamicResultIterator resultIter;
    226239        List<BioAssay> assays = bioAssaySet.getBioAssays().list(dc);
    227240        for (BioAssay assay : assays)
    228241        {
    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)
    248253          {
    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");
    252311          }
    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");
    281312        }
    282313        batcher.close();
     
    354385        storeValue(job, request, iterParameter);
    355386        storeValue(job, request, bioAssaySetParameter);
     387        storeValue(job, request, blockGroupParameter);
    356388        response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
    357389      }
  • trunk/src/core/net/sf/basedb/plugins/MedianRatioNormalization.java

    r2120 r2132  
    216216        for (BioAssay assay : assays)
    217217        {
    218           //TODO use block numbers to create subgroups
    219218          dc.saveItem(child.newBioAssay(assay));
    220219         
Note: See TracChangeset for help on using the changeset viewer.