Class AbstractAlphabet
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojava.bio.symbol.AbstractAlphabet
-
- All Implemented Interfaces:
Serializable,Annotatable,Alphabet,FiniteAlphabet,Changeable
- Direct Known Subclasses:
IntegerAlphabet.SubIntegerAlphabet,SimpleAlphabet,SingletonAlphabet
public abstract class AbstractAlphabet extends AbstractChangeable implements FiniteAlphabet, Serializable
An abstract implementation of
Alphabet.This provides the frame-work for maintaining the SymbolParser <-> name mappings and also for the ChangeListeners.
This class is for developers to derive from, not for use directly.
- Since:
- 1.1
- Author:
- Matthew Pocock, Greg Cox, Francois Pepin, Mark Schreiber
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.biojava.bio.Annotatable
Annotatable.AnnotationForwarder
-
-
Field Summary
Fields Modifier and Type Field Description static longserialVersionUID-
Fields inherited from interface org.biojava.bio.symbol.Alphabet
EMPTY_ALPHABET, PARSERS, SYMBOLS
-
Fields inherited from interface org.biojava.bio.Annotatable
ANNOTATION
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractAlphabet()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddSymbol(Symbol s)Adds a symbol to this alphabet.protected abstract voidaddSymbolImpl(AtomicSymbol s)booleancontains(Symbol sym)Returns whether or not this Alphabet contains the symbol.protected abstract booleancontainsImpl(AtomicSymbol s)SymbolgetAmbiguity(Set syms)Get a symbol that represents the set of symbols in syms.protected SymbolgetAmbiguityImpl(Set syms)Backend for getAmbiguity, called when it is actually necessarly to create a new symbol.SymbolgetGapSymbol()Get the 'gap' ambiguity symbol that is most appropriate for this alphabet.SymbolgetSymbol(List syms)Get a symbol from the Alphabet which corresponds to the specified ordered list of symbols.protected abstract AtomicSymbolgetSymbolImpl(List symList)SymbolTokenizationgetTokenization(String name)Get a SymbolTokenization by name.voidputTokenization(String name, SymbolTokenization parser)Assigns a symbol parser to a String object.protected ObjectreadResolve()To prevent duplication of a what should be a single instance of an existing alphabet.StringtoString()voidvalidate(Symbol sym)Throws a precanned IllegalSymbolException if the symbol is not contained within this Alphabet.-
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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.biojava.bio.symbol.Alphabet
getAlphabets, getName
-
Methods inherited from interface org.biojava.bio.Annotatable
getAnnotation
-
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
Methods inherited from interface org.biojava.bio.symbol.FiniteAlphabet
iterator, removeSymbol, size
-
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractAlphabet
protected AbstractAlphabet()
-
-
Method Detail
-
readResolve
protected Object readResolve() throws ObjectStreamException
To prevent duplication of a what should be a single instance of an existing alphabet. This method was written as protected so that subclasses even from other packages will inherit it. It should only be overridden with care.- Throws:
ObjectStreamException
-
putTokenization
public void putTokenization(String name, SymbolTokenization parser)
Assigns a symbol parser to a String object.
Afterwards, the parser can be retrieved using the getTokenization(Sting name) method.
-
getTokenization
public SymbolTokenization getTokenization(String name) throws NoSuchElementException, BioException
Description copied from interface:AlphabetGet a SymbolTokenization by name.
The parser returned is guaranteed to return Symbols and SymbolLists that conform to this alphabet.
Every alphabet should have a SymbolTokenzation under the name 'token' that uses the symbol token characters to translate a string into a SymbolList. Likewise, there should be a SymbolTokenization under the name 'name' that uses symbol names to identify symbols. Any other names may also be defined, but the behavior of the returned SymbolTokenization is not defined here.
A SymbolTokenization under the name 'default' should be defined for all sequences, that determines the behavior when printing out a sequence. Standard behavior is to define the 'token' SymbolTokenization as default if it exists, else to define the 'name' SymbolTokenization as the default, but others are possible.
- Specified by:
getTokenizationin interfaceAlphabet- Parameters:
name- the name of the parser- Returns:
- a parser for that name
- Throws:
NoSuchElementException- if the name is unknownBioException- if for any reason the tokenization could not be built
-
getAmbiguity
public final Symbol getAmbiguity(Set syms) throws IllegalSymbolException
Description copied from interface:AlphabetGet a symbol that represents the set of symbols in syms.
Syms must be a set of Symbol instances each of which is contained within this alphabet. This method is used to retrieve ambiguity symbols.
- Specified by:
getAmbiguityin interfaceAlphabet- Parameters:
syms- the Set of Symbols that will be found in getMatches of the returned symbol- Returns:
- a Symbol (possibly fly-weighted) for the Set of symbols in syms
- Throws:
IllegalSymbolException
-
getAmbiguityImpl
protected Symbol getAmbiguityImpl(Set syms) throws IllegalSymbolException
Backend for getAmbiguity, called when it is actually necessarly to create a new symbol. By default, calls AlphabetManager.createSymbol.- Throws:
IllegalSymbolException- Since:
- 1.3
-
getSymbol
public final Symbol getSymbol(List syms) throws IllegalSymbolException
Description copied from interface:AlphabetGet a symbol from the Alphabet which corresponds to the specified ordered list of symbols.
The symbol at i in the list must be a member of the i'th alphabet in getAlphabets. If all of the symbols in rl are atomic, then the resulting symbol will also be atomic. If any one of them is an ambiguity symbol then the resulting symbol will be the appropriate ambiguity symbol.
- Specified by:
getSymbolin interfaceAlphabet- Parameters:
syms- A list of Symbol instances- Throws:
IllegalSymbolException- if the members of rl are not Symbols over the alphabets returned fromgetAlphabets
-
getSymbolImpl
protected abstract AtomicSymbol getSymbolImpl(List symList) throws IllegalSymbolException
- Throws:
IllegalSymbolException
-
addSymbolImpl
protected abstract void addSymbolImpl(AtomicSymbol s) throws IllegalSymbolException, ChangeVetoException
-
addSymbol
public final void addSymbol(Symbol s) throws IllegalSymbolException, ChangeVetoException
Description copied from interface:FiniteAlphabetAdds a symbol to this alphabet.If the symbol matches more than one AtomicSymbol, then each symbol matching it will be added.
- Specified by:
addSymbolin interfaceFiniteAlphabet- Parameters:
s- the Symbol to add- Throws:
IllegalSymbolException- if the symbol is null, or if for any reason it can't be addedChangeVetoException- if either the alphabet doesn't allow symbols to be added, or the change was vetoed
-
contains
public final boolean contains(Symbol sym)
Description copied from interface:AlphabetReturns whether or not this Alphabet contains the symbol.
An alphabet contains an ambiguity symbol iff the ambiguity symbol's getMatches() returns an alphabet that is a proper sub-set of this alphabet. That means that every one of the symbols that could match the ambiguity symbol is also a member of this alphabet.
-
getGapSymbol
public final Symbol getGapSymbol()
Description copied from interface:AlphabetGet the 'gap' ambiguity symbol that is most appropriate for this alphabet.
In general, this will be a BasisSymbol that represents a list of AlphabetManager.getGapSymbol() the same length as the getAlphabets list.
- Specified by:
getGapSymbolin interfaceAlphabet- Returns:
- the appropriate gap Symbol instance
-
validate
public final void validate(Symbol sym) throws IllegalSymbolException
Description copied from interface:AlphabetThrows a precanned IllegalSymbolException if the symbol is not contained within this Alphabet.
This function is used all over the code to validate symbols as they enter a method. Also, the code is littered with catches for IllegalSymbolException. There is a preferred style of handling this, which should be covererd in the package documentation.
- Specified by:
validatein interfaceAlphabet- Parameters:
sym- the Symbol to validate- Throws:
IllegalSymbolException- if r is not contained in this alphabet
-
containsImpl
protected abstract boolean containsImpl(AtomicSymbol s)
-
-