text: user104: 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:
  >>> from Bio.Seq import Seq
  >>> Seq('AAAA').count('AA')
  2
  >>> 'AAAA'.count('AA')
  2
  
  
  user149: You can use finditer from python's re module. The advantage of this approach is it allows for getting the indices of those matches, which could be handy down the track.
  >>> import re
  >>> matches = re.finditer(r'(?=(AA))', 'AAAA')
  >>> indices = [match.span(1) for match in matches]
  >>> indices
  [(0, 2), (1, 3), (2, 4)]
  >>> num_matches = len(indices)
  >>> num_matches
  3
  
  
  user1085: I've encountered this problem before, and used python re module to solve this problem.
  import re
  all = re.findall(r'(?=(AA))','AAAA')
  counts = len(all)
  
  You can get more details in this thread
  
  user104: For Biopython 1.70, there is a new Seq.count_overlap() method, which includes optional start and end arguments:
  >>> from Bio.Seq import Seq
  >>> Seq('AAAA').count_overlap('AA')
  3
  >>> Seq('AAAA').count_overlap('AA', 1, 4)
  2
  
  This method is also implemented for the MutableSeq and UnknownSeq classes:
  >>> from Bio.Seq import MutableSeq, UnknownSeq
  >>> MutableSeq('AAAA').count_overlap('AA')
  3
  >>> UnknownSeq(4, character='A').count_overlap('AA')
  3
  
  
  Disclaimer: I co-contributed the .count_overlap() methods with Peter Cock, see 97709cc
  
original_text: 104: <p>Biopython's <code>.count()</code> methods, like Python's <code>str.count()</code>, perform a non-overlapping count, how can I do an overlapping one?</p>
  
  <p>For example, these code snippets <code>return 2</code>, but I want the answer <code>3</code>:</p>
  
  <pre><code>&gt;&gt;&gt; from Bio.Seq import Seq
  &gt;&gt;&gt; Seq('AAAA').count('AA')
  2
  &gt;&gt;&gt; 'AAAA'.count('AA')
  2
  </code></pre>
   149: <p>You can use <code>finditer</code> from python's <a href="https://docs.python.org/2/library/re.html#module-re" rel="nofollow noreferrer"><code>re</code></a> module. The advantage of this approach is it allows for getting the indices of those matches, which could be handy down the track.</p>
  
  <pre><code>&gt;&gt;&gt; import re
  &gt;&gt;&gt; matches = re.finditer(r'(?=(AA))', 'AAAA')
  &gt;&gt;&gt; indices = [match.span(1) for match in matches]
  &gt;&gt;&gt; indices
  [(0, 2), (1, 3), (2, 4)]
  &gt;&gt;&gt; num_matches = len(indices)
  &gt;&gt;&gt; num_matches
  3
  </code></pre>
   1085: <p>I've encountered this problem before, and used python <code>re</code> module to solve this problem.</p>
  
  <pre><code>import re
  all = re.findall(r'(?=(AA))','AAAA')
  counts = len(all)
  </code></pre>
  
  <p>You can get more details in this <a href="https://stackoverflow.com/questions/11430863/how-to-find-overlapping-matches-with-a-regexp">thread</a></p>
   104: <p>For Biopython 1.70, there is a new <code>Seq.count_overlap()</code> method, which includes optional <code>start</code> and <code>end</code> arguments:</p>
  
  <pre><code>&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
  </code></pre>
  
  <p>This method is also implemented for the <code>MutableSeq</code> and <code>UnknownSeq</code> classes:</p>
  
  <pre><code>&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
  </code></pre>
  
  <hr>
  
  <p>Disclaimer: I co-contributed the <code>.count_overlap()</code> methods with Peter Cock, see <a href="https://github.com/biopython/biopython/commit/97709cc7a4b8591e794b442796d41e4f7b855a0f" rel="noreferrer"><code>97709cc</code></a></p>
  