Skip to content

Instantly share code, notes, and snippets.

@mattravenhall
Created March 21, 2018 11:32
Show Gist options
  • Select an option

  • Save mattravenhall/2221437a6c32093a283266ff6e355c23 to your computer and use it in GitHub Desktop.

Select an option

Save mattravenhall/2221437a6c32093a283266ff6e355c23 to your computer and use it in GitHub Desktop.
Convert a fasta to a genbank file with SeqIO, accounting for issues with alphabets
# Fasta to Genbank (dna)
filename = 'example_fasta'
from Bio import SeqIO
from Bio.Alphabet import generic_dna
seqs = list(SeqIO.parse(filename+'.fa','fasta'))
for seq in seqs:
seq.seq.alphabet = generic_dna
SeqIO.write(seqs, filename+'.gbk', 'genbank')
@mattravenhall
Copy link
Author

Fasta to Genbank conversion with SeqIO requires that the seq alphabet types be converted to generic_dna. This short script avoids having to mess around with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment