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=Trueunless the selected regression backend and environment support GPU execution.Do NOT expect unsupported
methodvalues to fall back automatically.
- param network:
Graph containing
NodeDatanodes andLinkDataedges.- 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:
- 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:
- param scale_Y:
If True, standardize response values before fitting.
- type scale_Y:
- param alpha:
Penalty strength for
"elastic_net".- type alpha:
- param l1_ratio:
ElasticNet mixing parameter, with
0 <= l1_ratio <= 1. Forl1_ratio = 0the penalty is an L2 penalty. Forl1_ratio = 1it is an L1 penalty. For0 < l1_ratio < 1, the penalty is a combination of L1 and L2.- type l1_ratio:
- param use_gpu:
If True, request GPU tree fitting for
"gb_tree".- type use_gpu:
- param overwrite:
If True, recompute existing
regr_scorevalues.- type overwrite:
- returns:
Returns
networkonly when the graph has no edges. Otherwise, updates edgeregr_scoreand noderegr_fitnessattributes 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