我必须编写一个脚本,自动为我做一个 BLAST,而不是自动填充数据库。在脚本尝试填充数据库之前,一切都很顺利。然后我收到以下错误:
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
我知道填充数据库出了问题,但我不知道我能解决什么以及如何解决它。你能帮我么?这是我的代码:
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()