I have to make a script what automatic does a BLAST for me and than fill the database automatic. Everything goes wel until the script is trying to fill the database. Then I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rubenoldenkamp/anaconda/lib/python3.4/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 580, in runfile
execfile(filename, namespace)
File "/Users/rubenoldenkamp/anaconda/lib/python3.4/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "/Users/rubenoldenkamp/Documents/Python/BLASTscript.py", line 74, in <module>
ReadFile()
File "/Users/rubenoldenkamp/Documents/Python/BLASTscript.py", line 44, in ReadFile
BLASTfor(SeqFor)
File "/Users/rubenoldenkamp/Documents/Python/BLASTscript.py", line 72, in BLASTfor
fillblast(titel_lijst, score_lijst, e_lijst, iden_lijst, pos_lijst, gaps_lijst)
File "/Users/rubenoldenkamp/Documents/Python/BLASTscript.py", line 25, in fillblast
cursor.execute("INSERT INTO `pg2`.`blast` (`blast_sequentie_id`,`blast_titel`, `blast_score`, `blast_evalue`, `blast_gaps`, `blast_positives`, `blast_identity`) VALUES (%s, %s, %s,%s, %s,%s, %s);"(i,titel_lijst[i], score_lijst[i], e_lijst[i], iden_lijst[i], pos_lijst[i], gaps_lijst[i]))
TypeError: 'str' object is not callable
I know something with filling the database is going wrong, but I don't know what and how I can solve it. Can you please help me? This is my code:
import mysql.connector
import xlrd
from Bio.Blast import NCBIWWW
from Bio.Blast import NCBIXML
#Deze lijsten vullen met de sequentie header en sequentie uit het xlsx bestand!
def fillseq(SeqFor2, SeqFor3):
titels_lijst = SeqFor2
sequenties_lijst = SeqFor3
conn = mysql.connector.connect(host = "ithurtswhenip.nl", user = "pg2", password = "pg2", database= "pg2", port= "3307")
cursor = conn.cursor()
for i in range(0,len(titels_lijst)):
cursor.execute("INSERT INTO `pg2`.`sequenties` (`sequenties_id`,`sequenties_titel`, `sequenties_seq`) VALUES (%s,%s, %s);"(i,titels_lijst[i], sequenties_lijst[i]))
print("1 record toegevoegd")
cursor.commit()
cursor.close()
conn.close()
def fillblast(titel_lijst, score_lijst, e_lijst, iden_lijst, pos_lijst, gaps_lijst):
conn = mysql.connector.connect(host = "ithurtswhenip.nl", user = "pg2", password = "pg2", database= "pg2", port= "3307")
cursor = conn.cursor()
for i in range(0,len(titel_lijst)):
cursor.execute("INSERT INTO `pg2`.`blast` (`blast_sequentie_id`,`blast_titel`, `blast_score`, `blast_evalue`, `blast_gaps`, `blast_positives`, `blast_identity`) VALUES (%s, %s, %s,%s, %s,%s, %s);"(i,titel_lijst[i], score_lijst[i], e_lijst[i], iden_lijst[i], pos_lijst[i], gaps_lijst[i]))
print("1 record toegevoegd")
cursor.commit()
cursor.close()
conn.close()
def ReadFile():
sh = xlrd.open_workbook('TestBLAST.xlsx').sheet_by_index(0)
SeqFor = list()
SeqFor2 = list()
SeqFor3 = list()
for rownum in range(sh.nrows):
SeqFor.append(sh.cell(rownum, 1).value)
SeqFor2.append(sh.cell(rownum, 0).value)
SeqFor3.append(sh.cell(rownum, 1).value)
BLASTfor(SeqFor)
fillseq(SeqFor2, SeqFor3)
def BLASTfor(SeqFor):
sequence = SeqFor
for ForwardSeq in sequence:
results_handle = NCBIWWW.qblast("blastx","nr", ForwardSeq, hitlist_size = 1)
bestand= open ("blast_report.xml", "w")
bestand.writelines (results_handle.readlines())
bestand.close()
result = open("blast_report.xml", "r")
blast_records = NCBIXML.parse(result)
blast_record = next(blast_records)
titel_lijst, score_lijst, e_lijst, iden_lijst, pos_lijst, gaps_lijst = [], [], [], [], [] , []
E_VALUE_THRESH = 1
for alignment in blast_record.alignments:
for hsp in alignment.hsps:
if hsp.expect < E_VALUE_THRESH:
titel_lijst.append(alignment.title)
score_lijst.append(hsp.score)
e_lijst.append(hsp.expect)
iden_lijst.append(hsp.identities)
pos_lijst.append(hsp.positives)
gaps_lijst.append(hsp.gaps)
fillblast(titel_lijst, score_lijst, e_lijst, iden_lijst, pos_lijst, gaps_lijst)
ReadFile()
#BLASTfor()
#fillseq()
#z,x,c,v,b,n = fillblast()
In your
cursor.execute
lines you need a comma between the query string and the arguments list. As it stands you have something likestring(args)
which looks like a function, thus you get the error that you can't call a string.Just do that for all your
cursor.execute
statements