Add the GO parents of a gene's associated GO IDs to the gene's association.

def update_association(assc_gene2gos, go2obj):
    """Add the GO parents of a gene's associated GO IDs to the gene's association."""
    # Replaces update_association in GODag
    goids_avail = set(go2obj)
    # Get all assc GO IDs that are current
    goid_sets = assc_gene2gos.values()
    goids_assoc_all = set.union(*goid_sets)
    goids_assoc_cur = goids_assoc_all.intersection(goids_avail)
    # Get the subset of GO objects in the association
    go2obj_assc = {go:go2obj[go] for go in goids_assoc_cur}
    go2parents = get_go2parents_go2obj(go2obj_assc)
    # Update the association: update the GO set for each gene
    for goids_cur in goid_sets:
        parents = set()
        for goid in goids_cur.intersection(goids_avail):
            parents.update(go2parents[goid])
        goids_cur.update(parents)
    goids_bad = goids_assoc_all.difference(goids_avail)
    if goids_bad:
        sys.stderr.write("{N} GO IDs NOT FOUND IN ASSOCIATION: {GOs}\n".format(
            N=len(goids_bad), GOs=" ".join(goids_bad)))