2.17.2: 2011-06-17

net.sf.basedb.util.export.spotdata
Class BaseFileExporter

java.lang.Object
  extended by net.sf.basedb.util.export.spotdata.AbstractBioAssaySetExporter
      extended by 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: 2010-09-10 13:09:05 +0200 (Fri, 10 Sep 2010) $

Field Summary
private  BaseFileWriter out
           
private  Map<String,String> parameters
           
 
Constructor Summary
protected BaseFileExporter()
           
 
Method Summary
 void addAssayField(AssayField field)
          Adds an assay field to the exported file.
 void addAssayFields(Collection<? extends AssayField> fields)
          Add multiple assay fields in one go.
 void addReporterField(DynamicField field)
          Add information about a reporter field that should be exported.
 void addReporterFields(Collection<? extends DynamicField> fields)
          Add multiple reporter fields in one go.
 void addSpotField(DynamicField field)
          Add information about a spot field that should be exported.
 void addSpotFields(Collection<? extends DynamicField> fields)
          Add multiple spot fields in one go.
protected  void beginExport()
          Prepare the export by adding all experimental factors as assay fields if no fields have been specified.
protected  void exportAssaysSectionData()
          Export data for the 'assays' section that contains information about the bioassays in the source bioassay set.
protected  void exportAssaysSectionHeaders()
          Exports headers for the 'assays' section which contains metadata information about the assays in the bioassay set.
protected  boolean exportGlobalHeader()
          Export 'settings' and 'assays' sections.
protected  int exportSettingsSection()
          Export the settings section which contains all parameter values registered with setParameter(String, String).
protected  void exportSpotSectionData(List<BioAssay> assays, DynamicSpotQuery spotQuery, ProgressReporter progress, long count)
          Export the spot data of a 'spot' section.
protected  void exportSpotSectionHeaders(List<BioAssay> assays, long spotCount)
          Start a new 'spot' section and export the standard headers: 'channels, 'assays', 'columns', 'assayFields' and 'count'.
 List<AssayField> getAssayFields()
          Get the list of registered assay fields, in the order they were registered.
 boolean getAverageOnReporter()
           
protected  BaseFileWriter getBaseFileWriter()
          Get the writer that writes the data to the file.
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.
 String getParameter(String key)
          Get the current value of a 'settings' parameter.
 List<DynamicField> getReporterFields()
          Get the list of registered reporter fields, in the order they were registered.
 List<DynamicField> getSpotFields()
          Get the list of registered spot fields, in the order they were registered.
 void setAverageOnReporter(boolean averageOnReporter)
          Specify if the exported data should be averaged on reporter or not.
 void setParameter(String key, String value)
          Add a parameter that is exported in the 'settings' section, which is the first section in the BASEfile.
 void setWriter(BaseFileWriter out)
          Set the stream were the exported data should be written.
 
Methods inherited from class net.sf.basedb.util.export.spotdata.AbstractBioAssaySetExporter
addExperimentalFactorsAsAssayFields, cacheReporterData, checkInterrupted, copyReporterFields, doExport, endExport, exportGlobalFooter, exportSectionData, exportSectionFooter, exportSectionHeader, getAssayIndex, getBioAssays, getDbControl, getProgressReporter, getReporterQuery, getSnapshotManager, getSource, getSpotQuery, prepareAssayIndexMap, setDbControl, setProgress, setProgressReporter, setSnapshotManager, setSource, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameters

private Map<String,String> parameters

out

private BaseFileWriter out
Constructor Detail

BaseFileExporter

protected BaseFileExporter()
Method Detail

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.


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()

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

2.17.2: 2011-06-17