org.biojava.bio.seq.db.biosql
Class BioSQLSequenceDB

java.lang.Object
  extended byorg.biojava.bio.seq.db.biosql.BioSQLSequenceDB
All Implemented Interfaces:
Changeable, SequenceDB, SequenceDBLite

public class BioSQLSequenceDB
extends java.lang.Object
implements SequenceDB

SequenceDB keyed off a BioSQL database. This is an almost-complete implementation of the BioJava Sequence, SequenceDB, and Feature interfaces, and can be used in a wide range of applications.

Since:
1.3
Author:
Thomas Down, Matthew Pocock

Field Summary
 
Fields inherited from interface org.biojava.bio.seq.db.SequenceDBLite
SEQUENCES
 
Constructor Summary
BioSQLSequenceDB(java.lang.String dbURL, java.lang.String dbUser, java.lang.String dbPass, java.lang.String biodatabase, boolean create)
          Connect to a BioSQL database.
 
Method Summary
 void addChangeListener(ChangeListener cl)
          Add a listener that will be informed of all changes.
 void addChangeListener(ChangeListener cl, ChangeType ct)
          Add a listener that will be informed of changes of a given type.
 void addSequence(Sequence seq)
          Adds a sequence to the database.
 void createDummySequence(java.lang.String id, Alphabet alphabet, int length)
           
 FeatureHolder filter(FeatureFilter ff)
          Query features attached to all sequences in this database.
 java.lang.String getName()
          Get the name of this sequence database.
 Sequence getSequence(java.lang.String id)
          Retrieve a single sequence by its id.
 java.util.Set ids()
          Get an immutable set of all of the IDs in the database.
 boolean isUnchanging(ChangeType ct)
           A particular ChangeType can never be raised by this Changeable.
 void removeChangeListener(ChangeListener cl)
          Remove a listener that was interested in all types of changes.
 void removeChangeListener(ChangeListener cl, ChangeType ct)
          Remove a listener that was interested in a specific types of changes.
 void removeSequence(java.lang.String id)
          Remove the sequence associated with an ID from the database.
 SequenceIterator sequenceIterator()
          Returns a SequenceIterator over all sequences in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BioSQLSequenceDB

public BioSQLSequenceDB(java.lang.String dbURL,
                        java.lang.String dbUser,
                        java.lang.String dbPass,
                        java.lang.String biodatabase,
                        boolean create)
                 throws BioException
Connect to a BioSQL database.

Parameters:
dbURL - A JDBC database URL. For example, jdbc:postgresql://localhost/thomasd_biosql
dbUser - The username to use when connecting to the database (or an empty string).
dbPass - The password to use when connecting to the database (or an empty string).
biodatabase - The identifier of a namespace within the physical BioSQL database.
create - If the requested namespace doesn't exist, and this flag is true, a new namespace will be created.
Throws:
BioException - if an error occurs communicating with the database
Method Detail

getName

public java.lang.String getName()
Description copied from interface: SequenceDBLite
Get the name of this sequence database.

Specified by:
getName in interface SequenceDBLite
Returns:
the name of the sequence database, which may be null.

createDummySequence

public void createDummySequence(java.lang.String id,
                                Alphabet alphabet,
                                int length)
                         throws IllegalIDException,
                                ChangeVetoException,
                                BioException
Throws:
IllegalIDException
ChangeVetoException
BioException

addSequence

public void addSequence(Sequence seq)
                 throws IllegalIDException,
                        ChangeVetoException,
                        BioException
Description copied from interface: SequenceDBLite
Adds a sequence to the database.

Specified by:
addSequence in interface SequenceDBLite
Parameters:
seq - the Sequence to add
Throws:
IllegalIDException - if a uniqe ID could not be generated for seq
BioException - if something goes wrong with adding the sequence
ChangeVetoException - if either the database does not allow sequences to be added or the modification was vetoed

getSequence

public Sequence getSequence(java.lang.String id)
                     throws BioException,
                            IllegalIDException
Description copied from interface: SequenceDBLite
Retrieve a single sequence by its id.

Specified by:
getSequence in interface SequenceDBLite
Returns:
the Sequence with that id
Throws:
BioException - if there was a failure in retrieving the sequence
IllegalIDException - if the database doesn't know about the id

removeSequence

public void removeSequence(java.lang.String id)
                    throws IllegalIDException,
                           ChangeVetoException,
                           BioException
Description copied from interface: SequenceDBLite
Remove the sequence associated with an ID from the database.

Specified by:
removeSequence in interface SequenceDBLite
Parameters:
id - the ID of the sequence to remove
Throws:
BioException - if something failed while removing the sequence for that ID
ChangeVetoException - if either the database does not allow sequences to be removed or the modification was vetoed
IllegalIDException - if there is no sequence for the ID

ids

public java.util.Set ids()
Description copied from interface: SequenceDB
Get an immutable set of all of the IDs in the database. The ids are legal arguments to getSequence.

Specified by:
ids in interface SequenceDB
Returns:
a Set of ids - at the moment, strings

filter

public FeatureHolder filter(FeatureFilter ff)
Description copied from interface: SequenceDB
Query features attached to all sequences in this database. This is equivalent to applying filter to all sequences then merging the results.

Specified by:
filter in interface SequenceDB
Parameters:
ff - a FeatureFilter.

sequenceIterator

public SequenceIterator sequenceIterator()
Description copied from interface: SequenceDB
Returns a SequenceIterator over all sequences in the database. The order of retrieval is undefined.

Specified by:
sequenceIterator in interface SequenceDB
Returns:
a SequenceIterator over all sequences

addChangeListener

public void addChangeListener(ChangeListener cl)
Description copied from interface: Changeable
Add a listener that will be informed of all changes.

Specified by:
addChangeListener in interface Changeable
Parameters:
cl - the ChangeListener to add

addChangeListener

public void addChangeListener(ChangeListener cl,
                              ChangeType ct)
Description copied from interface: Changeable
Add a listener that will be informed of changes of a given type.

Specified by:
addChangeListener in interface Changeable
Parameters:
cl - the ChangeListener
ct - the ChangeType it is to be informed of

removeChangeListener

public void removeChangeListener(ChangeListener cl)
Description copied from interface: Changeable
Remove a listener that was interested in all types of changes.

Specified by:
removeChangeListener in interface Changeable
Parameters:
cl - a ChangeListener to remove

removeChangeListener

public void removeChangeListener(ChangeListener cl,
                                 ChangeType ct)
Description copied from interface: Changeable
Remove a listener that was interested in a specific types of changes.

Specified by:
removeChangeListener in interface Changeable
Parameters:
cl - a ChangeListener to remove
ct - the ChangeType that it was interested in

isUnchanging

public boolean isUnchanging(ChangeType ct)
Description copied from interface: Changeable

A particular ChangeType can never be raised by this Changeable.

If this returns true, then it is guaranteed that change events of this type (and all child types) can never under any circumstances be fired by this Changeable instance. If it returns false, that does not mean that this type of event will or even can be raised, but that it is worth registering listeners incase.

Specified by:
isUnchanging in interface Changeable
Parameters:
ct - the ChangeType to check
Returns:
true if ChangeEvents of this type are guaranteed to never be fired