def find_actual_position(ORI_gc, ORI_ta, TER_gc, TER_ta, gc_cum, ta_cum,
    positions):
    """
    Find position of ORI and TER - assumed to be before gene where predicted position is in
    and after the gene where the predicted position is in, respectively

    :param ORI_gc:      Predicted position of ORI using GC-skew
    :param ORI_ta:      Predicted position of ORI using TA-skew
    :param TER_gc:      Predicted position of TER using GC-skew
    :param TER_ta:      Predicted position of TER using TA-skew
    :param gc_cum:      List of cumulative GC-skews
    :param ta_cum:      List of cumulative TA-skews
    :param positions:   List of gene positions
    :return:            Actual position for ORI and TER using both GC and TA-skew,
                        and the indices values in the list (used later for plotting)
    """
    ori_gc_found = ter_gc_found = ori_ta_found = ter_ta_found = False
    """Loop through all genes, find the gene which contains the predicted position
    and set the new predicted position as the position before that gene (ORI) or after
    that gene (TER). Once all positions have been found, loop breaks."""
    for gene in positions:
        if not ori_gc_found:
            if positions[gene][0] <= ORI_gc <= positions[gene][1]:
                ORI_gc = positions[gene][0]
                ori_gc_found = True
        if not ter_gc_found:
            if positions[gene][0] <= TER_gc <= positions[gene][1]:
                TER_gc = positions[gene][1]
                ter_gc_found = True
        if not ori_ta_found:
            if positions[gene][0] <= ORI_ta <= positions[gene][1]:
                ORI_ta = positions[gene][0]
                ori_ta_found = True
        if not ter_ta_found:
            if positions[gene][0] <= TER_ta <= positions[gene][1]:
                TER_ta = positions[gene][1]
                ter_ta_found = True
        if ori_gc_found and ter_gc_found and ori_ta_found and ter_ta_found:
            break
    ORI_gc = ORI_gc - 1
    ORI_ta = ORI_ta - 1
    TER_gc = TER_gc - 1
    TER_ta = TER_ta - 1
    ORI_gc_val = gc_cum[ORI_gc]
    ORI_ta_val = ta_cum[ORI_ta]
    TER_gc_val = gc_cum[TER_gc]
    TER_ta_val = ta_cum[TER_ta]
    return (ORI_gc, ORI_gc_val, TER_gc, TER_gc_val, ORI_ta, ORI_ta_val,
        TER_ta, TER_ta_val)
