[Biopython-dev] function Bio.utils.count_monomers() is broken

Peter Slickers piet at clondiag.com
Fri Jan 17 12:47:14 EST 2003


Here is an example code to demonstrate an error caused by
function 'Bio.utils.count_monomers()':

#!/usr/bin/python

import string


def my_count_monomers(seq):
         """ Fixed version of 'Bio.utils.count_monomers()'
         """
         dict = {}
         ##s = buffer(seq.data)  # works for strings and array.arrays
         s = seq.data
         for c in seq.alphabet.letters:
                 dict[c] = string.count(s, c)
         return dict




import Bio.Seq
import Bio.utils
import Bio.Alphabet.IUPAC


seqObj = Bio.Seq.Seq("ACGCAGATAGCAGAT", \
         Bio.Alphabet.IUPAC.unambiguous_dna )


print
print  my_count_monomers(seqObj)
print
print  Bio.utils.count_monomers(seqObj)

-------------------------------------------------------------------

Here is my output from this script:


{'A': 6, 'C': 3, 'T': 2, 'G': 4}

Traceback (most recent call last):
   File "count_monomers.py", line 31, in ?
     print  Bio.utils.count_monomers(seqObj)
   File "/usr/local/lib/python2.2/site-packages/Bio/utils.py", line 63, in count_monomers
     dict[c] = string.count(s, c)
   File "/usr/local/lib/python2.2/string.py", line 161, in count
     return s.count(*args)
AttributeError: 'buffer' object has no attribute 'count'

-------------------------------------------------------------------

The error is caused by the usage of the buffer() function within 'Bio/utils.py'.
Just removing the buffer() function fixes the problem. This is
demonstrated by my modified version of the function, which
is defined at the top of the script.
(I have no idee why the buffer function is used in count_monomers().)


Just in case, I have python 2.2.2 and biopython 1.10 installed.

-- 


Peter
-------------------------------------------------------------------
Peter Slickers                             piet at clondiag.com
Clondiag Chip Technologies                 http://www.clondiag.com/
Löbstedter Str. 105
07749 Jena
Germany

Fon:  03641/5947-65                        Fax:  03641/5947-20
-------------------------------------------------------------------




More information about the Biopython-dev mailing list