def calculate_intervals_from_range(list_range):
    """
    Merge a list of continuous indexes into list of intervals.

    Parameters:
    list_range -- A list with compartment indexes to be merged into intervals.

    Output:
    A list of lists with intervals.
    """

    list_range = list(list_range)
    intervals = []
    for idx, item in enumerate(list_range):
        if not idx or item-1 != intervals[-1][-1]:
            intervals.append([item])
        else:
            intervals[-1].append(item)
    return(intervals)