Changeset 3887


Ignore:
Timestamp:
Oct 29, 2007, 9:45:30 AM (14 years ago)
Author:
Nicklas Nordborg
Message:

References #797: Enhance performance for LOWESS and Median-ratio plug-ins

Must sort by 'A' or 'ratio' in memory instead of in the database to avoid interference with the
sorting on 'block' when blockgroupsize is > 1

Location:
trunk/src/plugins/core/net/sf/basedb/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/LowessNormalization.java

    r3879 r3887  
    333333    Expression ch1 = Dynamic.column(VirtualColumn.channel(1));
    334334    Expression ch2 = Dynamic.column(VirtualColumn.channel(2));
    335     // A = log10(sqrt(ch1 * ch2))
    336     Expression pseudoA = Expressions.multiply(ch1, ch2);
    337     Expression A = Expressions.log10(Expressions.sqrt(pseudoA));
    338335
    339336    // Create restriction: ch1 > 0 and ch2 > 0
     
    364361    query.restrict(bioAssayRestriction);
    365362    query.order(Orders.asc(block));
    366     query.order(Orders.asc(pseudoA));
    367363     
    368364    // Normalize one bioassay at a time
     
    424420          if (toIndex > fromIndex)
    425421          {
    426             List<Double> smoothCurve = lowess(data.subList(fromIndex, toIndex), fitFraction, iterations, delta);
     422            List <SpotData> toNormalize = data.subList(fromIndex, toIndex);
     423            Collections.sort(toNormalize);
     424            List<Double> smoothCurve = lowess(toNormalize, fitFraction, iterations, delta);
    427425            for (int j = 0; j < smoothCurve.size(); ++j)
    428426            {
    429               SpotData spot = data.get(fromIndex + j);
     427              SpotData spot = toNormalize.get(j);
    430428              double factor = Math.exp(smoothCurve.get(j) * 0.5);
    431429              batcher.insert(bioassayColumn, spot.position, (float)(spot.ch1/factor), (float)(spot.ch2*factor));
     
    637635
    638636  private static class SpotData
     637    implements Comparable<SpotData>
    639638  {
    640639    final int position;
     
    655654      this.A = Math.log10(Math.sqrt(ch1 * ch2));
    656655    }
     656
     657    /**
     658      Sort by A in ascending order.
     659    */
     660    public int compareTo(SpotData o)
     661    {
     662      return this.A < o.A ? -1 : 1;
     663    }
     664   
    657665  }
    658666
  • trunk/src/plugins/core/net/sf/basedb/plugins/MedianRatioNormalization.java

    r3879 r3887  
    3030import java.util.Arrays;
    3131import java.util.Collection;
     32import java.util.Collections;
    3233import java.util.EnumSet;
    3334import java.util.HashSet;
     
    329330    Expression ch1 = Dynamic.column(VirtualColumn.channel(1));
    330331    Expression ch2 = Dynamic.column(VirtualColumn.channel(2));
    331     // ratio = ch1 / ch2
    332     Expression ratio = Expressions.divide(ch1, ch2);
    333332   
    334333    //   Create restriction: ch1 > minIntensity and ch2 > minIntensity
     
    360359    query.restrict(bioAssayRestriction);
    361360    query.order(Orders.asc(block));
    362     query.order(Orders.asc(ratio));
    363361
    364362    // Normalize one bioassay at a time
     
    425423            if (highIndex > lowIndex)
    426424            {
     425              List <SpotData> toNormalize = data.subList(fromIndex, toIndex);
     426              Collections.sort(toNormalize);
    427427              // Find median ratio in the current block range
    428               double median = median(data.subList(lowIndex, highIndex));
     428              double median = median(toNormalize);
    429429             
    430430              // Correct all spot intensities
     
    509509 
    510510  private static class SpotData
     511    implements Comparable<SpotData>
    511512  {
    512513    final int position;
     
    524525      this.ratio = ch1 / ch2;
    525526    }
     527    /**
     528      Sort by ratio in ascending order.
     529    */
     530    public int compareTo(SpotData o)
     531    {
     532      return this.ratio < o.ratio ? -1 : 1;
     533    }
    526534  }
    527535}
Note: See TracChangeset for help on using the changeset viewer.