|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.biojava.bio.symbol.AlphabetManager
Utility methods for working with Alphabets. Also acts as a registry for well-known alphabets.
The alphabet interfaces themselves don't give you a lot of help in actually getting an alphabet instance. This is where the AlphabetManager comes in handy. It helps out in serialization, generating derived alphabets and building CrossProductAlphabet instances. It also contains limited support for parsing complex alphabet names back into the alphabets.
Constructor Summary | |
AlphabetManager()
|
Method Summary | |
static Alphabet |
alphabetForName(java.lang.String name)
Retrieve the alphabet for a specific name. |
static java.util.Iterator |
alphabets()
Get an iterator over all alphabets known. |
static Symbol |
createSymbol(Annotation annotation,
java.util.List symList,
Alphabet alpha)
Generates a new Symbol instance that represents the tuple of Symbols in symList. |
static Symbol |
createSymbol(Annotation annotation,
java.util.Set symSet,
Alphabet alpha)
Generates a new Symbol instance that represents the tuple of Symbols in symList. |
static Symbol |
createSymbol(char token,
Annotation annotation,
java.util.List symList,
Alphabet alpha)
Deprecated. use the new version, without the token argument |
static Symbol |
createSymbol(char token,
Annotation annotation,
java.util.Set symSet,
Alphabet alpha)
Deprecated. use the three-arg version of this method instead. |
static AtomicSymbol |
createSymbol(char token,
java.lang.String name,
Annotation annotation)
Deprecated. Use the two-arg version of this method instead. |
static AtomicSymbol |
createSymbol(java.lang.String name)
Generate a new AtomicSymbol instance with a name and an Empty Annotation. |
static AtomicSymbol |
createSymbol(java.lang.String name,
Annotation annotation)
Generate a new AtomicSymbol instance with a name and Annotation. |
static java.util.List |
factorize(Alphabet alpha,
java.util.Set symSet)
Return a list of BasisSymbol instances that uniquely sum up all AtomicSymbol instances in symSet. |
static Alphabet |
generateCrossProductAlphaFromName(java.lang.String name)
Generates a new CrossProductAlphabet from the give name. |
static Symbol |
getAllAmbiguitySymbol(FiniteAlphabet alpha)
Return the ambiguity symbol which matches all symbols in a given alphabet. |
static java.util.Set |
getAllSymbols(FiniteAlphabet alpha)
Return a set containing all possible symbols which can be considered members of a given alphabet, including ambiguous symbols. |
static AlphabetIndex |
getAlphabetIndex(FiniteAlphabet alpha)
Get an indexer for a specified alphabet. |
static AlphabetIndex |
getAlphabetIndex(Symbol[] syms)
Get an indexer for an array of symbols. |
static Alphabet |
getCrossProductAlphabet(java.util.List aList)
Retrieve a CrossProductAlphabet instance over the alphabets in aList. |
static Alphabet |
getCrossProductAlphabet(java.util.List aList,
Alphabet parent)
Retrieve a CrossProductAlphabet instance over the alphabets in aList. |
static Alphabet |
getCrossProductAlphabet(java.util.List aList,
java.lang.String name)
|
static Symbol |
getGapSymbol()
Get the special `gap' Symbol. |
static Symbol |
getGapSymbol(java.util.List alphas)
Get the gap symbol appropriate to this list of alphabets. |
static AlphabetManager |
instance()
Deprecated. all AlphabetManager methods have become static |
static void |
loadAlphabets(org.xml.sax.InputSource is)
Load additional Alphabets, defined in XML format, into the AlphabetManager's registry. |
static void |
registerAlphabet(java.lang.String name,
Alphabet alphabet)
Register an alphabet by name. |
static boolean |
registered(java.lang.String name)
Has an Alphabet been registered by that name |
static Symbol |
symbolForName(java.lang.String name)
Retrieve the symbol represented a String object |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AlphabetManager()
Method Detail |
public static Symbol getAllAmbiguitySymbol(FiniteAlphabet alpha)
public static java.util.Set getAllSymbols(FiniteAlphabet alpha)
public static AlphabetManager instance()
public static Alphabet alphabetForName(java.lang.String name) throws java.util.NoSuchElementException
name
- the name of the alphabet
java.util.NoSuchElementException
- if there is no alphabet by that namepublic static Symbol symbolForName(java.lang.String name) throws java.util.NoSuchElementException
name
- of the string whose symbol you want to get
java.util.NoSuchElementException
- if the string name is invalid.public static void registerAlphabet(java.lang.String name, Alphabet alphabet)
name
- the name by which it can be retrievedalphabet
- the Alphabet to storepublic static boolean registered(java.lang.String name)
name
- the name of the alphabet
public static java.util.Iterator alphabets()
public static Symbol getGapSymbol()
Get the special `gap' Symbol.
The gap symbol is a Symbol that has an empty alphabet of matches. As such , ever alphabet contains gap, as there is no symbol that matches gap, so there is no case where an alphabet doesn't contain a symbol that matches gap.
Gap can be thought of as an empty sub-space within the space of all possible symbols. If you are working in a cross-product alphabet, you should chose whether to use gap to represent 'no symbol', or a basis symbol of the appropriate size built entirely of gaps to represent 'no symbol in each of the slots'. Perhaps this could be explained better.
public static Symbol getGapSymbol(java.util.List alphas)
Get the gap symbol appropriate to this list of alphabets.
The gap symbol with have the same shape a the alphabet list. It will be as long as the list, and if any of the alphabets in the list have a dimension greater than 1, it will also insert the appropriate gap there.
alphas
- List of alphabets
public static AtomicSymbol createSymbol(java.lang.String name, Annotation annotation)
Generate a new AtomicSymbol instance with a name and Annotation.
Use this method if you wish to create an AtomicSymbol instance. Initially it will not be a member of any alphabet.
name
- the String returned by getName()annotation
- the Annotation returned by getAnnotation()
public static AtomicSymbol createSymbol(java.lang.String name)
Generate a new AtomicSymbol instance with a name and an Empty Annotation.
Use this method if you wish to create an AtomicSymbol instance. Initially it will not be a member of any alphabet.
name
- the String returned by getName()
public static AtomicSymbol createSymbol(char token, java.lang.String name, Annotation annotation)
Generate a new AtomicSymbol instance with a token, name and Annotation.
Use this method if you wish to create an AtomicSymbol instance. Initially it will not be a member of any alphabet.
token
- the Char token returned by getToken() (ignpred as of BioJava 1.2)name
- the String returned by getName()
public static Symbol createSymbol(char token, Annotation annotation, java.util.List symList, Alphabet alpha) throws IllegalSymbolException
Generates a new Symbol instance that represents the tuple of Symbols in symList.
This method is most useful for writing Alphabet implementations. It should not be invoked by casual users. Use alphabet.getSymbol(List) instead.
token
- the Symbol's token [ignored since 1.2]symList
- a list of Symbol objectsalpha
- the Alphabet that this Symbol will reside in
IllegalSymbolException
public static Symbol createSymbol(Annotation annotation, java.util.List symList, Alphabet alpha) throws IllegalSymbolException
Generates a new Symbol instance that represents the tuple of Symbols in symList.
This method is most useful for writing Alphabet implementations. It should not be invoked by casual users. Use alphabet.getSymbol(List) instead.
symList
- a list of Symbol objectsalpha
- the Alphabet that this Symbol will reside in
IllegalSymbolException
public static Symbol createSymbol(char token, Annotation annotation, java.util.Set symSet, Alphabet alpha) throws IllegalSymbolException
Generates a new Symbol instance that represents the tuple of Symbols in symList.
This method is most useful for writing Alphabet implementations. It should not be invoked by users. Use alphabet.getSymbol(Set) instead.
token
- the Symbol's token [ignored since 1.2]symSet
- a Set of Symbol objectsalpha
- the Alphabet that this Symbol will reside in
IllegalSymbolException
public static Symbol createSymbol(Annotation annotation, java.util.Set symSet, Alphabet alpha) throws IllegalSymbolException
Generates a new Symbol instance that represents the tuple of Symbols in symList.
This method is most useful for writing Alphabet implementations. It should not be invoked by users. Use alphabet.getSymbol(Set) instead.
symSet
- a Set of Symbol objectsalpha
- the Alphabet that this Symbol will reside in
IllegalSymbolException
public static Alphabet generateCrossProductAlphaFromName(java.lang.String name)
name
- the name to parse
public static Alphabet getCrossProductAlphabet(java.util.List aList)
Retrieve a CrossProductAlphabet instance over the alphabets in aList.
If all of the alphabets in aList implements FiniteAlphabet then the method will return a FiniteAlphabet. Otherwise, it returns a non-finite alphabet.
If you call this method twice with a list containing the same alphabets, it will return the same alphabet. This promotes the re-use of alphabets and helps to maintain the 'flyweight' principal for finite alphabet symbols.
The resulting alphabet cpa will be retrievable via AlphabetManager.alphabetForName(cpa.getName())
aList
- a list of Alphabet objects
public static Alphabet getCrossProductAlphabet(java.util.List aList, java.lang.String name) throws IllegalAlphabetException
IllegalAlphabetException
public static Alphabet getCrossProductAlphabet(java.util.List aList, Alphabet parent)
Retrieve a CrossProductAlphabet instance over the alphabets in aList.
This method is most usefull for implementors of cross-product alphabets, allowing them to safely build the matches alphabets for ambiguity symbols.
If all of the alphabets in aList implements FiniteAlphabet then the method will return a FiniteAlphabet. Otherwise, it returns a non-finite alphabet.
If you call this method twice with a list containing the same alphabets, it will return the same alphabet. This promotes the re-use of alphabets and helps to maintain the 'flyweight' principal for finite alphabet symbols.
The resulting alphabet cpa will be retrievable via AlphabetManager.alphabetForName(cpa.getName())
aList
- a list of Alphabet objectsparent
- a parent alphabet
public static java.util.List factorize(Alphabet alpha, java.util.Set symSet) throws IllegalSymbolException
Return a list of BasisSymbol instances that uniquely sum up all AtomicSymbol instances in symSet. If the symbol can't be represented by a single list of BasisSymbol instances, return null.
This method is most useful for implementers of Alphabet and Symbol. It probably should not be invoked by users.
symSet
- the Set of AtomicSymbol instancesalpha
- the Alphabet instance that the Symbols are from
IllegalSymbolException
public static void loadAlphabets(org.xml.sax.InputSource is) throws org.xml.sax.SAXException, java.io.IOException, BioException
alphabetForName
.
is
- an InputSource
encapsulating the document to be parsed
java.io.IOException
- if there is an error accessing the stream
org.xml.sax.SAXException
- if there is an error while parsing the document
BioException
- if a problem occurs when creating the new Alphabets.public static AlphabetIndex getAlphabetIndex(FiniteAlphabet alpha)
alpha
- The alphabet to index
public static AlphabetIndex getAlphabetIndex(Symbol[] syms) throws IllegalSymbolException, BioException
syms
- the Symbols to index in that order
IllegalSymbolException
BioException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |