Changeset 1143 for plugins/base2


Ignore:
Timestamp:
Jul 28, 2009, 3:48:40 PM (14 years ago)
Author:
Martin Svensson
Message:

References #228 Added parameter to define which average method to use when running the plugin. The functionality is not tested yet.

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  
    3232import net.sf.basedb.core.Item;
    3333import net.sf.basedb.core.Permission;
     34import net.sf.basedb.core.PluginParameter;
    3435import net.sf.basedb.core.Type;
    3536import net.sf.basedb.core.VirtualColumn;
     
    6162  extends AbstractAnalysisPlugin
    6263{
     64  protected static final String arithmeticOption = "Arithmetic mean";
     65  protected static final String geometricOption = "Geometric mean";
    6366 
    6467  private static final Set<Permissions> permissions = new HashSet<Permissions>();
    6568 
     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  ); 
    6678 
    6779  /**
     
    210222    return data;
    211223  }
     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  }
    212268}
  • plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/AverageNormalization.java

    r1060 r1143  
    3232import net.sf.basedb.core.DynamicSpotQuery;
    3333import net.sf.basedb.core.FloatParameterType;
    34 import net.sf.basedb.core.IntensityTransform;
    3534import net.sf.basedb.core.InvalidUseOfNullException;
    3635import net.sf.basedb.core.Job;
     
    8988{
    9089  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"; 
    9491 
    9592  /*
     
    127124    new FloatParameterType(null, null, 100f, false)
    128125  );
    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     
    143127  /*
    144128    Information about this plug-in
     
    320304        if (useGlobalAvgInt)
    321305        {
    322           refValue = getGlobalGeometricMeanIntensity(dc, source, minIntensity);
     306          refValue = getGlobalGeometricMeanIntensity(dc, source, minIntensity, (String)job.getValue("averageMethod"));
    323307        }
    324308        else
     
    389373        parameters.add(getChildNameParameter(null, null, bas.getName()));
    390374        parameters.add(getChildDescriptionParameter(null, null, null));
    391 
    392         // Average normalization options
     375        // Average normalization options       
    393376        StringParameterType spt = new StringParameterType
    394377        (
    395378            null,
    396             bas.getIntensityTransform().equals(IntensityTransform.NONE) ? geometricOption : arithmeticOption ,
     379            bas.getIntensityTransform().getAverageMethod().toString(),
    397380            true, 1, 0, 0,
    398             Arrays.asList(new String[] {geometricOption, arithmeticOption} )
     381            Arrays.asList(arithmeticOption, geometricOption)
    399382        );
    400383        averageMethodParameter = new PluginParameter<String>
     
    437420    long numSpots;
    438421    long normalizedSpots = 0;
    439    
    440     boolean useGeometricMean = geometricOption.equals(job.getParameterValue("averageMethod"));
    441422   
    442423    // Create Transformation
     
    515496        if (dataSize == 0) continue;
    516497       
    517         // Calculate the 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)
    521502        {
    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;
    537507       
    538508        // Normalize data and put it into the child-bioassay set
     
    560530    either 1-channel or 2-channel data.
    561531   */
    562   private float getGlobalGeometricMeanIntensity(DbControl dc, BioAssaySet source,
    563                                                 float minIntensity)
     532  private float getGlobalGeometricMeanIntensity(DbControl dc, BioAssaySet source, float minIntensity, String averageMethod)
    564533    throws SQLException, BaseException
    565534  {
     
    574543    {
    575544    case 1:
    576       ratio = Expressions.ln(ch1);
     545      ratio = ch1;
    577546      break;
    578547    case 2:
     
    582551      throw new BaseException(noOfChannels + " channel-data is not supported by this plugin");
    583552    }   
    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   
    585558    query.select(Selects.expression(mean, "mean"));
    586559    query.restrict(intensityRestriction);
  • plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/QuantileNormalization.java

    r1051 r1143  
    3434import net.sf.basedb.core.RequestInformation;
    3535import net.sf.basedb.core.SpotBatcher;
     36import net.sf.basedb.core.StringParameterType;
    3637import net.sf.basedb.core.Transformation;
    3738import net.sf.basedb.core.VirtualColumn;
     
    223224        storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION));
    224225       
     226        storeValue(job, request, averageMethodParameter);
     227       
    225228        response.setDone("Job configuration completed", Job.ExecutionTime.MEDIUM);
    226229      }
     
    273276        parameters.add(getSourceBioAssaySetParameter(null, null));
    274277        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);
    276296
    277297        String description = "Set minimum intensity for each channel and properties for the child";
     
    300320      Job job, ProgressReporter progress)
    301321  {
     322    String averageMethod = (String)(job.getParameterValue("averageMethod"));
     323   
    302324    int noOfChannels = source.getRawDataType().getChannels();
    303325    long normalizedSpots = 0;
     
    320342          normalizedSpots + " spots normalized");
    321343   
    322     double[] rowSummaries = null;
     344    AverageCalculator[] rowCalculators = null;
    323345   
    324346    List<BioAssay> assays = source.getBioAssays().list(dc);
    325347    Map<Integer, File> fileMap = new HashMap<Integer, File>();
     348    String configuredAverageMethod = (String)job.getParameterValue(averageMethodParameter.getName());
    326349    int spotsPerAssay = -1;
    327350   
     
    342365     
    343366      // Write spot data to file and calculate row summaries
    344       if (rowSummaries == null) rowSummaries = new double[data.size()];
     367      if (rowCalculators == null) rowCalculators = new AverageCalculator[data.size()];
    345368      FileWriter fw = null;
    346369      try
     
    351374        for (int i=0; i<data.size(); i++)
    352375        {
    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());
    355379         
    356380          if (i > 0)fw.write("\n");
     
    378402      }
    379403    }
    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       
    388405    try
    389406    {
     
    418435          String[] lineInfo = line.split("\t");
    419436          AbstractSpotData spot = getSpotDataFromString(lineInfo);
    420           spot.setNormalizableData(rowAverages[rowIndex]);
     437          spot.setNormalizableData(rowCalculators[rowIndex].getAverage());
    421438          batcher.insert(columnNo, spot.getPosition(), spot.getChannelData());
    422439          normalizedSpots++;
Note: See TracChangeset for help on using the changeset viewer.