Class SimpleGappedSymbolList
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojava.bio.symbol.AbstractSymbolList
-
- org.biojava.bio.symbol.SimpleGappedSymbolList
-
- All Implemented Interfaces:
Serializable,GappedSymbolList,SymbolList,Changeable
- Direct Known Subclasses:
SimpleGappedSequence
public class SimpleGappedSymbolList extends AbstractSymbolList implements GappedSymbolList, 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classSimpleGappedSymbolList.BlockAn aligned block.-
Nested classes/interfaces inherited from class org.biojava.bio.symbol.AbstractSymbolList
AbstractSymbolList.EditScreener, AbstractSymbolList.EditTranslater
-
-
Field Summary
-
Fields inherited from interface org.biojava.bio.symbol.SymbolList
EDIT, EMPTY_LIST
-
-
Constructor Summary
Constructors Constructor Description SimpleGappedSymbolList(Alphabet alpha)SimpleGappedSymbolList(GappedSymbolList gappedSource)Create a new SimpleGappedSymbolList that will view source, inheriting all existing gaps.SimpleGappedSymbolList(SymbolList source)Create a new SimpleGappedSymbolList that will view source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGapInSource(int pos)Add a gap at pos within the source coordinates.voidaddGapInView(int pos)Add a single gap at pos within the view coordintates.voidaddGapsInSource(int pos, int length)Add length gaps at pos within the source coordinates.voidaddGapsInView(int pos, int length)Add length gaps at pos within the view coordinates.List<SimpleGappedSymbolList.Block>BlockIterator()Get list of the un-gapped region of the SymbolList.voiddumpBlocks()Debugging methodprotected intfindSourceBlock(int indx)Finds the index of the block containing the source coordinate indx.protected intfindSourceGap(int indx)Finds the index of the Block before the gap at indx within the following gap.protected intfindViewBlock(int indx)Finds the index of the Block containing indx within the view ranges.protected intfindViewGap(int indx)Finds the index of the Block before the gap at indx within the view range.intfirstNonGap()Return the index of the first Symbol that is not a Gap character.LocationgappedToLocation(Location l)Translates a Location from the gapped view into the underlying sequence.AlphabetgetAlphabet()The alphabet that this SymbolList is over.SymbolListgetSourceSymbolList()Return the underlying (ungapped) SymbolList.LocationgetUngappedLocation()Get a Location that contains exactly those positions that are not gaps.protected booleanisSane()intlastNonGap()Return the index of the last Symbol that is not a Gap character.intlength()The number of symbols in this SymbolList.LocationlocationToGapped(Location l)Translate a Location onto the gapped view, splitting blocks if necessaryvoidremoveGap(int pos)Remove a single gap at position pos in this GappedSymbolList.voidremoveGaps(int pos, int length)Remove some gaps at position pos in this GappedSymbolList.protected voidrenumber(int i, int delta)Renumber the view indexes from block, adding delta to each offset.intsourceToView(int indx)Coordinate conversion from source to view.protected intsourceToView(SimpleGappedSymbolList.Block b, int indx)Coordinate conversion from source to view.SymbolsymbolAt(int indx)Return the symbol at index, counting from 1.intviewToSource(int indx)Coordinate conversion from view to source.protected intviewToSource(SimpleGappedSymbolList.Block b, int indx)Coordinate conversion from view to source.-
Methods inherited from class org.biojava.bio.symbol.AbstractSymbolList
edit, equals, hashCode, iterator, seqString, subList, subStr, toList, toString
-
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
-
-
-
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
-
SimpleGappedSymbolList
public SimpleGappedSymbolList(Alphabet alpha)
-
-
Method Detail
-
addGapInSource
public void addGapInSource(int pos) throws IndexOutOfBoundsException
Description copied from interface:GappedSymbolListAdd a gap at pos within the source coordinates.- Specified by:
addGapInSourcein interfaceGappedSymbolList- Parameters:
pos- where to add the gap- Throws:
IndexOutOfBoundsException- if pos is not within 1->source.length()
-
addGapInView
public void addGapInView(int pos) throws IndexOutOfBoundsException
Description copied from interface:GappedSymbolListAdd 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:
addGapInViewin interfaceGappedSymbolList- Parameters:
pos- the position to add a gap before- Throws:
IndexOutOfBoundsException- if pos is not within 1->length+1
-
addGapsInSource
public void addGapsInSource(int pos, int length)
Description copied from interface:GappedSymbolListAdd length gaps at pos within the source coordinates.- Specified by:
addGapsInSourcein interfaceGappedSymbolList- Parameters:
pos- where to add the gaplength- how many gaps to add
-
addGapsInView
public void addGapsInView(int pos, int length) throws IndexOutOfBoundsException
Description copied from interface:GappedSymbolListAdd 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:
addGapsInViewin interfaceGappedSymbolList- Parameters:
pos- the position to add a gap beforelength- the number of gaps to insert- Throws:
IndexOutOfBoundsException- if pos is not within 1->length+1
-
BlockIterator
public List<SimpleGappedSymbolList.Block> 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
-
firstNonGap
public int firstNonGap()
Description copied from interface:GappedSymbolListReturn 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:
firstNonGapin interfaceGappedSymbolList- Returns:
- the index of the first character not to be a gap
-
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
-
getAlphabet
public Alphabet getAlphabet()
Description copied from interface:SymbolListThe alphabet that this SymbolList is over.Every symbol within this SymbolList is a member of this alphabet.
alphabet.contains(symbol) == truefor each symbol that is within this sequence.- Specified by:
getAlphabetin interfaceSymbolList- Returns:
- the alphabet
-
getSourceSymbolList
public SymbolList getSourceSymbolList()
Description copied from interface:GappedSymbolListReturn the underlying (ungapped) SymbolList.- Specified by:
getSourceSymbolListin interfaceGappedSymbolList
-
getUngappedLocation
public Location getUngappedLocation()
Description copied from interface:GappedSymbolListGet 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:
getUngappedLocationin interfaceGappedSymbolList- Returns:
- a new Location that contains all non-gap symbols
-
lastNonGap
public int lastNonGap()
Description copied from interface:GappedSymbolListReturn 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:
lastNonGapin interfaceGappedSymbolList- Returns:
- the index of the last character not to be a gap
-
length
public int length()
Description copied from interface:SymbolListThe number of symbols in this SymbolList.- Specified by:
lengthin interfaceSymbolList- Returns:
- the length
-
locationToGapped
public Location locationToGapped(Location l)
Translate a Location onto the gapped view, splitting blocks if necessary- Since:
- 1.3
-
removeGap
public void removeGap(int pos) throws IndexOutOfBoundsException, IllegalSymbolException
Description copied from interface:GappedSymbolListRemove a single gap at position pos in this GappedSymbolList.- Specified by:
removeGapin interfaceGappedSymbolList- Parameters:
pos- where to remove the gap- Throws:
IndexOutOfBoundsException- if pos is not within 1..lengthIllegalSymbolException- if the symbol at pos is not a gap
-
removeGaps
public void removeGaps(int pos, int length) throws IndexOutOfBoundsException, IllegalSymbolException
Description copied from interface:GappedSymbolListRemove some gaps at position pos in this GappedSymbolList.- Specified by:
removeGapsin interfaceGappedSymbolList- Parameters:
pos- where to remove the gapslength- how many to remove- Throws:
IndexOutOfBoundsException- if pos is not within 1..length() or if some of the Symbols within pos->(pos+length-1) are not gap SymbolsIllegalSymbolException- if the symbol at pos is not a gap
-
sourceToView
public final int sourceToView(int indx) throws IndexOutOfBoundsException
Description copied from interface:GappedSymbolListCoordinate conversion from source to view.- Specified by:
sourceToViewin interfaceGappedSymbolList- Parameters:
indx- the index to project- Returns:
- the position of indx projected from source to view
- Throws:
IndexOutOfBoundsException- if indx is not a valid source index
-
symbolAt
public Symbol symbolAt(int indx) throws IndexOutOfBoundsException
Description copied from interface:SymbolListReturn the symbol at index, counting from 1.- Specified by:
symbolAtin interfaceSymbolList- Parameters:
indx- the offset into this SymbolList- Returns:
- the Symbol at that index
- Throws:
IndexOutOfBoundsException- if index is less than 1, or greater than the length of the symbol list
-
viewToSource
public final int viewToSource(int indx) throws IndexOutOfBoundsException
Description copied from interface:GappedSymbolListCoordinate 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:
viewToSourcein interfaceGappedSymbolList- 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
-
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
-
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
-
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
-
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
-
isSane
protected boolean isSane()
-
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
-
sourceToView
protected final int sourceToView(SimpleGappedSymbolList.Block b, int indx)
Coordinate conversion from source to view.- Parameters:
b- the block containing indxindx- the index to project- Returns:
- the position of indx projected from source to view
-
viewToSource
protected final int viewToSource(SimpleGappedSymbolList.Block b, int indx)
Coordinate conversion from view to source.- Parameters:
b- the block containing indxindx- the index to project- Returns:
- the position of indx projected from view to source
-
-