org.aisb.bio.things
Class Sequence

java.lang.Object
  extended byorg.aisb.bio.things.Sequence
All Implemented Interfaces:
java.util.Collection, java.util.List

public class Sequence
extends java.lang.Object
implements java.util.List

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.

Author:
Doug DeJulio

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

type

public java.lang.Class type
Constructor Detail

Sequence

public Sequence(java.lang.Class monomer)

Sequence

public Sequence(java.lang.Class monomer,
                java.lang.String sequence)

Sequence

public Sequence(int count)

Sequence

public Sequence()
Method Detail

getType

public java.lang.Class getType()
Returns:
Returns the type.

setType

public void setType(java.lang.String type)

setType

public void setType(java.lang.Class type)
Set the type. This is used to validate all the elements that make up this sequence. For example, if the type is set to 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.

Parameters:
type - The type to set.

getFasta

public java.lang.String getFasta()
Return this sequence in FASTA format.

Returns:
The FASTA format version of the sequence.

getComment

public java.lang.String getComment()
Returns:
Returns the comment.

setComment

public void setComment(java.lang.String comment)
Parameters:
comment - The comment to set.

validate

public void validate(java.lang.Object element)
This method validates every object added to the sequence. This prevents us from accidentally creating a sequence that contains both amino acids and nucleotides for example. It's broken at the moment. This is okay for the first homework, since we're always working with amino acids.

Parameters:
element - The element to be added to the sequence.

validate

public void validate(java.util.Collection c)

loadFromString

public void loadFromString(java.lang.String input)
Take a string that makes sense given the type of sequence this is. For example, if we have a Sequence in which the type has been set to Nucleotide, the string "GATTACA" makes sense. The string is parsed and an ordered Collection of the appropriate object is created and stuffed into this Sequence's data field. In other words, we can take any sequence file and convert it into one very long string, create a new Sequence, call 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.

Parameters:
input -

appendFromString

public void appendFromString(java.lang.String input)

toString

public java.lang.String toString()

add

public void add(int index,
                java.lang.Object element)
Specified by:
add in interface java.util.List

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.List

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.List

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List

clear

public void clear()
Specified by:
clear in interface java.util.List

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.List

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.List

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.List

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.util.List

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List

listIterator

public java.util.ListIterator listIterator(int index)
Specified by:
listIterator in interface java.util.List

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.List

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.List

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.List

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Specified by:
set in interface java.util.List

size

public int size()
Specified by:
size in interface java.util.List

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.List

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.List