0

I am trying to create a loop to parse one by one 5 fasta files that I have in a same directory. Now I will explain a little bit, I have 5 fasta files with the genome of 5 microorganism, each one in each file. The idea is to obtain de Ids from each file and put them in to a dictionary {Mo_Id1:0, Mo_Id2:0...,Mo_Id5:0}

I think my loop reads the first file, but then it gave me the following error; No such file or directory 'GCF_000006532.1_ASM696v3_genomic.fna' (this is the name of the second file that I have in my folder). I show you my code:

from Bio import SeqIO
import os
dicc_MO=[]
    
files = os.listdir("/home/alumno/Escritorio/Asig2Python/Semana4/Tarea/genomas/genomas")

for f in files:
    for record_seqMO in SeqIO.parse(f,"fasta"):
        record_seqMO.id not in dicc_MO: 
            dicc_MO[record_seqMO.id] = 0
        
print(dicc_MO)

With dicc_MO i was trying to check if the loop was OKEY, in that case, I should have a dictionary where the keys are the microorganism name and the values are 0.

Mateo Torres
  • 1,545
  • 1
  • 13
  • 22

1 Answers1

0

The command os.listdir only shows the name of files without path. So you need to add path to each file name in your list files.

from Bio import SeqIO
import os
dicc_MO=[]
    
files=os.listdir("/home/alumno/Escritorio/Asig2Python/Semana4/Tarea/genomas/genomas")

for f in files:
    f = f + "/home/alumno/Escritorio/Asig2Python/Semana4/Tarea/genomas/genomas/"
    for record_seqMO in SeqIO.parse(f,"fasta"):
    ...
Jie
  • 372
  • 3
  • 10