Skip to content

Instantly share code, notes, and snippets.

@armanbilge
Last active August 29, 2015 14:20
Show Gist options
  • Save armanbilge/b48a62be1fae743844ae to your computer and use it in GitHub Desktop.
Save armanbilge/b48a62be1fae743844ae to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
from Bio import SeqIO
for fn in sys.argv[1:]:
with open(fn, 'r') as f:
print('\t<data id="{}" name="alignment">'.format(fn[:-len('_unphased.nex')]))
for record in SeqIO.parse(f, 'nexus'):
if record.id.endswith('_1'):
print('\t\t<sequence taxon="{}" totalcount="4" value="{}"/>'.format(record.id, record.seq))
print('\t</data>')
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment