T
- the type of sequence elements (tokens) the implementing model object works withpublic interface AlignmentModel<T>
All sequences stored are identified by an string ID and not by their names that are possibly displayed to an application user, because these names might change during runtime. Subclasses must ensure that these IDs are unique and do not change during runtime. Additionally IDs of deleted sequences should not be reused, because other objects might have stored references to these using its ID and therefore would not be able to determine that the sequence became deleted, if a new sequence with the same ID is present.
The ordering of sequences in an AlignmentContentArea
is not defined by the model implementation
but by the instance returned by AlignmentContentArea#getSequenceOrder()
.
Note that this interface leaves it up to the implementation if the alignment data is organized in objects
storing whole sequences (rows) or another storage pattern. If your implementation uses sequence objects
consider implementing SequenceAccessAlignmentModel
.
SequenceAccessAlignmentModel
,
AbstractUndecoratedAlignmentModel
,
AbstractMapBasedAlignmentModel
,
AbstractBasicAlignmentModelView
,
DelegatedAlignmentModelView
Modifier and Type | Method and Description |
---|---|
java.lang.String |
addSequence(java.lang.String sequenceName)
Adds a new empty sequence to the underlying data source and generates an ID for it.
|
java.lang.String |
addSequence(java.lang.String sequenceName,
java.lang.String sequenceID)
Adds a new empty sequence to the underlying data source assigning the specified ID to it.
|
void |
appendToken(java.lang.String sequenceID,
T token)
Appends a token at the end of the sequence.
|
void |
appendTokens(java.lang.String sequenceID,
java.util.Collection<? extends T> tokens)
Appends a sequence of tokens starting at the end of the current sequence.
|
boolean |
containsSequence(java.lang.String sequenceID)
Checks if a sequence associated with the specified unique identifier is contained in this model.
|
java.util.Set<AlignmentModelChangeListener> |
getChangeListeners()
Returns all change listeners currently attached to this object.
|
java.lang.String |
getID()
Some implementations may specify string identifying an alignment, which is then returned
by this method.
|
java.lang.String |
getLabel()
Returns a string labeling this alignment.
|
int |
getMaxSequenceLength()
Returns the length of the longest sequence in the alignment which is equivalent to the length of
the alignment.
|
int |
getSequenceCount()
Returns the number of sequences in the underlying data source.
|
int |
getSequenceLength(java.lang.String sequenceID)
Returns the length of the specified sequence.
|
T |
getTokenAt(java.lang.String sequenceID,
int index)
Returns the token at the specified position.
|
TokenSet<T> |
getTokenSet()
Returns the token set which is supported by the implementation.
|
AlignmentModelWriteType |
getWriteType()
Returns a value that specifies if whole sequences or single tokens can be edited in the underlying
data source.
|
void |
insertTokenAt(java.lang.String sequenceID,
int index,
T token)
Inserts a token at the specified position.
|
void |
insertTokensAt(java.lang.String sequenceID,
int beginIndex,
java.util.Collection<? extends T> tokens)
Inserts a sequence of tokens starting at the specified position.
|
boolean |
isSequencesReadOnly()
Checks of whole sequences can be changed in the underlying data source
|
boolean |
isTokensReadOnly()
Checks of tokens can be changed in the underlying data source
|
boolean |
removeSequence(java.lang.String sequenceID)
Removes the specified sequence from the underlying data source.
|
void |
removeTokenAt(java.lang.String sequenceID,
int index)
Removes the token at the specified position from the underlying data source.
|
void |
removeTokensAt(java.lang.String sequenceID,
int beginIndex,
int endIndex)
Removes the token inside the specified interval from the underlying data source.
|
java.lang.String |
renameSequence(java.lang.String sequenceID,
java.lang.String newSequenceName)
Renames a sequence in the underlying data source.
|
java.util.Iterator<java.lang.String> |
sequenceIDIterator()
Returns an iterator over unique IDs of all sequences contained in the underlying data source
in the order they are stored in this model.
|
java.util.Set<java.lang.String> |
sequenceIDsByName(java.lang.String sequenceName)
Returns the set of unique sequence IDs associated with the specified name.
|
java.lang.String |
sequenceNameByID(java.lang.String sequenceID)
Returns the sequence name (that would be visible to the application user) associated with the
specified unique ID.
|
void |
setID(java.lang.String id)
Allows to specify a new ID for this alignment.
|
void |
setLabel(java.lang.String label)
Allows to specify a new label for this alignment.
|
void |
setTokenAt(java.lang.String sequenceID,
int index,
T token)
Replaces the token at the specified position by the passed token.
|
void |
setTokensAt(java.lang.String sequenceID,
int beginIndex,
java.util.Collection<? extends T> tokens)
Replaces a sequence of tokens starting at the specified position.
|
void |
setTokenSet(TokenSet<T> set)
Replaces the current token set with the specified one.
|
java.lang.String getID()
null
if none is assignedvoid setID(java.lang.String id)
id
- the new IDjava.lang.UnsupportedOperationException
- if this implementation does not allow to change IDsjava.lang.String getLabel()
void setLabel(java.lang.String label) throws java.lang.UnsupportedOperationException
label
- the new labeljava.lang.UnsupportedOperationException
- if this implementation does not allow to change labelsTokenSet<T> getTokenSet()
void setTokenSet(TokenSet<T> set) throws java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException
set
- the new token set to be usedjava.lang.UnsupportedOperationException
- if this implementation does not support changing token sets during runtimejava.lang.IllegalArgumentException
- if the specified token set is not a valid replacement for the previous one (in some
does way does not fulfill the needs of the implementation)int getSequenceLength(java.lang.String sequenceID)
sequenceID
- the identifier the sequence in the alignment-1
if no sequence with the specified name existsint getMaxSequenceLength()
Note that this value represents the number of compounds of the specified data type. If e.g. a DNA data source is viewed as amino acid data this method would still return the number of nucleotides in the longest sequence.
0
if there are not sequences contained
in the underlying data sourceAlignmentModelWriteType getWriteType()
boolean isTokensReadOnly()
true
if token can be written or removed, false
otherwiseboolean isSequencesReadOnly()
true
if sequences can be written, renamed or removed, false
otherwiseboolean containsSequence(java.lang.String sequenceID)
sequenceID
- the ID of the sequence to checked ontrue
if an according sequence was found, false
otherwisejava.util.Set<java.lang.String> sequenceIDsByName(java.lang.String sequenceName)
sequenceName
- the name of the sequence that would be visible to the application userjava.lang.String sequenceNameByID(java.lang.String sequenceID)
sequenceID
- the unique unmodifiable ID the sequence is identified bynull
if no sequence with this ID is contained in this modeljava.lang.String addSequence(java.lang.String sequenceName) throws AlignmentSourceNotWritableException
sequenceName
- the name of the new sequenceAlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencesjava.lang.String addSequence(java.lang.String sequenceName, java.lang.String sequenceID) throws AlignmentSourceNotWritableException, java.lang.IllegalArgumentException
sequenceName
- the name of the new sequencesequenceID
- the ID the new sequence shall havesequenceID
)AlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencesjava.lang.IllegalArgumentException
- if a sequence with the specified ID is already present in this modelboolean removeSequence(java.lang.String sequenceID) throws AlignmentSourceNotWritableException
sequenceID
- the unique ID of the sequence to be removedtrue
if an sequence with the specified ID was removed, false
if no sequence with the specified ID was contained in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencesjava.lang.String renameSequence(java.lang.String sequenceID, java.lang.String newSequenceName) throws AlignmentSourceNotWritableException, SequenceNotFoundException
sequenceID
- the ID of the sequence to be renamednewSequenceName
- the new name the sequence shall haveAlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencesDuplicateSequenceNameException
- if a sequence with the specified new name is already present in
the underlying data sourceSequenceNotFoundException
- if a sequence with the specified ID is not present the underlying
data sourcejava.util.Iterator<java.lang.String> sequenceIDIterator()
int getSequenceCount()
java.util.Set<AlignmentModelChangeListener> getChangeListeners()
This method returns the same object in every call. Therefore changes made to different references always affect all references.
T getTokenAt(java.lang.String sequenceID, int index)
sequenceID
- the identifier the sequence where the token is containedindex
- the index of the element contained in the specified sequence (The first element has the index 0.)SequenceNotFoundException
- if no according sequence to the specified ID was found in this modeljava.lang.IndexOutOfBoundsException
- if the specified index is below zero or greater or equal to the length of the
specified sequencevoid setTokenAt(java.lang.String sequenceID, int index, T token) throws AlignmentSourceNotWritableException
sequenceID
- the identifier the sequence where the token is containedindex
- the index of the element to be replaced (The first element has the index 0.)token
- the new token for the specified positionAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensSequenceNotFoundException
- if no according sequence to the specified ID was found in this modeljava.lang.IndexOutOfBoundsException
- if the specified index is below zero or greater or equal to the length of the
specified sequence (Note that not all implementations will throw this exception for indices above zero.
Some may also elongate the sequence accordingly and will up the new positions with e.g. gaps.)void setTokensAt(java.lang.String sequenceID, int beginIndex, java.util.Collection<? extends T> tokens) throws AlignmentSourceNotWritableException
sequenceID
- the identifier the sequence where the token is containedbeginIndex
- the index of the first element to be replaced
(The first element in the sequence has the index 0.)tokens
- the new tokens for the specified positionAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensSequenceNotFoundException
- if no according sequence to the specified ID was found in this modelAlignmentModelUtils.charSequenceToTokenList(CharSequence, TokenSet)
void appendToken(java.lang.String sequenceID, T token) throws AlignmentSourceNotWritableException
sequenceID
- the identifier the sequence in the alignmenttoken
- the token to be insertedSequenceNotFoundException
- if no according sequence to the specified ID was found in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensvoid appendTokens(java.lang.String sequenceID, java.util.Collection<? extends T> tokens) throws AlignmentSourceNotWritableException
sequenceID
- the identifier the sequence where the token is containedtokens
- the new tokens for the specified positionSequenceNotFoundException
- if no according sequence to the specified ID was found in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensAlignmentModelUtils.charSequenceToTokenList(CharSequence, TokenSet)
void insertTokenAt(java.lang.String sequenceID, int index, T token) throws AlignmentSourceNotWritableException
sequenceID
- the identifier the sequence in the alignmentindex
- the new index the inserted element will have
(0 <= elementIndex < sequenceLength
)token
- the token to be insertedSequenceNotFoundException
- if no according sequence to the specified ID was found in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensvoid insertTokensAt(java.lang.String sequenceID, int beginIndex, java.util.Collection<? extends T> tokens) throws AlignmentSourceNotWritableException
tokens
.sequenceID
- the identifier the sequence where the token is containedbeginIndex
- the index of the first element to be replaced
(The first element in the sequence has the index 0.)tokens
- the new tokens for the specified positionSequenceNotFoundException
- if no according sequence to the specified ID was found in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensAlignmentModelUtils.charSequenceToTokenList(CharSequence, TokenSet)
void removeTokenAt(java.lang.String sequenceID, int index) throws AlignmentSourceNotWritableException
sequenceID
- the identifier the sequence in the alignmentindex
- the index of the element to be removed (The first element has the index 0.)SequenceNotFoundException
- if no according sequence to the specified ID was found in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensvoid removeTokensAt(java.lang.String sequenceID, int beginIndex, int endIndex) throws AlignmentSourceNotWritableException
beginIndex
and extends to the
token at index endIndex - 1). Thus the length of the subsequence is {@code endIndex - beginIndex}.sequenceID
- the identifier the sequence in the alignmentbeginIndex
- the beginning index, inclusiveendIndex
- the ending index, exclusiveSequenceNotFoundException
- if no according sequence to the specified ID was found in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokens