Changeset 752


Ignore:
Timestamp:
Sep 3, 2008, 11:09:37 AM (13 years ago)
Author:
Martin Svensson
Message:

Fixes #119 Create Rank Invariant normalization

File:
1 edited

Legend:

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

    r751 r752  
    11/**
    2   $Id
     2  $Id$
    33
    44  Copyright (C) 2008 Martin Svensson
     
    3131import net.sf.basedb.core.DynamicResultIterator;
    3232import net.sf.basedb.core.DynamicSpotQuery;
    33 import net.sf.basedb.core.FloatParameterType;
    3433import net.sf.basedb.core.Job;
    3534import net.sf.basedb.core.PluginParameter;
     
    4746import net.sf.basedb.core.plugin.Response;
    4847import net.sf.basedb.core.query.Dynamic;
    49 import net.sf.basedb.core.query.Restriction;
    5048import net.sf.basedb.core.query.Selects;
    5149import net.sf.basedb.core.query.SqlResult;
     
    7169
    7270/**
    73  
     71  Normalization plug-in that using the 'Rank Invariant'
     72  algorithm to normalize data.
     73  The normalization process first read the spot data for
     74  one assay at the time from the database and then make an ascending sort
     75  before it is written to a temporarily file.
     76  Row averages over the assays for each ranked row is calculated when all assays have been processed.
     77  In the created child the ranked spot data will be replaced by the row average for that row.
     78     
    7479    @author Martin
    7580  @version 1.0
     
    8085  implements InteractivePlugin, SignalTarget
    8186{
     87 
     88  /**
     89    Hold job parameters to configure
     90   */
    8291  private RequestInformation configureJob = null;
    8392 
     
    8796  private ThreadSignalHandler signalHandler;
    8897 
    89    
    90   private PluginParameter<Float> minIntensityParameter  = new PluginParameter<Float>
    91   (
    92     "minIntensity",
    93     "Minimum intensity",
    94     "Use spots with int greater than [value].",
    95     null
    96   );
    97  
    98   private final static PluginParameter<?> normalizationSection = new PluginParameter<String>(
    99     "normalizationSection",
    100     "Normalization options",
    101     "",
    102     null
    103   );
    104  
     98  /**
     99    Holds information about this plug-in
     100   */
    105101  private final static About about = new AboutImpl
    106102  (
     
    108104    "This normalization plug-in uses the rank invariant algorithm to adjust sample signals.\n" +
    109105    "Currently 1-channel or 2-channel are supported\n" +
    110     "This plug-in is part of the BASE 2 normalizers package.",
     106    "This plug-in is part of the BASE normalizers package.",
    111107    Normalizations.PACKAGE_VERSION,
    112108    Normalizations.COPYRIGHT,
     
    145141        String childName = Values.getString((String)job.getValue(CHILD_NAME), source.getName());
    146142        String childDescription = (String)job.getValue(CHILD_DESCRIPTION);
    147         float minIntensity = (Float)job.getValue(minIntensityParameter.getName());
    148143        Job currentJob = this.getCurrentJob(dc);
    149144       
    150145        BioAssaySet child = null;
    151146       
    152         child = normalize(dc, source, currentJob, minIntensity, progress);
     147        child = normalize(dc, source, currentJob, progress);
    153148       
    154149        //Finish up
     
    213208        storeValue(job, request, ri.getParameter(CHILD_NAME));
    214209        storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION));
    215 
    216         // Normalization specific parameters
    217         storeValue(job, request, minIntensityParameter);
    218210       
    219211        response.setDone("Job configuration completed", Job.ExecutionTime.MEDIUM);
     
    249241   */
    250242
     243  /*
     244    Returns the job parameters in a RequestInformation object
     245   */
    251246  private RequestInformation getConfiguredJobParameters()
    252247  {
     
    258253      {
    259254        BioAssaySet bas = getCurrentBioAssaySet(dc);
    260         int nofChannels=bas.getRawDataType().getChannels();
    261255       
    262256        List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    263        
    264         // min-intensity's default value
    265         FloatParameterType fpt=new FloatParameterType(0F , null, 100F, true);
    266         if (nofChannels==1) fpt=new FloatParameterType(null , null, 0F, true);
    267         minIntensityParameter = new PluginParameter<Float>
    268         (
    269           minIntensityParameter.getName(),
    270           minIntensityParameter.getLabel(),
    271           minIntensityParameter.getDescription(),
    272           fpt
    273         );
    274257       
    275258        // Source and child bioassay set parameters
     
    278261        parameters.add(getChildDescriptionParameter(null, null, null));
    279262
    280         // Average normalization options
    281         parameters.add(normalizationSection);
    282         parameters.add(minIntensityParameter);
    283        
    284         String description = "Set min intensity for each channel and properties for the child";
     263        String description = "Set minimum intensity for each channel and properties for the child";
    285264       
    286265        configureJob = new RequestInformation
     
    305284  @SuppressWarnings("unchecked")
    306285  private BioAssaySet normalize(DbControl dc, BioAssaySet source,
    307       Job job, float minIntensity, ProgressReporter progress)
     286      Job job, ProgressReporter progress)
    308287  {
    309288    int noOfChannels = source.getRawDataType().getChannels();
    310289    long normalizedSpots = 0;
    311290       
    312     // Query to receive spot data from data base
     291    // Get query to recieve the spot data.
    313292    DynamicSpotQuery query = source.getSpotData();
    314     // Restriction to get intensities greater than 'minIntensity' for each channel
    315     Restriction intensityRestriction = getIntensityRestriction(noOfChannels, minIntensity);
    316     query.restrictPermanent(intensityRestriction);
     293   
    317294    // Get no spots in assay
    318295    long numSpots = query.count(dc);
    319296    query.reset();
    320297   
    321     // Configure query
     298    // Configure query which column to select data from
    322299    query.select(Dynamic.select(VirtualColumn.POSITION));
    323300    query.select(Selects.expression(ch1, "ch1"));
    324     if (noOfChannels > 1) query.select(Selects.expression(ch2, "ch2"));   
     301    if (noOfChannels > 1) query.select(Selects.expression(ch2, "ch2")); 
    325302    query.restrict(bioAssayRestriction);
    326303   
     
    357334        File tempFile = File.createTempFile("Rank", null);
    358335        FileWriter fw = new FileWriter(tempFile);
    359         // Write spot information to a file and summarize the rows.
    360336        for (int i=0; i<data.size(); i++)
    361337        {
    362           AbstractSpotData spot = data.get(i);
    363           double newRowValue = assays.indexOf(assay) > 0 ?
    364               (rowSummaries[i] + spot.getNormalizableData()) :
    365               spot.getNormalizableData();
    366           rowSummaries[i] = newRowValue;
     338          AbstractSpotData spot = data.get(i);         
     339          rowSummaries[i] += spot.getNormalizableData();
    367340         
    368341          if (i > 0)fw.write("\n");
     
    371344        fw.flush();
    372345        fw.close();
     346
     347        // Map the file with the assay's data cube column no.
    373348        fileMap.put((int)assay.getDataCubeColumnNo(), tempFile);
    374349      }
     
    400375      SpotBatcher batcher = child.getSpotBatcher();
    401376           
    402       // Read each assay's file and take the position order and change to the normalized value.
     377      /*
     378        Read each assay file, line by line and put in
     379        the normalized data to the child for each position.     
     380       */
    403381      for (BioAssay assay : assays)
    404382      {
     
    420398          rowIndex++;
    421399        }
    422        
     400        // Clean up
     401        input.close();
     402        assayFile.delete();
     403       
     404        // Update progress
    423405        if(progress != null) progress.display(
    424406            (int)((100L * normalizedSpots)/numSpots),
     
    433415  }
    434416 
     417  /*
     418    Gets an assay's spots
     419   */
    435420  @SuppressWarnings("unchecked")
    436421  private List<AbstractSpotData> getSpots(DbControl dc, BioAssay assay, DynamicSpotQuery query, int channels)
     
    443428      query.setParameter("bioAssayColumn", (int)bioassayColumn, Type.INT);
    444429      DynamicResultIterator it = query.iterate(dc);
    445      
    446      
    447430     
    448431      // Handling spot data, writing to file and add to a sortable list     
     
    480463  }
    481464 
     465  /*
     466    Gets values from a tab-separated string and create an AbstractSpotData object.
     467    The input string must look like either:
     468    position\tCh1Intensity\tCh2Intensity
     469    or
     470    position\tCh1Intensity
     471   */
    482472  private AbstractSpotData<?> getSpotDataFromString(String[] tabbedLine)
    483473  {
Note: See TracChangeset for help on using the changeset viewer.