How can I do an overlapping sequence count in Biopython? Biopython's .count() methods, like Python's str.count(), perform a non-overlapping count, how can I do an overlapping one?

For example, these code snippets return 2, but I want the answer 3:

&gt;&gt;&gt; from Bio.Seq import Seq
&gt;&gt;&gt; Seq('AAAA').count('AA')
2
&gt;&gt;&gt; 'AAAA'.count('AA')
2
For Biopython 1.70, there is a new Seq.count_overlap() method, which includes optional start and end arguments:

&gt;&gt;&gt; from Bio.Seq import Seq
&gt;&gt;&gt; Seq('AAAA').count_overlap('AA')
3
&gt;&gt;&gt; Seq('AAAA').count_overlap('AA', 1, 4)
2


This method is also implemented for the MutableSeq and UnknownSeq classes:

&gt;&gt;&gt; from Bio.Seq import MutableSeq, UnknownSeq
&gt;&gt;&gt; MutableSeq('AAAA').count_overlap('AA')
3
&gt;&gt;&gt; UnknownSeq(4, character='A').count_overlap('AA')
3




Disclaimer: I co-contributed the .count_overlap() methods with Peter Cock, see 97709cc