org.biojava.bio.seq.io
Class FastaFormat

java.lang.Object
  extended byorg.biojava.bio.seq.io.FastaFormat
All Implemented Interfaces:
java.util.EventListener, ParseErrorListener, ParseErrorSource, SequenceFormat, java.io.Serializable

public class FastaFormat
extends java.lang.Object
implements SequenceFormat, java.io.Serializable, ParseErrorListener, ParseErrorSource

Format object representing FASTA files. These files are almost pure sequence data. The only `sequence property' reported by this parser is PROPERTY_DESCRIPTIONLINE, which is the contents of the sequence's description line (the line starting with a '>' character). Normally, the first word of this is a sequence ID. If you wish it to be interpreted as such, you should use FastaDescriptionLineParser as a SeqIO filter.

Author:
Thomas Down, Matthew Pocock, Greg Cox
See Also:
Serialized Form

Field Summary
static java.lang.String DEFAULT
           
static java.lang.String PROPERTY_DESCRIPTIONLINE
          Constant string which is the property key used to notify listeners of the description lines of FASTA sequences.
 
Constructor Summary
FastaFormat()
           
 
Method Summary
 void addParseErrorListener(ParseErrorListener theListener)
          Adds a parse error listener to the list of listeners if it isn't already included.
 void BadLineParsed(ParseErrorEvent theEvent)
          This method determines the behaviour when a bad line is processed.
protected  java.lang.String describeSequence(Sequence seq)
          Return a suitable description line for a Sequence.
 java.lang.String getDefaultFormat()
          Deprecated.  
 int getLineWidth()
          Retrive the current line width.
protected  void notifyParseErrorEvent(ParseErrorEvent theEvent)
          Passes the event on to all the listeners registered for ParseErrorEvents.
 boolean readSequence(java.io.BufferedReader reader, SymbolTokenization symParser, SeqIOListener siol)
          Read a sequence and pass data on to a SeqIOListener.
 void removeParseErrorListener(ParseErrorListener theListener)
          Removes a parse error listener from the list of listeners if it is included.
 void setLineWidth(int width)
          Set the line width.
 void writeSequence(Sequence seq, java.io.PrintStream os)
          writeSequence writes a sequence to the specified PrintStream, using the default format.
 void writeSequence(Sequence seq, java.lang.String format, java.io.PrintStream os)
          Deprecated. use writeSequence(Sequence seq, PrintStream os)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final java.lang.String DEFAULT
See Also:
Constant Field Values

PROPERTY_DESCRIPTIONLINE

public static final java.lang.String PROPERTY_DESCRIPTIONLINE
Constant string which is the property key used to notify listeners of the description lines of FASTA sequences.

See Also:
Constant Field Values
Constructor Detail

FastaFormat

public FastaFormat()
Method Detail

getLineWidth

public int getLineWidth()
Retrive the current line width.

Returns:
the line width

setLineWidth

public void setLineWidth(int width)
Set the line width.

When writing, the lines of sequence will never be longer than the line width.

Parameters:
width - the new line width

readSequence

public boolean readSequence(java.io.BufferedReader reader,
                            SymbolTokenization symParser,
                            SeqIOListener siol)
                     throws IllegalSymbolException,
                            java.io.IOException,
                            ParseException
Description copied from interface: SequenceFormat
Read a sequence and pass data on to a SeqIOListener.

Specified by:
readSequence in interface SequenceFormat
Parameters:
reader - The stream of data to parse.
symParser - A SymbolParser defining a mapping from character data to Symbols.
siol - A listener to notify when data is extracted from the stream.
Returns:
a boolean indicating whether or not the stream contains any more sequences.
Throws:
java.io.IOException - if an error occurs while reading from the stream.
IllegalSymbolException - if it is not possible to translate character data from the stream into valid BioJava symbols.
ParseException

describeSequence

protected java.lang.String describeSequence(Sequence seq)
Return a suitable description line for a Sequence. If the sequence's annotation bundle contains PROPERTY_DESCRIPTIONLINE, this is used verbatim. Otherwise, the sequence's name is used.


writeSequence

public void writeSequence(Sequence seq,
                          java.io.PrintStream os)
                   throws java.io.IOException
Description copied from interface: SequenceFormat
writeSequence writes a sequence to the specified PrintStream, using the default format.

Specified by:
writeSequence in interface SequenceFormat
Parameters:
seq - the sequence to write out.
os - the printstream to write to.
Throws:
java.io.IOException

writeSequence

public void writeSequence(Sequence seq,
                          java.lang.String format,
                          java.io.PrintStream os)
                   throws java.io.IOException
Deprecated. use writeSequence(Sequence seq, PrintStream os)

writeSequence writes a sequence to the specified PrintStream, using the specified format.

Specified by:
writeSequence in interface SequenceFormat
Parameters:
seq - a Sequence to write out.
format - a String indicating which sub-format of those available from a particular SequenceFormat implemention to use when writing.
os - a PrintStream object.
Throws:
java.io.IOException - if an error occurs.

getDefaultFormat

public java.lang.String getDefaultFormat()
Deprecated.  

getDefaultFormat returns the String identifier for the default format.

Specified by:
getDefaultFormat in interface SequenceFormat
Returns:
a String.

addParseErrorListener

public void addParseErrorListener(ParseErrorListener theListener)
Adds a parse error listener to the list of listeners if it isn't already included.

Specified by:
addParseErrorListener in interface ParseErrorSource
Parameters:
theListener - Listener to be added.

removeParseErrorListener

public void removeParseErrorListener(ParseErrorListener theListener)
Removes a parse error listener from the list of listeners if it is included.

Specified by:
removeParseErrorListener in interface ParseErrorSource
Parameters:
theListener - Listener to be removed.

BadLineParsed

public void BadLineParsed(ParseErrorEvent theEvent)
This method determines the behaviour when a bad line is processed. Some options are to log the error, throw an exception, ignore it completely, or pass the event through.

This method should be overwritten when different behavior is desired.

Specified by:
BadLineParsed in interface ParseErrorListener
Parameters:
theEvent - The event that contains the bad line and token.

notifyParseErrorEvent

protected void notifyParseErrorEvent(ParseErrorEvent theEvent)
Passes the event on to all the listeners registered for ParseErrorEvents.

Parameters:
theEvent - The event to be handed to the listeners.