Changeset 689


Ignore:
Timestamp:
May 5, 2008, 4:16:25 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Addresses #110. Added MAD based outlier removal of negative control beadsets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.illumina/trunk/src/net/sf/basedb/illumina/plugins/DetectionPValue.java

    r686 r689  
    3333import net.sf.basedb.core.Experiment;
    3434import net.sf.basedb.core.ExtraValueType;
     35import net.sf.basedb.core.FloatParameterType;
    3536import net.sf.basedb.core.Item;
    3637import net.sf.basedb.core.Job;
     
    108109  private RequestInformation configureJob;
    109110
    110   private static final String defaultChildName="Detection P-value";
    111 
    112   private static final Set<Permissions> permissions = new HashSet<Permissions>();
    113 
    114111  /**
    115112     List of selectable 1-channel array types. DASL (2-channel) type
     
    138135      );
    139136
     137  private static final String defaultChildName="Detection P-value";
     138
     139  private static final Set<Permissions> permissions = new HashSet<Permissions>();
     140
     141  /**
     142     Set the cut-off for excluding outliers in the negative control
     143     pool of bead sets. The median absolute deviation (MAD) method is
     144     used for outlier exclusion.
     145   */
     146  private static final PluginParameter<Float> outlierParameter = new PluginParameter<Float>
     147    ( "outlier_cutoff",
     148      "Outlier cut-off",
     149      "The median absolute deviation (MAD) method is used for negative " +
     150      "control outlier exclusion",
     151      new FloatParameterType(0F,null,5F,true)
     152      );
     153
    140154  /**
    141155    Make it possible to abort the job.
     
    172186        // Plug-in options
    173187        storeValue(job, request, arrayType1Parameter);
     188        storeValue(job, request, outlierParameter);
    174189
    175190        // Estimate execution time
     
    227242        // background correction method
    228243        parameters.add(arrayType1Parameter);
     244        parameters.add(outlierParameter);
    229245 
    230246        configureJob = new RequestInformation(
     
    311327
    312328
    313   float pvalue(float[] sortedArray, float intensity)
    314   {
    315     int arraysize=sortedArray.length;
    316     int i=arraysize-1;
    317     while (i>-1 && sortedArray[i]>intensity) --i;
    318     return (float)(1.0-(1.0+i)/arraysize);
     329  private int[] locateOutlierBoundary(float [] sortedIntensity, float cutoff)
     330  {
     331    float controlMedian=median(sortedIntensity);
     332
     333    float[] absMedianDistance=new float[sortedIntensity.length];
     334    for (int i=0; i<absMedianDistance.length; ++i)
     335      absMedianDistance[i]=Math.abs(sortedIntensity[i]-controlMedian);
     336    Arrays.sort(absMedianDistance);
     337    float MAD=median(absMedianDistance);
     338
     339    float MADcut=cutoff*MAD;
     340    int controlstart=0;
     341    while ((controlMedian-sortedIntensity[controlstart]) > MADcut)
     342      controlstart++;
     343    int controlend=sortedIntensity.length;
     344    while ((sortedIntensity[--controlend]-controlMedian) > MADcut);
     345
     346    int[] indexStartStop = new int[2];
     347    indexStartStop[0]=controlstart;
     348    indexStartStop[1]=controlend;
     349    return indexStartStop;
     350  }
     351
     352
     353  private float median(float[] sortedArray)
     354  {
     355    int mid=sortedArray.length/2;
     356    return (sortedArray.length%2==0 ? (sortedArray[mid-1]+sortedArray[mid])/2 : sortedArray[mid]);
     357  }
     358
     359
     360  float pvalue(float[] sortedArray, int startIndex, int stopIndex, float intensity)
     361  {
     362    int i=stopIndex;
     363    while (i>=startIndex && sortedArray[i]>intensity) --i;
     364    return (float)(1.0-(1.0+i)/(stopIndex-startIndex+1));
    319365  }
    320366
     
    337383    {
    338384      String arrayType = (String)job.getValue(arrayType1Parameter.getName());
    339       if (progress != null)
    340         progress.display(0, ("Preparing detection P-value calculation for " +
    341                              arrayType));
    342385      dc = sc.newDbControl();
    343386      BioAssaySet source = getSourceBioAssaySet(dc);
     
    416459          }
    417460          dri.close();
     461          int[] controlStartStop=
     462            locateOutlierBoundary(sortedControlIntensity,
     463                                  (Float)job.getValue(outlierParameter.getName()));
    418464
    419465          checkInterrupted();
     
    430476            SqlResult result = dri.next();
    431477            batcher.insert(result.getShort(columnIndex), result.getInt(positionIndex),
    432                            pvalue(sortedControlIntensity,result.getFloat(ch1Index)));
     478                           pvalue(sortedControlIntensity, controlStartStop[0],
     479                                  controlStartStop[1], result.getFloat(ch1Index)));
    433480          }
    434481          dri.close();
Note: See TracChangeset for help on using the changeset viewer.