def records_from_join_res(list_of_tuples):
    """
    Given a list of tuples from the result of a sqlalchemy join query returns
    a dictionary mapping a class to a set of instances of that class.

    :param list_of_tuples: sqlalchemy join query result (list of tuples)
    :return: dictionary of classes to unique instances set (dict)
             {Class: {inst1, inst2}}
    """
    class_instances = {}  # {Class: {inst1, inst2}}
    # iterate through each substrate/phosphosite/kinase
    for instances_tuple in list_of_tuples:
        # iterate through each instance inthe tuple
        for instance in instances_tuple:
            if instance:
                # add a dict key for each type of class
                class_obj = type(instance)
                cls_set = class_instances.setdefault(class_obj, set())
                cls_set.add(instance)
    return class_instances