Class AbstractBioAssaySetExporter

java.lang.Object
net.sf.basedb.util.export.spotdata.AbstractBioAssaySetExporter
Direct Known Subclasses:
BaseFileExporter, BfsExporter

public abstract class AbstractBioAssaySetExporter
extends Object
An abstract superclass for all exporters that exports spot data from a bioassay set. The purpose of this class is to collect some minimal configurations options (such as the source bioassay set and a DbControl) and to outline a generic export procedure. This class also has a lot of support functionality for subclass that wants to specify exactly which information that should be exported (spot data, reporter annotations, assay annotations, etc.), query generation, progress reporting, thread interruption controls, etc.

The exporter has been designed to export three types of information associated with a bioassay set.

  • Spot data: intensity values, extra values, raw data values
  • Reporter data: reporter annotations, position extra values
  • Bioassay data: annotations

Subclass implementors can override doExport() if they wish. A better option is to override the other methods that are called from this method in this order:

  1. beginExport(): One time only
  2. exportGlobalHeader(): One time only. If false is returned, the export skips to the last step
  3. exportSectionHeader(): One or more times
  4. exportSectionData(): One or more times
  5. exportSectionFooter(): One or more times. If true is returned, the steps 3-5 are repeated.
  6. endExport(RuntimeException): Always called last. If the parameter is not null an error has occurred
