def recode_classes(lines):
    """
    Function which takes a set of data read in (lines) and converts it into a PARROT-compliant set of 
    lines files where classes start at 0. This works for both residue and sequence datatypes.

    Parameters
    -----------
    lines : list
        The lines list is a list of lists, where each sublist corresponds to a line in a parsed
        datafile. If the dataype is sequence then each sublist has three elements (id, sequence, class/score),
        while if the datatype is residues then each sublists has n elements (id, sequence, per-residue scores or 
        classes for each residue).


    Returns
    -------------
    list
        Returns a revised lines list, where sequence or residue classes are guarenteed to start at 0 and increase
        non-monnotonically.
    
    """
    
    # initialize empty vars
    classes = set([])
    class_mapping = {}


    # first figure out the number of classes
    for line in lines:
        classes = classes.union(set(line[2:]))

    n_classes = len(classes)

    if n_classes > 100:
        print('WARNING: 100 individual classes found. This is probably not a good classification problem...')

    # next build a dictionary that maps each unique class (sorted) back to a monotonically increasing
    # number of class labels starting at 0
    classes = list(classes)
    classes.sort()

    idx = 0
    for i in classes:
        class_mapping[i] = idx
        idx = idx + 1

    # Finally, build a new lines list, where the sequence or residues classes are mapped
    # via the class_mapping dictionary 
    new_lines = []
    for line in lines:

        # convert the class
        tmp = [line[0], line[1]]       
        tmp.extend([str(class_mapping[i]) for i in line[2:]])

        new_lines.append(tmp)
        
    return (new_lines, class_mapping)