[Biopython-dev] [Bug 2616] New: BioSQL support for Psycopg2

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Tue Oct 14 12:42:41 EDT 2008


http://bugzilla.open-bio.org/show_bug.cgi?id=2616

           Summary: BioSQL support for Psycopg2
           Product: Biopython
           Version: 1.48
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: BioSQL
        AssignedTo: biopython-dev at biopython.org
        ReportedBy: cymon.cox at gmail.com


Biopython 1.48 BioSQL does not support the psycopg2 PostgreSQL driver
(http://www.initd.org/pub/software/psycopg/). Current support is for the
psycopg1 driver only - the latest of which is 3 yrs old and no longer
developed.

As far as I can tell the only change is to how autocommit is flagged.

PATCH:
=========================================================================
diff -ruN BioSQL/BioSeqDatabase.py
/usr/local/lib/python2.5/site-packages/BioSQL/BioSeqDatabase.py
--- BioSQL/BioSeqDatabase.py    2008-08-27 17:34:16.000000000 +0100
+++ /usr/local/lib/python2.5/site-packages/BioSQL/BioSeqDatabase.py    
2008-10-14 15:57:07.000000000 +0100
@@ -53,7 +53,7 @@
         if kw.has_key("passwd"):
             kw["password"] = kw["passwd"]
             del kw["passwd"]
-    if driver == "psycopg" and not kw.get("database"):
+    if driver in ["psycopg", "psycopg2"] and not kw.get("database"):
         kw["database"] = "template1"
     try:
         conn = connect(**kw)
@@ -134,7 +134,7 @@
         # 1. PostgreSQL can load it all at once and actually needs to
         # due to FUNCTION defines at the end of the SQL which mess up
         # the splitting by semicolons
-        if self.module_name in ["psycopg"]:
+        if self.module_name in ["psycopg", "psycopg2"]:
             self.adaptor.cursor.execute(sql)
         # 2. MySQL needs the database loading split up into single lines of
         # SQL executed one at a time
diff -ruN BioSQL/DBUtils.py
/usr/local/lib/python2.5/site-packages/BioSQL/DBUtils.py
--- BioSQL/DBUtils.py   2008-03-21 10:48:32.000000000 +0000
+++ /usr/local/lib/python2.5/site-packages/BioSQL/DBUtils.py    2008-10-14
15:57:28.000000000 +0100
@@ -68,7 +68,17 @@

     def autocommit(self, conn, y = True):
         conn.autocommit(y)
+
 _dbutils["psycopg"] = Psycopg_dbutils
+ 
+class Psycopg2_dbutils(Psycopg_dbutils):
+    def autocommit(self, conn, y = True):
+        if y:
+            conn.set_isolation_level(0)
+        else:
+            conn.set_isolation_level(1)
+
+_dbutils["psycopg2"] = Psycopg2_dbutils

 class Pgdb_dbutils(Generic_dbutils):
     """Add support for pgdb in the PyGreSQL database connectivity package.

========================================================================

Tests/test_BioSQL.py :

[cymon at chara Tests]$ python test_BioSQL.py
Load SeqRecord objects into a BioSQL database. ... ok
Get a list of all items in the database. ... ok
Test retrieval of items using various ids. ... ok
Make sure Seqs from BioSQL implement the right interface. ... ok
Check SeqFeatures of a sequence. ... ok
Make sure SeqRecords from BioSQL implement the right interface. ... ok
Check that slices of sequences are retrieved properly. ... ok
Make sure all records are correctly loaded. ... ok
Indepth check that SeqFeatures are transmitted through the db. ... ok

----------------------------------------------------------------------
Ran 9 tests in 19.749s

OK

With a tweak to test_BioSQL_SeqIO.py :
154         else :
155             #Should both be lists of strings...
156             old_f.qualifiers[key].sort()
157             new_f.qualifiers[key].sort()
158             assert old_f.qualifiers[key] == new_f.qualifiers[key]

One record in the tests has two \allele features "T" and "C" so they need to be
sorted before comparison.

$ python test_BioSQL_SeqIO.py > out
$ diff out output/test_BioSQL_SeqIO 
0a1
> test_BioSQL_SeqIO
$ 

BUT both _FAIL_ when run with the run_tests.py.

The short exercises in the BioSQL wiki (after the unit tests) also run fine.


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


More information about the Biopython-dev mailing list