Repository: biopython/biopython

Issue:
Should we remove/replace Bio.Alphabet?
Filing this meta-issue, since we don't seem to have a single place discussing this on GitHub.

**My (likely biased) summary from those discussions is no one likes the current alphabet system, and most people ignore it.**

Biopython has a complicated hard to use legacy alphabet system in ``Bio.Alphabet`` which is used as a typing system (e.g. can't do reverse-complement on a protein), can store some useful information like the expected letters, if gapped and the gap character (although only one), and a stop codon symbol (although only one).

The objects in ``Bio.Alphabet`` cover three-letter alphabets as well as the more commonly used one-letter alphabets, although the ``Seq`` object effectively assumes the later only. Three-letter alphabets can be used with the array-based ``MutableSeq`` object, but it is very fragile and many things break - thus #1681.

Note we do not (currently) validate the expected letters when making a sequence object with an alphabet with an explicit set of expected letters -  #1040.

Discussion on #1674 (hiding alphabets) has meant we now hide the alphabet in the ``Seq`` object representation if it is the default alphabet. Discussion there, and on #1681, and on the mailing list suggests going further and *removing* ``Bio.Alphabet`` entirely.

Note that removal is not as simple as it might sound - it will require some delicate modifications, for example several of the parsers in ``Bio.SeqIO`` use the alphabet to store the sequence type (important metadata in more than one file format).

I personally do like the typing system aspect of the alphabet system, but think we only need a much simpler DNA/RNA/nucleotide/protein/other system (more like an enum). I started looking at that on this branch which aimed to break as little existing code as possible: https://github.com/peterjc/biopython/tree/alpha_lite



Discussion:
I don't think it's productive to restart this discussion. We have been discussing this since 2005 (this is not a typo), if not earlier.

As a reminder, in August 2018 we called for a Biopython Enhancement Proposal on alphabets, where we invited people in favor of having alphabets in Biopython to work out a detailed proposal on the purpose and implementation of alphabets:
https://lists.open-bio.org/pipermail/biopython/2018-August/016524.html
with a time limit of January 1, 2020 after which alphabets would be removed from Biopython if no agreement on a proposal was reached.

Overall, there was little interest from users and developers. Thomas Wemyss stepped up to work out a proposal, but in the end concluded that it was better to remove alphabets:
https://lists.open-bio.org/pipermail/biopython/2018-October/016556.html

@peterjc  Can you take over from Thomas and write a BEP?
This wasn't meant to restart the conversation - but be a visible marker. To that end, I'll lock this issue.

@peterjc  OK, thanks!
Locking the issue preventing GitHub automatically linking pull request #2050 (just merged) which declared ``Bio.Alphabet`` as obsolete, and added a ``PendingDeprecationWarning`` (which is silent by default).

See also our https://biopython.org/wiki/Deprecation_policy
Note to self for a possible reduced sequence type system: ``enum34`` (available on PyPI) is the new Python stdlib enum module available in Python 3.4 backported for previous versions of Python from 2.4 to 3.3. tested on 2.6, 2.7, and 3.3+
See also #2488, which includes a reminder that for many people the only place they need to use ``Bio.Alphabet`` is in constructing ``SeqRecord`` objects for output in GenBank or other formats which need to know DNA vs RNA vs Protein explicitly.
Following the release of Biopython 1.77 (May 2020) which was focused on removing Python 2 specific code, we are currently removing internal use of ``Bio.Alphabet`` objects. The ``Seq`` objects will no long use this attribute for type checking.

Where recording the molecule type is required (some file formats need this), the ``SeqRecord`` annotation is used instead. Specifically, the ``.annotations['molecule_type']`` field which was already used in the GenBank/EMBL parser. This should be a string containing "DNA", "RNA", "protein". It can be a longer string like "mRNA".
With the recent work up to and including #3168, Biopython no longer uses ``Bio.Alphabet`` internally and we should be OK to remove or deprecate it in the next release (Biopython 1.78). We still need to look at documentation and helping people transition, see e.g. examples on #3156.

Resolving patch:
diff --git a/Bio/Alphabet/__init__.py b/Bio/Alphabet/__init__.py
--- a/Bio/Alphabet/__init__.py
+++ b/Bio/Alphabet/__init__.py
@@ -13,12 +13,10 @@
 therefore removed from Biopython in release 1.78. Instead, the molecule type is
 included as an annotation on SeqRecords where appropriate.
 
-Please see
-https://github.com/biopython/biopython/issues/3156
-for examples showing how to transition from Bio.Alphabet to molecule type
-annotations.
+Please see https://biopython.org/wiki/Alphabet for examples showing how to
+transition from Bio.Alphabet to molecule type annotations.
 """
 
 raise ImportError(
-    "Bio.Alphabet has been removed from Biopython. In many cases, the alphabet can simply be ignored and removed from scripts. In a few cases, you may need to specify the ``molecule_type`` as an annotation on a SeqRecord for your script to work correctly. Please see https://github.com/biopython/biopython/issues/3156 for more information."
+    "Bio.Alphabet has been removed from Biopython. In many cases, the alphabet can simply be ignored and removed from scripts. In a few cases, you may need to specify the ``molecule_type`` as an annotation on a SeqRecord for your script to work correctly. Please see https://biopython.org/wiki/Alphabet for more information."
 )


Test patch: