public abstract class AbstractSymbolList extends AbstractChangeable implements SymbolList
Abstract helper implementation of the SymbolList core interface. To produce a
concrete SymbolList implementation, you need only implement the
getAlphabet
, length
and symbolAt
methods. Iterators and sublists are handled for you automatically.
This class makes many custom SymbolList implementations very quick to implement. See org.biojava.bio.seq.tools.ComplementSymbolList for an example of this.
To make a mutable SymbolList, override the implementation of edit to perform the apropreate edit. If your implementation of SymbolList is a view onto an underlying SymbolList, then you must forward any apropreate edit requests to that list, and forward all events from the underlying list to your listeners.
Modifier and Type | Class and Description |
---|---|
class |
AbstractSymbolList.EditScreener
This adapter screens all edit events to see if they overlap with a window
of interest.
|
class |
AbstractSymbolList.EditTranslater
This translates edit events that fall within a window into window
co-ordinates.
|
EDIT, EMPTY_LIST
Modifier | Constructor and Description |
---|---|
protected |
AbstractSymbolList() |
Modifier and Type | Method and Description |
---|---|
void |
edit(Edit edit)
Apply an edit to the SymbolList as specified by the edit object.
|
boolean |
equals(Object o)
Provides logical equality for two SymbolLists that share the same list of
canonical symbols
|
int |
hashCode() |
Iterator<Symbol> |
iterator()
An Iterator over all Symbols in this SymbolList.
|
String |
seqString()
Stringify this symbol list.
|
SymbolList |
subList(int start,
int end)
Return a new SymbolList for the symbols start to end inclusive.
|
String |
subStr(int start,
int end)
Return a region of this symbol list as a String.
|
List<Symbol> |
toList()
Returns a List of symbols.
|
String |
toString() |
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getAlphabet, length, symbolAt
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
protected AbstractSymbolList()
public Iterator<Symbol> iterator()
SymbolList
This is an ordered iterator over the Symbols. It cannot be used to edit the underlying symbols.
iterator
in interface SymbolList
public SymbolList subList(int start, int end)
SymbolList
The resulting SymbolList will count from 1 to (end-start + 1) inclusive, and refer to the symbols start to end of the original sequence.
subList
in interface SymbolList
start
- the first symbol of the new SymbolListend
- the last symbol (inclusive) of the new SymbolListpublic List<Symbol> toList()
SymbolList
This is an immutable list of symbols. Do not edit it.
toList
in interface SymbolList
public String seqString()
SymbolList
It is expected that this will use the symbol's token to render each symbol. It should be parsable back into a SymbolList using the default token parser for this alphabet.
seqString
in interface SymbolList
public String subStr(int start, int end)
SymbolList
This should use the same rules as seqString.
subStr
in interface SymbolList
start
- the first symbol to includeend
- the last symbol to includepublic void edit(Edit edit) throws IllegalAlphabetException, ChangeVetoException
SymbolList
All edits can be broken down into a series of operations that change contiguous blocks of the sequence. This represent a one of those operations.
When applied, this Edit will replace 'length' number of symbols starting a position 'pos' by the SymbolList 'replacement'. This allow to do insertions (length=0), deletions (replacement=SymbolList.EMPTY_LIST) and replacements (length>=1 and replacement.length()>=1).
The pos and pos+length should always be valid positions on the SymbolList to:
SymbolList seq = DNATools.createDNA("atcaaaaacgctagc");
System.out.println(seq.seqString());
// delete 5 bases from position 4
Edit ed = new Edit(4, 5, SymbolList.EMPTY_LIST);
seq.edit(ed);
System.out.println(seq.seqString());
// delete one base from the start
ed = new Edit(1, 1, SymbolList.EMPTY_LIST);
seq.edit(ed);
// delete one base from the end
ed = new Edit(seq.length(), 1, SymbolList.EMPTY_LIST);
seq.edit(ed);
System.out.println(seq.seqString());
// overwrite 2 bases from position 3 with "tt"
ed = new Edit(3, 2, DNATools.createDNA("tt"));
seq.edit(ed);
System.out.println(seq.seqString());
// add 6 bases to the start
ed = new Edit(1, 0, DNATools.createDNA("aattgg");
seq.edit(ed);
System.out.println(seq.seqString());
// add 4 bases to the end
ed = new Edit(seq.length() + 1, 0, DNATools.createDNA("tttt"));
seq.edit(ed);
System.out.println(seq.seqString());
// full edit
ed = new Edit(3, 2, DNATools.createDNA("aatagaa");
seq.edit(ed);
System.out.println(seq.seqString());
edit
in interface SymbolList
edit
- the Edit to performIllegalAlphabetException
- if the SymbolList to insert has an
incompatible alphabetChangeVetoException
- if either the SymboList does not support the
edit, or if the change was vetoedpublic boolean equals(Object o)
Copyright © 2014 BioJava. All rights reserved.