[Biopython-dev] Checking alphabet argument in alignments

Peter biopython at maubp.freeserve.co.uk
Fri Jul 11 10:33:22 UTC 2008


I'd like to add the following check to the __init__ method of the
Bio.Align.Generic.Alignment object (our base alignment class),

>         if not (isinstance(alphabet, Alphabet.Alphabet) \
>         or isinstance(alphabet, Alphabet.AlphabetEncoder)):
>             raise ValueError("Invalid alphabet argument")

This will prevent subtle user errors like this:

from Bio import Alphabet
from Bio.Align.Generic import Alignment
a = Alignment(Alphabet.ProteinAlphabet)

which should be:

from Bio import Alphabet
from Bio.Align.Generic import Alignment
a = Alignment(Alphabet.ProteinAlphabet())

The only downside I have thought of is if anyone has created their own
alignment class which does NOT subclass the original
Bio.Alphabet.Alphabet class.

This same test could (should?) also be added to the Seq and MutableSeq objects.

What do people think?

Peter



More information about the Biopython-dev mailing list