2.9.0: 2008-11-26

net.sf.basedb.clients.web
Class ExperimentExplorer

java.lang.Object
  extended by net.sf.basedb.clients.web.ExperimentExplorer

public class ExperimentExplorer
extends Object

A class for storing settings and doing work related to the experiment explorer tool in the web interface. The JSP pages that uses this class are located in the www/views/experiments/explorer directory and it's subdirectory.

This class is used two things:

Most of the settings are stored in regular ItemContext: objects. This means that they will be saved to the database when the user logs out and loaded again the next time they are needed. Each experiment explorer uses two ItemContext objects. One for storing the settings for the reporter search page and one for the view page. The reporter search settings are stored in the context SessionControl.getCurrentContext(Item.REPORTER, "explorer.id") and the view page settings are stored in SessionControl.getCurrentContext(Item.SPOTDATA, "explorer.id") where "id" is replaced by the bioassayset's id.

Version:
2.0
Author:
nicklas
Last modified
$Date: 2008-09-26 14:29:03 +0200 (Fri, 26 Sep 2008) $

Nested Class Summary
static class ExperimentExplorer.AnnotationGroup
          An annotation group contains statistical information about the spot values falling into the group.
static class ExperimentExplorer.AnnotationSummary
          An annotation summary object keeps track of intensities and other statistical information based on the annotation group.
 
Field Summary
private  int annotationTypeId
          The currently selected annotation on the view page.
private  Map<Short,Integer> bioAssays
          Maps a bioassays cube column number to it's id for fast loading by the getBioAssay(DbControl, short) method.
private  BioAssaySet bioAssaySet
          The bioassay set we are exploring.
private  int cacheSize
          The current cache size.
static String[] COLORS
          Predefined colors for annotation groups
static int DEFAULT_CACHE_SIZE
          The size of the cache that stores reporter id's matching the search.
private static ItemContext defaultReporterContext
          The default context for the reporter search page.
private static Map<RawDataType,ItemContext> defaultSpotContexts
          Stores default context for the spot data list on the view page.
private  int firstCachedIndex
          The index of the first cached reporter id.
private  int lastCachedIndex
          The index of the first cached reporter id.
private  int matchingReporters
          Number of reporter that match the reporter search.
private  int positionIndex
          The index of the curren position on the view page.
private  int[] reporterIds
          The cache of reporter ids.
private  int reporterIndex
          The index of the current reporter on the view page.
static int SPOT_ALL
          Special value to use in the setPositionIndex(int) method to show all positions.
static int SPOT_AVG
          Special value to use in the setPositionIndex(int) method to calculate the average for each bioassay.
 
Constructor Summary
private ExperimentExplorer(BioAssaySet bioAssaySet)
          Create a new experiment explorer.
 
Method Summary
 ItemContext getAndSetReporterContext(SessionControl sc, PageContext pageContext)
          Get and update the current settings for the reporter context.
 ItemContext getAndSetSpotContext(SessionControl sc, PageContext pageContext)
          Get and update the current settings for the spot context.
 ExperimentExplorer.AnnotationSummary getAnnotationSummary(DbControl dc, AnnotationType annotationType)
          Get an AnnotationSummary object which can be used to calculate means and other values for each annotation group.
 int getAnnotationTypeId()
          Get the id of the selected annotation type.
 List<AnnotationType> getAnnotationTypes(DbControl dc, boolean includeBioAssayAnnotations)
          Get the annotation types that are of interest in this experiment.
 BioAssay getBioAssay(DbControl dc, short columnNo)
          Get the bioassay with the specified column number in the data cube.
 BioAssaySet getBioAssaySet(DbControl dc)
          Get the bioassay set that is currently beeing explored.
 int getCacheSize()
          The number of reporter id'd to cache.
 ItemContext getDefaultReporterContext()
          Get the default reporter context that is used to initialise the actual context.
 ItemContext getDefaultSpotContext()
          Get the default spot context that is used to initialise the actual context.
