Dynamic API - Filtering a bioassayset

Contents

This document describes the process of filtering an existing bioassayset.

See also

Last updated: $Date: 2009-04-06 14:52:39 +0200 (må, 06 apr 2009) $

1. Prerequisites

2. Run the job

  1. Create a new Transformation item.
  2. Link the source bioassayset to the transformation.
  3. Create a new BioAssaySet using the same DataCubeLayer as the source bioassayset.
  4. Create a new BioAssay item for each bioassay in the source bioassayset.
  5. Each of the new bioassays should link to one and only one source bioassay and use the same DataCubeColumn as the source.
  6. Create a new FilterBatcher
  7. Create a DynamicQuery that reads data from the source bioassayset.
  8. If the filter can be expressed as a SQL WHERE statement:
    1. Add filter parameters to the query.
    2. Pass the query to the FilterBatcher.insert(AbstractSqlQuery) method.
    otherwise:
    1. Execute the query and apply the filter in memory.
    2. Use the FilterBatcher.insert(column, position) method to insert the spots that passed the filter.
  9. Commit

Note! Most of the above steps are implemented by the net.sf.basedb.util.XXXXX class. Most plugins should be able to use the methods in that class. TODO - add example and implement similar functionality for filters that the IntensityCalculatorUtil class provides for intensity calculators.

/**
  Filter a BioAssaySet using a restriction.
*/
public BioAssaySet filterBioAssaySet(BioAssaySet source, Expression restriction)
{
  DbControl dc = source.getDbControl();

  // Create Transformation
  Transformation t = source.newTransformation(null);
  dc.saveItem(t);

  // Create a new BioAssaySet using the same data cube and layer
  BioAssaySet filtered = t.newProduct(null, null, true);
  filtered.setName("Filtered bioassayset");
  dc.saveItem(filtered);

  // Get all column and position coordinate for all spots that pass the filter
  DynamicQuery query = source.getSpotData();
  query.select(Dynamic.select(VirtualColumn.COLUMN));
  query.select(Dynamic.select(VirtualColumn.POSITION));
  query.restrict(restriction);

  // Create a FilterBatcher
  FilterBatcher filterBatcher = filtered.getFilterBatcher();
  
  // TODO - when implemented by the core this should be possible:
  // filterBatcher.insert(query);

  // Load the spot data and insert coordinates with batcher
  DynamicResultIterator spots = query.iterate(dc);
  int column = spots.getIndex(VirtualColumn.COLUMN.getName());
  int position = spots.getIndex(VirtualColumn.POSITION.getName());
  while (spots.hasNext())
  {
    SqlResult r = spots.next();
    filterBatcher.insert(r.getShort(column), r.getInt(position));
  }

  // Close, commit and return
  filterBatcher.close();
  dc.commit();
  return filtered;
}