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

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

public class BioSQLSequenceDB
extends AbstractChangeable
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. Note: It now uses BioSQL schema version 1.0 (Post Singapore) All previous versions are no longer supported.

Since:
1.3
Author:
Thomas Down, Matthew Pocock, Simon Foote, Len Trigg

Field Summary
 
Fields inherited from interface org.biojava.bio.seq.db.SequenceDBLite
SEQUENCES
 
Constructor Summary
BioSQLSequenceDB(DataSource ds, String biodatabase, boolean create)
           
BioSQLSequenceDB(String dbURL, String dbUser, String dbPass, String biodatabase, boolean create)
          Connect to a BioSQL database.
BioSQLSequenceDB(String dbDriver, String dbURL, String dbUser, String dbPass, String biodatabase, boolean create)
          Connect to a BioSQL database.
 
Method Summary
 Ontology addOntology(Ontology onto)
           
 void addSequence(Sequence seq)
          Adds a sequence to the database.
 void createDummySequence(String id, Alphabet alphabet, int length)
           
 Ontology createOntology(String name, String description)
           
 FeatureHolder filter(FeatureFilter ff)
          Query features attached to all sequences in this database.
 String getName()
          Get the name of this sequence database.
 Ontology getOntology(String name)
           
 Sequence getSequence(String id)
          Retrieve a single sequence by its id.
 Set ids()
          Get an immutable set of all of the IDs in the database.
 void removeSequence(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 org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
 

Constructor Detail

BioSQLSequenceDB

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

Parameters:
dbDriver - A JDBC database driver. For example, com.jdbc.mysql.Driver
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

BioSQLSequenceDB

public BioSQLSequenceDB(String dbURL,
                        String dbUser,
                        String dbPass,
                        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

BioSQLSequenceDB

public BioSQLSequenceDB(DataSource ds,
                        String biodatabase,
                        boolean create)
                 throws BioException
Method Detail

createOntology

public Ontology createOntology(String name,
                               String description)
                        throws Exception
Throws:
Exception

getOntology

public Ontology getOntology(String name)
                     throws Exception
Throws:
Exception

addOntology

public Ontology addOntology(Ontology onto)
                     throws Exception
Throws:
Exception

getName

public 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(String id,
                                Alphabet alphabet,
                                int length)
                         throws ChangeVetoException,
                                BioException
Throws:
ChangeVetoException
BioException

addSequence

public void addSequence(Sequence seq)
                 throws 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:
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(String id)
                     throws BioException
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

removeSequence

public void removeSequence(String id)
                    throws 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:
ChangeVetoException - if either the database does not allow sequences to be removed or the modification was vetoed
BioException - if something failed while removing the sequence for that ID

ids

public 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