Created
November 11, 2015 03:00
-
-
Save mdshw5/6eca5b250d3e7060aa99 to your computer and use it in GitHub Desktop.
biostars 165335
This file contains hidden or 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
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