Class BaseFileExporter

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

public abstract class BaseFileExporter extends AbstractBioAssaySetExporter
A superclass for exporters that exports spot data to BASEfile format. This class exposes several other configuration parameters that are specific for BASEfile:s.
Version:
2.12
Author:
Nicklas
Last modified
$Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
  • Field Details

  • Constructor Details

    • BaseFileExporter

      protected BaseFileExporter()
  • Method Details

    • setWriter

      public void setWriter(BaseFileWriter out)
      Set the stream were the exported data should be written. It is expected that the given writer is a fresh writer and that no data has been written to it yet.
    • setAutoCloseWriters

      public void setAutoCloseWriters(boolean autoClose)
      If this option is set then all writers are automatically closed when all data has been writted to them. This setting is enabled by default.
      Since:
      3.2
    • setParameter

      public void setParameter(String key, String value)
      Add a parameter that is exported in the 'settings' section, which is the first section in the BASEfile. There can only be one value for a given key. The parameters are written to the file in the order they are registered by this method.
      Parameters:
      key - The parameter key (if null this method call is ignored)
      value - The parameter value (may be null)
    • getParameter

      public String getParameter(String key)
      Get the current value of a 'settings' parameter.
      Parameters:
      key - The parameter key
      Returns:
      The value, or null if no values has been registered for the key (or if the registered value is null)
    • addSpotField

      public void addSpotField(DynamicField field)
      Description copied from class: AbstractBioAssaySetExporter
      Add information about a spot field that should be exported.
      Overrides:
      addSpotField in class AbstractBioAssaySetExporter
      Parameters:
      field - The spot field (null is ignored)
    • addSpotFields

      public void addSpotFields(Collection<? extends DynamicField> fields)
      Add multiple spot fields in one go. A null collection is ignored and so are null values in the collection.
      Parameters:
      fields - A collection with the fields that should be added
    • getSpotFields

      public List<DynamicField> getSpotFields()
      Description copied from class: AbstractBioAssaySetExporter
      Get the list of registered spot fields, in the order they were registered.
      Overrides:
      getSpotFields in class AbstractBioAssaySetExporter
    • addReporterField

      public void addReporterField(DynamicField field)
      Description copied from class: AbstractBioAssaySetExporter
      Add information about a reporter field that should be exported.
      Overrides:
      addReporterField in class AbstractBioAssaySetExporter
      Parameters:
      field - The reporter field (null is ignored)
    • addReporterFields

      public void addReporterFields(Collection<? extends DynamicField> fields)
      Add multiple reporter fields in one go. A null collection is ignored and so are null values in the collection.
      Parameters:
      fields - A collection with the fields that should be added
    • getReporterFields

      public List<DynamicField> getReporterFields()
      Description copied from class: AbstractBioAssaySetExporter
      Get the list of registered reporter fields, in the order they were registered.
      Overrides:
      getReporterFields in class AbstractBioAssaySetExporter
    • addAssayField

      public void addAssayField(AssayField field)
      Adds an assay field to the exported file. If no fields has been added the exporter will automaticall export the assay id and name and all experimental factor values.
      Overrides:
      addAssayField in class AbstractBioAssaySetExporter
      Parameters:
      field - The assay field (null is ignored)
      Since:
      2.16
    • addAssayFields

      public void addAssayFields(Collection<? extends AssayField> fields)
      Add multiple assay fields in one go. A null collection is ignored and so are null values in the collection. If no fields has been added the exporter will automaticall export the assay id and name and all experimental factor values.
      Parameters:
      fields - A collection with the fields that should be added
      Since:
      2.16
    • getAssayFields

      public List<AssayField> getAssayFields()
      Description copied from class: AbstractBioAssaySetExporter
      Get the list of registered assay fields, in the order they were registered.
      Overrides:
      getAssayFields in class AbstractBioAssaySetExporter
      Since:
      2.16
    • setAverageOnReporter

      public void setAverageOnReporter(boolean averageOnReporter)
      Description copied from class: AbstractBioAssaySetExporter
      Specify if the exported data should be averaged on reporter or not.
      Overrides:
      setAverageOnReporter in class AbstractBioAssaySetExporter
    • getAverageOnReporter

      public boolean getAverageOnReporter()
      Overrides:
      getAverageOnReporter in class AbstractBioAssaySetExporter
    • beginExport

      protected void beginExport()
      Prepare the export by adding all experimental factors as assay fields if no fields have been specified.
      Overrides:
      beginExport in class AbstractBioAssaySetExporter
    • exportGlobalHeader

      protected boolean exportGlobalHeader()
      Export 'settings' and 'assays' sections.
      Overrides:
      exportGlobalHeader in class AbstractBioAssaySetExporter
      Returns:
      TRUE to continue with a section AbstractBioAssaySetExporter.exportSectionHeader(), FALSE to continue with global footers AbstractBioAssaySetExporter.exportGlobalFooter()
    • endExport

      protected void endExport(RuntimeException e)
      Description copied from class: AbstractBioAssaySetExporter
      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.
      Overrides:
      endExport in class AbstractBioAssaySetExporter
    • getBaseFileWriter

      protected BaseFileWriter getBaseFileWriter()
      Get the writer that writes the data to the file.
    • exportSettingsSection

      protected int exportSettingsSection()
      Export the settings section which contains all parameter values registered with setParameter(String, String). If a parameter with key=section exists the value of that parameter is used as the name of this section, otherwise 'settings' is used as name. If the 'section' parameter exists, it must be the first parameter. It is not allowed in other places and will generate an exception.

      This method leaves the BASEfile writer in the header part in case the caller wants to add more headers.

      If no parameters has been registered this section is skipped.

      Returns:
      The number of parameters written, not including the 'section' parameter
    • exportAssaysSectionHeaders

      protected void exportAssaysSectionHeaders()
      Exports headers for the 'assays' section which contains metadata information about the assays in the bioassay set. This method leaves the BASEfile writer in the header part in case the caller wants to add more headers.
    • exportAssaysSectionData

      protected void exportAssaysSectionData()
      Export data for the 'assays' section that contains information about the bioassays in the source bioassay set. Each data line consists of the 'id', 'name' and annotations for a bioassay.
    • exportSpotSectionHeaders

      protected void exportSpotSectionHeaders(List<BioAssay> assays, long spotCount)
      Start a new 'spot' section and export the standard headers: 'channels, 'assays', 'columns', 'assayFields' and 'count'. This method leaves the BASEfile writer in the header part in case the caller wants to add more headers.
      Parameters:
      assays - The bioassays that this section contains data for
      spotCount - The number of data lines that is going to be written in the data part
    • exportSpotSectionData

      protected void exportSpotSectionData(List<BioAssay> assays, DynamicSpotQuery spotQuery, ProgressReporter progress, long count)
      Export the spot data of a 'spot' section. The given query should return the given number of spot fields PLUS the spot position and column (in that order). Reporter data is expected to have been cached by AbstractBioAssaySetExporter.cacheReporterData() and is copied to the output by AbstractBioAssaySetExporter.copyReporterFields(int, Object[], int).

      A new data row is generated each time the position number changes. If each row should contain data from more than one assay an index map must be given. The index map should map the bioassay column to the ordinal number of the assay in the list of assays.

      Parameters:
      assays - A list of with the bioassays that the current spot data section contains data for
      spotQuery - The query used to retreive the data
      progress - An optional progress reporter, if given progress is reported from 0 to 100%
      count - The total number of spots must be given for the progress reporting to work
    • getCountQuery

      protected DynamicSpotQuery getCountQuery(boolean bioAssayRestriction)
      Get a configured query that counts the number of data lines that is about to be written in a data section. The returned query finds this value by calculating the number of unique positions or, if average on reporters is enabled, the number of unique reporters.
      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 configured query. Use AbstractSqlQuery.count(DbControl) to get the count