static ExperimentExplorer getExplorer(BioAssaySet bioAssaySet)
          Get the existing experiment explorer for a bioassayset or create a new one if none exist yet.
 int getMatchingReporters(DbControl dc)
          Get the number of reporters matching the current reporter filter.
 int getNumBioAssays()
          Get the number of bioassays in the bioassayset.
 int getNumPositions(DbControl dc, ReporterData reporter)
          Get the number of unique positions a reporter is present in among all bioassays in the bioassayset.
 int getNumReporters()
          Get the total number of unique reporters found in the bioassayset.
 int getNumSpots()
          Get the total number of spots in the bioassayset.
 int getPosition(DbControl dc, ReporterData reporter, int positionIndex)
          Get the position number for the specified reporter and position index.
 int getPositionIndex()
          Get the index of the current position.
 ReporterData getReporter(DbControl dc, int index)
          Get the reporter for the specified index.
 int getReporterIndex()
          Get the index of the current reporter.
 DynamicSpotQuery getReporterQuery(DbControl dc, List<String> selectionList)
          Get a query returning the reporter data used by the reporter search page.
 DynamicSpotQuery getSpotQuery(DbControl dc, ReporterData reporter, int positionIndex, List<TableColumn> selectionList)
          Get a query returning spot data for a given reporter and position.
 String getSubContext()
          Get the subcontext name used for the ItemContext objects related to this explorer.
 void setAnnotationTypeId(int annotationTypeId)
          Set the id of the selected annotation type.
 void setCacheSize(int cacheSize)
          Set the size of the reporter cache.
 void setPositionIndex(int positionIndex)
          Set the index of the curren position.
 void setReporterIndex(int reporterIndex)
          Set the index of the currently viewed reporter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPOT_ALL

public static final int SPOT_ALL
Special value to use in the setPositionIndex(int) method to show all positions.

See Also:
Constant Field Values

SPOT_AVG

public static final int SPOT_AVG
Special value to use in the setPositionIndex(int) method to calculate the average for each bioassay.

See Also:
Constant Field Values

DEFAULT_CACHE_SIZE

public static final int DEFAULT_CACHE_SIZE
The size of the cache that stores reporter id's matching the search.

See Also:
getCacheSize(), Constant Field Values

COLORS

public static final String[] COLORS
Predefined colors for annotation groups


defaultReporterContext

private static final ItemContext defaultReporterContext
The default context for the reporter search page.


defaultSpotContexts

private static final Map<RawDataType,ItemContext> defaultSpotContexts
Stores default context for the spot data list on the view page. Different defaults for each raw data type since they can have different number of channels.


bioAssaySet

private final BioAssaySet bioAssaySet
The bioassay set we are exploring.


bioAssays

private final Map<Short,Integer> bioAssays
Maps a bioassays cube column number to it's id for fast loading by the getBioAssay(DbControl, short) method.


reporterIds

private int[] reporterIds
The cache of reporter ids.

See Also:
getCacheSize()

cacheSize

private int cacheSize
The current cache size.


firstCachedIndex

private int firstCachedIndex
The index of the first cached reporter id.

See Also:
getReporterIndex()

lastCachedIndex

private int lastCachedIndex
The index of the first cached reporter id.

See Also:
getReporterIndex()

reporterIndex

private int reporterIndex
The index of the current reporter on the view page.

See Also:
getReporterIndex()

positionIndex

private int positionIndex
The index of the curren position on the view page.

See Also:
getPositionIndex()

matchingReporters

private int matchingReporters
Number of reporter that match the reporter search.


annotationTypeId

private int annotationTypeId
The currently selected annotation on the view page.

Constructor Detail

ExperimentExplorer

private ExperimentExplorer(BioAssaySet bioAssaySet)
Create a new experiment explorer.

Method Detail

getExplorer

public static ExperimentExplorer getExplorer(BioAssaySet bioAssaySet)
Get the existing experiment explorer for a bioassayset or create a new one if none exist yet. The returned object is cached in the SessionControl:s session settings.

Parameters:
bioAssaySet - The bioassay set to get an experiment explorer for
Returns:
An ExperimentExplorer object

getBioAssaySet

public BioAssaySet getBioAssaySet(DbControl dc)
Get the bioassay set that is currently beeing explored.

Parameters:
dc - The DbControl used for access the database
Returns:
The BioAssaySet object
See Also:
BioAssaySet.getById(DbControl, int)

