Changeset 748


Ignore:
Timestamp:
Aug 27, 2008, 11:07:58 AM (13 years ago)
Author:
Martin Svensson
Message:

Fixes #117 Create average nomralization plug-in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/AverageNormalization.java

    r746 r748  
    5353import net.sf.basedb.core.query.Expression;
    5454import net.sf.basedb.core.query.Expressions;
     55import net.sf.basedb.core.query.Restriction;
     56import net.sf.basedb.core.query.Restrictions;
    5557import net.sf.basedb.core.query.Selects;
    5658import net.sf.basedb.core.query.SqlResult;
     
    125127  );
    126128 
     129  private PluginParameter<Float> minIntensityParameter = new PluginParameter<Float>
     130  (
     131    "minIntensity",
     132    "Minimum intensity",
     133    "Use spots with both int greater than [value]",
     134    null
     135  );
     136 
     137  /**
     138    Section for normalization options
     139  */
     140  protected static final PluginParameter<String> normalizationSection = new PluginParameter<String>(
     141    "normalizationSection",
     142    "Normalization options",
     143    "",
     144    null
     145  );
     146 
    127147  /*
    128148    From SignalTarget interface
     
    163183        // Child name, description and transformation
    164184        storeValue(job, request, ri.getParameter(CHILD_NAME));
    165         storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION));       
     185        storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION));
     186        // Average specific parameters
     187        storeValue(job, request, minIntensityParameter);
    166188        storeValue(job, request, ri.getParameter("useGlobalAvgInt"));
    167189       
     
    244266        String childName = Values.getString((String)job.getValue(CHILD_NAME), source.getName());
    245267        String childDescription = (String)job.getValue(CHILD_DESCRIPTION);
     268        float minIntensity = (Float)job.getValue(minIntensityParameter.getName());
    246269        Job currentJob = this.getCurrentJob(dc);
    247270       
     
    252275        if (useGlobalAvgInt)
    253276        {
    254           refValue = getGlobalAvgIntensity(dc, source);
     277          refValue = getGlobalAvgIntensity(dc, source, minIntensity);
    255278        }
    256279        else
     
    261284        //Normalize the data
    262285        BioAssaySet child = null;       
    263         child = normalize(dc, source, currentJob, refValue, progress);
     286        child = normalize(dc, source, currentJob, refValue, minIntensity, progress);
    264287       
    265288        //Finish up
     
    296319      {
    297320        BioAssaySet bas = getCurrentBioAssaySet(dc);
     321        int nofChannels=bas.getRawDataType().getChannels();
     322       
    298323        List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
     324       
     325        // min-intensity's default value
     326        FloatParameterType fpt=new FloatParameterType(0F , null, 100F, true);
     327        if (nofChannels==1) fpt=new FloatParameterType(null , null, 0F, true);
     328        minIntensityParameter = new PluginParameter<Float>
     329        (
     330          minIntensityParameter.getName(),
     331          minIntensityParameter.getLabel(),
     332          minIntensityParameter.getDescription(),
     333          fpt
     334          );
    299335       
    300336        // Source and child bioassay set parameters
     
    303339        parameters.add(getChildDescriptionParameter(null, null, null));
    304340
     341        // Average normalization options
     342        parameters.add(normalizationSection);
     343        parameters.add(minIntensityParameter);
    305344        parameters.add(useGlobalAverageIntensityParameter);
    306345        parameters.add(referenceValueParameter);
     
    324363 
    325364  private BioAssaySet normalize(DbControl dc, BioAssaySet source, Job job, float refValue,
    326       ProgressReporter progress)
     365      float minIntensity, ProgressReporter progress)
    327366  {
    328367    int noOfChannels = source.getRawDataType().getChannels();
     
    344383    // Query to receive spot data
    345384    DynamicSpotQuery query = source.getSpotData();
     385    Restriction intensityRestriction = getIntensityRestriction(noOfChannels, minIntensity);
     386    query.restrictPermanent(intensityRestriction);
    346387    numSpots = query.count(dc);
    347388    query.reset();
     
    436477    either 1-channel or 2-channel data.
    437478   */
    438   private float getGlobalAvgIntensity(DbControl dc, BioAssaySet source)
     479  private float getGlobalAvgIntensity(DbControl dc, BioAssaySet source, float minIntensity)
    439480    throws SQLException, BaseException
    440481  {
     
    442483    Expression mean = null;
    443484    DynamicSpotQuery query = source.getSpotData();
     485    Restriction intensityRestriction = getIntensityRestriction(noOfChannels, minIntensity);
    444486    float meanValue = 0;
    445487   
     
    459501    }   
    460502    query.select(Selects.expression(mean, "mean"));
     503    query.restrict(intensityRestriction);
    461504    DynamicResultIterator it = query.iterate(dc);
    462505    if (it.hasNext())
     
    468511    return meanValue;
    469512  }
     513 
     514  /*
     515    Gets a 'greater than' restriction for the specified number of channels.
     516   */
     517  private Restriction getIntensityRestriction(int noOfChannels, float minIntensity)
     518  {
     519    Restriction intensityRestriction = null;   
     520    if (noOfChannels == 1)
     521    {
     522      intensityRestriction = Restrictions.gt(Dynamic.column(VirtualColumn.channel(1)), Expressions.aFloat(minIntensity));
     523    }
     524    else
     525    {
     526      Restriction[] restrictions = new Restriction[noOfChannels];
     527      for (int i=0; i<noOfChannels; i++)
     528      {
     529        restrictions[i] = Restrictions.gt(Dynamic.column(VirtualColumn.channel(i+1)), Expressions.aFloat(minIntensity));
     530      }
     531      intensityRestriction = Restrictions.and(restrictions);
     532    }
     533    return intensityRestriction;
     534  }
    470535}
Note: See TracChangeset for help on using the changeset viewer.