org.biojava3.core.sequence.storage
Class SingleCompoundSequenceReader<C extends Compound>

java.lang.Object
  extended by org.biojava3.core.sequence.storage.SingleCompoundSequenceReader<C>
All Implemented Interfaces:
Iterable<C>, Accessioned, ProxySequenceReader<C>, Sequence<C>, SequenceReader<C>

public class SingleCompoundSequenceReader<C extends Compound>
extends Object
implements ProxySequenceReader<C>

An implementation of the SequenceReader interface which for every call will return only 1 compound (given to it during construction; a String is also valid but will require a CompoundSet). The idea is to represent large runs of a single compound without the memory footprint of storing these compounds e.g. a run of 10KB of Ns in a DNASequence.

Author:
ayates

Constructor Summary
SingleCompoundSequenceReader(C compound, CompoundSet<C> compoundSet, int length)
          Build the object with a compound rather than a String
SingleCompoundSequenceReader(String compound, CompoundSet<C> compoundSet, int length)
          Public constructor to be used with String based constructor
 
Method Summary
 int countCompounds(C... compounds)
          Delegates to SequenceMixin#countCompounds(org.biojava3.core.sequence.template.Sequence, C[])
 boolean equals(Object o)
           
 AccessionID getAccession()
          Unsupoorted
 List<C> getAsList()
          Delegates to SequenceMixin.toList(org.biojava3.core.sequence.template.Sequence)
 C getCompoundAt(int position)
          Always returns the compound given at construction
 CompoundSet<C> getCompoundSet()
          Returns the compound set given at construction
 int getIndexOf(C compound)
          Returns 1 if the given compound is equal to the one given during construction; otherwise will return -1.
 SequenceView<C> getInverse()
          Does the right thing to get the inverse of the current Sequence.
 int getLastIndexOf(C compound)
          Returns the length of the Sequence if the given compound was equal to the one given during construction.
 int getLength()
          Returns the length given during construction
 String getSequenceAsString()
          Delegates to SequenceMixin.toList(org.biojava3.core.sequence.template.Sequence)
 SequenceView<C> getSubSequence(Integer start, Integer end)
          Creates a SequenceProxyView for the given coordinates
 int hashCode()
           
 Iterator<C> iterator()
          Returns an instance of SequenceMixin.SequenceIterator
 void setCompoundSet(CompoundSet<C> compoundSet)
          Unsupported
 void setContents(String sequence)
          Unsupported
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleCompoundSequenceReader

public SingleCompoundSequenceReader(String compound,
                                    CompoundSet<C> compoundSet,
                                    int length)
Public constructor to be used with String based constructor


SingleCompoundSequenceReader

public SingleCompoundSequenceReader(C compound,
                                    CompoundSet<C> compoundSet,
                                    int length)
Build the object with a compound rather than a String

Method Detail

setCompoundSet

public void setCompoundSet(CompoundSet<C> compoundSet)
Unsupported

Specified by:
setCompoundSet in interface SequenceReader<C extends Compound>

setContents

public void setContents(String sequence)
Unsupported

Specified by:
setContents in interface SequenceReader<C extends Compound>

getLength

public int getLength()
Returns the length given during construction

Specified by:
getLength in interface Sequence<C extends Compound>

getCompoundAt

public C getCompoundAt(int position)
Always returns the compound given at construction

Specified by:
getCompoundAt in interface Sequence<C extends Compound>
Parameters:
position - Biological index (1 to n)
Returns:
Compound at the specified position

getIndexOf

public int getIndexOf(C compound)
Returns 1 if the given compound is equal to the one given during construction; otherwise will return -1.

Specified by:
getIndexOf in interface Sequence<C extends Compound>
Parameters:
compound - Compounds to look for
Returns:
Index of the first position of the compound in the sequence (1 to n)

getLastIndexOf

public int getLastIndexOf(C compound)
Returns the length of the Sequence if the given compound was equal to the one given during construction. Otherwise returns -1

Specified by:
getLastIndexOf in interface Sequence<C extends Compound>
Parameters:
compound - Compounds to look for
Returns:
Index of the last position of the compound in the sequence (1 to n)

getSequenceAsString

public String getSequenceAsString()
Delegates to SequenceMixin.toList(org.biojava3.core.sequence.template.Sequence)

Specified by:
getSequenceAsString in interface Sequence<C extends Compound>

getAsList

public List<C> getAsList()
Delegates to SequenceMixin.toList(org.biojava3.core.sequence.template.Sequence)

Specified by:
getAsList in interface Sequence<C extends Compound>

getSubSequence

public SequenceView<C> getSubSequence(Integer start,
                                      Integer end)
Creates a SequenceProxyView for the given coordinates

Specified by:
getSubSequence in interface Sequence<C extends Compound>
Parameters:
start - Biological index start; must be greater than 0
end - Biological end; must be less than length + 1
Returns:
A SequenceView of the offset

getCompoundSet

public CompoundSet<C> getCompoundSet()
Returns the compound set given at construction

Specified by:
getCompoundSet in interface Sequence<C extends Compound>

getAccession

public AccessionID getAccession()
Unsupoorted

Specified by:
getAccession in interface Accessioned

countCompounds

public int countCompounds(C... compounds)
Delegates to SequenceMixin#countCompounds(org.biojava3.core.sequence.template.Sequence, C[])

Specified by:
countCompounds in interface Sequence<C extends Compound>
Parameters:
compounds - Vargs of the compounds to count
Returns:
Number of times a compound was found

iterator

public Iterator<C> iterator()
Returns an instance of SequenceMixin.SequenceIterator

Specified by:
iterator in interface Iterable<C extends Compound>

getInverse

public SequenceView<C> getInverse()
Description copied from interface: Sequence
Does the right thing to get the inverse of the current Sequence. This means either reversing the Sequence and optionally complementing the Sequence.

Specified by:
getInverse in interface Sequence<C extends Compound>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object