Skip to content

Instantly share code, notes, and snippets.

@mdshw5
Created November 11, 2015 03:00
Show Gist options
  • Save mdshw5/6eca5b250d3e7060aa99 to your computer and use it in GitHub Desktop.
Save mdshw5/6eca5b250d3e7060aa99 to your computer and use it in GitHub Desktop.
biostars 165335
from pyfaidx import Fasta
name_map = {}
with open('newnames.txt') as newnames:
next(newnames) # remove header
for line in newnames:
old, new = line.rstrip().split()
name_map[old] = new
with open('seqnew.fa', 'w') as new_fasta:
# replace the fasta sequence names for lookup
fasta = Fasta('seq.fa', key_function = lambda x: name_map[x])
for seq in fasta:
new_fasta.write(seq.name + '/n')
for line in seq:
new_fasta.write(line + '/n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment