org.jscience.biology.alignment
Class CharSequence

java.lang.Object
  extended by org.jscience.biology.alignment.CharSequence

public class CharSequence
extends java.lang.Object

This class implements a sequence of characters stored as an array that provides random access to any position in constant time.

The input can come from any source, provided it is encapsulated in a proper Reader instance. The stream is expected to be ready (i.e. the next read operation must return the first character of the sequence) and it is not closed when its end is reached, so the client is allowed to reset it and maybe use it for another purpose.

Sequences can contain letters only although lines started with the COMMENT_CHAR character ('>') are regarded as comments and are completely skipped. White spaces (including tabs, line feeds and carriage returns) are also ignored throughout.

This class is used by two sequence alignment algorithms: SmithWaterman and NeedlemanWunsch.

See Also:
SmithWaterman, NeedlemanWunsch

Field Summary
protected static char COMMENT_CHAR
          The character used to start a comment line in a sequence file.
protected  char[] sequence
          Stores the sequence as an array of characters.
 
Constructor Summary
CharSequence(java.io.Reader reader)
          Creates a new instance of a CharSequence, loading the sequence data from the Reader input stream.
 
Method Summary
 char charAt(int pos)
          Returns the character at a given position.
 int length()
          Returns the number of characters of this sequence.
 java.lang.String toString()
          Returns a string representation of the sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMMENT_CHAR

protected static final char COMMENT_CHAR
The character used to start a comment line in a sequence file. When this character is found, the rest of the line is ignored.

See Also:
Constant Field Values

sequence

protected char[] sequence
Stores the sequence as an array of characters.

Constructor Detail

CharSequence

public CharSequence(java.io.Reader reader)
             throws java.io.IOException,
                    InvalidSequenceException
Creates a new instance of a CharSequence, loading the sequence data from the Reader input stream.

Parameters:
reader - source of characters for this sequence
Throws:
java.io.IOException - if an I/O exception occurs when reading the input
InvalidSequenceException - if the input does not contain a valid sequence
Method Detail

length

public int length()
Returns the number of characters of this sequence.

Returns:
int number of characters of this sequence

charAt

public char charAt(int pos)
Returns the character at a given position. For the client, the first character is at position 1, while the last character is at position length(). This is convinient for sequence alignment algorithms based on a classic dynamic programming matrix since the sequences usually start at row/column 1. This method does not check boundaries, therefore an ArrayIndexOutOfBoundsException may be raised if pos is out of bounds.

Parameters:
pos - position of character (from 1 to length() inclusive)
Returns:
the character

toString

public java.lang.String toString()
Returns a string representation of the sequence.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the sequence