-1

I have written a python function which will take a single genbank file and pull the nucleotide sequences out, writing it over the original file..

from Bio import SeqIO
from Bio.SeqRecord import SeqRecord
_Sequences = []
def func(file):
    for rec in SeqIO.parse(file, "genbank"):
        id = "{}:{}{}".format(rec.id, rec.features[2].location, rec.description)
        sequence = SeqRecord(rec.seq, id=id, description="")
        _Sequences.append(sequence)
    SeqIO.write(_Sequences, file, 'fasta')
    return

then..

func("file.fasta")

This works great for a single file but I need to figure out how to loop over all files in my directory and perform this command. I haven't used python in awhile so any help is appreciated.

Taliamycota
  • 125
  • 7
  • Take a look at these alternatives: https://stackoverflow.com/questions/10377998/how-can-i-iterate-over-files-in-a-given-directory – d1sh4 Aug 12 '21 at 20:55

1 Answers1

0

try this out :

import glob
 

print(glob.glob('yourDirectory//*.*'))
for filename in glob.glob('yourDirectory//*.*'):
    print(filename)
    # your code here 
Ahmad Akel Omar
  • 317
  • 2
  • 11