Skip to content

Instantly share code, notes, and snippets.

@flashton2003
Created January 17, 2016 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flashton2003/eb1951aab22b005d565e to your computer and use it in GitHub Desktop.
Save flashton2003/eb1951aab22b005d565e to your computer and use it in GitHub Desktop.
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