Interface GappedSymbolList

  • All Superinterfaces:
    Changeable, SymbolList
    All Known Subinterfaces:
    GappedSequence
    All Known Implementing Classes:
    SimpleGappedSequence, SimpleGappedSymbolList

    public interface GappedSymbolList
    extends SymbolList
    This extends SymbolList with API for manipulating, inserting and deleting gaps.

    You could make a SymbolList that contains gaps directly. However, this leaves you with a nasty problem if you wish to support gap-edit operations. Also, the original SymbolList must either be coppied or lost.

    GappedSymbolList solves these problems. It will maintain a data-structure that places gaps. You can add and remove the gaps by using the public API.

    For gap-insert operations, the insert index is the position that will become a gap. The symbol currently there will move to a higher index. To insert leading gaps, add gaps at index 1. To insert trailing gaps, add gaps at index length+1.

    Since:
    1.3
    Author:
    Matthew Pocock
    • Method Detail

      • viewToSource

        int viewToSource​(int indx)
                  throws IndexOutOfBoundsException
        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).

        Parameters:
        indx - the index to project
        Returns:
        the position of indx projected from view to source
        Throws:
        IndexOutOfBoundsException - if indx is not a valid view index
      • addGapInView

        void addGapInView​(int pos)
                   throws IndexOutOfBoundsException
        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.

        Parameters:
        pos - the position to add a gap before
        Throws:
        IndexOutOfBoundsException - if pos is not within 1->length+1
      • addGapsInView

        void addGapsInView​(int pos,
                           int length)
                    throws IndexOutOfBoundsException
        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.

        Parameters:
        pos - the position to add a gap before
        length - the number of gaps to insert
        Throws:
        IndexOutOfBoundsException - if pos is not within 1->length+1
      • firstNonGap

        int firstNonGap()
        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.

        Returns:
        the index of the first character not to be a gap
      • lastNonGap

        int lastNonGap()
        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.

        Returns:
        the index of the last character not to be a gap
      • getUngappedLocation

        Location getUngappedLocation()
        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.

        Returns:
        a new Location that contains all non-gap symbols