def read_attributes(filename, delim='\t', ids = []):
    """
    Read attributes from filename.
    Attribute file should be 1 row per attribute and
    columns corresponding to nodes with that attribute.
    """
    attribute_dict = dict()
    with open(filename, 'r') as f:
        for attr_id, line in enumerate(f):
            ## ignore any attributes not in 'ids' list (if given)
            if len(ids) > 0 and attr_id not in ids:
                continue

            L = line.strip().split(delim)
            for node in L:
                attribute_dict.setdefault(node, [])
                attribute_dict[node].append(attr_id)

    return attribute_dict