de.jstacs.data.sequences
Class SparseSequence

java.lang.Object
  extended by de.jstacs.data.Sequence
      extended by de.jstacs.data.sequences.DiscreteSequence
          extended by de.jstacs.data.sequences.SparseSequence
All Implemented Interfaces:
Comparable<Sequence>

public final class SparseSequence
extends DiscreteSequence

This class is an implementation for sequence on one alphabet with length 4. This implementation can be used for instance for DNA sequences.

The symbols are encoded in the bits of the primitive type long, which allows to save 32 symbols in one long. Therefore an instance of this class is more memory efficient than any other DiscreteSequence, e.g. ByteSequence. But on the other hand side this class will be a little bit slower when accessing single positions.

Author:
Jens Keilwagen

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.data.Sequence
Sequence.CompositeSequence, Sequence.SubSequence
 
Field Summary
 
Fields inherited from class de.jstacs.data.Sequence
alphabetCon, annotation, rc
 
Constructor Summary
SparseSequence(AlphabetContainer alphCon, String seq)
          This constructor creates an instance from a String.
SparseSequence(AlphabetContainer alphCon, SymbolExtractor se)
          This constructor creates an instance from a SymbolExtractor.
 
Method Summary
 SparseSequence complement(int start, int end)
          This method returns a new instance of sequence containing a part of the complementary current sequence.
 int discreteVal(int pos)
          Returns the discrete value of position pos.
protected  Sequence flatCloneWithoutAnnotation()
          Works in analogy to Object.clone(), but does not clone the annotation.
 int getLength()
          Returns the length of the sequence
 SparseSequence reverse(int start, int end)
          This method returns a new instance of sequence containing a part of the reverse current sequence.
 SparseSequence reverseComplement(int start, int end)
          This method returns a new sequence instance containing a part of the complementary current sequence.
 
Methods inherited from class de.jstacs.data.sequences.DiscreteSequence
continuousVal
 
Methods inherited from class de.jstacs.data.Sequence
annotate, compareTo, complement, create, create, create, equals, getAlphabetContainer, getAnnotation, getCompositeSequence, getCompositeSequence, getSubSequence, getSubSequence, getSubSequence, getSubSequence, hashCode, reverse, reverseComplement, toDiscrete, toString, toString, toString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SparseSequence

public SparseSequence(AlphabetContainer alphCon,
                      String seq)
               throws WrongSequenceTypeException,
                      WrongAlphabetException
This constructor creates an instance from a String.

Parameters:
alphCon - the AlphabetContainer
seq - the sequence as String
Throws:
WrongSequenceTypeException - if the AlphabetContainer is not simple or the internal Alphabet has more than 4 symbols
WrongAlphabetException - if the AlphabetContainer is not discrete

SparseSequence

public SparseSequence(AlphabetContainer alphCon,
                      SymbolExtractor se)
               throws WrongSequenceTypeException,
                      WrongAlphabetException
This constructor creates an instance from a SymbolExtractor.

Parameters:
alphCon - the AlphabetContainer
se - the SymbolExtractor
Throws:
WrongSequenceTypeException - if the AlphabetContainer is not simple or the internal Alphabet has more than 4 symbols
WrongAlphabetException - if the AlphabetContainer is not discrete
Method Detail

discreteVal

public int discreteVal(int pos)
Description copied from class: Sequence
Returns the discrete value of position pos.

Specified by:
discreteVal in class Sequence
Parameters:
pos - the position
Returns:
the discrete value of position pos

getLength

public int getLength()
Description copied from class: Sequence
Returns the length of the sequence

Specified by:
getLength in class Sequence
Returns:
the length

complement

public SparseSequence complement(int start,
                                 int end)
                          throws OperationNotSupportedException
Description copied from class: Sequence
This method returns a new instance of sequence containing a part of the complementary current sequence.
So for instance invoking this method on the sequence "TAATA" with an AlphabetContainer on DNAAlphabet returns "ATTAT".

Overrides:
complement in class Sequence
Parameters:
start - the start position (inclusive) in the original sequence
end - the end position (exclusive) in the original sequence
Returns:
the complementary sequence
Throws:
OperationNotSupportedException - if the current sequence is not based on a ComplementableDiscreteAlphabet
See Also:
ComplementableDiscreteAlphabet

reverse

public SparseSequence reverse(int start,
                              int end)
                       throws OperationNotSupportedException
Description copied from class: Sequence
This method returns a new instance of sequence containing a part of the reverse current sequence.

Overrides:
reverse in class Sequence
Parameters:
start - the start position (inclusive) in the original sequence
end - the end position (exclusive) in the original sequence
Returns:
the reverse sequence
Throws:
OperationNotSupportedException - if the current sequence is based on an AlphabetContainer that is not simple.

reverseComplement

public SparseSequence reverseComplement(int start,
                                        int end)
                                 throws OperationNotSupportedException
Description copied from class: Sequence
This method returns a new sequence instance containing a part of the complementary current sequence. For more details see the methods reverse() and complement().

Overrides:
reverseComplement in class Sequence
Parameters:
start - the start position (inclusive) in the original sequence
end - the end position (exclusive) in the original sequence
Returns:
the reverse complementary sequence
Throws:
OperationNotSupportedException - if the current sequence is not discrete and simple
See Also:
Sequence.reverse(), Sequence.complement(), ComplementableDiscreteAlphabet

flatCloneWithoutAnnotation

protected Sequence flatCloneWithoutAnnotation()
Description copied from class: Sequence
Works in analogy to Object.clone(), but does not clone the annotation. This method is used in Sequence.annotate(boolean, SequenceAnnotation...).

Specified by:
flatCloneWithoutAnnotation in class Sequence
Returns:
the cloned Sequence.CompositeSequence without annotation