def assign_best_matches(self, xg):
        """
        For each node in the xref graph, tag best match edges
        """
        logging.info("assigning best matches for {} nodes".format(len(xg.nodes())))
        for i in xg.nodes():
            xrefmap = self._neighborscores_by_ontology(xg, i)
            for (ontid,score_node_pairs) in xrefmap.items():
                score_node_pairs.sort(reverse=True)
                (best_score,best_node) = score_node_pairs[0]
                logging.info("BEST for {}: {} in {} from {}".format(i, best_node, ontid, score_node_pairs))
                edge = xg[i][best_node]
                dirn = self._dirn(edge, i, best_node)
                best_kwd = 'best_' + dirn
                if len(score_node_pairs) == 1 or score_node_pairs[0] > score_node_pairs[1]:
                    edge[best_kwd] = 2
                else:
                    edge[best_kwd] = 1
                for (score,j) in score_node_pairs:
                    edge_ij = xg[i][j]
                    dirn_ij = self._dirn(edge_ij, i, j)
                    edge_ij['cpr_'+dirn_ij] = score / sum([s for s,_ in score_node_pairs])
        for (i,j,edge) in xg.edges(data=True):
            # reciprocal score is set if (A) i is best for j, and (B) j is best for i
            rs = 0
            if 'best_fwd' in edge and 'best_rev' in edge:
                rs = edge['best_fwd'] * edge['best_rev']
            edge['reciprocal_score'] = rs
            edge['cpr'] = edge['cpr_fwd'] * edge['cpr_rev']
def assign_best_matches ( self , xg ) : logging . info ( "assigning best matches for {} nodes" . format ( len ( xg . nodes ( ) ) ) ) for i in xg . nodes ( ) : xrefmap = self . _neighborscores_by_ontology ( xg , i ) for ( ontid , score_node_pairs ) in xrefmap . items ( ) : score_node_pairs . sort ( reverse = True ) ( best_score , best_node ) = score_node_pairs [ 0 ] logging . info ( "BEST for {}: {} in {} from {}" . format ( i , best_node , ontid , score_node_pairs ) ) edge = xg [ i ] [ best_node ] dirn = self . _dirn ( edge , i , best_node ) best_kwd = 'best_' + dirn if len ( score_node_pairs ) == 1 or score_node_pairs [ 0 ] > score_node_pairs [ 1 ] : edge [ best_kwd ] = 2 else : edge [ best_kwd ] = 1 for ( score , j ) in score_node_pairs : edge_ij = xg [ i ] [ j ] dirn_ij = self . _dirn ( edge_ij , i , j ) edge_ij [ 'cpr_' + dirn_ij ] = score / sum ( [ s for s , _ in score_node_pairs ] ) for ( i , j , edge ) in xg . edges ( data = True ) : rs = 0 if 'best_fwd' in edge and 'best_rev' in edge : rs = edge [ 'best_fwd' ] * edge [ 'best_rev' ] edge [ 'reciprocal_score' ] = rs edge [ 'cpr' ] = edge [ 'cpr_fwd' ] * edge [ 'cpr_rev' ]
For each node in the xref graph, tag best match edges