CharSequence (NeoBio API)

Overview | Package | Class | Tree | Index | Help
| NeoBio API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## neobio.alignment
Class CharSequence

    java.lang.Object
      |
      +--neobio.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.

Author:
  Sergio A. de Carvalho Jr.
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

Overview | Package | Class | Tree | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

http://neobio.sourceforge.net
NeoBio is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. NeoBio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with NeoBio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.