[BioPython] Problem with python and mysql
pap501 at york.ac.uk
pap501 at york.ac.uk
Thu Mar 31 05:21:34 EST 2005
Hi
I am a masters student at the University of York working on a project to
create a database of DNA sequences.
I am trying to grab information from text files using a python script to
insert data into a MySQL table. The problem is that although I can query
MySQL through Python I cannot write into MySQL through Python. I am using
the Windows platform with Python version 2.4 with Biopython installed and
MySQL Server 4.1.
I have attached my python script to this email.
The script takes each text file in turn (although only one is listed in the
script at the mo) and inserts the library code, Genbank code (primary key),
TiGR code (if there is one, null otherwise) and the DNA sequence (string of
characters). Each file is a library of ~2000 DNA sequences. The python
script runs but does not write the information into my MySQL table. When I
query the table in MySQL it says that the table is empty.
Can anyone advise me what to do? Is it soemthing to do with the setup of
MySQL and/or Python or a problem with the Python script?
Any advice would be greatly appreciated.
Many thanks
Phil
-------------- next part --------------
import cStringIO
import os
import MySQLdb
conn= MySQLdb.connect (host="localhost",
user ="root",
passwd ="p1geon1",
db="phil")
allfilenames=('F50',)
for a in allfilenames:
print a
input8=open ('SsGI_library_#'+a+'.txt','r')
outfile=open('outtest.txt', 'w')
i8=input8.read()
# print i8
listofentries=i8.split('>')
for li in listofentries:
print li
numbers=li.split('\n')[0]
print numbers
seq=li.split('\n')[1]
# print numbers
bothnumbers=numbers.split('\t')
print bothnumbers
gb=bothnumbers[0]
if len(bothnumbers)==2:
tnum= bothnumbers [1]
else:
tnum='NULL'
qry="insert into sequences2 values('%s','%s','%s','%s');"% (a, gb, tnum, seq)
print qry
conn.query(qry)
More information about the BioPython
mailing list