Changeset 744


Ignore:
Timestamp:
Aug 26, 2008, 9:54:01 AM (13 years ago)
Author:
Martin Svensson
Message:

References #117 Corrected a package name. Also changed the way global average intensity is calculated in the AverageNormalization? plug-in. It is now calculated by the database instead of the plug-in.

Location:
plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb
Files:
3 edited
1 moved

Legend:

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

    r728 r744  
    2424*/
    2525
    26 package net.sf.basedb.normalizations;
     26package net.sf.basedb.normalizers;
    2727
    2828/**
    2929    @author Martin
    30     @version 2.7
     30    @version 1.0
    3131 
    3232 */
     
    4141    URL where more information about this package can be found
    4242   */
    43   public static final String URL = "http://baseplugins.thep.lu.se/wiki/net.sf.basedb.normalizations";
     43  public static final String URL = "http://baseplugins.thep.lu.se/wiki/net.sf.basedb.normalizers";
    4444 
    4545  /**
  • plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/AverageNormalization.java

    r743 r744  
    6161import net.sf.basedb.core.signal.SignalTarget;
    6262import net.sf.basedb.core.signal.ThreadSignalHandler;
    63 import net.sf.basedb.normalizations.Normalizations;
     63import net.sf.basedb.normalizers.Normalizations;
    6464import net.sf.basedb.util.Values;
    6565
     
    114114  );
    115115   
    116  
    117116  private final About about = new AboutImpl
    118117  (
    119118    "Average normalization plug-in",
    120119    "This normalization plug-in uses the average algorithm to adjust sample signals.\n" +
    121     "\n" +
    122     "This plug-in is part of the BASE 2 normalization package.",
     120    "Currently 1-channel or 2-channel are supported\n" +
     121    "This plug-in is part of the BASE 2 normalizers package.",
    123122    Normalizations.PACKAGE_VERSION,
    124123    Normalizations.COPYRIGHT,
     
    127126    Normalizations.URL
    128127  );
    129    
    130   // Expressions used to get data
    131   private final Expression ch1 = Dynamic.column(VirtualColumn.channel(1));
    132   private final Expression ch2 = Dynamic.column(VirtualColumn.channel(2));
    133   // Create restriction: column = :bioAssayColumn
    134   Restriction bioAssayRestriction = Restrictions.eq(
    135     Dynamic.column(VirtualColumn.COLUMN),
    136     Expressions.parameter("bioAssayColumn") );
    137128 
    138129  /*
     
    246237        Job currentJob = this.getCurrentJob(dc);
    247238       
    248         int noOfChannels = source.getRawDataType().getChannels();
    249239        boolean useGlobalAvgInt = yesOption.equals((String)job.getValue("useGlobalAverageIntensity"));
    250240        float refValue = 0;
    251241       
    252         DynamicSpotQuery query = source.getSpotData();
    253        
    254242        // Get the reference value to use when calculating the scale factor     
    255243        if (useGlobalAvgInt)
    256         {
    257           double total = 0;
    258           long numberOfSpots = 0;
    259           query.select(Selects.expression(ch1, "ch1"));
    260           List<BioAssay> assays = source.getBioAssays().list(dc);
    261           query.restrict(bioAssayRestriction);
    262        
    263           for (BioAssay assay : assays)
    264           {
    265             // Load spot data for this bioassay
    266             short bioassayColumn = assay.getDataCubeColumnNo();
    267             query.setParameter("bioAssayColumn", (int)bioassayColumn, Type.INT);
    268             DynamicResultIterator it;
    269             int ch1Index;
    270             switch (noOfChannels)
    271             {
    272             case 1:
    273               it = query.iterate(dc);
    274               ch1Index = it.getIndex("ch1");
    275               while (it.hasNext())
    276               {
    277                 SqlResult r = it.next();
    278                 total = total + r.getFloat(ch1Index);
    279                 numberOfSpots++;
    280               }
    281               it.close();
    282               break;
    283              
    284             case 2:
    285               query.select(Selects.expression(ch2, "ch2"));
    286               it = query.iterate(dc);
    287               ch1Index = it.getIndex("ch1");
    288               int ch2Index = it.getIndex("ch2");
    289               while (it.hasNext())
    290               {
    291                 SqlResult r = it.next();
    292                 float ratio = r.getFloat(ch1Index)/r.getFloat(ch2Index);
    293                 total = total + ratio;
    294                 numberOfSpots++;
    295               }
    296               it.close();
    297               break;
    298             }
    299           }
    300           refValue = new Float(total / numberOfSpots);
     244        {
     245          refValue = getGlobalAvgIntensity(dc, source);
    301246        }
    302247        else
     
    327272      }
    328273    }
     274    else
     275    {
     276      response.setError("Unknown command: " + command, null);
     277    }
    329278  }
    330279 
     
    367316      ProgressReporter progress)
    368317  {
     318    int noOfChannels = source.getRawDataType().getChannels();
     319    long numSpots;
     320    long normalizedSpots = 0;
     321   
    369322    // Create Transformation
    370323    Transformation t = source.newTransformation(job);
     
    381334    // Query to receive spot data
    382335    DynamicSpotQuery query = source.getSpotData();
    383        
    384     // Create restriction: column = :bioAssayColumn
    385     Restriction bioAssayRestriction = Restrictions.eq(
    386       Dynamic.column(VirtualColumn.COLUMN),
    387       Expressions.parameter("bioAssayColumn") );
    388    
     336    numSpots = query.count(dc);
     337    query.reset();
     338       
    389339    query.select(Dynamic.select(VirtualColumn.POSITION));
    390340    query.select(Selects.expression(ch1, "ch1"));
    391     query.select(Selects.expression(ch2, "ch2"));
     341    if (noOfChannels > 1) query.select(Selects.expression(ch2, "ch2"));   
    392342    query.restrict(bioAssayRestriction);
     343   
     344    if (progress != null)
     345      progress.display((int)((100L * normalizedSpots) / numSpots),
     346                       normalizedSpots + " spots normalized");
    393347   
    394348    // Normalize one bioassay at a time
    395349    List<BioAssay> assays = source.getBioAssays().list(dc);
    396     int noOfChannels = source.getRawDataType().getChannels();
    397    
    398350    try
    399351    {
     
    402354        checkInterrupted();
    403355       
    404         float scaleFactor = 0;
     356        float scaleFactor = 1;
    405357        List<Normalizable> data = new ArrayList<Normalizable> ();
    406358       
     
    408360        short bioassayColumn = assay.getDataCubeColumnNo();
    409361        query.setParameter("bioAssayColumn", (int)bioassayColumn, Type.INT);
    410        
    411362       
    412363        DynamicResultIterator it = query.iterate(dc);
     
    441392        int dataSize = data.size();
    442393        if (dataSize == 0) continue;
     394       
     395        // Calculate the average intensity for the current assay.
    443396        double sum = 0;
    444397        for (Normalizable d : data)
     
    449402        scaleFactor = refValue / assayAverage;
    450403       
     404        // Normalize data and put it into the child-bioassay set
    451405        for (Normalizable d : data)
    452406        {
    453407          d.setNormalizableData(scaleFactor * d.getNormalizableData());
    454408          batcher.insert(bioassayColumn, d.getPosition(), d.getChannelData());
    455         }
    456       }
     409          normalizedSpots++;
     410        }
     411        if (progress != null)
     412          progress.display((int)((100L * normalizedSpots) / numSpots),
     413                           normalizedSpots + " spots normalized");
     414      }
     415      batcher.flush();
    457416    }
    458417    catch(SQLException e)
     
    460419      throw new BaseException(e);
    461420    }
    462     return null;
     421    return child;
     422  }
     423 
     424  /*
     425    Gets the average intensity for a complete bioassay set of
     426    either 1-channel or 2-channel data.
     427   */
     428  private float getGlobalAvgIntensity(DbControl dc, BioAssaySet source)
     429    throws SQLException, BaseException
     430  {
     431    int noOfChannels = source.getRawDataType().getChannels();
     432    Expression mean = null;
     433    DynamicSpotQuery query = source.getSpotData();
     434    float meanValue = 0;
     435   
     436    switch (noOfChannels)
     437    {
     438    case 1:
     439      mean = Aggregations.mean(ch1);
     440      break;
     441     
     442    case 2:
     443      Expression ratio = Expressions.divide(ch1, ch2);
     444      mean = Aggregations.mean(ratio);
     445      break;
     446     
     447    default:
     448      throw new BaseException(noOfChannels + " channel-data is not supported by this plugin");
     449    }   
     450    query.select(Selects.expression(mean, "mean"));
     451    DynamicResultIterator it = query.iterate(dc);
     452    if (it.hasNext())
     453    {
     454      meanValue = it.next().getFloat(it.getIndex("mean"));
     455    }   
     456    else throw new BaseException("The global average intensity could not be calculated");
     457   
     458    return meanValue;
    463459  }
    464460}
  • plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/CubicSplineNormalization.java

    r728 r744  
    4343import net.sf.basedb.core.signal.SignalTarget;
    4444import net.sf.basedb.core.signal.ThreadSignalHandler;
    45 import net.sf.basedb.normalizations.Normalizations;
     45import net.sf.basedb.normalizers.Normalizations;
    4646import net.sf.basedb.util.Values;
    4747
Note: See TracChangeset for help on using the changeset viewer.