org.biojava.bio.seq.io
Class SwissprotFileFormer

java.lang.Object
  extended byorg.biojava.bio.seq.io.AbstractGenEmblFileFormer
      extended byorg.biojava.bio.seq.io.SwissprotFileFormer
All Implemented Interfaces:
SeqFileFormer, SeqIOListener

public class SwissprotFileFormer
extends org.biojava.bio.seq.io.AbstractGenEmblFileFormer
implements SeqFileFormer

Formats a sequence into Swissprot/TrEMBL format. Modeled after EmblFileFormer.

Since:
1.2
Author:
Greg Cox

Constructor Summary
protected SwissprotFileFormer()
          Creates a new SwissprotFileFormer using System.out stream.
protected SwissprotFileFormer(java.io.PrintStream theStream)
          Creates a new SwissprotFileFormer using the specified stream.
 
Method Summary
 void addFeatureProperty(java.lang.Object key, java.lang.Object value)
          Null implementation
 void addSequenceProperty(java.lang.Object key, java.lang.Object value)
          Notify the listener of a sequence-wide property.
 void addSymbols(Alphabet theAlphabet, Symbol[] theSymbols, int theStart, int theLength)
          Prints out the sequences properties in order.
protected  java.util.List breakSymbolArray(Alphabet theAlphabet, Symbol[] theSymbols, int theStart, int theLength)
          Converts the symbol list passed in into an array of strings.
 void endFeature()
          Null implementation.
 void endSequence()
          Notify the listener that processing of the sequence is complete.
protected  void fillBuffer(java.lang.StringBuffer theBuffer, int theLength)
          Simple method that adds spaces onto the buffer passed in.
 java.lang.String formatLocation(Feature theFeature)
          Creates a string representation of the location of a feature
 java.lang.String formatLocation(Location loc, StrandedFeature.Strand strand)
          formatLocation creates an EMBL/Genbank style representation of a Location.
 java.lang.StringBuffer formatLocation(java.lang.StringBuffer theBuffer, Location theLocation)
          formatLocation creates a String representation of a Location.
 java.lang.StringBuffer formatLocation(java.lang.StringBuffer theBuffer, Location theLocation, StrandedFeature.Strand theStrand)
          formatLocation creates a String representation of a Location.
protected  java.lang.StringBuffer formatPoint(int theMinIndex, int theMaxIndex, boolean isFuzzy)
          Formats the points from fuzzy locations.
 java.io.PrintStream getPrintStream()
          getPrintStream returns the PrintStream to which an instance of SwissprotFileFormer will write the formatted data.
protected  void printOutSequenceHeaderLine(Alphabet theAlphabet, Symbol[] theSymbols, int theStart, int theLength)
          Prints out sequence header with only length data.
 void setName(java.lang.String theName)
          The name is printed out as part of the identifier line.
 void setPrintStream(java.io.PrintStream theStream)
          setPrintStream informs an instance which PrintStream to use.
 void setURI(java.lang.String theURI)
          Null implementation.
 void startFeature(Feature.Template templ)
          Null implementation.
 void startSequence()
          Start the processing of a sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwissprotFileFormer

protected SwissprotFileFormer()
Creates a new SwissprotFileFormer using System.out stream.


SwissprotFileFormer

protected SwissprotFileFormer(java.io.PrintStream theStream)
Creates a new SwissprotFileFormer using the specified stream.

Parameters:
theStream - a PrintStream object.
Method Detail

startSequence

public void startSequence()
                   throws ParseException
Start the processing of a sequence. This method exists primarily to enforce the life-cycles of SeqIOListener objects.

Specified by:
startSequence in interface SeqIOListener
Throws:
ParseException

endSequence

public void endSequence()
                 throws ParseException
Notify the listener that processing of the sequence is complete.

Specified by:
endSequence in interface SeqIOListener
Throws:
ParseException

setName

public void setName(java.lang.String theName)
             throws ParseException
The name is printed out as part of the identifier line. It will be replaced if an ID keyword exists in the annotations.

Specified by:
setName in interface SeqIOListener
Throws:
ParseException

setURI

public void setURI(java.lang.String theURI)
            throws ParseException
Null implementation. This object formats and prints a sequence. The URI alone cannot be printed in Swissprot format. Therefore, it's easiest to ignore it. *

Specified by:
setURI in interface SeqIOListener
Throws:
ParseException

addSymbols

public void addSymbols(Alphabet theAlphabet,
                       Symbol[] theSymbols,
                       int theStart,
                       int theLength)
                throws IllegalAlphabetException
Prints out the sequences properties in order. Prints out the symbol array passed in in lines of 60, blocks of 10

Specified by:
addSymbols in interface SeqIOListener
Parameters:
theAlphabet - The alphabet of the symbol data
theSymbols - An array containing symbols
theStart - The start offset of valid data within the array
theLength - The number of valid symbols in the array
Throws:
IllegalAlphabetException - if we can't cope with this alphabet.

addSequenceProperty

public void addSequenceProperty(java.lang.Object key,
                                java.lang.Object value)
                         throws ParseException
Notify the listener of a sequence-wide property. This might be stored as an entry in the sequence's annotation bundle. Checks for possible known properties to be shown in the file.

