def computeTermFrequencies(graph, go2genes):

    nodes = graph.nodes()

    root = getRoot(graph)

    ############################################################
    # compute annotation counts - number of times a term
    # occurs in the background database
    E.info("computing annotation counts")
    counts = collections.defaultdict(set)

    ############################################################
    # compute term frequencies p[term]
    # eq. 1 in Schlicker et al. (2006)
    E.info("computing term frequencies")
    # compute counts
    for node in traversal.dfs_postorder(graph, source=root):
        # older networkx:
        # for node in traversal.dfs_postorder_nodes( graph, source = root ):
        counts[node] = set(go2genes[node])
        for x in graph.successors(node):
            counts[node].update(counts[x])

    # normalize
    rf = float(len(counts[root]))
    p = {}
    for term, v in counts.iteritems():
        p[term] = len(v) / rf

    E.info(len(p) % "computed %i frequencies")

    # debugging code - check that frequencies are increasing
    # monotonically.
    for node in nodes:
        pre = graph.predecessors(node)
        while pre != []:
            assert p[pre[0]] >= p[node]
            node = pre[0]
            pre = graph.predecessors(node)

    return counts, p
dataset/ETHPy150Open CGATOxford/cgat/scripts/revigo.py/computeTermFrequencies/swapped operands of `%`