Posts Tagged ‘mysql’

Using MySQLdb 1.2.2 with python 2.6.1

Thursday, April 9th, 2009

When importing MySQLdb 1.2.2 into python 2.6.1 an error is reported:

Python 2.6.1 (r261:67515, Dec  7 2008, 08:27:41)
[GCC 4.3.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLDB
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ImportError: No module named MySQLDB
>>> import MySQLdb
/usr/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet

This is because the sets module is not built-in into the core distribution of python.

To get rid of this error and use the more efficient built-in set
type, do the following in the __init__.py file that was reported:

* comment line 34:

When importing MySQLdb 1.2.2 into python 2.6.1 an error is reported:

Python 2.6.1 (r261:67515, Dec  7 2008, 08:27:41)
[GCC 4.3.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLDB
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ImportError: No module named MySQLDB
>>> import MySQLdb
/usr/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet

This is because the sets module is not built-in into the core distribution of python.

To get rid of this error and use the more efficient built-in set
type, do the following in the __init__.py file that was reported:

* comment line 34: from sets import ImmutableSet

* add after that line: ImmutableSet = frozenset

* comment line 41 in the original file: from sets import BaseSet

* add after that line: BaseSet = set

Like this the built-in types will be used anytime a BaseSet or an ImmutableSet is referenced.

Now everything works fine:

Python 2.6.1 (r261:67515, Dec  7 2008, 08:27:41)
[GCC 4.3.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLdb
>>> MySQLdb.version_info
(1, 2, 2, ‘final’, 0)
>>>

Laplacian modified Bayesian classifier

Tuesday, February 5th, 2008

I needed a Bayesian classifier with support for some custom add-ons. The implementation that is in the script provided here has been done in Python. It reads data from tab-separated textfiles or alternatively supports reading from MySQL databases. Additionally, it also has the possibility to include combinations of features as orthogonal sparse bigrams (OSBs). The classifier gives the scores and class labels for a user-definable number of classes. The source code is well documented with comments. There is no usage() function as of yet, so the command line arguments are only documented within the source.
(more…)

Dump molecules and info from an SDF file to a MySQL database

Monday, February 4th, 2008

This script can be used to dump all molecules from an SDF file with all or a specified subset of corresponding SDF tags into an SQL database, in this case MySQL.
SDF parsing: The script parses SDF files and initialises an instance of class Molecule for each parsed molecule. A dictionary of associated SDF tags is available as Molecule.SDFdict, all SDF tags found are in the list Molecule.SDFtags, the connection table in Molecule.CTAB. Either all or a few selected tags are then written into a database. MySQL: A database has to be created manually (create database ). The name of the table where to write the structural info (i.e. CTAB) has to be specified on the command line. At least one SDF tag has to be specified on the command line. Additional SDF tags to be written to the database are specified as a colon-separated list. (more…)