Skip to content

Instantly share code, notes, and snippets.

@brevans
Last active August 29, 2015 13:56
Show Gist options
  • Save brevans/9329372 to your computer and use it in GitHub Desktop.
Save brevans/9329372 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from os import path
from glob import iglob
import re
trans = {'AGO':'DAR', 'CAZ':'GUN', 'CF':'CF', 'F':'CF',
'CRU':'POR', 'ESP':'HOO', 'LG':'ABI', 'LP':'VIC',
'LT':'VIC', 'PBL':'PBL', 'PBR':'PBR', 'PZ':'EPH',
'SCR':'CHA', 'VA':'VAN', 'VD':'MIC'}
for fi in iglob('consensus/*.fa'):
in_file = open(fi)
out_name = re.sub('\.fa$', '', path.basename(fi)) + '_species.fa'
out_file = open(path.join('consensus',out_name), 'w')
for l in in_file:
if l.startswith('>'):
mat = re.match('>([A-Z]+)([_\d]*)', l)
matches = mat.groups()
out_file.write(''.join([l.rstrip(), '_', trans[matches[0]], '\n']))
else:
out_file.write(l)
out_file.close()
in_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment