• 0 views
•
link
Looking for matching names in fasta file and genbank records
Is there a python way to look at genbank files in a different directory to see if the names of the files are listed on a fasta file?
• 1,420 views
•
link
1 answer
In Python you can do this:
import fnmatch
import os
from Bio import SeqIO
filenames = [f for f in os.listdir("your_folder") if fnmatch.fnmatch(f, '*.gb')]
records = SeqIO.parse('records.fasta', 'fasta')
for rec in records:
for title in filenames:
if title in rec.description:
print('Match for ' + str(title))
print('In: ', rec.id)
• 0 views
•
link
Alternatively for making filenames, use Python's glob module to make a list of full pathnames with matches in the specified folder combined with os.path.basename() to retain just the filename:
import glob
filenames = [os.path.basename(x) for x in glob.glob(os.path.join('your_folder','*.gb'))]
• 0 views
•
link
Log in to answer this question.