Changeset 1060


Ignore:
Timestamp:
May 11, 2009, 1:06:16 PM (14 years ago)
Author:
Martin Svensson
Message:

Fixes #195 Normalizers should ask user for how to calculate averages

File:
1 edited

Legend:

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

    r947 r1060  
    3232import net.sf.basedb.core.DynamicSpotQuery;
    3333import net.sf.basedb.core.FloatParameterType;
     34import net.sf.basedb.core.IntensityTransform;
    3435import net.sf.basedb.core.InvalidUseOfNullException;
    3536import net.sf.basedb.core.Job;
     
    8990  private static final String yesOption = "yes";
    9091  private static final String noOption = "no";
     92  private static final String geometricOption = "geometric";
     93  private static final String arithmeticOption = "arithmetic";
    9194 
    9295  /*
     
    123126    "This parameter cannot be null if 'Use global geometric mean intensity' is " + noOption + ".",
    124127    new FloatParameterType(null, null, 100f, false)
     128  );
     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
    125141  );
    126142   
     
    212228        storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION));
    213229        // Average specific parameters
     230        storeValue(job, request, averageMethodParameter);
    214231        storeValue(job, request, minIntensityParameter);
    215232        storeValue(job, request, ri.getParameter("useGlobalAvgInt"));
    216        
     233               
    217234        // Reference value cannot be null if the global average intensity shouldn't be used.
    218235        String useGlobal = (String)request.getParameterValue("useGlobalAvgInt");
     
    374391
    375392        // Average normalization options
     393        StringParameterType spt = new StringParameterType
     394        (
     395            null,
     396            bas.getIntensityTransform().equals(IntensityTransform.NONE) ? geometricOption : arithmeticOption ,
     397            true, 1, 0, 0,
     398            Arrays.asList(new String[] {geometricOption, arithmeticOption} )
     399        );
     400        averageMethodParameter = new PluginParameter<String>
     401        (
     402          averageMethodParameter.getName(),
     403          averageMethodParameter.getLabel(),
     404          averageMethodParameter.getDescription(),
     405          spt
     406        );
    376407        parameters.add(normalizationSection);
     408        parameters.add(averageMethodParameter);
    377409        parameters.add(minIntensityParameter);
    378410        parameters.add(useGlobalAverageIntensityParameter);
     
    405437    long numSpots;
    406438    long normalizedSpots = 0;
     439   
     440    boolean useGeometricMean = geometricOption.equals(job.getParameterValue("averageMethod"));
    407441   
    408442    // Create Transformation
     
    483517        // Calculate the average intensity for the current assay.
    484518        double sum = 0;
    485         for (Normalizable d : data)
    486         {
    487           sum = sum + Math.log(d.getNormalizableData());
    488         }
    489         float assayAverage = (float)Math.exp(sum/dataSize);
     519        float assayAverage;
     520        if (useGeometricMean)
     521        {
     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        }
    490536        scaleFactor = refValue / assayAverage;
    491537       
Note: See TracChangeset for help on using the changeset viewer.