<p>Quickly ...</p>
<pre><code>from Bio.Alphabet import generic_protein
from Bio.Seq import Seq
</code></pre>
<p>then ..</p>
<pre><code>myprot = Seq('EXAMPLEPROT', alphabet=generic_protein)
    
</code></pre>

CC BY-SA 4.0
2023-10-27T20:55:20.600Z
Thanks, I tried without setting the alphabet but `Seq` needs that parameter. Let me try another way of importing the `Alphabet`
El Dude
CC BY-SA 4.0
2023-10-27T20:56:43.393Z
Using `generic_alphabet` tells me this: `ValueError: Need a Nucleotide or Protein alphabet`
El Dude
CC BY-SA 4.0
2023-10-27T20:58:55.510Z
I was wrong, `generic_protein` does the trick, not `generic_alphabet`
El Dude
CC BY-SA 4.0
2023-10-27T20:59:42.320Z
Thanks @ElDude done .. many thanks.
M__
CC BY-SA 4.0
2023-10-27T20:53:26.817Z
2023-10-27T20:59:10.280Z
2023-10-27T20:59:10.280Z
M__
<p>I am trying to store a GenBank file that could be read by Geneious later.
I found an example how to create the GenBank file <a href="https://stackoverflow.com/questions/65216225/writing-and-saving-genbank-files-with-biobython-seqio-module">here</a></p>
<p>But now I run into <code>Alphabet</code> issues.
I tried all protein classes from the <a href="https://biopython.org/docs/1.75/api/Bio.Alphabet.IUPAC.html" rel="nofollow noreferrer">documentation</a>, but all fail with the same error:</p>
<p><code>TypeError: Invalid alphabet found, &lt;class 'Bio.Alphabet.ProteinAlphabet'&gt;.</code></p>
<p>I dont know what else to do here? Using <code>biopython==1.73</code></p>
<pre><code>    record = SeqRecord.SeqRecord(
        Seq.Seq(&quot;MIRQALAVAALLLAGTAQADGLIDN&quot;, alphabet=Alphabet.ProteinAlphabet),
        id=&quot;FooBar&quot;,
    )

    with NamedTemporaryFile(mode=&quot;w&quot;) as genbank:
        SeqIO.write(record, genbank, &quot;genbank&quot;)
        pass
</code></pre>

CC BY-SA 4.0
2023-10-29T07:30:57.867Z
If possible, please show a minimum reproducible chunk of code. The code shown here does not include any library imports, so will not work as-is.
gringer
<python><genbank><biopython>
BioPython SeqIO fails with Invalid Alphabet found
# BioPython SeqIO fails with Invalid Alphabet found

(Asked by: username_0 on 2023-10-27)

I am trying to store a GenBank file that could be read by Geneious later.
I found an example how to create the GenBank file here
But now I run into Alphabet issues.
I tried all protein classes from the documentation, but all fail with the same error:
TypeError: Invalid alphabet found, .
I dont know what else to do here? Using biopython==1.73
    record = SeqRecord.SeqRecord(
        Seq.Seq("MIRQALAVAALLLAGTAQADGLIDN", alphabet=Alphabet.ProteinAlphabet),
        id="FooBar",
    )

    with NamedTemporaryFile(mode="w") as genbank:
        SeqIO.write(record, genbank, "genbank")
        pass

**Tags:** python, genbank, biopython
> **Comments:**
> **username_1**: If possible, please show a minimum reproducible chunk of code. The code shown here does not include any library imports, so will not work as-is.  

---

## 1 answers

### Answer by username_2 on 2023-10-27. Score: 1 | Accepted answer

Quickly ...
from Bio.Alphabet import generic_protein
from Bio.Seq import Seq

then ..
myprot = Seq('EXAMPLEPROT', alphabet=generic_protein)

> **Comments:**
> **username_0**: Thanks, I tried without setting the alphabet but `Seq` needs that parameter. Let me try another way of importing the `Alphabet`  
> **username_0**: Using `generic_alphabet` tells me this: `ValueError: Need a Nucleotide or Protein alphabet`  
> **username_0**: I was wrong, `generic_protein` does the trick, not `generic_alphabet`  
> **username_2**: Thanks @ElDude done .. many thanks.  

---

