title: Python print lines from to
body: <p>I would like to solve my problem, which is:
  When conditions are met for my line, print out all lines starting from this line up until this line + value</p>
  
  <p>I have a code looking like this:</p>
  
  <pre><code>import re
  ##
  def round_down(num):
      return num - (num%100000)  ###reduce search space
  ##
  ##
  ##def Filter(infile, outfile):
  ##out = open(outfile,'w')
  infile = open('AT_rich','r')
  cov = open('30x_good_ok_bad_0COV','r') ###File with non platinum regions
  #platinum_region = [row for row in Pt]
  platinum_region={}  ### create dictionary for non platinum regions. Works fast
  platinum_region['chrM']={}
  platinum_region['chrM'][0]=[]
  ct=0
  for region in infile:
      (chr,start,end,types,length)= region.strip().split()
      start=int(start)
      end=int(end)
      length = int(length)
      rounded_start=round_down(start)
  ##
      if not (chr in platinum_region):
          platinum_region[chr]={}
      if not (rounded_start in platinum_region[chr]):
          platinum_region[chr][rounded_start]=[]
      platinum_region[chr][rounded_start].append({'start':start,'end':end,'length':length})
  ##
  ##c=0
  for vcf_line in cov: ###process file with indels
  ##    if (c % 1000 ==0):print "c ",c
  ##    c=c+1
      vcf_data = vcf_line.strip().split()
      vcf_chrom=vcf_data[0]
      vcf_pos=int(vcf_data[1])
      vcf_end=int(vcf_data[2])
      coverage = int(vcf_data[3])
      rounded_vcf_position=round_down(vcf_pos) ###round positions to reduce search space
  ##    print vcf_chrom
      ##    for vcf_line in infile: ###process file with indels
  ##    if (c % 1000 ==0):print "c ",c
      overlapping = 'false'
      if vcf_chrom in platinum_region and rounded_vcf_position in platinum_region[vcf_chrom]:
          for region in platinum_region[vcf_chrom][rounded_vcf_position]:
              if (vcf_pos == region['start']):# and vcf_end == region['end']):# and (vcf_end &gt; region['start'] and vcf_end &lt; region['end']):
                  if vcf_chrom != 'chrX' and vcf_chrom != 'chrY':
                      print vcf_data
  </code></pre>
  
  <p>Files are just set of intervals start-end, first column[0] conatins chromosome ex.'chr1':</p>
  
  <p>cov:</p>
  
  <pre><code>chr1    1   3   AT_rich 3
  chr1    5   8   AT_rich 4
  chr1    10  12  AT_rich 3
  </code></pre>
  
  <p>last column is the region['length']</p>
  
  <p>infile:</p>
  
  <pre><code>chr1    1   2   4247
  chr1    2   3   4244
  chr1    3   5   4224
  chr1    5   7   4251
  chr1    7   8   4251
  chr1    8   12   4254
  chr1    12   15   4253
  </code></pre>
  
  <p>output would be:</p>
  
  <pre><code>chr1    1   2   4247
  chr1    2   3   4244
  chr1    5   7   4251
  chr1    7   8   4251
  chr1    8   12   4254## here there isn't really start-start matching position, but there is an overlap between two files
  chr1    12   15   4253
  </code></pre>
  
  <p>so the main idea is, if region from one file(cov) starts at the position of the region from second file(infile). Print all positions starting from this matching start position up until the length of the region from first file(cov). Sometimes there is not exact matching position, just some overlap, so in this case we can probably not care about those (even though it would be nice to also have them in output)</p>
  
  <p>I would like to print lines starting from vcf_data(when conditions met) until vcf_data + region['length']. What is the way to add this to my code? </p>