[Biopython-dev] test_MarkovModel.py and Numeric/numpy work?

Michiel de Hoon mjldehoon at yahoo.com
Sat Sep 20 03:00:09 UTC 2008


This is an example where the old Numerical Python and the new NumPy need different code at the Python-level.

The Numerical Python -dependent code was:

p_initial = _safe_copy_and_check(p_initial, (N,)) or _random_norm(N)

Here, _safe_copy_and_check returns an array. NumPy does not allow interpreting an array as a boolean, so instead we have to use:

p_initial = _safe_copy_and_check(p_initial, (N,))
if not p_initial.any():
     p_initial = _random_norm(N)

which is the code Brad uploaded to CVS.

However, Numerical Python arrays don't have the .any() method, so this fails with the old Numerical Python.

Let's first see if anybody wants to continue using the old Numerical Python. If so, we can add some try:except: around the call to p_initial.any(). If not, then Brad's code is fine.

--Michiel.


--- On Thu, 9/18/08, Peter <biopython at maubp.freeserve.co.uk> wrote:

> From: Peter <biopython at maubp.freeserve.co.uk>
> Subject: [Biopython-dev] test_MarkovModel.py and Numeric/numpy work?
> To: "BioPython-Dev Mailing List" <biopython-dev at lists.open-bio.org>
> Date: Thursday, September 18, 2008, 11:00 AM
> Hi all,
> 
> I'm back from my one week holiday, and after I updated
> my machine I'm
> seeing a new failure in test_MarkovModel.py is probably
> related to the
> Numeric/numpy work,
> 
> $ python run_tests.py test_MarkovModel.py
> test_MarkovModel ... ERROR
> (output cut)
> 
> $python test_MarkovModel.py
> TESTING train_visible
> Training HMM
> Classifying
> [(['0', '0', '1', '2',
> '3', '3'], 0.0082128906250000053)]
> STATES: 0 1 2 3
> ALPHABET: A C G T
> INITIAL:
>   0: 1.00
>   1: 0.00
>   2: 0.00
>   3: 0.00
> TRANSITION:
>   0: 0.20 0.80 0.00 0.00
>   1: 0.00 0.50 0.50 0.00
>   2: 0.00 0.00 0.50 0.50
>   3: 0.00 0.00 0.00 1.00
> EMISSION:
>   0: 0.67 0.11 0.11 0.11
>   1: 0.08 0.75 0.08 0.08
>   2: 0.08 0.08 0.75 0.08
>   3: 0.03 0.03 0.03 0.91
> TESTING baum welch
> Training HMM
> Traceback (most recent call last):
>   File "test_MarkovModel.py", line 64, in
> <module>
>     p_emission=p_emission
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/Bio/MarkovModel.py",
> line 181, in _baum_welch
>     if not p_initial.any():
> AttributeError: any
> 
> $ python
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright",
> "credits" or "license" for more
> information.
> >>> import Numeric
> >>> Numeric.__version__
> '24.2'
> >>> import numpy
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: No module named numpy
> >>>
> 
> The above is on Mac OS X 10.5 (Tiger) with Numeric
> installed, but not
> numpy.  I see something similar but slightly different on a
> Linux
> machine with both Numeric and an old version of numpy.
> 
> Looking at the CVS log, I wonder if this is due to the
> switch from an
> array based or, to an if based manipulation of p_initial,
> p_transition
> and p_emission?
> http://cvs.biopython.org/cgi-bin/viewcvs/viewcvs.cgi/biopython/Bio/MarkovModel.py.diff?r1=1.3&r2=1.4&cvsroot=biopython
> 
> Peter
> _______________________________________________
> Biopython-dev mailing list
> Biopython-dev at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biopython-dev


      



More information about the Biopython-dev mailing list