title: How to obtain overlapping patterns with Python finditer?
body: <p>I'm using a python script that is searching for a pattern in a fasta file. It is working very well but it does not return overlapping strings. Unfortunately, I'm interested in potential overlapping strings. Since I'm not a programmer (I'm just trying to learn Python), I was wondering if someone could modify the script in order to find overlapping strings. I think that the regex module could do it but I tried to install it on my computer (Windows) without succes. I got this:</p>
  
  <pre><code>C:\Python33&gt;regex-2014.02.19&gt;python setup.py install
  running install
  running build
  running build_py
  runnning built_ext
  building'_regex' extension
  error:Unable to find vcvarsall.bat
  </code></pre>
  
  <p>For me it would be easier to work with a modified script. So here is my script:</p>
  
  <pre><code>import re
  import sys
  
  psq_re_f= re.compile('G{3,}.{1,7}?G{3,}.{1,7}?G{3,}.{1,7}?G{3,}') #((?&lt;=G)[^G]|(?&lt;!G).)
  psq_re_r= re.compile('C{3,}.{1,7}?C{3,}.{1,7}?C{3,}.{1,7}?C{3,}') #((?&lt;=C)[^C]|(?&lt;!C).)
  
  
  filename = input('Enter the name of the input fasta file: ')
  ref_seq_fh = open(filename)
  
  outputfileg = open("strelkaindels_quadg.txt",'wt')
  outputfilec = open("strelkaindels_quadc.txt",'wt')
  
  outputfileg.write('#\tID\tEntry Length\tStart\tEnd\tLength\tStrand\tSequence\n')
  outputfilec.write('#\tID\tEntry Length\tStart\tEnd\tLength\tStrand\tSequence\n')
  
  count = 0
  ref_seq = []
  line = (ref_seq_fh.readline()).strip()
  chr = re.sub('^&gt;', '', line)
  chr1 = chr.split (":")
  #line = (ref_seq_fh.readline()).strip()
  while True:
      while line.startswith('&gt;') is False:
          ref_seq.append(line)
          line = (ref_seq_fh.readline()).strip()
          if line == '':
              break
      ref_seq = ''.join(ref_seq)
      for m in re.finditer(psq_re_f, ref_seq):
          count=count+1
          outputfileg.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' %(count, chr1[0], len(ref_seq), m.start(), m.end(), len(m.group(0)), '+', m.group(0))+'\n')
      for m in re.finditer(psq_re_r, ref_seq):
          count=count+1
          outputfilec.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' %(count, chr1[0], len(ref_seq), m.start(), m.end(), len(m.group(0)), '-', m.group(0))+'\n')
      chr = re.sub('^&gt;', '', line)
      chr1 = chr.split (":")
      ref_seq = []
      line= (ref_seq_fh.readline()).strip()
      if line == '':
          break
  
  
  outputfileg.close()
  outputfilec.close()
  </code></pre>
  
  <p>Finally an example of fasta file (text-based format for representing nucleotide sequences) widely used in biology:</p>
  
  <pre><code>&gt;id_1
  agatagatgatagatatagagagcgcgctagatcgatcgatcgagtcgatcgcgcggggggcccctctctctctatagggacatacga
  &gt;id_2
  agacatcagatacagagatatttacataacaagagatacag
  &gt;id_3
  cgctctagctcctcctctcgcgtagctagctctctctaacatgattagaattcagatcgatcgatcgatggttttttttctctct
  and so on...
  </code></pre>
  
  <p>For example, let's imagine the following sequence:</p>
  
  <pre><code>GGGTGGGTGGGCGGGAGGG
  </code></pre>
  
  <p>The script will return only this string: </p>
  
  <pre><code>GGGTGGGTGGGCGGG
  </code></pre>
  
  <p>But I would like to also get that one too: </p>
  
  <pre><code>GGGTGGGCGGGAGGG
  </code></pre>