[BioPython] Question about Seq.count()

Peter biopython at maubp.freeserve.co.uk
Fri Oct 19 14:50:56 UTC 2007


> I've found the bug!
>
> The code for Bio.Seq.count is:
>
> def count(self, item):
>         return len([x for x in self.data if x == item])

Yeah - by design this (and the functionally similar version for the
MutableSeq) both expect the count argument to be a single letter.  The
simple fix for the Seq object is to use the string method internally:

def count(self, item):
        return self.data.count(item)

For the MutableSeq things are not so straight forward, but supporting
multiple character arguments can be done.

> What about using regular expressions instead?
> ...
> What do you think?

I think the Seq object's count method should act just like a normal
python string's count method.  If anyone wants to get fancy with
regular expressions, they can do so.

Peter



More information about the Biopython mailing list