genevector.aggregation

genevector/_aggregation.py — graph aggregation registry and implementations.

aggr_mean(X_dense, graph, include_self=False, **kwargs)[source]

Mean aggregation over graph neighbors.

Parameters:
  • X_dense (np.ndarray) – Expression matrix (cells x genes).

  • graph (scipy.sparse matrix) – Adjacency matrix (any graph topology).

  • include_self (bool) – If True, blend 50/50 between self and neighbor mean.

Returns:

Aggregated expression, same shape as X_dense.

Return type:

np.ndarray

get_aggregation(name)[source]

Look up a registered aggregation function by name, or return a callable directly.

Parameters:

name (str or callable) – Name of registered aggregation, or a callable with signature f(X_dense, graph, **params) -> np.ndarray.

Returns:

The aggregation function.

Return type:

callable

Raises:

ValueError – If name is a string and not registered.

register_aggregation(name)[source]

Decorator to register an aggregation function.

genevector/_graph_targets.py — graph-aware co-expression targets.

target_graph_xcorr(X, gene_names, graph=None, aggr='mean', aggr_params=None, **kwargs)[source]

Cross-correlation between self-expression and graph-neighbor-aggregated expression.

Computes bivariate cross-correlation for all gene pairs: for each gene A and gene B, measures the correlation between A’s expression in each cell and B’s aggregated expression in that cell’s graph neighbors. The result is symmetrized.

Parameters:
  • X (sparse or dense matrix) – Expression matrix (cells x genes).

  • gene_names (list of str) – Gene symbols.

  • graph (scipy.sparse matrix) – Adjacency matrix (spatial, TCR, or any graph topology).

  • aggr (str or callable) – Aggregation method name or function. Default “mean”.

  • aggr_params (dict, optional) – Extra keyword arguments passed to the aggregation function.

Returns:

scores[gene_a][gene_b] = float, cross-correlation in [-1, 1].

Return type:

dict of dict