The 'module' object cannot be called - Bio.IUPAC

When i try

from Bio.Alphabet import IUPAC from Bio import Seq my_prot = Seq("AGTACACTGGT", IUPAC.protein) 

Why the following error occurs:

 TypeError: 'module' object is not callable 

PS: this is an example from the BioPython Cookbook

+4
source share
2 answers

In the BioPython source code, the "Seq" class is located in the " Seq.py " file in the path /Seq/Seq.py

Meaning ... You need to import the Seq (file), which means its "Module", and then call the "Seq" class in the "Seq" module

So try the following:

 from Bio.Alphabet import IUPAC from Bio import Seq my_prot=Seq.Seq("AGTACACTGGT",IUPAC.protein) 

If you are ever confused in Python about what you import and what you call, you can do this:

 import Bio.Seq print type(Bio.Seq) >>> <type 'module'> print type(Bio.Seq.Seq) >>> <type 'classobj'> 
+8
source

Ben gave a good clear answer explaining this problem. I think you copied the example incorrectly,

 >>> from Bio.Seq import Seq >>> from Bio.Alphabet import IUPAC >>> my_prot = Seq("AGTACACTGGT", IUPAC.protein) >>> my_prot Seq('AGTACACTGGT', IUPACProtein()) >>> my_prot.alphabet IUPACProtein() 

At least that's what he is currently saying http://www.biopython.org/DIST/docs/tutorial/Tutorial.html

Note that the reason for the confusion would be avoided if Biopython used seq (lower case) for the module and Seq (header) for the class, which is now recommended for Python, see http://www.python.org/dev/ peps / pep-0008 /

+1
source

Source: https://habr.com/ru/post/1346310/


All Articles