Class SimpleSymbolList
- All Implemented Interfaces:
Serializable
,EventListener
,SymbolList
,Changeable
,ChangeListener
SimpleSymbolList is now editable. edit() has been implemented in a way that edits are relatively inefficient, but symbolAt() is very efficient.
A new constructor SimpleSymbolList(SymbolParser,String) has been added so you can now simply turn a String into a SymbolList. This is mostly to provide a simple way to create a SymbolList for people just trying to get their feet wet. So here is an example.
String seqString = "gaattc";
FiniteAlphabet dna = (FiniteAlphabet) AlphabetManager.alphabetForName("DNA");
SymbolParser parser = dna.getTokenization("token");
SymbolList mySl = new SimpleSymbolList (parser,seqString);
System.out.println("Look at my sequence " + mySl.seqString());
with the right parser you should be able to make a protein sequence from the String "AspAlaValIleAsp"
subList() is implemented such that subLists are views of the original until such time as the underlying SymbolList is edited in a way that would modify the subList, at which point the subList gets its own array of Symbols and does not reflect the edit to the original. When subList() is called on another subList (which is a veiw SimpleSymbolList) the new SimpleSymbolList is a view of the original, not the subList.
- Author:
- Thomas Down, David Waring, David Huen (another constructor), George Waldon
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.biojava.bio.symbol.AbstractSymbolList
AbstractSymbolList.EditScreener, AbstractSymbolList.EditTranslater
Nested classes/interfaces inherited from interface org.biojava.utils.ChangeListener
ChangeListener.AlwaysVetoListener, ChangeListener.ChangeEventRecorder, ChangeListener.LoggingListener
-
Field Summary
Fields inherited from interface org.biojava.utils.ChangeListener
ALWAYS_VETO, LOG_TO_OUT
Fields inherited from interface org.biojava.bio.symbol.SymbolList
EDIT, EMPTY_LIST
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleSymbolList
(SymbolTokenization parser, String seqString) Construct a SymbolList from a string.SimpleSymbolList
(Alphabet alpha) Construct an empty SimpleSymbolList.SimpleSymbolList
(Alphabet alpha, List rList) Construct a SymbolList containing the symbols in the specified list.SimpleSymbolList
(Symbol[] symbols, int length, Alphabet alphabet) Construct a SimpleSymbolList given the Symbol array that backs it.Construct a copy of an existing SymbolList. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new Symbol to the end of this list.void
Apply and edit to the SymbolList as specified by Edit.protected void
finalize()
Get the alphabet of this SymbolList.Symbol[]
Return the Java Symbol[] array that backs this object.int
length()
Get the length of this SymbolList.void
postChange
(ChangeEvent cev) Called when a change has just taken place.void
preChange
(ChangeEvent cev) On preChange() we convert the SymolList to a non-veiw version, giving it its own copy of symbolssubList
(int start, int end) create a subList of the original, this will be a view until either the original symbolList or the sublist is editedsymbolAt
(int pos) Find a symbol at a specified offset in the SymbolList.Methods inherited from class org.biojava.bio.symbol.AbstractSymbolList
equals, hashCode, iterator, seqString, subStr, toList, toString
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
Constructor Details
-
SimpleSymbolList
Construct an empty SimpleSymbolList.- Parameters:
alpha
- The alphabet of legal symbols in this list.
-
SimpleSymbolList
Construct a SymbolList containing the symbols in the specified list.- Parameters:
alpha
- The alphabet of legal symbols for this list.rList
- A Java List of symbols.- Throws:
IllegalSymbolException
- if a Symbol is not in the specified alphabet.ClassCastException
- if rList contains objects which do not implement Symbol.
-
SimpleSymbolList
Construct a SymbolList from a string.- Parameters:
parser
- A SymbolParser for whatever your string is -- e.g. alphabet.getParser("token").seqString
- A Java List of symbols.- Throws:
IllegalSymbolException
- if a Symbol is not in the specified alphabet.
-
SimpleSymbolList
Construct a copy of an existing SymbolList.- Parameters:
sl
- the list to copy.
-
SimpleSymbolList
Construct a SimpleSymbolList given the Symbol array that backs it. Used primarily with the chunked SymbolList builder but could be used elsewhere too.
-
-
Method Details
-
finalize
-
getAlphabet
Get the alphabet of this SymbolList.- Specified by:
getAlphabet
in interfaceSymbolList
- Returns:
- the alphabet
-
length
Get the length of this SymbolList.- Specified by:
length
in interfaceSymbolList
- Returns:
- the length
-
symbolAt
Find a symbol at a specified offset in the SymbolList.- Specified by:
symbolAt
in interfaceSymbolList
- Parameters:
pos
- Position in biological coordinates (1..length)- Returns:
- the Symbol at that index
-
subList
create a subList of the original, this will be a view until either the original symbolList or the sublist is edited- Specified by:
subList
in interfaceSymbolList
- Overrides:
subList
in classAbstractSymbolList
- Parameters:
start
- the first symbol of the new SymbolListend
- the last symbol (inclusive) of the new SymbolList
-
edit
public void edit(Edit edit) throws IndexOutOfBoundsException, IllegalAlphabetException, ChangeVetoException Apply and edit to the SymbolList as specified by Edit.edit() is now supported using the ChangeEvent system. SubLists do NOT reflect edits.
- Specified by:
edit
in interfaceSymbolList
- Overrides:
edit
in classAbstractSymbolList
- Parameters:
edit
- the Edit to perform- Throws:
IndexOutOfBoundsException
- if the edit does not lie within the SymbolListIllegalAlphabetException
- if the SymbolList to insert has an incompatible alphabetChangeVetoException
- if either the SymboList does not support the edit, or if the change was vetoed
-
preChange
On preChange() we convert the SymolList to a non-veiw version, giving it its own copy of symbols- Specified by:
preChange
in interfaceChangeListener
- Parameters:
cev
- An event encapsulating the change which is about to take place.- Throws:
ChangeVetoException
- Description of ExceptionChangeVetoException
- if the receiver does not wish this change to occur at this time.
-
postChange
Description copied from interface:ChangeListener
Called when a change has just taken place.
This method is the place to perform any behavior in response to the change event.
- Specified by:
postChange
in interfaceChangeListener
- Parameters:
cev
- An event encapsulating the change which has occured.
-
addSymbol
Add a new Symbol to the end of this list.- Parameters:
sym
- Symbol to add- Throws:
IllegalSymbolException
- if the Symbol is not in this list's alphabetChangeVetoException
-
getSymbolArray
Return the Java Symbol[] array that backs this object. primarily used to accelerate reconstruction of symbol lists in the packed chunked symbol list implementation.
-