[Biojava-l] Ontology and BioSQL

Richard HOLLAND hollandr at gis.a-star.edu.sg
Thu Dec 2 05:04:00 EST 2004


Found it, I think!

In Ontology.Impl, when you create a triple and it has a listener, it
does this:

	1. Fires a pre-change Ontology.TRIPLE event.
	2. Calls addTerm(t) where t is the triple being created.
	3. Calls addTriple(t) where t is the triple being created.
	4. Fires a post-change Ontology.TRIPLE event.

The post-change Ontology.TRIPLE event causes the persistTriple() routine
in OntologySQL to be called. The first thing this routine does is call
persistTerm() on itself, but this raises an exception because the term
has somehow already been created. How? Well...

Step 2 of the above calls addTerm(t) in Ontology.Impl, which fires a
pre-change Ontology.TERM event on the term, puts the term into its
internal map, then fires a post-change Ontology.TERM event on the term.
Because the term (ie. Triple) is being monitored, these events are
picked up by OntologySQL and result in the term being created in the
database. Hence, when persistTriple() is later called via step 4, the
term is already there and that first call to persistTerm() in the
persistTriple() method is redundant.

SO... How to fix? My suggestion would be removing the call to
persistTerm() from the start of the persistTriple() method in
OntologySQL, as the action has already been done at this stage by the
Ontology.TERM change event.

cheers,
Richard

Richard Holland
Bioinformatics Specialist
GIS extension 8199   
 
---------------------------------------------
This email is confidential and may be privileged. If you are not the
intended recipient, please delete it and notify us immediately. Please
do not copy or use it for any purpose, or disclose its content to any
other person. Thank you.
---------------------------------------------


