Class BfsExporter

    • Constructor Detail

      • BfsExporter

        protected BfsExporter()
    • Method Detail

      • 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.
      • setMetadataWriter

        public void setMetadataWriter​(MetadataWriter metadataWriter)
        Set the stream were the metadata should be written. This stream is required before it is possible to start the export. It is expected that the given writer is a fresh writer and that no data has been written to it yet.
      • setReporterAnnotationsWriter

        public void setReporterAnnotationsWriter​(AnnotationWriter reporterWriter)
        Set the stream were reporter annotations should be written. This is optional and if not given, no reporter annotations file is generated. The writer must return a filename from AnnotationWriter.getFilename() since this is required in the metadata file.

        Use addReporterField(DynamicField) to register reporter fields to export. The position number is always exported.

        Parameters:
        reporterWriter - An annotation writer, or null if no reporter annotation file should be created
      • setAssayAnnotationsWriter

        public void setAssayAnnotationsWriter​(AnnotationWriter assayWriter)
        Set the stream were assay annotations should be written. This is optional and if not given, no assay annotations file is generated. The writer must return a filename from AnnotationWriter.getFilename() since this is required in the metadata file.

        Use addAssayField(AssayField) to register fields to export. The assay id is always exported.

        Parameters:
        assayWriter - An annotation writer, or null if no assay annotations file should be created
      • setDataWriterFactory

        public void setDataWriterFactory​(DataWriterFactory<?> dataWriterFactory)
        Set the data writer factory to use for generating spot data files. What files that are required depends on the BFS subtype. Eg. the serial format uses a file per assay and the matrix format uses a file per spot field. A data writer factory is optional and if not given, no spot data is exported.
        Parameters:
        dataWriterFactory - A data writer factory, or null if no spot data files should be created
      • setParameter

        public void setParameter​(String key,
                                 String... values)
        Add a parameter that is exported in the [parameters] section. There can be one or more values for a given key, which are then separated by tab characters. The parameters are written to the file in the order they are registered by this method.

        NOTE! Calling this method twice with the same key, overwrites the existing parameters, but doesn't change the order they are written to the file.

        Parameters:
        key - The parameter key (if null this method call is ignored)
        values - The parameter value (may be null)
      • getParameter

        public String[] getParameter​(String key)
        Get the current value of a 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)
      • 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
      • 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.
        Parameters:
        fields - A collection with the fields that should be added
      • 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
      • addExtraFile

        public void addExtraFile​(String key,
                                 String filename)
        Add information about an extra data file that is included as part of the BFS. This exporter will register this information as an entry in the [files] section in the metadata file. It will not check that the file actually exists or do any other action with the file.

        File entries are written in the order they are registered by this method. Multiple entries with the same key are allowed (eg. the previous entry is not replaced).

        Parameters:
        key - The key for the file
        filename - The name of the file
      • validate

        protected void validate()
        Description copied from class: AbstractBioAssaySetExporter
        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.
        Overrides:
        validate in class AbstractBioAssaySetExporter
      • beginExport

        protected void beginExport()
        Validates that all required properties has been set and initialises other things that are needed.
        Overrides:
        beginExport in class AbstractBioAssaySetExporter
      • getBFSSubtype

        public String getBFSSubtype()
        Get the BFS subtype. This method may be overridden by subclasses. The default implementation returns null. The subtype is written to the metadata file: MetadataWriter.setSubtype(String).
      • getMetadataWriter

        protected MetadataWriter getMetadataWriter()
        Get the writer were metadata should be printed.
      • getReporterAnnotationsWriter

        protected AnnotationWriter getReporterAnnotationsWriter()
        Get the writer were reporter annotations should be printed. Can be null.
      • getAssayAnnotationsWriter

        protected AnnotationWriter getAssayAnnotationsWriter()
        Get the writer were assay annotations should be printed. Can be null.
      • getDataWriterFactory

        protected DataWriterFactory getDataWriterFactory()
        Get the factory that creates data writers. Can be null.
      • exportMetadata

        protected void exportMetadata()
        Export the metadata file which contains information about the other files (reporter annotations, assay annotations and spot data), plug-in parameters, etc. Plug-in parameters are registered with setParameter(String, String[]) and are written to the [parameters] section. If no parameters has been registered this section is skipped.
      • exportReporterAnnotations

        protected void exportReporterAnnotations​(ProgressReporter progress,
                                                 long count)
        Export the reporter annotations. This method is ignored if getReporterAnnotationsWriter() returns null. The position is used as the value for the id column. Other columns are exported as given by getReporterFields().

        If a progress reporter is given, progress is updated between 0 and 100%.

        This method needs to be executed after exportSpotData(ProgressReporter, long) since we need to know which positions that was exported.

        Parameters:
        progress - An optional progress reporter
        count - The total number of reporters, or 0 if not known
      • exportAssayAnnotations

        protected void exportAssayAnnotations()
        Export the assay annotations. This method is ignored if getAssayAnnotationsWriter() returns null. The assay ID is used as the value for the id column. Other columns are exported as given by getAssayFields().
      • exportSpotData

        protected long exportSpotData​(ProgressReporter progress,
                                      long count)
        Export spot data. This method needs to be executed even if no spot fields has been selected. The reason is that we need to find out the positions that are used in the bioassay set when exporting reporter annotations. The only exception is if also no reporter annotations are exported.
        Parameters:
        progress - An optional progress reporter
        count - The expected number of spots or 0 if not known
        Returns:
        The number of spots processed
      • createDataWriters

        protected abstract List<DataWriter> createDataWriters()
                                                       throws IOException
        Create the exact number of data writers that is needed to export the desired data. Each data writer needs to specify a filename (DataWriter.getFilename() and the number of data columns (DataWriter.getColumnCount()) it is going to write.

        This method must be implemented by a subclass and is called once from the beginExport() method unless no data writer factory has been set up.

        Returns:
        A list with data writers
        Throws:
        IOException - If there is a problem with creating the writers
      • arrangeData

        protected abstract void arrangeData​(int position,
                                            short column,
                                            Object[][] data,
                                            Object[] spotData)
        Arrange the data that was returned by the query into the data writers array. The data array is a two-demensional array. The first index represents a datawriter and goes from 0 to the one below the number of data writers returned by createDataWriters(). The size of the second index is determined by the number of columns for the data writer (eg. DataWriter.getColumnCount().

        This method must be implemented by a subclass which should copy data from the spotdata array into the data array. The data array is flushed to the data writers every time the position coordinate changes. Thus, this method can be called multiple times with different column (=assay) coordinates.

        Parameters:
        position - The current position of the spot data
        column - The current column of the spot data
        data - The data array to copy the data to
        spotData - The current row of spot data, in the same order as getSpotFields()