2.8.3: 2008-10-15

net.sf.basedb.plugins
Class BioAssaySetExporter

java.lang.Object
  extended by net.sf.basedb.core.plugin.AbstractPlugin
      extended by net.sf.basedb.core.plugin.AbstractExporterPlugin
          extended by net.sf.basedb.plugins.BioAssaySetExporter
All Implemented Interfaces:
ImmediateDownloadExporter, InteractivePlugin, Plugin, SignalTarget

public class BioAssaySetExporter
extends AbstractExporterPlugin
implements InteractivePlugin, SignalTarget

Exporter for bioassay sets. Supported formats: - Tab Delimited, Multiple Sample Files (TDMS Format) for use in MeV (available from http://www.tm4.org). - BASEfile. - Plain Matrix, see documentation for exportPlainMatrix method for a description of the format.

Version:
2.1
Author:
enell, jari, peter
Last modified
$Date: 2008-09-17 14:27:26 +0200 (Wed, 17 Sep 2008) $

Nested Class Summary
 class BioAssaySetExporter.QueryItem
           
private  class BioAssaySetExporter.QueryItemTitleComparator
           
 
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin
Plugin.MainType
 
Field Summary
private static About about
           
private  BioAssaySet bas
           
private  PluginParameter<BioAssaySet> bioAssaySetParameter
           
private static String COMMAND_CONFIGURE_BASEFILE
           
private  RequestInformation configureJob
           
private  RequestInformation configureJobBasefile
           
private  DbControl dc
           
private static String FORMAT_BASEFILE
           
private static String FORMAT_MEV
           
private static String FORMAT_PLAIN_MATRIX
           
private  PluginParameter<String> formatParameter
           
private  PluginParameter<Boolean> geneAveragesParameter
           
private static Set<GuiContext> guiContexts
           
private static Set<Permissions> permissions
           
private  PluginParameter<Boolean> serialFormatParameter
           
private  ThreadSignalHandler signalHandler
           
private  PluginParameter<String> usedColumnsParameter
           
private  PluginParameter<String> usedFieldsParameter
           
 
Fields inherited from class net.sf.basedb.core.plugin.AbstractExporterPlugin
optionalSaveAsType, OVERWRITE, overwriteType, requiredSaveAsType, SAVE_AS
 
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc
 
Constructor Summary
BioAssaySetExporter()
           
 
Method Summary
protected  void begin(DbControl dc)
          Called just before the export starts.
 void configure(GuiContext context, Request request, Response response)
          Configure the plugin.
protected  void end(boolean success)
          Called just after everything has been committed to the database, or immediately after an error has ocurred.
 void exportBaseFileMatrix(BioAssaySet bas, File file, Map<String,String> parameters, List<String> reporterFields, List<String> spotFields, Boolean mergeReporters)
          Export the data from a bioassayset as a serial BASEfile.
 void exportBaseFileMatrix(BioAssaySet bas, OutputStream os, Map<String,String> parameters, List<String> reporterFields, List<String> spotFields, boolean mergeReporters)
           
private  void exportBaseFileSectionAssays(PrintWriter out, DbControl dc, BioAssaySet bas)
           
private  void exportBaseFileSectionHead(PrintWriter out, Map<String,String> parameters)
           
private  void exportBaseFileSectionSpots(PrintWriter out, DbControl dc, BioAssaySet bas, DynamicSpotQuery query, List<String> reporterFields, List<String> spotFields, List<BioAssay> assays, Map<String,BioAssaySetExporter.QueryItem> qi, long count, boolean mergeOnReporters)
           
 void exportBaseFileSerial(BioAssaySet bas, File file, Map<String,String> parameters, List<String> reporterFields, List<String> spotFields, Boolean mergeReporters)
          Export the data from a bioassayset as a serial BASEfile.
 void exportBaseFileSerial(BioAssaySet bas, OutputStream os, Map<String,String> parameters, List<String> reporterFields, List<String> spotFields, boolean mergeReporters)
           
 void exportMeV(BioAssaySet bioassayset, OutputStream to, ProgressReporter progress)
          Export bioassayset data in MeV format.
 void exportPlainMatrix(BioAssaySet bioassayset, OutputStream os, ProgressReporter progress)
          Export bioassayset data in plain matrix format.
 About getAbout()
          Get information about the plugin, such as name, version, authors, etc.
private  List<BioAssaySetExporter.QueryItem> getBaseFileExtraQI(DbControl dc, BioAssaySet bas)
           
private  List<BioAssaySetExporter.QueryItem> getBaseFileFormulaQI(DbControl dc, BioAssaySet bas)
           
private  Map<String,BioAssaySetExporter.QueryItem> getBaseFileQIMap(DbControl dc, BioAssaySet bas)
           
private  List<BioAssaySetExporter.QueryItem> getBaseFileRawQI(BioAssaySet bas)
           
private  List<BioAssaySetExporter.QueryItem> getBaseFileReporterQI()
           
private  List<BioAssaySetExporter.QueryItem> getBaseFileSpotQI(BioAssaySet bas)
           
private  long getBaseFileSpotSectionCount(DbControl dc, DynamicSpotQuery count, boolean mergeReporters)
           
private  RequestInformation getConfigureBasefileParameters(GuiContext context)
           
private  RequestInformation getConfigureJobParameters(GuiContext context, Boolean requireFile)
           
 List<AnnotationType> getExperimentalFactors(DbControl dc, BioAssaySet bas)
           
 Set<GuiContext> getGuiContexts()
          Get a set containing all items that the plugin handles.
 Plugin.MainType getMainType()
          Get the type of the plugin.
 Collection<Permissions> getPermissions()
          Request create and write access to File:s and Directory:s and read access to Experiment:s and User:s.
 RequestInformation getRequestInformation(GuiContext context, String command)
          This method will return the RequestInformation for a given command, i.e.
 SignalHandler getSignalHandler()
          Get the signal handler that is handling signals on behalf of this object.
protected  String getSuccessMessage()
          Called if the export was successful to let the subclass generate a simple message that is sent back to the core and user interface.
 String isInContext(GuiContext context, Object item)
          Check if the plugin can be used on the specified object.
protected  void performExport(ExportOutputStream out, ProgressReporter progress)
          Perform the export.
 boolean requiresConfiguration()
          Returns FALSE, since that is how the plugins used to work before this method was introduced.
 boolean supportsConfigurations()
          Returns TRUE, since that is how the plugins used to work before this method was introduced.
 
Methods inherited from class net.sf.basedb.core.plugin.AbstractExporterPlugin
doExport, getOverwrite, getOverwriteParameter, getSaveAsParameter, getSaveAsPath, getSaveTo, pathCanBeUsed, run
 
Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin
checkInterrupted, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getOverwriteAnnotationsParameters, init, log, log, storeValue, storeValue, storeValues, validateRequestParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.plugin.Plugin
done, init, run
 

Field Detail

signalHandler

private ThreadSignalHandler signalHandler

dc

private DbControl dc

bas

private BioAssaySet bas

about

private static final About about

configureJob

private RequestInformation configureJob

configureJobBasefile

private RequestInformation configureJobBasefile

guiContexts

private static final Set<GuiContext> guiContexts

permissions

private static final Set<Permissions> permissions

bioAssaySetParameter

private PluginParameter<BioAssaySet> bioAssaySetParameter

formatParameter

private PluginParameter<String> formatParameter

serialFormatParameter

private PluginParameter<Boolean> serialFormatParameter

geneAveragesParameter

private PluginParameter<Boolean> geneAveragesParameter

usedFieldsParameter

private PluginParameter<String> usedFieldsParameter

usedColumnsParameter

private PluginParameter<String> usedColumnsParameter

COMMAND_CONFIGURE_BASEFILE

private static final String COMMAND_CONFIGURE_BASEFILE
See Also:
Constant Field Values

FORMAT_BASEFILE

private static final String FORMAT_BASEFILE
See Also:
Constant Field Values

FORMAT_MEV

private static final String FORMAT_MEV
See Also:
Constant Field Values

FORMAT_PLAIN_MATRIX

private static final String FORMAT_PLAIN_MATRIX
See Also:
Constant Field Values
Constructor Detail

BioAssaySetExporter

public BioAssaySetExporter()
Method Detail

configure

public void configure(GuiContext context,
                      Request request,
                      Response response)
Description copied from interface: InteractivePlugin
Configure the plugin. Hopefully the client is supplying values for the parameters specified by InteractivePlugin.getRequestInformation(GuiContext, String).

Specified by:
configure in interface InteractivePlugin
Parameters:
context - The current context of the client application, it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
request - Request object with the command and parameters
response - Response object in for the plugin to response through

getSignalHandler

public SignalHandler getSignalHandler()
Description copied from interface: SignalTarget
Get the signal handler that is handling signals on behalf of this object. Multiple invokations of this method may receive the same or different objects. Null may be returned if, for some reason, the current object instance doesn't want to receive signals. Returning null is the same as not implementing this interface.

Specified by:
getSignalHandler in interface SignalTarget
Returns:
A SignalHandler object, or null if the current instance doesn't support signals

exportBaseFileMatrix

public void exportBaseFileMatrix(BioAssaySet bas,
                                 File file,
                                 Map<String,String> parameters,
                                 List<String> reporterFields,
                                 List<String> spotFields,
                                 Boolean mergeReporters)
                          throws IOException,
                                 SQLException
Export the data from a bioassayset as a serial BASEfile. The reporterFields and spotFields parameter must identify the data to export.

The reporterFields parameter supports the following:

rep.<property> The reporter property with the specified name, for example: rep.externalId, rep.symbol or a property defined in the extended properties file.
The spotFields parameter supports the following:
intensityN The intensity in channel N
position The position number for this spot in the data matrix
raw.<property> The raw data property with the specified name, for example: raw.x, raw.row or a property defined by the raw data type.
frm.<id> The value of the formula with the specified ID.
xtra.<externalId> The value of the extra value with the specified external ID.

Parameters:
bas - The bioassayset to export
file - The file to export to
parameters - Header information that should go at the top of the BASEfile
reporterFields - The reporter fields that should be exportered
spotFields - The spot fields that should be exported
mergeReporters - TRUE to merge spot data having the same reporter (currently not supported)
Throws:
IOException - If there is an IO error
SQLException - If there is an error reading from the database

exportBaseFileMatrix

public void exportBaseFileMatrix(BioAssaySet bas,
                                 OutputStream os,
                                 Map<String,String> parameters,
                                 List<String> reporterFields,
                                 List<String> spotFields,
                                 boolean mergeReporters)
                          throws IOException,
                                 SQLException
Throws:
IOException
SQLException

exportBaseFileSectionAssays

private void exportBaseFileSectionAssays(PrintWriter out,
                                         DbControl dc,
                                         BioAssaySet bas)

exportBaseFileSectionHead

private void exportBaseFileSectionHead(PrintWriter out,
                                       Map<String,String> parameters)

exportBaseFileSerial

public void exportBaseFileSerial(BioAssaySet bas,
                                 File file,
                                 Map<String,String> parameters,
                                 List<String> reporterFields,
                                 List<String> spotFields,
                                 Boolean mergeReporters)
                          throws IOException,
                                 SQLException
Export the data from a bioassayset as a serial BASEfile. See exportBaseFileMatrix(BioAssaySet, File, Map, List, List, Boolean) for information about the naming of parameters.

Parameters:
bas - The bioassayset to export
file - The file to export to
parameters - Header information that should go at the top of the BASEfile
reporterFields - The reporter fields that should be exportered
spotFields - The spot fields that should be exported
mergeReporters - TRUE to merge spot data having the same reporter (currently not supported)
Throws:
IOException - If there is an IO error
SQLException - If there is an error reading from the database

exportBaseFileSerial

public void exportBaseFileSerial(BioAssaySet bas,
                                 OutputStream os,
                                 Map<String,String> parameters,
                                 List<String> reporterFields,
                                 List<String> spotFields,
                                 boolean mergeReporters)
                          throws IOException,
                                 SQLException
Throws:
IOException
SQLException

exportBaseFileSectionSpots

private void exportBaseFileSectionSpots(PrintWriter out,
                                        DbControl dc,
                                        BioAssaySet bas,
                                        DynamicSpotQuery query,
                                        List<String> reporterFields,
                                        List<String> spotFields,
                                        List<BioAssay> assays,
                                        Map<String,BioAssaySetExporter.QueryItem> qi,
                                        long count,
                                        boolean mergeOnReporters)
                                 throws SQLException
Throws:
SQLException

exportMeV

public void exportMeV(BioAssaySet bioassayset,
                      OutputStream to,
                      ProgressReporter progress)
               throws IOException,
                      SQLException
Export bioassayset data in MeV format. The export includes all reporter information and all experimental factor information. If the expriment is a two-channel experiment the ch1/ch2 ratio (non-log value!) is exported as the expression value otherwise the raw intensity of channel 1 is exported.

Parameters:
bioassayset - The bioassayset to export
to - The stream to write the exported data to
progress - An optional progress reporter
Throws:
IOException - If there is an IO error
SQLException - If there is an error reading from the database

exportPlainMatrix

public void exportPlainMatrix(BioAssaySet bioassayset,
                              OutputStream os,
                              ProgressReporter progress)
                       throws IOException,
                              SQLException
Export bioassayset data in plain matrix format. Plain matrix format is simply a matrix with no header nor reporter information. Each column in the matrix corresponds to an assay, and each row corresponds to a reporter. Missing values are reported as entries with no number and 'NaN' is reported for undefined values (such as division with zero). Note, reporters with no measurement within a bioassay set are not reported at all, i.e., a row is not exported with misssing values only. To be clear, we state this once more: Rows (reporters) are only exported if one or more columns (assays) have a value. The value can be 'NaN'. The data exported depends on the underlying microarray platform; - 1-channel: raw ch1 intensity - 2-channel: the fraction ch1/ch2, note! non-log value The justification for exporting non-log values for 2-channel data is to follow the MeV export format where non-log data is exported for 2-channel data. 'NaN' is returned for zero ch2 values. The plug-in or user that uses this method must keep track of the row and column information themselves. The row is sorted in ascending position order, the columns are sorted in ascending column order.

Parameters:
bioassayset - The bioassayset to export
os - The stream to write the exported data to
progress - An optional progress reporter
Throws:
IOException - If there is an IO error
SQLException - If there is an error reading from the database

getAbout

public About getAbout()
Description copied from interface: Plugin
Get information about the plugin, such as name, version, authors, etc.

Specified by:
getAbout in interface Plugin
Returns:
An About object

getBaseFileSpotSectionCount

private long getBaseFileSpotSectionCount(DbControl dc,
                                         DynamicSpotQuery count,
                                         boolean mergeReporters)

getBaseFileExtraQI

private List<BioAssaySetExporter.QueryItem> getBaseFileExtraQI(DbControl dc,
                                                               BioAssaySet bas)

getBaseFileFormulaQI

private List<BioAssaySetExporter.QueryItem> getBaseFileFormulaQI(DbControl dc,
                                                                 BioAssaySet bas)

getBaseFileQIMap

private Map<String,BioAssaySetExporter.QueryItem> getBaseFileQIMap(DbControl dc,
                                                                   BioAssaySet bas)

getBaseFileRawQI

private List<BioAssaySetExporter.QueryItem> getBaseFileRawQI(BioAssaySet bas)

getBaseFileReporterQI

private List<BioAssaySetExporter.QueryItem> getBaseFileReporterQI()

getBaseFileSpotQI

private List<BioAssaySetExporter.QueryItem> getBaseFileSpotQI(BioAssaySet bas)

getConfigureBasefileParameters

private RequestInformation getConfigureBasefileParameters(GuiContext context)

getConfigureJobParameters

private RequestInformation getConfigureJobParameters(GuiContext context,
                                                     Boolean requireFile)

getExperimentalFactors

public List<AnnotationType> getExperimentalFactors(DbControl dc,
                                                   BioAssaySet bas)

getGuiContexts

public Set<GuiContext> getGuiContexts()
Description copied from interface: InteractivePlugin
Get a set containing all items that the plugin handles. Ie. if the plugin imports reporters, return a set containing Item.REPORTER. This information is used by client applications to put the plugin in the proper place in the user interface.

Specified by:
getGuiContexts in interface InteractivePlugin
Returns:
A Set containing Item:s, or null if the plugin is not concerned about items

getMainType

public Plugin.MainType getMainType()
Description copied from interface: Plugin
Get the type of the plugin. This method must always return the same value.

Specified by:
getMainType in interface Plugin
Overrides:
getMainType in class AbstractExporterPlugin
Returns:
MainType.EXPORT

getPermissions

public Collection<Permissions> getPermissions()
Request create and write access to File:s and Directory:s and read access to Experiment:s and User:s.

Specified by:
getPermissions in interface Plugin
Overrides:
getPermissions in class AbstractPlugin
Returns:
A collection of permissions or null to not use permissions

getRequestInformation

public RequestInformation getRequestInformation(GuiContext context,
                                                String command)
                                         throws BaseException
Description copied from interface: InteractivePlugin
This method will return the RequestInformation for a given command, i.e. the list of parameters and some nice help text.

Specified by:
getRequestInformation in interface InteractivePlugin
Parameters:
context - The current context of the client application, it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
command - The command
Returns:
The RequestInformation for the command
Throws:
BaseException - if there is an error

isInContext

public String isInContext(GuiContext context,
                          Object item)
Description copied from interface: InteractivePlugin
Check if the plugin can be used on the specified object. The item is either a BasicItem or BasicData object, or null if called from a list context. A client application should only call this method for contexts matching one of the contexts in the set returned by the InteractivePlugin.getGuiContexts() method. For GuiContext.Type.ITEM contexts an item of the correct type should be passed as a parameter.

The plug-in can response with a null value indicating success, a warning-level message or throw an exception to indicate an error-level message. Client application should normally only show error-level messages to users, unless the user has requested to see warning messages.

NOTE! Before BASE 2.4 all messages were treated as error-level messages.

Specified by:
isInContext in interface InteractivePlugin
Parameters:
context - The current context of the client application, it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
item - The currently active item, it's type should match the GuiContext.getItem() type, or null if the context is a list context
Returns:
Null if the plugin can use that item, or a warning-level message explaining why the plugin can't be used

requiresConfiguration

public boolean requiresConfiguration()
Description copied from class: AbstractPlugin
Returns FALSE, since that is how the plugins used to work before this method was introduced.

Specified by:
requiresConfiguration in interface Plugin
Overrides:
requiresConfiguration in class AbstractPlugin
Returns:
TRUE or FALSE

begin

protected void begin(DbControl dc)
Description copied from class: AbstractExporterPlugin
Called just before the export starts. A subclass may override this method if it needs to initialise some resources.

Overrides:
begin in class AbstractExporterPlugin
Parameters:
dc - The DbControl that is used to write to the database. A subclass may use this read from the database as well
See Also:
AbstractExporterPlugin.end(boolean)

performExport

protected void performExport(ExportOutputStream out,
                             ProgressReporter progress)
                      throws IOException
Description copied from class: AbstractExporterPlugin
Perform the export. This method replaces the ImmediateDownloadExporter.doExport(ExportOutputStream, ProgressReporter) method.

Specified by:
performExport in class AbstractExporterPlugin
Parameters:
out - Output stream to write the exported data to
progress - An optional progress reporter
Throws:
IOException

end

protected void end(boolean success)
Description copied from class: AbstractExporterPlugin
Called just after everything has been committed to the database, or immediately after an error has ocurred. A subclass should clean up any resources aquired in the AbstractExporterPlugin.begin(DbControl) method here.

Overrides:
end in class AbstractExporterPlugin
Parameters:
success - TRUE if the file was parsed successfully, FALSE otherwise
See Also:
AbstractExporterPlugin.begin(DbControl)

getSuccessMessage

protected String getSuccessMessage()
Description copied from class: AbstractExporterPlugin
Called if the export was successful to let the subclass generate a simple message that is sent back to the core and user interface. An example message might by: 178 reporters exported successfully. The default implementation always return null.

Overrides:
getSuccessMessage in class AbstractExporterPlugin

supportsConfigurations

public boolean supportsConfigurations()
Description copied from class: AbstractPlugin
Returns TRUE, since that is how the plugins used to work before this method was introduced.

Specified by:
supportsConfigurations in interface Plugin
Overrides:
supportsConfigurations in class AbstractPlugin
Returns:
TRUE or FALSE

2.8.3: 2008-10-15