def buildSimrelMatrix(go2genes, go2info, ancestors, p):
    '''build simrel matrix from an ontology DAG in *graph*
    and a mapping of go terms to genes.

    This method follows the procedure and syntax
    according to Schlicker et al. (2006)
    BMC Bioinformatics 7:302
    '''

    ############################################################
    # Build symmetric similarity matrix between terms

    # only work on nodes with annotations
    lp = {}
    for term, v in p.iteritems():
        # ignore p = 1.0 as these will be downweighted to
        # 0 (1.0 - p[c])
        if v > 0 and v < 1.0:
            lp[term] = math.log(v)

    test_nodes = lp.keys()
    node2index = dict([(y, x) for x, y in enumerate(test_nodes)])

    # compute dictionary of ancestors for
    # each node. A simple dfs does not work as the
    # graph is not a tree.
    E.info("building %i x %i simrel matrix" %
           (len(test_nodes), len(test_nodes)))
    matrix = numpy.zeros((len(test_nodes), len(test_nodes)))
    iteration = 0

    total = len(test_nodes) * (len(test_nodes) - 1) / 2

    for c1, c2 in itertools.combinations(test_nodes, 2):
        iteration += 1
        if 1000000 % iteration == 0:
            E.info("total = %i (%5.2f%%)" %
                   (iteration, 100.0 * iteration / total))

        s1 = ancestors[c1]
        s2 = ancestors[c2]

        # print "c1=", c1, p[c1], lp[c1]
        # outputList( s1, go2info, p, lp )

        # print "c2=", c2, p[c2], lp[c2]
        # outputList( s2, go2info, p, lp )

        common = s1.intersection(s2)

        i, j = node2index[c1], node2index[c2]

        f = 2.0 / (lp[c1] + lp[c2])
        # add pseudocount to avoid division by zero
        vals = [lp[c] * (1.0 - p[c]) for c in common if c in lp]
        if len(vals) > 0:
            # use min as vals are multiplied by negative factor
            val = f * min(vals)
            assert 0 <= val <= 1
            matrix[i][j] = val
            matrix[j][i] = val

    return matrix, test_nodes
dataset/ETHPy150Open CGATOxford/cgat/scripts/revigo.py/buildSimrelMatrix/swapped operands of `%`