getNumBioAssays

public int getNumBioAssays()
Get the number of bioassays in the bioassayset.


getBioAssay

public BioAssay getBioAssay(DbControl dc,
                            short columnNo)
Get the bioassay with the specified column number in the data cube. This method is useful since spot queries (see getSpotQuery(DbControl, ReporterData, int, List)) can only return the column number, but we usually want to display the name, etc.

Parameters:
dc - The DbControl object used to get the bioassay
columnNo - The colum number
Returns:
The bioassay with the specified column number or null if no bioassay is found

getCacheSize

public int getCacheSize()
The number of reporter id'd to cache. For performance reasons the id's of the reporters matching the reporter search are cached. This means we can step forwards and backwards more quickly on the view page since we don't have to execute the reporter search each time. If the cache is empty or we step outside the boundaries the cache is reloaded with reporters symmetrically located around the index setReporterIndex(int) setting.

Returns:
The size of the cache

setCacheSize

public void setCacheSize(int cacheSize)
Set the size of the reporter cache.

Parameters:
cacheSize - The size
See Also:
getCacheSize()

getNumReporters

public int getNumReporters()
Get the total number of unique reporters found in the bioassayset.

See Also:
BioAssaySet.getNumReporters()

getNumSpots

public int getNumSpots()
Get the total number of spots in the bioassayset.

See Also:
BioAssaySet.getNumSpots()

getSubContext

public String getSubContext()
Get the subcontext name used for the ItemContext objects related to this explorer. The name is created like this: explorer.id where id is replaced with the id of the bioassayset we are exploring.

Returns:
The subcontext name

getDefaultSpotContext

public ItemContext getDefaultSpotContext()
Get the default spot context that is used to initialise the actual context.

Returns:
An ItemContext object

getDefaultReporterContext

public ItemContext getDefaultReporterContext()
Get the default reporter context that is used to initialise the actual context.

Returns:
An ItemContext object

getAndSetSpotContext

public ItemContext getAndSetSpotContext(SessionControl sc,
                                        PageContext pageContext)
Get and update the current settings for the spot context. The spot context is used on the view page for the list with spot data.

Parameters:
sc - The SessionControl of the logged in user
pageContext - The PageContext containing the updated settings, or null to not update the settings
Returns:
An ItemContext object
See Also:
Base.getAndSetCurrentContext(SessionControl, Item, PageContext, ItemContext)

getAndSetReporterContext

public ItemContext getAndSetReporterContext(SessionControl sc,
                                            PageContext pageContext)
Get and update the current settings for the reporter context. The reporter context is used on the reporter search page.

Parameters:
sc - The SessionControl of the logged in user
pageContext - The PageContext containing the updated settings, or null to not update the settings
Returns:
An ItemContext object
See Also:
Base.getAndSetCurrentContext(SessionControl, Item, PageContext, ItemContext)

getAnnotationTypeId

public int getAnnotationTypeId()
Get the id of the selected annotation type.

Returns:
The id of the selected annotation type or 0 if no annotation type is selected

setAnnotationTypeId

public void setAnnotationTypeId(int annotationTypeId)
Set the id of the selected annotation type.

Parameters:
annotationTypeId - The annotation type id or 0 if none is selected

getAnnotationTypes

public List<AnnotationType> getAnnotationTypes(DbControl dc,
                                               boolean includeBioAssayAnnotations)
Get the annotation types that are of interest in this experiment. Ie. the experimental factors of the experiment the bioassayset we are exploring belongs to. Optionally, you can also get annotations for bioassays.

Parameters:
dc - The DbControl for database access
includeBioAssayAnnotations - If bioassay annotation should be included even if they are not experimental factors
Returns:
A list of annotation types, null may be returned if no annotation types exists
See Also:
Experiment.getExperimentalFactors()

getAnnotationSummary

public ExperimentExplorer.AnnotationSummary getAnnotationSummary(DbControl dc,
                                                                 AnnotationType annotationType)
