Biopython SeqRecord alphabet compatibility
Entering edit mode
3 months ago


I am using Biopython v 1.76. I have collected a list of SeqFeatures (containing specific qualifiers and a SeqFeature.FeatureLocation only) and added these to a SeqRecord containing a Seq object:

seq_record = SeqRecord(seq_obj, 
                       id = 'my_id', 
                       annotations = {'extended_up':extended_up, 
                       features = features_collected)

I am trying to write the SeqRecord to a .gbk file using:

SeqIO.write(seq_record, 'plswork.gbk', 'genbank')

This gives me the following error:

ValueError: Need a Nucleotide or Protein alphabet

Initially I did not specify an alphabet for the seq_obj object used in the SeqRecord, as it looks like the alphabet concept is getting dropped and is marked as obsolete in the docs (

However, when I got the error above, I tried to set the seq_obj alphabet to SingleLetterAlphabet - this gave the error TypeError: Invalid alphabet found, <class 'Bio.Alphabet.SingleLetterAlphabet'>

I also tried DNAAlphabet - this gave the error TypeError: Invalid alphabet found, <class 'Bio.Alphabet.DNAAlphabet'>

I'm not sure why the alphabets are invalid - they still seem to feature in the Biopython version I am using (

Has anyone got any pointers?


alphabet biopython • 173 views
Entering edit mode
3 months ago

Looks like I wasn't instantiating my alphabet class. I was doing Seq(string, alphabet = Alphabet.DNAAlphabet) - it should be Seq(string, alphabet = Alphabet.DNAAlphabet()). Credit - Biopython Translation Error?. I'll leave up in case anyone else has a similar issue :P


Login before adding your answer.

Traffic: 2682 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6