Class JoiningSequenceReader<C extends Compound>

java.lang.Object
org.biojava3.core.sequence.storage.JoiningSequenceReader<C>
Type Parameters:
C - Tyoe of compound to hold
All Implemented Interfaces:
Iterable<C>, Accessioned, ProxySequenceReader<C>, Sequence<C>, SequenceReader<C>

public class JoiningSequenceReader<C extends Compound> extends Object implements ProxySequenceReader<C>
This reader actually proxies onto multiple types of sequence in order to allow a number of sequence objects to act as if they are one sequence. The code takes in any number of sequences, records the minimum and maximum bounds each sequence covers with respect to 1 position indexing and then binary searches these when a position is requested. Because of this 0 length Sequences are excluded during construction. Performance is not as good as if you are using a flat sequence however the speed of lookup is more than adaquate for most situations. Using the iterator gives the best performance as this does not rely on the binary search mechanism instead iterating through each sequence in turn.
Author:
ayates
  • Constructor Details

    • JoiningSequenceReader

      public JoiningSequenceReader(Sequence<C>... sequences)
      Allows creation of the store from Vargs Sequence objects. CompoundSet defaults to the first element of the array (assuming there are elements available during construction otherwise we will throw an illegal state exception).
    • JoiningSequenceReader

      public JoiningSequenceReader(List<Sequence<C>> sequences)
      Allows creation of the store from List<Sequence>. CompoundSet defaults to the first element of the List (assuming there are elements available during construction otherwise we will throw an illegal state exception).
    • JoiningSequenceReader

      @SafeVarargs public JoiningSequenceReader(CompoundSet<C> compoundSet, Sequence<C>... sequences)
    • JoiningSequenceReader

      public JoiningSequenceReader(CompoundSet<C> compoundSet, List<Sequence<C>> sequences)
  • Method Details

    • getCompoundAt

      public C getCompoundAt(int position)
      Description copied from interface: Sequence
      Returns the Compound at the given biological index
      Specified by:
      getCompoundAt in interface Sequence<C extends Compound>
      Parameters:
      position - Biological index (1 to n)
      Returns:
      Compound at the specified position
    • getCompoundSet

      public CompoundSet<C> getCompoundSet()
      Description copied from interface: Sequence
      Gets the compound set used to back this Sequence
      Specified by:
      getCompoundSet in interface Sequence<C extends Compound>
    • getLength

      public int getLength()
      Description copied from interface: Sequence
      Returns the length of the Sequence
      Specified by:
      getLength in interface Sequence<C extends Compound>
    • iterator

      public Iterator<C> iterator()
      Iterator implementation which attempts to move through the 2D structure attempting to skip onto the next sequence as & when it is asked to
      Specified by:
      iterator in interface Iterable<C extends Compound>
    • setCompoundSet

      public void setCompoundSet(CompoundSet<C> compoundSet)
      Specified by:
      setCompoundSet in interface SequenceReader<C extends Compound>
    • setContents

      public void setContents(String sequence)
      Specified by:
      setContents in interface SequenceReader<C extends Compound>
    • countCompounds

      public int countCompounds(C... compounds)
      Description copied from interface: Sequence
      Returns the number of times we found a compound in the Sequence
      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
    • getAccession

      public AccessionID getAccession() throws UnsupportedOperationException
      Description copied from interface: Accessioned
      Returns the AccessionID this location is currently bound with
      Specified by:
      getAccession in interface Accessioned
      Throws:
      UnsupportedOperationException
    • getAsList

      public List<C> getAsList()
      Description copied from interface: Sequence
      Returns the Sequence as a List of compounds
      Specified by:
      getAsList in interface Sequence<C extends Compound>
    • getIndexOf

      public int getIndexOf(C compound)
      Description copied from interface: Sequence
      Scans through the Sequence looking for the first occurrence of the given compound
      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)
      Description copied from interface: Sequence
      Scans through the Sequence looking for the last occurrence of the given compound
      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()
      Description copied from interface: Sequence
      Returns the String representation of the Sequence
      Specified by:
      getSequenceAsString in interface Sequence<C extends Compound>
    • 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 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
    • 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>