Get an AnnotationSummary object which can be used to calculate means and other values for each annotation group. When the annotation summary object is create each bioassay is placed in one annotation group based on which annotatations it have. Each annotation group is unique and is the only one with the same combination of annotation values. More than one bioassay may be placed in the same group if they are annotated with the same values.

Parameters:
dc - The DbControl for database access
annotationType - The annotation type, mustn't be null
Returns:
An AnnotationSummary object
See Also:
ExperimentExplorer.AnnotationGroup.getAnnotationValues()

getMatchingReporters

public int getMatchingReporters(DbControl dc)
Get the number of reporters matching the current reporter filter.

Parameters:
dc - The DbControl for database access
Returns:
an int of matching reporters

getReporterIndex

public int getReporterIndex()
Get the index of the current reporter. It should be a value between 0 and getMatchingReporters(DbControl)-1.

See Also:
getReporter(DbControl, int)

setReporterIndex

public void setReporterIndex(int reporterIndex)
Set the index of the currently viewed reporter. If the index is below zero or greater than or equal to getMatchingReporters(DbControl) it is set to the nearest index.

Parameters:
reporterIndex - The new index
See Also:
getReporter(DbControl, int)

getReporter

public ReporterData getReporter(DbControl dc,
                                int index)
Get the reporter for the specified index. If the index is outside the cached range or if the cache is empty the cache is reloaded with new reporters symmetrically located around the specified index.

Parameters:
dc - The DbControl to use for database access
index - The index
Returns:
The reporter or null if no reporter is found at the specified index
See Also:
getCacheSize()

getNumPositions

public int getNumPositions(DbControl dc,
                           ReporterData reporter)
Get the number of unique positions a reporter is present in among all bioassays in the bioassayset.

Parameters:
dc - The DbControl to use for database access
reporter - The reporter, or null to find spots without any reporter

getPositionIndex

public int getPositionIndex()
Get the index of the current position. It should be a value between 0 and getNumPositions(DbControl, ReporterData)-1, or one of the SPOT_ALL or SPOT_AVG special values (negative).

Returns:
The current index
See Also:
getPosition(DbControl, ReporterData, int)

setPositionIndex

public void setPositionIndex(int positionIndex)
Set the index of the curren position.

Parameters:
positionIndex - The new index
See Also:
getPositionIndex(), getPosition(DbControl, ReporterData, int)

getPosition

public int getPosition(DbControl dc,
                       ReporterData reporter,
                       int positionIndex)
Get the position number for the specified reporter and position index. The metod will query the data for all positions with the specified reporter, sort them by position and return the value given by the positionIndex parameter.

Parameters:
dc - The DbControl for database access
reporter - The reporter to look for, or null to find spots without reporter
positionIndex - The index of the position to find
Returns:
The position number

getReporterQuery

public DynamicSpotQuery getReporterQuery(DbControl dc,
                                         List<String> selectionList)
Get a query returning the reporter data used by the reporter search page. Note that the query is DynamicSpotQuery and not a DataQuery. This means that we don't get ReporterData objects as a result and that we must specify the properties to select (see ItemContext.configureQuery(DbControl, DynamicQuery, List)).

The reporter id is always included as the first selected property so it doesn't have to be in the selection list.

Parameters:
dc - The DbControl for database access
selectionList - The properties that the query should select
Returns:
A query
See Also:
ItemContext.configureQuery(DbControl, DynamicQuery, List)

getSpotQuery

public DynamicSpotQuery getSpotQuery(DbControl dc,
                                     ReporterData reporter,
                                     int positionIndex,
                                     List<TableColumn> selectionList)
Get a query returning spot data for a given reporter and position. This query is used by the view page to list the spot data for each bioassay.

The column number is always included as the first selected property. If the SPOT_AVG is specified for positionIndex a count of the number of positions is included as the second selected property. Otherwise, the position number is included as the second selected property.

Then, all channel intensities are selected.

See ItemContext.getDynamicExpression(DbControl, String) for more information about how to specify additional selection properties.

Parameters:
dc - The DbControl for database access
reporter - The reporter, or null to get data for spots without a reporter
positionIndex - The index of the position, or one the special values SPOT_ALL or SPOT_AVG
selectionList - The data that the query should select
Returns:
A query

2.9.0: 2008-11-26