[Biopython] Alphabet question

Eric Talevich eric.talevich at gmail.com
Tue May 11 23:34:22 UTC 2010


On Tue, May 11, 2010 at 7:11 PM, Sebastian Bassi <sbassi at gmail.com> wrote:

> I tried this:
>
> >>> from Bio.Seq import Seq
> >>> from Bio.Alphabet import IUPAC
> >>> seq_1 = Seq('GATCGATGGGCCTATATAGGA', IUPAC.unambiguous_dna)
> >>> seq_1
> Seq('GATCGATGGGCCTATATAGGA', IUPACUnambiguousDNA())
>
> I wonder why the alphabet argument is entered as IUPAC.unambiguous_dna
> but when I see the object, this argument is printed as
> IUPACUnambiguousDNA().
>

Hi Sebastian,

The IUPAC.unambiguous_dna object is a copy of IUPACUnambiguousDNA(), already
instantiated. It shows up in the source code of Bio/Alphabet/IUPAC.py as:

unambiguous_dna = IUPACUnambiguousDNA()

So you could do:

>>> from Bio.Seq import Seq
>>> from Bio.Alphabet import IUPAC
>>> seq_1 = Seq('GATCGATGGGCCTATATAGGA', IUPAC.IUPACUnambiguousDNA())
>>> seq_1
Seq('GATCGATGGGCCTATATAGGA', IUPACUnambiguousDNA())

Looking at it that way, the repr() is kind of deceptive. It doesn't match
unless you've imported the IUPACUnambiguousDNA class directly.


The problem with this is that I was expecting to do:
>
> seq_2 = Seq('GATCGATGGGCCTATATAGGA', IUPACUnambiguousDNA())
>
> Since:
>
> >>> seq_1
> Seq('GATCGATGGGCCTATATAGGA', IUPACUnambiguousDNA())
>
> But when I try to do it, I get this:
>
> >>> seq_2 = Seq('GATCGATGGGCCTATATAGGA', IUPACUnambiguousDNA())
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> NameError: name 'IUPACUnambiguousDNA' is not defined
>

The NameError occurs because you haven't imported IUPACUnambiguousDNA
directly; you just have the IUPAC module, so you need the "IUPAC." prefix.

Cheers,
Eric



More information about the Biopython mailing list