[Biojava-l] Problem Inserting Genbank File

Michael Joss mjoss at bio.mq.edu.au
Tue Aug 1 12:41:03 UTC 2006


Hi Richard and fellow listers,
             Will teach me to be all gung-ho. Asking me to post the
entire source code made me actually look at what I had written. I
realised I had commented out a line that had been giving me trouble... I
imagine it is actually useful for something.. maybe connecting BiojavaX
to the DB ;) Thats what you get for patching a whole bunch of examples
together when you have no idea what you are doing I guess.

I am now getting an error with the previously commented code that
doesn't make a lot of sense to me?? 

It says:
Exception in thread "main" java.lang.IllegalArgumentException: Parameter
must be a org.hibernate.Session object
        at
org.biojavax.bio.db.biosql.BioSQLRichObjectBuilder.<init>(BioSQLRichObjectBuilder.java:68)
        at
org.biojavax.RichObjectFactory.connectToBioSQL(RichObjectFactory.java:221)
        at biojavaxtest.Main.main(Main.java:45)

 but sess definitly is a org.hibernate.Session object.. isn't it? 

Sorry if I am being a pain its kinna tough learning Java and Biojava and
hibernate at the same time. I am sure once I get the ball rolling I will
be ok.

Cheers

Joss

Source code
|
|
V

package biojavaxtest;

import java.io.BufferedReader;
import java.io.FileReader;
import org.biojavax.Namespace;
import org.biojavax.RichObjectFactory;
import org.biojavax.bio.db.RichSequenceDB;
import org.biojavax.bio.db.biosql.BioSQLRichSequenceDB;
import org.biojavax.bio.seq.RichSequence;
import org.biojavax.bio.seq.RichSequenceIterator;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


/**
 *
 * @author Joss
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        org.apache.log4j.BasicConfigurator.configure();
        SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();  
        // open the session
        Session sess = sessionFactory.openSession();                    
                    
        // connect it to BioJavaX
        RichObjectFactory.connectToBioSQL(sess);  //### Was commented
out in previous post ###
        Transaction tx = sess.beginTransaction();
        try {
        // create the RichSequenceDB wrapper around the Hibernate
session
            RichSequenceDB db = new BioSQLRichSequenceDB(sess);   

            RichSequence seq1 = db.getRichSequence("AE012130");    //
load the sequence where name='AE012130'
            BufferedReader br = new BufferedReader(new
FileReader("C:/CODE/AY928791.GBANK"));
    // a namespace to override that in the file
            Namespace ns = RichObjectFactory.getDefaultNamespace();
    // we are reading DNA sequences
            RichSequenceIterator seqs =
RichSequence.IOTools.readGenbankDNA(br,ns);
            while (seqs.hasNext()) {
                  RichSequence seq2 = seqs.nextRichSequence();
                  db.addRichSequence(seq2);
            }
    // add it to the database
 
          tx.commit();
            System.out.println("Changes committed.");
            
        } catch (Exception e) {
            tx.rollback();
            System.out.println("Changes rolled back.");
            e.printStackTrace();
        }
        
        sess.close();    // disconnect from the database 
        

    }
    
}



More information about the Biojava-l mailing list