Version:
2.12
Author:
Nicklas
Last modified
$Date: 2017-06-07 13:28:31 +0200 (on, 07 jun 2017) $
  • Field Details

  • Constructor Details

    • AbstractBioAssaySetExporter

      protected AbstractBioAssaySetExporter()
  • Method Details

    • setDbControl

      public void setDbControl​(DbControl dc)
      Set's the DbControl that should be used to get data from the database.
    • getDbControl

      public DbControl getDbControl()
      Get the current DbControl.
    • setSnapshotManager

      public void setSnapshotManager​(SnapshotManager snapshotManager)
      Set's the snapshot manager that should be used to load annotation values. If no snapshot manager is provided an internal, temporary one is used.
      Since:
      2.14
    • getSnapshotManager

      public SnapshotManager getSnapshotManager()
      Get the current snapshot manager.
      Since:
      2.14
    • setProgressReporter

      public void setProgressReporter​(ProgressReporter progress)
      Set the progress reporter that is used to report progress. Subclasses can call setProgress(int, String) to update the current status.
    • getProgressReporter

      public ProgressReporter getProgressReporter()
      Get the progress reporter
    • setSource

      public void setSource​(BioAssaySet source)
      Set the bioassay set that is used as a source for the spot data.
    • getSource

      public BioAssaySet getSource()
      Get the source bioassay set.
    • addSpotField

      protected void addSpotField​(DynamicField field)
      Add information about a spot field that should be exported.
      Parameters:
      field - The spot field (null is ignored)
    • getSpotFields

      protected List<DynamicField> getSpotFields()
      Get the list of registered spot fields, in the order they were registered.
    • addReporterField

      protected void addReporterField​(DynamicField field)
      Add information about a reporter field that should be exported.
      Parameters:
      field - The reporter field (null is ignored)
    • getReporterFields

      protected List<DynamicField> getReporterFields()
      Get the list of registered reporter fields, in the order they were registered.
    • addAssayField

      protected void addAssayField​(AssayField field)
      Add information about an assay field that should be exported.
      Parameters:
      field - The assay field (null is ignored)
    • getAssayFields

      protected List<AssayField> getAssayFields()
      Get the list of registered assay fields, in the order they were registered.
    • setAverageOnReporter

      protected void setAverageOnReporter​(boolean averageOnReporter)
      Specify if the exported data should be averaged on reporter or not.
    • getAverageOnReporter

      protected boolean getAverageOnReporter()
    • doExport

      public void doExport()
      Run the export.
    • validate

      protected void validate()
      Validate that all required options has been set and that other options have sensible values. Subclasses that override this method should call super.validate(). The default implementation will at least validate that a DbControl and a source bioassay set has been set.
      Since:
      2.15
    • beginExport

      protected void beginExport()
      Make preparations for the export. Subclasses that need to initialise things should override this method. This is the first method that is called from doExport() and is only called once. The default implementation does nothing.
    • exportGlobalHeader

      protected boolean exportGlobalHeader()
      Export global headers or other data that only appear once in the beginning of the exported file. This method is called after beginExport() and is only called once. The return value can be used to indicate if the export should continue with sections or with global footers. The default implementation does nothing and returns TRUE.
      Returns:
      TRUE to continue with a section exportSectionHeader(), FALSE to continue with global footers exportGlobalFooter()
    • exportSectionHeader

      protected void exportSectionHeader()
      Start a new section in the export by exporting section headers. This method is called after exportGlobalHeader() and may be called multiple times as determined by the return value of exportSectionFooter(). The default implementation does nothing.
    • exportSectionData

      protected void exportSectionData()
      Export section data. This method is called after exportSectionHeader() and may be called multiple times as determined by the return value of exportSectionFooter(). The default implementation does nothing.
    • exportSectionFooter

      protected boolean exportSectionFooter()
      End the section by exporting a footer. This method is called after exportSectionData(). The return value is used to determine if the export should be repeated with a new section or if it should move on to global footers. The default implementation returns false.
      Returns:
      TRUE to continue with another section exportSectionHeader(), FALSE to continue with global footers exportGlobalFooter()
    • exportGlobalFooter

      protected void exportGlobalFooter()
      Export global footer or other data that only appears once in the end of the exported file. This method is called after FALSE has been returned from either exportGlobalHeader() or exportSectionFooter(). The default implementation does nothing.
    • endExport

      protected void endExport​(RuntimeException e)
      End the export and clean up/close all aquired resources. This method is always called last. In the case of an error the exception parameter has a non-null value. The default implementation clears up values that has been cached so it is recommended that subclasses always call this method as part of their own cleanup. If the subclass implementation wants to throw a different exception it is recommended that the given exception is chained to allow developers to debug problems.
    • getBioAssays

      protected List<BioAssay> getBioAssays()
      Get a list with all bioassays in the source bioassay set. The list is sorted by assay name and id. The list is cached internally and if this method is called several times, the same list is returned.
    • addExperimentalFactorsAsAssayFields

      protected void addExperimentalFactorsAsAssayFields()
      Adds all experimental factors from the experiment that the source bioassay set belongs to as assay fields. The experimental factors are ordered by name.
    • getSpotQuery

      protected DynamicSpotQuery getSpotQuery​(boolean bioAssayRestriction)
      Get a configured query for spot data that returns all fields that has been registered with addSpotField(DynamicField). The fields are selected in the order they were registered. This method also adds the position and column of the spot as the last two fields. Note! If the setAverageOnReporter(boolean) option has been enabled there is no unique position so the query returns the reporter id instead of the position in this case.
      Parameters:
      bioAssayRestriction - If TRUE a restriction is added to the query to make it return data for a single bioassay only. Use query.setParameter("bioAssayColumn", (int)bioAssay.getDataCubeColumnNo(), Type.INT) to set the value for the restriction
      Returns:
      A prepared query
    • getReporterQuery

      protected DynamicPositionQuery getReporterQuery()
      Get a configured query for position data that returns all fields that has been registered with addReporterField(DynamicField). The fields are selected in the order they were registered. This method also adds the position of the spot as the last field.

      Note 1! If the setAverageOnReporter(boolean) option has been enabled there is no unique position so the query returns the reporter id instead of the position in this case.

      Note 2! If the setAverageOnReporter(boolean) option has been enabled the query may return the same reporter information multiple times.

      Note 3! A subclass may override this method, but it should at least still select the same number of fields as is expected from the default implementation.

      Returns:
      A prepared query
    • cacheReporterData

      protected int cacheReporterData()
      Loads and caches reporter data in an internal structure for quick access. This method will execute the query returned by getReporterQuery() and read all data into a memory structure. The data is indexed by position number or by reporter id (if average on reporters is enabled).
    • prepareAssayIndexMap

      protected void prepareAssayIndexMap​(List<BioAssay> assays, int firstIndex, int columnsPerAssay)
      Prepare a cache that maps the bioassay column (BioAssay.getDataCubeColumnNo()) value to an index in the 'data' array this is generated. The map is generated as follows:
      • first assay -> firstIndex
      • second assay -> firstIndex + columnsPerAssay
      • third assay -> firtsIndex + 2 * columnsPerAssay
      • ... and so on

      Use getAssayIndex(short) to get the indexed values.

      Parameters:
      assays - The assays that should be mapped
      firstIndex - The index of the first assay
      columnsPerAssay - Number of columns for each assay
    • getAssayIndex

      protected int getAssayIndex​(short column)
      Get the cached index value for an assay when you know the assay's column number.
      Parameters:
      column - The column number (BioAssay.getDataCubeColumnNo())
      Returns:
      The index of the first position in the 'data' array that data for the assay should be written to.
      See Also:
      prepareAssayIndexMap(List, int, int)
    • copyReporterFields

      protected void copyReporterFields​(int key, Object[] data, int startIndex)
      Copy cached reporter data into a data array.
      Parameters:
      key - The cache key (=position or reporter id)
      data - The data array to copy to
      startIndex - The start index in the data array for the first reporter field
    • setProgress

      protected void setProgress​(int percent, String message)
      Update the progress of the export.
      See Also:
      ProgressReporter