|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.aisb.bio.things.Sequence
This is the basis for any implementation of any sequence.
Classes and methods that work on sequences should refer to this,
and not directly to the classes that extend it. It is an implementation of
the List
interface, which is an extension of the Collection
interface. This
means there are already a lot of sophisticated Java tools that will work directly
on it. It also means that you ought not assume the implementations are thread safe.
There is a lot of "junk code" here. We create a ArrayList
and wrap it with a bunch of methods that validate the inputs against the type of sequence
we have, for inputs that would modify the contents. Very little of that code is worth
looking at. However, doing this allows us to focus on adding interesting methods while
preserving the List
and Collection
interfaces.
Of particular note is the loadFromString
method. This takes a string of characters
representing a sequence. It then generates an actual Sequence of the Monomers represented
by those characters.
We can tighten this up a lot later on. This was just the easiest implementation for me to blast out quickly.
Field Summary | |
java.lang.Class |
type
|
Constructor Summary | |
Sequence()
|
|
Sequence(java.lang.Class monomer)
|
|
Sequence(java.lang.Class monomer,
java.lang.String sequence)
|
|
Sequence(int count)
|
Method Summary | |
void |
add(int index,
java.lang.Object element)
|
boolean |
add(java.lang.Object o)
|
boolean |
addAll(java.util.Collection c)
|
boolean |
addAll(int index,
java.util.Collection c)
|
void |
appendFromString(java.lang.String input)
|
void |
clear()
|
boolean |
contains(java.lang.Object o)
|
boolean |
containsAll(java.util.Collection c)
|
java.lang.Object |
get(int index)
|
java.lang.String |
getComment()
|
java.lang.String |
getFasta()
Return this sequence in FASTA format. |
java.lang.Class |
getType()
|
int |
indexOf(java.lang.Object o)
|
boolean |
isEmpty()
|
java.util.Iterator |
iterator()
|
int |
lastIndexOf(java.lang.Object o)
|
java.util.ListIterator |
listIterator()
|
java.util.ListIterator |
listIterator(int index)
|
void |
loadFromString(java.lang.String input)
Take a string that makes sense given the type of sequence this is. |
java.lang.Object |
remove(int index)
|
boolean |
remove(java.lang.Object o)
|
boolean |
removeAll(java.util.Collection c)
|
boolean |
retainAll(java.util.Collection c)
|
java.lang.Object |
set(int index,
java.lang.Object element)
|
void |
setComment(java.lang.String comment)
|
void |
setType(java.lang.Class type)
Set the type. |
void |
setType(java.lang.String type)
|
int |
size()
|
java.util.List |
subList(int fromIndex,
int toIndex)
|
java.lang.Object[] |
toArray()
|
java.lang.Object[] |
toArray(java.lang.Object[] a)
|
java.lang.String |
toString()
|
void |
validate(java.util.Collection c)
|
void |
validate(java.lang.Object element)
This method validates every object added to the sequence. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
equals, hashCode |
Field Detail |
public java.lang.Class type
Constructor Detail |
public Sequence(java.lang.Class monomer)
public Sequence(java.lang.Class monomer, java.lang.String sequence)
public Sequence(int count)
public Sequence()
Method Detail |
public java.lang.Class getType()
public void setType(java.lang.String type)
public void setType(java.lang.Class type)
AminoAcid
, attempts to add an
object of type Nucleotide
will fail. However, attempts to add elements of a
subclass of AminoAcid
, such as a class describing some constrained set of amino
acids, will succeed.
Every class used must be descended from Monomer
.
type
- The type to set.public java.lang.String getFasta()
public java.lang.String getComment()
public void setComment(java.lang.String comment)
comment
- The comment to set.public void validate(java.lang.Object element)
element
- The element to be added to the sequence.public void validate(java.util.Collection c)
public void loadFromString(java.lang.String input)
setType
on that new Sequence to teach it what it's
a sequence of, and pass that string into the loadFromString
method, and we're done.
input
- public void appendFromString(java.lang.String input)
public java.lang.String toString()
public void add(int index, java.lang.Object element)
add
in interface java.util.List
public boolean add(java.lang.Object o)
add
in interface java.util.List
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.List
public boolean addAll(int index, java.util.Collection c)
addAll
in interface java.util.List
public void clear()
clear
in interface java.util.List
public boolean contains(java.lang.Object o)
contains
in interface java.util.List
public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.List
public java.lang.Object get(int index)
get
in interface java.util.List
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List
public boolean isEmpty()
isEmpty
in interface java.util.List
public java.util.Iterator iterator()
iterator
in interface java.util.List
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
public java.util.ListIterator listIterator(int index)
listIterator
in interface java.util.List
public java.lang.Object remove(int index)
remove
in interface java.util.List
public boolean remove(java.lang.Object o)
remove
in interface java.util.List
public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.List
public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.List
public java.lang.Object set(int index, java.lang.Object element)
set
in interface java.util.List
public int size()
size
in interface java.util.List
public java.util.List subList(int fromIndex, int toIndex)
subList
in interface java.util.List
public java.lang.Object[] toArray()
toArray
in interface java.util.List
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.List
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |