cafaeval.graph

class cafaeval.graph.Graph(namespace, terms_dict, ia_dict=None, orphans=False)[source]

Bases: object

Ontology class. One ontology == one namespace DAG is the adjacence matrix (sparse) which represent a Directed Acyclic Graph where DAG(i,j) == 1 means that the go term i is_a (or is part_of) j Parents that are in a different namespace are discarded

top_sort()[source]

Takes a sparse matrix representing a DAG and returns an array with nodes indexes in topological order https://en.wikipedia.org/wiki/Topological_sorting

set_ia(ia_dict)[source]
class cafaeval.graph.Prediction(ids, matrix, namespace=None)[source]

Bases: object

The score matrix contains the scores given by the predictor for every node of the ontology

class cafaeval.graph.GroundTruth(ids, matrix, namespace=None)[source]

Bases: object

cafaeval.graph.propagate_to_coo(triples, ont, mode='max')[source]

Sparse-native propagation that never materialises a dense matrix.

Takes input non-zeros triples = (rows, cols, scores) and returns the propagated non-zeros (out_rows, out_cols, out_vals) after pushing each score up to every ancestor (self inclusive) and reducing by (row, ancestor) with a group-max. This is exactly the result _propagate_sparse_pushup would scatter into a freshly-zeroed dense matrix for mode='max' (where every output cell’s value is the group max, since each input cell is its own ancestor), so callers that build a CSR/COO directly get bit-identical values without the O(n_prot*n_terms) allocation. Only mode='max' is supported; mode='fill' differs (zero-only overwrite) and must use the dense path.

cafaeval.graph.propagate(matrix, ont, order, mode='max', parallel=0, chunk_rows=65536, _shm_name=None, _shape=None, _dtype_str=None, _row_start=None, _row_end=None, _deepest=None, _triples=None)[source]

Update inplace the score matrix (proteins x terms) propagating scores up to the root. mode='max' takes the max of each term and its children; mode='fill' only updates rows where the current term is zero.

When parallel > 1 and the estimated work is above the threshold the matrix is shared across processes via shared_memory (spawn context) and rows are partitioned among workers. Recursive calls re-enter this function through the _shm_name path.