public final class AlphabetManager extends Object
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 and Description |
---|
AlphabetManager() |
Modifier and Type | Method and Description |
---|---|
static Alphabet |
alphabetForName(String name)
Retrieve the alphabet for a specific name.
|
static Iterator |
alphabets()
Get an iterator over all alphabets known.
|
static Symbol |
createSymbol(Annotation annotation,
List symList,
Alphabet alpha)
Generates a new Symbol instance that represents the tuple of Symbols in
symList.
|
static Symbol |
createSymbol(Annotation annotation,
Set symSet,
Alphabet alpha)
Generates a new Symbol instance that represents the tuple of Symbols in
symList.
|
static Symbol |
createSymbol(char token,
Annotation annotation,
List symList,
Alphabet alpha)
Deprecated.
use the new version, without the token argument
|
static Symbol |
createSymbol(char token,
Annotation annotation,
Set symSet,
Alphabet alpha)
Deprecated.
use the three-arg version of this method instead.
|
static AtomicSymbol |
createSymbol(char token,
String name,
Annotation annotation)
Deprecated.
Use the two-arg version of this method instead.
|
static AtomicSymbol |
createSymbol(String name)
Generate a new AtomicSymbol instance with a name and an Empty Annotation.
|
static AtomicSymbol |
createSymbol(String name,
Annotation annotation)
Generate a new AtomicSymbol instance with a name and Annotation.
|
static List |
factorize(Alphabet alpha,
Set symSet)
Return a list of BasisSymbol instances that uniquely sum up all
AtomicSymbol
instances in symSet.
|
static Alphabet |
generateCrossProductAlphaFromName(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 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(List aList)
Retrieve a CrossProductAlphabet instance over the alphabets in aList.
|
static Alphabet |
getCrossProductAlphabet(List aList,
Alphabet parent)
Retrieve a CrossProductAlphabet instance over the alphabets in aList.
|
static Alphabet |
getCrossProductAlphabet(List aList,
String name)
Attempts to create a cross product alphabet and register it under a name.
|
static Symbol |
getGapSymbol()
Get the special `gap' Symbol.
|
static Symbol |
getGapSymbol(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(InputSource is)
Load additional Alphabets, defined in XML format, into the AlphabetManager's registry.
|
static void |
registerAlphabet(String[] names,
Alphabet alphabet)
Register and Alphabet by more than one name.
|
static void |
registerAlphabet(String name,
Alphabet alphabet)
Register an alphabet by name.
|
static boolean |
registered(String name)
Has an Alphabet been registered by that name
|
static Set |
registrations()
A set of names under which Alphabets have been registered.
|
static Symbol |
symbolForLifeScienceID(LifeScienceIdentifier lsid)
Retreives the Symbol for the LSID
|
static Symbol |
symbolForName(String name)
Deprecated.
use symbolForLifeScienceID() instead
|
public AlphabetManager()
public static AlphabetManager instance()
public static Symbol getAllAmbiguitySymbol(FiniteAlphabet alpha)
alpha
- The alphabetpublic static Set getAllSymbols(FiniteAlphabet alpha)
alpha
- The alphabetalpha
public static Alphabet alphabetForName(String name) throws NoSuchElementException
name
- the name of the alphabetNoSuchElementException
- if there is no alphabet by that namepublic static Symbol symbolForName(String name) throws NoSuchElementException
name
- of the string whose symbol you want to getNoSuchElementException
- if the string name is invalid.public static Symbol symbolForLifeScienceID(LifeScienceIdentifier lsid)
lsid
- the URN for the Symbolpublic static void registerAlphabet(String name, Alphabet alphabet)
name
- the name by which it can be retrievedalphabet
- the Alphabet to storepublic static void registerAlphabet(String[] names, Alphabet alphabet)
registerAlphabet(String name, Alphabet alphabet)
several
times.names
- the names by which it can be retrievedalphabet
- the Alphabet to storepublic static Set registrations()
Set
of Strings
public static boolean registered(String name)
name
- the name of the alphabetpublic static 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(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 alphabetspublic static AtomicSymbol createSymbol(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(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, 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()annotation
- the Annotation returned by getAnnotation()public static Symbol createSymbol(char token, Annotation annotation, 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.
annotation
- The annotation bundle for the symboltoken
- the Symbol's token [ignored since 1.2]symList
- a list of Symbol objectsalpha
- the Alphabet that this Symbol will reside inIllegalSymbolException
- If the Symbol cannot be madepublic static Symbol createSymbol(Annotation annotation, List symList, Alphabet alpha) throws IllegalSymbolException
Generates a new Symbol instance that represents the tuple of Symbols in symList. This will attempt to return the same symbol for the same list.
This method is most useful for writing Alphabet implementations. It should not be invoked by casual users. Use alphabet.getSymbol(List) instead.
annotation
- The annotation bundle for the SymbolsymList
- a list of Symbol objectsalpha
- the Alphabet that this Symbol will reside inIllegalSymbolException
- If the Symbol cannot be madepublic static Symbol createSymbol(char token, Annotation annotation, 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]annotation
- the Symbol's AnnotationsymSet
- a Set of Symbol objectsalpha
- the Alphabet that this Symbol will reside inIllegalSymbolException
- If the Symbol cannot be madepublic static Symbol createSymbol(Annotation annotation, 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.
annotation
- the Symbol's AnnotationsymSet
- a Set of Symbol objectsalpha
- the Alphabet that this Symbol will reside inIllegalSymbolException
- If the Symbol cannot be madepublic static Alphabet generateCrossProductAlphaFromName(String name)
name
- the name to parsepublic static Alphabet getCrossProductAlphabet(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 objectspublic static Alphabet getCrossProductAlphabet(List aList, String name) throws IllegalAlphabetException
aList
- A list of alphabetsname
- The name which the new alphabet will be registered under.IllegalAlphabetException
- If the Alphabet cannot be made or a different
alphabet is already registed under this name.public static Alphabet getCrossProductAlphabet(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 alphabetpublic static List factorize(Alphabet alpha, 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 fromIllegalSymbolException
- In practice it should not. If it does it probably
indicates a subtle bug somewhere in AlphabetManagerpublic static void loadAlphabets(InputSource is) throws SAXException, IOException, BioException
alphabetForName
.is
- an InputSource
encapsulating the document to be parsedIOException
- if there is an error accessing the streamSAXException
- if there is an error while parsing the documentBioException
- if a problem occurs when creating the new Alphabets.public static AlphabetIndex getAlphabetIndex(FiniteAlphabet alpha)
alpha
- The alphabet to indexpublic static AlphabetIndex getAlphabetIndex(Symbol[] syms) throws IllegalSymbolException, BioException
syms
- the Symbols to index in that orderIllegalSymbolException
BioException
Copyright © 2014 BioJava. All rights reserved.