Class SimpleGappedSymbolList

  • All Implemented Interfaces:
    java.io.Serializable, GappedSymbolList, SymbolList, Changeable
    Direct Known Subclasses:
    SimpleGappedSequence

    public class SimpleGappedSymbolList
    extends AbstractSymbolList
    implements GappedSymbolList, java.io.Serializable
    This implementation of GappedSymbolList wraps a SymbolList, allowing you to insert gaps. Please note that this is a view onto another SymbolList. Gaps created and removed are only in the view not the underlying original. This means that any gaps present in the original cannot be manipulated in this view. To manipulate the original you would need to use Edit objects.
    Since:
    1.3
    Author:
    Matthew Pocock
    See Also:
    Serialized Form
    • Constructor Detail

      • SimpleGappedSymbolList

        public SimpleGappedSymbolList​(GappedSymbolList gappedSource)
        Create a new SimpleGappedSymbolList that will view source, inheriting all existing gaps.
        Parameters:
        gappedSource - the underlying sequence
      • SimpleGappedSymbolList

        public SimpleGappedSymbolList​(SymbolList source)
        Create a new SimpleGappedSymbolList that will view source.
        Parameters:
        source - the underlying sequence
    • Method Detail

      • findSourceBlock

        protected final int findSourceBlock​(int indx)
        Finds the index of the block containing the source coordinate indx.
        Parameters:
        indx - the index to find
        Returns:
        the index of the Block containing indx
      • findViewBlock

        protected final int findViewBlock​(int indx)
        Finds the index of the Block containing indx within the view ranges.

        If indx is not within a view block, then it is the index of a gap. The method will return -(indx+1) where indx is the block emediately following the gap.

        Parameters:
        indx - the index to find within a view range.
        Returns:
        the index of the block containing index or one less than the negative of the index of the block following the gap
      • findSourceGap

        protected final int findSourceGap​(int indx)
        Finds the index of the Block before the gap at indx within the following gap.
        Parameters:
        indx - the index to find within a gap
        Returns:
        the index of the block with indx in the gap
      • findViewGap

        protected final int findViewGap​(int indx)
        Finds the index of the Block before the gap at indx within the view range.

        If indx is in-fact a real symbol, then there will be no Block before it. In this case, the method returns -2. It returns -1 if indx is within the leading gaps and blocks.size()-1 if it is within the trailing gaps.

        Parameters:
        indx - the index to find within a view range
        Returns:
        the index of the block with indx in the following gap
      • viewToSource

        protected final int viewToSource​(SimpleGappedSymbolList.Block b,
                                         int indx)
        Coordinate conversion from view to source.
        Parameters:
        b - the block containing indx
        indx - the index to project
        Returns:
        the position of indx projected from view to source
      • viewToSource

        public final int viewToSource​(int indx)
                               throws java.lang.IndexOutOfBoundsException
        Description copied from interface: GappedSymbolList
        Coordinate conversion from view to source.

        If the index can be projected onto the source, the index it projects onto is returned. If it falls within a gap, then the index of the first symbol after the run of gaps is negated and returned. If the index is after the last block of symbols (and therefore in the trailing list of gaps), then it returns -(length + 1).

        Specified by:
        viewToSource in interface GappedSymbolList
        Parameters:
        indx - the index to project
        Returns:
        the position of indx projected from view to source
        Throws:
        java.lang.IndexOutOfBoundsException - if indx is not a valid view index
      • sourceToView

        protected final int sourceToView​(SimpleGappedSymbolList.Block b,
                                         int indx)
        Coordinate conversion from source to view.
        Parameters:
        b - the block containing indx
        indx - the index to project
        Returns:
        the position of indx projected from source to view
      • sourceToView

        public final int sourceToView​(int indx)
                               throws java.lang.IndexOutOfBoundsException
        Description copied from interface: GappedSymbolList
        Coordinate conversion from source to view.
        Specified by:
        sourceToView in interface GappedSymbolList
        Parameters:
        indx - the index to project
        Returns:
        the position of indx projected from source to view
        Throws:
        java.lang.IndexOutOfBoundsException - if indx is not a valid source index
      • renumber

        protected final void renumber​(int i,
                                      int delta)
        Renumber the view indexes from block, adding delta to each offset.

        This adjusts viewStart and viewEnd to be += delta for each block i->blocks.size(), and sets the total length to += delta.

        Parameters:
        i - the first
      • addGapInView

        public void addGapInView​(int pos)
                          throws java.lang.IndexOutOfBoundsException
        Description copied from interface: GappedSymbolList
        Add a single gap at pos within the view coordintates.

        this.symbolAt(pos) will then return gap. Adding a gap at 1 will prepend gaps. Adding a gap at (length+1) will append a gap.

        Specified by:
        addGapInView in interface GappedSymbolList
        Parameters:
        pos - the position to add a gap before
        Throws:
        java.lang.IndexOutOfBoundsException - if pos is not within 1->length+1
      • addGapsInView

        public void addGapsInView​(int pos,
                                  int length)
                           throws java.lang.IndexOutOfBoundsException
        Description copied from interface: GappedSymbolList
        Add length gaps at pos within the view coordinates.

        this.symbolAt(i) will then return gap for i = (pos .. pos+count-1). Adding gaps at 1 will prepend gaps. Adding gaps at (length+1) will append gaps.

        Specified by:
        addGapsInView in interface GappedSymbolList
        Parameters:
        pos - the position to add a gap before
        length - the number of gaps to insert
        Throws:
        java.lang.IndexOutOfBoundsException - if pos is not within 1->length+1
      • addGapInSource

        public void addGapInSource​(int pos)
                            throws java.lang.IndexOutOfBoundsException
        Description copied from interface: GappedSymbolList
        Add a gap at pos within the source coordinates.
        Specified by:
        addGapInSource in interface GappedSymbolList
        Parameters:
        pos - where to add the gap
        Throws:
        java.lang.IndexOutOfBoundsException - if pos is not within 1->source.length()
      • addGapsInSource

        public void addGapsInSource​(int pos,
                                    int length)
        Description copied from interface: GappedSymbolList
        Add length gaps at pos within the source coordinates.
        Specified by:
        addGapsInSource in interface GappedSymbolList
        Parameters:
        pos - where to add the gap
        length - how many gaps to add
      • removeGap

        public void removeGap​(int pos)
                       throws java.lang.IndexOutOfBoundsException,
                              IllegalSymbolException
        Description copied from interface: GappedSymbolList
        Remove a single gap at position pos in this GappedSymbolList.
        Specified by:
        removeGap in interface GappedSymbolList
        Parameters:
        pos - where to remove the gap
        Throws:
        java.lang.IndexOutOfBoundsException - if pos is not within 1..length
        IllegalSymbolException - if the symbol at pos is not a gap
      • removeGaps

        public void removeGaps​(int pos,
                               int length)
                        throws java.lang.IndexOutOfBoundsException,
                               IllegalSymbolException
        Description copied from interface: GappedSymbolList
        Remove some gaps at position pos in this GappedSymbolList.
        Specified by:
        removeGaps in interface GappedSymbolList
        Parameters:
        pos - where to remove the gaps
        length - how many to remove
        Throws:
        java.lang.IndexOutOfBoundsException - if pos is not within 1..length() or if some of the Symbols within pos->(pos+length-1) are not gap Symbols
        IllegalSymbolException - if the symbol at pos is not a gap
      • getAlphabet

        public Alphabet getAlphabet()
        Description copied from interface: SymbolList
        The alphabet that this SymbolList is over.

        Every symbol within this SymbolList is a member of this alphabet. alphabet.contains(symbol) == true for each symbol that is within this sequence.

        Specified by:
        getAlphabet in interface SymbolList
        Returns:
        the alphabet
      • length

        public int length()
        Description copied from interface: SymbolList
        The number of symbols in this SymbolList.
        Specified by:
        length in interface SymbolList
        Returns:
        the length
      • symbolAt

        public Symbol symbolAt​(int indx)
                        throws java.lang.IndexOutOfBoundsException
        Description copied from interface: SymbolList
        Return the symbol at index, counting from 1.
        Specified by:
        symbolAt in interface SymbolList
        Parameters:
        indx - the offset into this SymbolList
        Returns:
        the Symbol at that index
        Throws:
        java.lang.IndexOutOfBoundsException - if index is less than 1, or greater than the length of the symbol list
      • firstNonGap

        public int firstNonGap()
        Description copied from interface: GappedSymbolList
        Return the index of the first Symbol that is not a Gap character.

        All symbols before firstNonGap are leading gaps. firstNonGap is effectively the index in the view of symbol 1 in the original sequence.

        Specified by:
        firstNonGap in interface GappedSymbolList
        Returns:
        the index of the first character not to be a gap
      • lastNonGap

        public int lastNonGap()
        Description copied from interface: GappedSymbolList
        Return the index of the last Symbol that is not a Gap character.

        All symbols after lastNonGap untill length are trailing gaps. lastNonGap is effectively the index in the view of symbol length in the original sequence.

        Specified by:
        lastNonGap in interface GappedSymbolList
        Returns:
        the index of the last character not to be a gap
      • BlockIterator

        public java.util.List BlockIterator()
        Get list of the un-gapped region of the SymbolList.

        The gapped symbol list can be represented as a list of ungapped regions. Given a list of start-stop pairs in the ungapped coordinate system each with a corresponding pair of start-stop pairs in the gapped view, the entire gapped list can be reconstructed.

        Returns:
        a List of Block instances
      • dumpBlocks

        public void dumpBlocks()
        Debugging method
      • locationToGapped

        public Location locationToGapped​(Location l)
        Translate a Location onto the gapped view, splitting blocks if necessary
        Since:
        1.3
      • gappedToLocation

        public Location gappedToLocation​(Location l)
        Translates a Location from the gapped view into the underlying sequence. End points that are in gaps are moved 'inwards' to shorten the location.
        Since:
        1.3
      • getUngappedLocation

        public Location getUngappedLocation()
        Description copied from interface: GappedSymbolList
        Get a Location that contains exactly those positions that are not gaps.

        This will be a Location that contains every symbol in the underlying ungapped sequence. Every symbol not in the Location is not from the underlying sequence and is a gap.

        Specified by:
        getUngappedLocation in interface GappedSymbolList
        Returns:
        a new Location that contains all non-gap symbols
      • isSane

        protected boolean isSane()