> -----Original Message-----
> From: biojava-l-bounces at portal.open-bio.org 
> [mailto:biojava-l-bounces at portal.open-bio.org] On Behalf Of 
> Richard HOLLAND
> Sent: Thursday, December 02, 2004 4:53 PM
> To: mark.schreiber at group.novartis.com
> Cc: biojava-l at biojava.org
> Subject: RE: [Biojava-l] Ontology and BioSQL
> 
> 
> Yup, this problem happened since the very first time I ran it 
> on an empty database. The terms get created in term, the term 
> representing the triple gets created in term, but it does not 
> create the relationship in term_relationship. 
> 
> The exception is being thrown by the persistTerm call on the 
> very first line of persistTriple.
> 
> I'm thinking that this is something to do with the 
> OntologyMonitor? That it is seeing the Triple get created, 
> but because the Triple is an instanceof Term it is firing two 
> change events
> - one for the Term representation, the
> other for the Triple representation? That's the only way I 
> can see the Triple being created in the term table but not in 
> the term_relationship table, as otherwise we'd be getting 
> exceptions halfway through persistTriple way after that call 
> to persistTerm at the beginning, which we're not.
> 
> In other words, the Triple already exists in the term table 
> _before_ persistTriple is getting called. Why? How? Hmm.
> 
> cheers,
> Richard
> 
> Richard Holland
> Bioinformatics Specialist
> GIS extension 8199   
>  
> ---------------------------------------------
> This email is confidential and may be privileged. If you are 
> not the intended recipient, please delete it and notify us 
> immediately. Please do not copy or use it for any purpose, or 
> disclose its content to any other person. Thank you.
> ---------------------------------------------
> 
> 
> > -----Original Message-----
> > From: mark.schreiber at group.novartis.com
> > [mailto:mark.schreiber at group.novartis.com] 
> > Sent: Thursday, December 02, 2004 4:18 PM
> > To: Richard HOLLAND
> > Cc: biojava-l at biojava.org; biojava-l-bounces at portal.open-bio.org
> > Subject: Re: [Biojava-l] Ontology and BioSQL
> > 
> > 
> > Hi -
> > 
> > The code responsible for the insert is:
> > 
> >   private void persistTriple(Connection conn, Ontology ont,
> > Triple triple)
> >           throws SQLException
> >   {
> >     persistTerm(conn, triple);
> > 
> >     PreparedStatement import_trip = conn.prepareStatement(
> >             "insert into term_relationship " +
> >             "       (subject_term_id, predicate_term_id, 
> > object_term_id,
> > ontology_id) " +
> >             "values (?, ?, ?, ?)"
> >     );
> >     import_trip.setInt(1, termID(triple.getSubject()));
> >     import_trip.setInt(2, termID(triple.getPredicate()));
> >     import_trip.setInt(3, termID(triple.getObject()));
> >     import_trip.setInt(4, ontologyID(ont));
> >     import_trip.executeUpdate();
> >     import_trip.close();
> >     int tripID = dbHelper.getInsertID(conn, "term_relationship", 
> > "term_relationship_id");
> > 
> >     PreparedStatement link_trip_to_term = conn.prepareStatement(
> >             "insert into term_relationship_term " +
> >             "       (term_relationship_id, term_id) " +
> >             "values (?, ?)" );
> >     link_trip_to_term.setInt(1, tripID);
> >     link_trip_to_term.setInt(2, termID(triple));
> >     link_trip_to_term.executeUpdate();
> >     link_trip_to_term.close();
> > 
> >     //System.err.println("Persisted triple: " + triple);
> >   }
> > 
> > I can't immediately see any attempt to write it twice.  Are
> > you removing 
> > the old triples before running the program again?
> > 
> > - Mark
> > 
> > 
> > 
> > 
> > 
> > "Richard HOLLAND" <hollandr at gis.a-star.edu.sg>
> > Sent by: biojava-l-bounces at portal.open-bio.org
> > 12/02/2004 02:16 PM
> > 
> >  
> >         To:     <biojava-l at biojava.org>
> >         cc:     (bcc: Mark Schreiber/GP/Novartis)
> >         Subject:        [Biojava-l] Ontology and BioSQL
> > 
> > 
> > Hi all,
> > 
> > I am trying to use the Ontology class in Biojava 1.4rc1 to
> > create terms and triples, which are automatically persisted 
> > using the BioSQL links in BioJava. Here is my code:
> > 
> >         BioSQLSequenceDB db = new BioSQLSequenceDB(dbURL,
> >         dbUser,
> >         dbPass,
> >         biodatabase,
> >         createIfMissing);
> >  
> >         Ontology o = db.createOntology("MyOntology","An
> > ontology"); // Use getOntology to update
> >         Term MyGroup = o.createTerm("MyGroup","My favourite 
> terms.");
> >         Term Boo = o.createTerm("Boo","A fright");
> >         Term ISA = o.createTerm("ISA","Is a");
> >         Term Joke = o.createTerm("Joke","Something funny");
> >         o.createTriple(Boo,Joke,ISA,null,null);
> > 
> > I get the following exception (NB. the ontology does not
> > exist yet but the database connection is just fine):
> > 
> > Exception in thread "main"
> > org.biojava.bio.BioRuntimeException: Error removing from 
> > BioSQL tables (rolled back successfully)  at 
> > org.biojava.bio.seq.db.biosql.OntologySQL.persistTriple(Ontolo
> > gySQL.java
> > :588)
> >  at 
> > org.biojava.bio.seq.db.biosql.OntologySQL.access$300(OntologyS
> > QL.java:61
> > )
> >  at 
> > org.biojava.bio.seq.db.biosql.OntologySQL$OntologyMonitor.post
> > Change(Ont
> > ologySQL.java:512)
> >  at 
> > org.biojava.utils.ChangeSupport.firePostChangeEvent(ChangeSupp
> > ort.java:3
> > 38)
> >  at 
> org.biojava.ontology.Ontology$Impl.createTriple(Ontology.java:497)
> >  at testapp.LoadOntology.main(LoadOntology.java:61)
> > Caused by: java.sql.SQLException: Failed to persist term: 
> > ISA(Boo, Joke) from ontology: ontology: MyOntology with 
> > error: 1 : 23000  at 
> > org.biojava.bio.seq.db.biosql.OntologySQL.persistTerm(Ontology
> > SQL.java:5
> > 62)
> >  at 
> > org.biojava.bio.seq.db.biosql.OntologySQL.persistTriple(Ontolo
> > gySQL.java
> > :595)
> >  at 
> > org.biojava.bio.seq.db.biosql.OntologySQL.persistTriple(Ontolo
> > gySQL.java
> > :576)
> >  ... 5 more
> > Caused by: java.sql.SQLException: ORA-00001: unique constraint
> > (BIOSQL_OWNER.XAK1TERM) violated
> >  at 
> > oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseErr
> > or.java:12
> > 5)
> >  at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
> >  at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
> >  at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
> >  at 
> > oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedSta
> > tement.jav
> > a:181)
> >  at 
> > oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPr
> > eparedStat
> > ement.java:543)
> >  at 
> > oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(Oracle
> > Statement.
> > java:1028)
> >  at 
> > oracle.jdbc.driver.OraclePreparedStatement.executeInternal(Ora
> > clePrepare
> > dStatement.java:2888)
> >  at 
> > oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(Oracl
> > ePreparedS
> > tatement.java:2960)
> >  at 
> > org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpd
> > ate(Delega
> > tingPreparedStatement.java:101)
> >  at 
> > org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpd
> > ate(Delega
> > tingPreparedStatement.java:101)
> >  at 
> > org.biojava.bio.seq.db.biosql.OntologySQL.persistTerm(Ontology
> > SQL.java:5
> > 54)
> >  ... 7 more
> > Java Result: 1
> > 
> > When I check in the database, I find that the ontology has
> > been created, and entries made in term for each of the terms, 
> > and also an entry has been made in term for the triple 
> > itself. So why the exception? Is it trying to insert the 
> triple twice?
> > 
> > cheers,
> > Richard
> > 
> > Richard Holland
> > Bioinformatics Specialist
> > Genome Institute of Singapore
> > 60 Biopolis Street, #02-01 Genome, Singapore 138672
> > Tel: (65) 6478 8000   DID: (65) 6478 8199
> > Email: hollandr at gis.a-star.edu.sg
> >  
> > ---------------------------------------------
> > This email is confidential and may be privileged. If you are
> > not the intended recipient, please delete it and notify us 
> > immediately. Please do not copy or use it for any purpose, or 
> > disclose its content to any other person. Thank you.
> > ---------------------------------------------
> > 
> > _______________________________________________
> > Biojava-l mailing list  -  Biojava-l at biojava.org
> > http://biojava.org/mailman/listinfo/biojava-l
> > 
> > 
> > 
> > 
> 
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l at biojava.org 
> http://biojava.org/mailman/listinfo/biojava-l
> 



More information about the Biojava-l mailing list