2
seqteste.txt or List:
>gb:KX262887|Organism:Zika virus|Strain Name:103451|Segment:null|Subtype:Asian|Host:Human
GTTGTTGATCTGTGTGAATCAGACTGCGACAGTTCGAGTTTGAAGCGAAAGCTAGCAACAGTATCAACAG
GTTTTATTTTGGATTTGGAAACGAGAGTTTCTGGTCATGAAAAACCCAAAAAAGAAATCCGGAGGATTCC
>gb:KX262887|Organism:Zika virus|Strain Name:103451|Segment:null|Subtype:Asian|Host:Human
GTTGTTGATCTGTGTGAATCAGACTGCGACAGTTCGAGTTTGAAGCGAAAGCTAGCAACAGTATCAACAG
GTTTTATTTTGGATTTGGAAACGAGAGTTTCTGGTCATGAAAAACCCAAAAAAGAAATCCGGAGGATTCC
>gb:KX262887|Organism:Zika virus|Strain Name:103451|Segment:null|Subtype:Asian|Host:Human
GTTGTTGATCTGTGTGAATCAGACTGCGACAGTTCGAGTTTGAAGCGAAAGCTAGCAACAGTATCAACAG
GTTTTATTTTGGATTTGGAAACGAGAGTTTCTGGTCATGAAAAACCCAAAAAAGAAATCCGGAGGATTCC
mysqldb:
id id_name host organism seq
script/ code:
import pymysql.cursors
import pymysql as MySQLdb
import pymysql
from Bio import SeqIO
try:
conexao = MySQLdb.connect(host="localhost",user="root",passwd="",db="db_teste")
print("conectado")
print(conexao)
except:
print("Não conectado")
for item in SeqIO.parse('seqteste.txt', 'fasta'):
dados = print('>{}\t{}'.format(str(item.description).replace('|', '\t'), item.seq),)
with conexao:
with conexao.cursor() as cursor:
sql = "INSERT INTO `tabelateste` (`id`, `id_name`, `host`, `organism`, `seq`) VALUES(3, %s, %s, %s,%s)"
print(sql)
cursor.execute(sql,(3,dados,dados,dados,dados))
conexao.commit()
error:
INSERT INTO `tabelateste` (`id`, `id_name`, `host`, `organism`, `seq`) VALUES(3, %s, %s, %s,%s)
Traceback (most recent call last):
File "c:\Users\B\Desktop\codeinserir.py", line 21, in <module>
cursor.execute(sql,(3,dados,dados,dados,dados))
File "C:\Users\B\AppData\Local\Programs\Python\Python39\lib\site-packages\pymysql\cursors.py", line 146, in execute
query = self.mogrify(query, args)
File "C:\Users\B\AppData\Local\Programs\Python\Python39\lib\site-packages\pymysql\cursors.py", line 125, in mogrify
query = query % self._escape_args(args, conn)
TypeError: not all arguments converted during string formatting
code2 :
for linha in alllines:
seqt = linha.replace("|","\t")
seqin = SeqIO.parse(seqt, "fasta")
for i in seqin:
print(i.id,i.seq)
with con:
with con.cursor() as cursor:
sql = "INSERT INTO `tabelateste` (`id_name`,`seq`) VALUES (%s, %s)"
cursor.execute(sql,(i.id , i.seq))
con.commit()
error:
Traceback (most recent call last):
File "c:\Users\B\Desktop\codeinserir.py", line 25, in <module>
DEanalysisfile = open (argumentos.file, 'r')
TypeError: expected str, bytes or os.PathLike object, not NoneType
expected exit:
mysqldb
id id_name host organism seq
1 gb:KX262887 Human Zika Virus aatgtgttt
I am trying to insert data from a seqteste.txt file into a mysql database but the result is always null. How to resolve this problem? What am I doing wrong??
Using the first example, test by taking 3 out of the tuple, stand alone like this
cursor.execute(sql,(dados,dados,dados,dados))
, because "3" is already harcoded in the query.– Miguel