Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import os
from Bio import SeqIO
from BCBio import GFF
root_dir = '/Users/flashton/projects/nctc3000/2016.01.17'
def main(root_dir):
for each in os.listdir(root_dir):
with open('%s/%s' % (root_dir, each)) as fi:
basename = each.split('.')[0]
if each.endswith('embl'):
with open('%s/%s.fa' % (root_dir, basename), 'w') as fo:
for rec in SeqIO.parse(fi, 'embl'):
fo.write('>%s\n' % rec.id)
fo.write('%s\n' % rec.seq)
elif each.endswith('gff'):
with open('%s/%s.fa' % (root_dir, basename), 'w') as fo:
try:
for rec in GFF.parse(fi):
fo.write('>%s\n' % rec.id)
fo.write('%s\n' % rec.seq)
except:
print each, 'no dice'
# os.system('rm -rf %s/%s' % (root_dir, each))
main(root_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment