snapatac2.tl.add_regr_scores#

snapatac2.tl.add_regr_scores(network, *, peak_mat=None, gene_mat=None, select=None, method='elastic_net', scale_X=False, scale_Y=False, alpha=1.0, l1_ratio=0.5, use_gpu=False, overwrite=False)[source]#

Add regression-based importance scores to network edges.

Use this function to model each target node from its parent nodes and store per-edge regression scores plus target-node model fitness.

Anti-Patterns#

  • Do NOT pass peak and gene matrices with different obs_names.

  • Do NOT set use_gpu=True unless the selected regression backend and environment support GPU execution.

  • Do NOT expect unsupported method values to fall back automatically.

param network:

Graph containing NodeData nodes and LinkData edges.

type network:

PyDiGraph

param peak_mat:

Cell-by-region matrix with region names in .var_names.

type peak_mat:

AnnData | AnnDataSet | None

param gene_mat:

Cell-by-gene matrix with gene names in .var_names.

type gene_mat:

AnnData | AnnDataSet | None

param select:

Gene ids to score. If None, score all eligible target genes.

type select:

list[str] | None

param method:

Regression backend used to score parent nodes.

type method:

Literal['gb_tree', 'elastic_net']

param scale_X:

If True, standardize predictor values before fitting.

type scale_X:

bool

param scale_Y:

If True, standardize response values before fitting.

type scale_Y:

bool

param alpha:

Penalty strength for "elastic_net".

type alpha:

float

param l1_ratio:

ElasticNet mixing parameter, with 0 <= l1_ratio <= 1. For l1_ratio = 0 the penalty is an L2 penalty. For l1_ratio = 1 it is an L1 penalty. For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

type l1_ratio:

float

param use_gpu:

If True, request GPU tree fitting for "gb_tree".

type use_gpu:

bool

param overwrite:

If True, recompute existing regr_score values.

type overwrite:

bool

returns:

Returns network only when the graph has no edges. Otherwise, updates edge regr_score and node regr_fitness attributes in place and returns None.

rtype:

rustworkx.PyDiGraph | None

Examples

>>> import snapatac2 as snap
>>> adata = snap.datasets.pbmc5k(type="annotated_h5ad")
>>> gene_mat = snap.pp.make_gene_matrix(adata, snap.genome.hg38)
>>> network = snap.tl.init_network_from_annotation(list(adata.var_names[:10]), snap.genome.hg38)
>>> snap.tl.add_regr_scores(network, peak_mat=adata, gene_mat=gene_mat, method="elastic_net")
>>> network.num_edges() >= 0
True