Last active
August 29, 2015 13:56
-
-
Save brevans/9329372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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