def select_overlap(
        cxn, ref_name, taxon_name, beg_lo, beg_hi, end, iteration=0):
    """
    Find the best overlapping contig for the assembly.

    Find an overlapping contig that starts anywhere between beg_lo & beg_hi.
    Is must also end somewhere after the given end marker. We want the contig
    that extends the stitched sequence by the longest amount so we ORDER BY
    end descending & choose the first one.
    """
    sql = """
        SELECT *
          FROM exonerate
         WHERE ref_name   = ?
           AND taxon_name = ?
           AND iteration  = ?
           AND end        > ?
           AND beg BETWEEN ? AND ?
         ORDER BY end DESC, contig_name
         LIMIT 1;
        """
    result = cxn.execute(
        sql, (ref_name, taxon_name, iteration, end, beg_lo, beg_hi))
    return result.fetchone()