Given a row containing the peak of the QTL and all the rows of
    the linkage group of the said QTL (splitted per trait), determine
    the QTL interval and find the start and stop marker of the said
    interval.
    The interval is a LOD 2 interval.
    The approach is conservative in the way it takes the first and last
    marker within the interval.

    :arg peak, a list containing the row information for the peak marker
    :arg block, a hash containing per column, all the rows in the
        linkage group of this QTL, splitted per trait.
    :arg headers, the first row of the QTL matrix file, used to determine
        which block to look at for each trait process.

def _extrac_qtl(peak, block, headers):
    """ Given a row containing the peak of the QTL and all the rows of
    the linkage group of the said QTL (splitted per trait), determine
    the QTL interval and find the start and stop marker of the said
    interval.
    The interval is a LOD 2 interval.
    The approach is conservative in the way it takes the first and last
    marker within the interval.

    :arg peak, a list containing the row information for the peak marker
    :arg block, a hash containing per column, all the rows in the
        linkage group of this QTL, splitted per trait.
    :arg headers, the first row of the QTL matrix file, used to determine
        which block to look at for each trait process.

    """
    qtls = []
    if not peak:
        return qtls
    threshold = 2
    for trait in peak:
        blockcnt = headers.index(trait)
        local_block = block[blockcnt]
        lod2_threshold = float(peak[trait][-1]) - float(threshold)
        # Search QTL start
        cnt = local_block.index(peak[trait])
        start = local_block[cnt]
        while cnt >= 0:
            start = local_block[cnt]
            if re.match(r'c\d+\.loc[\d\.]+', local_block[cnt][0]):
                cnt = cnt - 1
                continue
            if float(local_block[cnt][-1]) < lod2_threshold:
                break
            cnt = cnt - 1

        # Search QTL end
        end = []
        cnt = local_block.index(peak[trait])
        end = local_block[cnt]
        while cnt < len(local_block):
            end = local_block[cnt]
            if re.match(r'c\d+\.loc[\d\.]+', local_block[cnt][0]):
                cnt += 1
                continue
            if float(local_block[cnt][-1]) < lod2_threshold:
                break
            cnt = cnt + 1

        qtl = QTL()
        qtl.trait = trait
        qtl.start_mk = start[0]
        qtl.start_position = start[2]
        qtl.peak_mk = peak[trait][0]
        qtl.peak_start_position = peak[trait][2]
        qtl.peak_stop_position = peak[trait][2]
        qtl.stop_mk = end[0]
        qtl.stop_position = end[2]
        qtls.append(qtl)
    return qtls