Specified by:
addSequenceProperty in interface SeqIOListener
Throws:
ParseException

startFeature

public void startFeature(Feature.Template templ)
                  throws ParseException
Null implementation.

Specified by:
startFeature in interface SeqIOListener
Throws:
ParseException

endFeature

public void endFeature()
                throws ParseException
Null implementation.

Specified by:
endFeature in interface SeqIOListener
Throws:
ParseException

addFeatureProperty

public void addFeatureProperty(java.lang.Object key,
                               java.lang.Object value)
                        throws ParseException
Null implementation

Specified by:
addFeatureProperty in interface SeqIOListener
Throws:
ParseException

getPrintStream

public java.io.PrintStream getPrintStream()
getPrintStream returns the PrintStream to which an instance of SwissprotFileFormer will write the formatted data. The default is System.out

Specified by:
getPrintStream in interface SeqFileFormer
Returns:
the PrintStream which will be written to.

setPrintStream

public void setPrintStream(java.io.PrintStream theStream)
setPrintStream informs an instance which PrintStream to use.

Specified by:
setPrintStream in interface SeqFileFormer
Parameters:
theStream - a PrintStream to write to.

formatLocation

public java.lang.StringBuffer formatLocation(java.lang.StringBuffer theBuffer,
                                             Location theLocation,
                                             StrandedFeature.Strand theStrand)
formatLocation creates a String representation of a Location. Strand information is ignored, as Swissprot files represent proteins. An alternative form of this function does not take a Strand; that form is available only on SwissprotFileFormer; it is not part of the SeqFileFormer interface.

Specified by:
formatLocation in interface SeqFileFormer
Parameters:
theBuffer - a StringBuffer to append the location to.
theLocation - a Location to format.
theStrand - a StrandedFeature.Strand indicating nothing of relevance
Returns:
a StringBuffer with the location appended.

formatLocation

public java.lang.String formatLocation(Feature theFeature)
Creates a string representation of the location of a feature

Specified by:
formatLocation in interface SeqFileFormer
Parameters:
theFeature - The feature with the location to format
Returns:
String The formatted location

formatLocation

public java.lang.StringBuffer formatLocation(java.lang.StringBuffer theBuffer,
                                             Location theLocation)
formatLocation creates a String representation of a Location. The stringbuffer returned represents columns 15-27 of the Swissprot feature table entry. An alternative form of this function takes a Strand; that form is part of the SeqFileFormer interface.

Parameters:
theBuffer - a StringBuffer to append the location to.
theLocation - a Location to format.
Returns:
a StringBuffer with the location appended.

printOutSequenceHeaderLine

protected void printOutSequenceHeaderLine(Alphabet theAlphabet,
                                          Symbol[] theSymbols,
                                          int theStart,
                                          int theLength)
                                   throws IllegalAlphabetException
Prints out sequence header with only length data.

Parameters:
theAlphabet - The alphabet of the symbol data
theSymbols - An array containing symbols
theStart - The start offset of valid data within the array
theLength - The number of valid symbols in the array
Throws:
IllegalAlphabetException - if we can't cope with this alphabet.

breakSymbolArray

protected java.util.List breakSymbolArray(Alphabet theAlphabet,
                                          Symbol[] theSymbols,
                                          int theStart,
                                          int theLength)
                                   throws IllegalAlphabetException
Converts the symbol list passed in into an array of strings. The strings will be blocks of ten, with six blocks on a line.

Parameters:
theAlphabet - The alphabet of the symbol data
theSymbols - An array containing symbols
theStart - The start offset of valid data within the array
theLength - The number of valid symbols in the array
Returns:
The symbol list passed in broken into blocks of ten characters, six to a string.
Throws:
IllegalAlphabetException - if we can't cope with this alphabet.

fillBuffer

protected void fillBuffer(java.lang.StringBuffer theBuffer,
                          int theLength)
Simple method that adds spaces onto the buffer passed in. This method exists to refactor some code used in location formatting. It isn't intended to be generally used.

Parameters:
theBuffer - Buffer to append whitespace to.
theLength - Ammount of whitespace to append.

formatPoint

protected java.lang.StringBuffer formatPoint(int theMinIndex,
                                             int theMaxIndex,
                                             boolean isFuzzy)
Formats the points from fuzzy locations. This is called easily with this.formatPoint(FuzzyLocation.getInnerMax(), FuzzyLocation.getOuterMax(), FuzzyLocation.isFuzzyMax())

Parameters:
theMaxIndex - Inner index of the fuzzy point
theMinIndex - Outer index of the fuzzy point
isFuzzy - Indicates if this point is fuzzy

formatLocation

public java.lang.String formatLocation(Location loc,
                                       StrandedFeature.Strand strand)
formatLocation creates an EMBL/Genbank style representation of a Location. This is a convenience method only. The version which has a StringBuffer parameter (and returns the StringBuffer) is preferred. If a compound location is formatted using this method, it is returned as a join-type location rather than an order-type.

Parameters:
loc - a Location to format.
strand - a StrandedFeature.Strand indicating the Location's strand.
Returns:
a StringBuffer.