def ancestors(parent_table, cycle_idx, walker_idx, ancestor_cycle=0):
    """Returns the lineage of ancestors as walker indices leading up to
    the given walker.

    Parameters
    ----------
    parent_table : list of list of int
    cycle_idx : int
        Cycle of walker to query.
    walker_idx : int
        Walker index in to query along with cycle_idx.
    ancestor_cycle : int
        Index of cycle in history to go back to. Must be less than cycle_idx.

    Returns
    -------
    ancestor_trace : list of tuples of ints (traj_idx, cycle_idx)
        Contig walker trace of the ancestors leading up to the queried walker.
        The contig is sequence of cycles in the parent table.

    """

    lineage = [(walker_idx, cycle_idx)]

    previous_walker = walker_idx

    for curr_cycle_idx in range(cycle_idx-1, ancestor_cycle-1, -1):
            previous_walker = parent_table[curr_cycle_idx][previous_walker]

            # check for discontinuities, e.g. warping events
            if previous_walker == -1:
                # there are no more continuous ancestors for this
                # walker so we cannot return ancestors back to the
                # requested cycle just return the ancestors to this
                # point
                break

            previous_point = (previous_walker, curr_cycle_idx)
            lineage.insert(0, previous_point)

    return lineage