I have several files in a directory:
CHIKV1-X-gb_AB455493.fasta
CHIKV1-X-gb_AB455494.fasta
CHIKV1-X-gb_AB455494.fasta
...
File contents:
>lcl|NC_004162.2_cds_NP_690588.1_1 [locus_tag=CHIKVgp1] [db_xref=GeneID:956309] [protein=nonstructural polyprotein] [protein_id=NP_690588.1] [location=77..7501] [gbkey=CDS]
------------------------------------------------------------
----------------atggatcctgtgtacgtggacatagacgctgacagcgccttttt
gaaggccctgcaacgtgcgtaccccatgtttgaggtggaacctaggcaggtcacaccgaa
tgaccatgctaatgctagagcgttctcgcatctagctataaaactaatagagcaggaaat
tgatcccgactcaaccatcctggatattggtagtgcgccagcaaggaggatgatgtcgga
------------------------------------------------------------
------------------------------------------------------------
---------
>gb:AB455493|Organism:Chikungunya virus|Strain Name:SL11131|Segment:null|Host:Human
atggctgcgtgagacacacgtagcctaccagtttcttactgctctactctgcaaagcaag
agattaataacccatcatggatcctgtgtacgtggacatagacgctgacagcgccttctt
gaaggccctgcaacgtgcgtaccccatgtttgaggtggaaccaaggcaggtcacaccgaa
tgaccatgctaatgctagagcgttctcgcatctagctataaaactaatagagcaggaaat
tgaccccgactcaaccatcctggatatcggcagtgcgccagcaaggaggatgatgtcgga
I have this code:
import pymysql as MySQLdb
from Bio import SeqIO
import click
import re
from collections import defaultdict
from Bio import AlignIO
import os
def conexao():
try:
conn = MySQLdb.connect(
host="localhost", user="root", passwd="", db=""
)
print("conectado")
return conn
except MySQLdb.Error as e:
print(f"Erro ao conectar no Servidor MySQL: {e}")
def desconectar(conn):
if conn:
conn.close()
@click.command()
@click.option(
"--path", default=".", type=click.Path(exists=True), help="Path para ser listado."
)
def ls2(path):
with os.scandir(path) as d:
for e in d:
if not e.name.startswith(".") and e.is_file():
lista_line = e.name
for i in lista_line:
seqaln = AlignIO.read(lista_line, "fasta")
for record in seqaln:
id_alnRef = seqaln[0].id
print(id_alnRef)
id_alnG = seqaln[1].id
id_alnGE = re.search(r".*|", id_alnG)
id_alnGE = re.sub("|", " ", id_alnGE[0])
seq1 = seqaln[0].seq
seq2 = seqaln[1].seq
alinhamento = (
">"
+ id_alnRef
+ "n"
+ seq1
+ "n"
+ ">"
+ id_alnGE
+ "n"
+ seq2
+ "n"
)
conn = conexao()
try:
cursor = conn.cursor()
cursor.execute(
f"INSERT INTO tblAlinhamentos(FK_genomaID,FK_RefCdsID, seqAln)"
f"VALUES( '{id_alnGE}', '{id_alnRef}','{alinhamento}');"
)
conn.commit()
print(
f"INSERT INTO tblAlinhamentos(FK_genomaID, FK_RefCdsID, seqAln)"
f"VALUES('{id_alnGE}', '{id_alnRef}', '{alinhamento}');"
)
except MySQLdb.Error as e:
print(f"Erro ao conectar no Servidor MySQL: {e}")
ls2()
desconectar(conn)
expected exit
PK_a FK_genomaID FK_RefCdsID seqAln
1 gb:H3455 lc|xxxx atgtatgat
2 gb:H3456 lc|xxxx atgtatgat
3 gb:H3456 lc|xxxx atgtatgat
however I cannot insert all files in the directory ... Only one or two contents of the files are inserted. In the directory there are more than two files. What am I doing wrong?