Class BitSequenceReader<C extends Compound>
- java.lang.Object
-
- org.biojava.nbio.core.sequence.storage.BitSequenceReader<C>
-
- Type Parameters:
C
- Type of compound; must extendNucleotideCompound
- All Implemented Interfaces:
Iterable<C>
,Accessioned
,ProxySequenceReader<C>
,Sequence<C>
,SequenceReader<C>
- Direct Known Subclasses:
FourBitSequenceReader
,TwoBitSequenceReader
public class BitSequenceReader<C extends Compound> extends Object implements ProxySequenceReader<C>
An implementation of the popular bit encodings. This class provides the Sequence view over what is actually carried out in theBitSequenceReader.BitArrayWorker
instances. These are the objects that carry out array storage as well as indexing into those arrays. New bit encodings can be written by extending this class and a worker class. There are a number of issues with this type of storage engine:- We can only support a finite number of
Compound
s; 2 bit allows no N compounds - For real savings you must read the sequence in using your own
Reader and a
BitSequenceReader.BitArrayWorker
instance
- Author:
- ayates
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BitSequenceReader.BitArrayWorker<C extends Compound>
The logic of working with a bit has been separated out into this class to help developers create the bit data structures without having to put the code into an intermediate format and to also use the format without the need to copy this code.
-
Constructor Summary
Constructors Constructor Description BitSequenceReader(BitSequenceReader.BitArrayWorker<C> worker, AccessionID accession)
Instance which allows you to supply a different @{BitArrayWorker} object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
countCompounds(C... compounds)
Counts the number of times a compound appears in this sequence storeboolean
equals(Object o)
AccessionID
getAccession()
Returns the AccessionID this location is currently bound withList<C>
getAsList()
Returns this Sequence store as a ListC
getCompoundAt(int position)
Returns the compound at the specified biological indexCompoundSet<C>
getCompoundSet()
Returns the compound set backing this storeint
getIndexOf(C compound)
Returns the first occurrence of the given compound in this store; performs a linear searchSequenceView<C>
getInverse()
Does the right thing to get the inverse of the current Sequence.int
getLastIndexOf(C compound)
Returns the last occurrence of the given compound in this store; performs a linear searchint
getLength()
Returns the length of the sequenceString
getSequenceAsString()
Returns the sequence as a StringSequenceView<C>
getSubSequence(int start, int end)
Returns a sub sequence viewSequenceView<C>
getSubSequence(Integer start, Integer end)
Returns a portion of the sequence from the different positions.int
hashCode()
Iterator<C>
iterator()
Provides basic iterable access to this classvoid
setCompoundSet(CompoundSet<C> compoundSet)
Class is immutable & so this is unsupportedvoid
setContents(String sequence)
Class is immutable & so this is unsupported-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
BitSequenceReader
public BitSequenceReader(BitSequenceReader.BitArrayWorker<C> worker, AccessionID accession)
Instance which allows you to supply a different @{BitArrayWorker} object.
-
-
Method Detail
-
setCompoundSet
public void setCompoundSet(CompoundSet<C> compoundSet)
Class is immutable & so this is unsupported- Specified by:
setCompoundSet
in interfaceSequenceReader<C extends Compound>
-
setContents
public void setContents(String sequence) throws CompoundNotFoundException
Class is immutable & so this is unsupported- Specified by:
setContents
in interfaceSequenceReader<C extends Compound>
- Throws:
CompoundNotFoundException
-
countCompounds
public int countCompounds(C... compounds)
Counts the number of times a compound appears in this sequence store- Specified by:
countCompounds
in interfaceSequence<C extends Compound>
- Parameters:
compounds
- Vargs of the compounds to count- Returns:
- Number of times a compound was found
-
getAccession
public AccessionID getAccession()
Description copied from interface:Accessioned
Returns the AccessionID this location is currently bound with- Specified by:
getAccession
in interfaceAccessioned
-
getCompoundAt
public C getCompoundAt(int position)
Returns the compound at the specified biological index- Specified by:
getCompoundAt
in interfaceSequence<C extends Compound>
- Parameters:
position
- Biological index (1 to n)- Returns:
- Compound at the specified position
-
getCompoundSet
public CompoundSet<C> getCompoundSet()
Returns the compound set backing this store- Specified by:
getCompoundSet
in interfaceSequence<C extends Compound>
-
getIndexOf
public int getIndexOf(C compound)
Returns the first occurrence of the given compound in this store; performs a linear search- Specified by:
getIndexOf
in interfaceSequence<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 last occurrence of the given compound in this store; performs a linear search- Specified by:
getLastIndexOf
in interfaceSequence<C extends Compound>
- Parameters:
compound
- Compounds to look for- Returns:
- Index of the last position of the compound in the sequence (1 to n)
-
getLength
public int getLength()
Returns the length of the sequence
-
getSequenceAsString
public String getSequenceAsString()
Returns the sequence as a String- Specified by:
getSequenceAsString
in interfaceSequence<C extends Compound>
-
getSubSequence
public SequenceView<C> getSubSequence(int start, int end)
Returns a sub sequence view
-
getSubSequence
public SequenceView<C> getSubSequence(Integer start, Integer end)
Description copied from interface:Sequence
Returns a portion of the sequence from the different positions. This is indexed from 1- Specified by:
getSubSequence
in interfaceSequence<C extends Compound>
- Parameters:
start
- Biological index start; must be greater than 0end
- Biological end; must be less than length + 1- Returns:
- A SequenceView of the offset
-
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 interfaceSequence<C extends Compound>
-
-