Class BaseFileExporter
java.lang.Object
net.sf.basedb.util.export.spotdata.AbstractBioAssaySetExporter
net.sf.basedb.util.export.spotdata.BaseFileExporter
- Direct Known Subclasses:
MatrixBaseFileExporter
,SerialBaseFileExporter
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Prepare the export by adding all experimental factors as assay fields if no fields have been specified.protected void
End the export and clean up/close all aquired resources.protected void
Export data for the 'assays' section that contains information about the bioassays in the source bioassay set.protected void
Exports headers for the 'assays' section which contains metadata information about the assays in the bioassay set.protected boolean
Export 'settings' and 'assays' sections.protected int
Export the settings section which contains all parameter values registered withsetParameter(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'.Get the list of registered assay fields, in the order they were registered.boolean
protected BaseFileWriter
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.getParameter
(String key) Get the current value of a 'settings' parameter.Get the list of registered reporter fields, in the order they were registered.Get the list of registered spot fields, in the order they were registered.void
setAutoCloseWriters
(boolean autoClose) If this option is set then all writers are automatically closed when all data has been writted to them.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, copyReporterFields, doExport, exportGlobalFooter, exportSectionData, exportSectionFooter, exportSectionHeader, getAssayIndex, getBioAssays, getDbControl, getProgressReporter, getReporterQuery, getSnapshotManager, getSource, getSpotQuery, prepareAssayIndexMap, setDbControl, setProgress, setProgressReporter, setSnapshotManager, setSource, validate
-
Field Details
-
parameters
-
out
-
autoCloseWriters
private boolean autoCloseWriters
-
-
Constructor Details
-
BaseFileExporter
protected BaseFileExporter()
-
-
Method Details
-
setWriter
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
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
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
Description copied from class:AbstractBioAssaySetExporter
Add information about a spot field that should be exported.- Overrides:
addSpotField
in classAbstractBioAssaySetExporter
- Parameters:
field
- The spot field (null is ignored)
-
addSpotFields
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
Description copied from class:AbstractBioAssaySetExporter
Get the list of registered spot fields, in the order they were registered.- Overrides:
getSpotFields
in classAbstractBioAssaySetExporter
-
addReporterField
Description copied from class:AbstractBioAssaySetExporter
Add information about a reporter field that should be exported.- Overrides:
addReporterField
in classAbstractBioAssaySetExporter
- Parameters:
field
- The reporter field (null is ignored)
-
addReporterFields
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
Description copied from class:AbstractBioAssaySetExporter
Get the list of registered reporter fields, in the order they were registered.- Overrides:
getReporterFields
in classAbstractBioAssaySetExporter
-
addAssayField
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 classAbstractBioAssaySetExporter
- Parameters:
field
- The assay field (null is ignored)- Since:
- 2.16
-
addAssayFields
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
Description copied from class:AbstractBioAssaySetExporter
Get the list of registered assay fields, in the order they were registered.- Overrides:
getAssayFields
in classAbstractBioAssaySetExporter
- 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 classAbstractBioAssaySetExporter
-
getAverageOnReporter
public boolean getAverageOnReporter()- Overrides:
getAverageOnReporter
in classAbstractBioAssaySetExporter
-
beginExport
protected void beginExport()Prepare the export by adding all experimental factors as assay fields if no fields have been specified.- Overrides:
beginExport
in classAbstractBioAssaySetExporter
-
exportGlobalHeader
protected boolean exportGlobalHeader()Export 'settings' and 'assays' sections.- Overrides:
exportGlobalHeader
in classAbstractBioAssaySetExporter
- Returns:
- TRUE to continue with a section
AbstractBioAssaySetExporter.exportSectionHeader()
, FALSE to continue with global footersAbstractBioAssaySetExporter.exportGlobalFooter()
-
endExport
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 classAbstractBioAssaySetExporter
-
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 withsetParameter(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
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 forspotCount
- 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 byAbstractBioAssaySetExporter.cacheReporterData()
and is copied to the output byAbstractBioAssaySetExporter.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 forspotQuery
- The query used to retreive the dataprogress
- 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
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. Usequery.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
-