def countGOassociations(validTerms, gafDict):
    """
     Counts the number of genes associated with at least one of the provided GO terms.

     Parameters
     ----------
     validTerms : set
         A set of GO terms. Should include the GO id of interest and all of its children.
     gafDict : dict
         A dictionary that maps Uniprot ACs to GO IDs.

     Returns
     -------
     int
         The number of associated genes.
     """

    GOcounter = 0

    # For each gene:GO id set pair in the GAF dictionary
    for gene, GOids in gafDict.items():
        # Increment the GO counter if the valid terms set shares a member
        # with the GO id set of the current gene
        # https://stackoverflow.com/questions/3170055/test-if-lists-share-any-items-in-python
        if not validTerms.isdisjoint(GOids):
            GOcounter += 1

    return GOcounter