public abstract class DataFormat
extends javax.swing.filechooser.FileFilter
Class to represent reading of data formats.
To add new formats, you must not only extend this class, but also add your your format to the variable 'FORMAT_LIST', so it can be displayed to the user in all open/save dialogue boxes. Also, the 'autodetect' and 'getFormat' methods must be modified to include your new format.
Please note that no further file formats are expected for BioLegato, at this time, because it is assumed that readseq will handle translating all formats not internally supported by BioLegato into FastA or GenBANK, which is supported internally by BioLegato.
Modifier and Type | Field and Description |
---|---|
static DataFormat |
FASTA
A static final object used for handling FastA files.
|
static DataFormat[] |
FORMAT_LIST
The list of available file formats
|
static DataFormat |
GDEFILE
A static final object used for handling normal GDE files.
|
static DataFormat |
GDEFLAT
A static final object used for handling GDE flat-files.
|
static DataFormat |
GENBANK
A static final object used for handling GenBank files.
|
Constructor and Description |
---|
DataFormat()
Creates a new instance of DataFormat
|
Modifier and Type | Method and Description |
---|---|
static DataFormat |
autodetect(java.util.Scanner data)
Used to auto-detect file formats.
|
void |
convertFrom(Dataset datamodel,
java.util.Scanner data,
int x,
int y)
Converts a string from the given file format into the BioLegato
internal format.
|
abstract boolean |
convertSequence(Dataset datamodel,
java.util.Scanner source,
int x,
int y,
boolean addonly)
Converts a single sequence from a scanner into BioLegato.
|
void |
convertTo(java.lang.Appendable destination,
Dataset datamodel,
int y)
Converts data from the BioLegato's sequence canvas internal format
to the given file format specified by the DataFormat object.
|
void |
convertTo(java.lang.Appendable destination,
Dataset datamodel,
int y,
int offset,
int length)
Converts data from the BioLegato's sequence canvas internal format
to the given file format.
|
abstract void |
convertTo(java.lang.Appendable destination,
Seq data,
int offset,
int length)
Converts data from the BioLegato's sequence canvas internal format
to the given file format.
|
static DataFormat |
getFormat(java.lang.String hashname)
Finds the file type that corresponds to a given GDE/PCD file format
hashname (returns the GDE flat file, by default, if not successful).
|
protected abstract boolean |
isFormat(java.util.Scanner test)
Used as part of the DataFormat auto-detection algorithm.
|
public static final DataFormat GENBANK
public static final DataFormat GDEFILE
public static final DataFormat GDEFLAT
public static final DataFormat FASTA
public static final DataFormat[] FORMAT_LIST
public final void convertTo(java.lang.Appendable destination, Dataset datamodel, int y) throws java.io.IOException
Converts data from the BioLegato's sequence canvas internal format to the given file format specified by the DataFormat object.
This version is a stub method to call the more elaborate version of the method which handles the offset and length parameters (passing an offset value of zero, and a length of -1, representing the entire length of the line in the data model).
destination
- the destination Appendable to write the data to.datamodel
- the data model object to read from.y
- the line number to read from the data model.java.io.IOException
- if an error occurs while writing to the destination.public final void convertTo(java.lang.Appendable destination, Dataset datamodel, int y, int offset, int length) throws java.io.IOException
Converts data from the BioLegato's sequence canvas internal format to the given file format.
This version is a stub method to call the more elaborate version of the method which handles a sequence from the data model directly.
destination
- the destination Appendable to write the data to.datamodel
- the data model object to read from.y
- the line number to read from the data model.offset
- the X-co-ordinate to start the conversion at.length
- the number of characters to read from the 'offset'.
NOTE: a value less than zero is considered to
mean the length of the entire sequence on
line 'y'. Additionally, values greater than
the length are also treated to be exactly the
length of the entire sequence on line 'y'.java.io.IOException
- if an error occurs while writing to the destination.public abstract void convertTo(java.lang.Appendable destination, Seq data, int offset, int length) throws java.io.IOException
Converts data from the BioLegato's sequence canvas internal format to the given file format.
This method does the actual conversion (thus, you should override this method for any sub-classes).
destination
- the destination Appendable to write the data to.data
- the sequence object to convert.offset
- the offset in the sequence to start the conversion.length
- the number of characters to convert.java.io.IOException
- if an error occurs while writing to the destination.public void convertFrom(Dataset datamodel, java.util.Scanner data, int x, int y) throws java.io.IOException
Converts a string from the given file format into the BioLegato internal format.
This implementation of the method just calls the more elaborate convertSequence (which returns a boolean) until all of the sequences are loaded from the stream/reader object (wrapped in a scanner, incrementing the value of y every time the convertSequence method is called, until convertSequence returns false).
Please be sure to set the delimiter for the scanner object before using it.
datamodel
- the destination data model to store the converted
sequence data.data
- the Scanner object to parse data from.x
- the X-coordinate (character offset) in the data
model to insert the converted sequence data.y
- the Y-coordinate (line) in the data model to insert
the converted sequence data.java.io.IOException
- any exceptions that occur while reading the stream.public abstract boolean convertSequence(Dataset datamodel, java.util.Scanner source, int x, int y, boolean addonly) throws java.io.IOException
Converts a single sequence from a scanner into BioLegato.
Please be sure to set the delimiter for the scanner object before using it.
datamodel
- the destination data model to store the converted
sequence data.source
- the data source to parse data from.x
- the X-coordinate (character offset) in the data
model to insert the converted sequence data.y
- the Y-coordinate (line) in the data model to insert
the converted sequence data.addonly
- whether to not overwrite any data in the data model,
by only adding sequence data after the end of the
data model object.java.io.IOException
- any exceptions that occur while reading the stream.protected abstract boolean isFormat(java.util.Scanner test) throws java.io.IOException
Used as part of the DataFormat auto-detection algorithm. This method tests if the data represented in a scanner can be parsed by the current DataFormat object.
Please be sure to set the delimiter for the scanner object before using it.
test
- the Scanner object to parse and determine if it contains
data which can be parsed by this DataFormat object.java.io.IOException
- returns any possible I/O exceptions
(such as mark not supported)public static DataFormat autodetect(java.util.Scanner data) throws java.io.IOException
Used to auto-detect file formats.
Please be sure to set the delimiter for the scanner object before using it.
data
- the string to detect the file format of.java.io.IOException
public static DataFormat getFormat(java.lang.String hashname)
hashname
- the PCD/GDE hash name to search for.Copyright © 2008-2022 University of Manitoba.