This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Biopython SeqRecord alphabet compatibility

Hello,

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, 
                                      'extended_down':extended_down},
                       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 (https://biopython.org/docs/1.75/api/Bio.Alphabet.html).

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 (https://biopython.org/docs/1.76/api/Bio.Alphabet.html).

Has anyone got any pointers?

Cheers!

alphabet biopython

1 answer

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

Log in to answer this question.