Gene sets and regulons¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
Worked through in Gene set analysis and GRN inference on PBMCs.
Gene set scores¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
ScMatrixRes
dataclass
¶
ScMatrixRes(
values: ndarray,
columns: tuple[str, ...],
cell_ids: ndarray,
cell_indices: ndarray,
index_col: str,
)
Cells x gene sets scores, for cells and meta cells alike.
The row index names which obs it joins onto.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
ndarray
|
|
columns |
tuple[str, ...]
|
The gene set names. |
cell_ids |
ndarray
|
The cell (or meta cell) ids, row order. |
cell_indices |
ndarray
|
0-based store index (or meta cell row) of each row. |
index_col |
str
|
|
aucell
¶
aucell(
sc: ScOrMc,
gs_list: GeneSets,
*,
aucell_params: AucellParams | None = None,
streaming: bool | None = None,
verbose: Verbose = True,
) -> ScMatrixRes
AUCell scores.
Ranks the genes within each cell and scores how high a gene set sits;
see AucellParams for the three statistics. Meta cells rank their raw
counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells. |
required |
gs_list
|
GeneSets
|
Gene set name to gene ids. Unknown ids warn and drop. |
required |
aucell_params
|
AucellParams | None
|
The parameters. |
None
|
streaming
|
bool | None
|
Read the cells in chunks. |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScMatrixRes
|
The |
References
Aibar, et al., Nat. Methods, 2017.
Examples:
module_scores
¶
module_scores(
sc: ScOrScSubset,
gs_list: GeneSets,
*,
n_bins: int = 24,
n_ctrl: int = 100,
seed: int = 42,
streaming: bool | None = None,
verbose: Verbose = True,
) -> ScMatrixRes
Module activity scores.
Seurat's AddModuleScore: per gene set the mean expression of its genes
minus that of control genes drawn from the same expression bins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrScSubset
|
The experiment or a subset. |
required |
gs_list
|
GeneSets
|
Gene set name to gene ids. Unknown ids warn and drop. |
required |
n_bins
|
int
|
Expression bins. |
24
|
n_ctrl
|
int
|
Control genes per gene set gene. |
100
|
seed
|
int
|
Seed for the control draws. |
42
|
streaming
|
bool | None
|
Read the cells in chunks. |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScMatrixRes
|
The |
References
Tirosh, et al., Science, 2016.
Examples:
get_data
¶
get_data(
res: ScMatrixRes,
*,
columns: Sequence[str] | None = None,
) -> DataFrame
The scores as an obs frame for add_obs.
One column per gene set plus the 0-based cell_idx (meta_cell_idx for
meta cells).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res
|
ScMatrixRes
|
The scores. |
required |
columns
|
Sequence[str] | None
|
Gene sets to keep. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On an unknown gene set. |
VISION signatures¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
VisionAutocorRes
dataclass
¶
VisionAutocorRes(
vision_matrix: ScMatrixRes, auto_cor: DataFrame
)
VISION scores with their autocorrelation.
Attributes:
| Name | Type | Description |
|---|---|---|
vision_matrix |
ScMatrixRes
|
The scores. |
auto_cor |
DataFrame
|
|
vision
¶
vision(
sc: ScOrMc,
gs_list: Signatures,
*,
streaming: bool | None = None,
verbose: Verbose = True,
) -> ScMatrixRes
VISION signature scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells. |
required |
gs_list
|
Signatures
|
Signature name to |
required |
streaming
|
bool | None
|
Read the cells in chunks. |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScMatrixRes
|
The |
References
DeTomaso, et al., Nat. Commun., 2019.
Examples:
vision_w_autocor
¶
vision_w_autocor(
sc: ScOrMc,
gs_list: Signatures,
embd_to_use: str,
*,
no_embd_to_use: int | None = None,
use_knn: bool = True,
vision_params: VisionParams | None = None,
streaming: bool | None = None,
seed: int = 42,
verbose: Verbose = True,
) -> VisionAutocorRes
VISION scores with their local autocorrelation.
Scores the signatures, then tests each for spatial structure: Geary's C
over the kNN graph, against random signatures of similar size and
balance (generate_null_perm_gs).
The random signatures come from numpy's generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells, with the embedding. |
required |
gs_list
|
Signatures
|
Signature name to |
required |
embd_to_use
|
str
|
The embedding for the kNN search, e.g. |
required |
no_embd_to_use
|
int | None
|
Leading embedding dimensions to use. |
None
|
use_knn
|
bool
|
Take the cached kNN rather than searching the embedding. |
True
|
vision_params
|
VisionParams | None
|
The null and kNN parameters. |
None
|
streaming
|
bool | None
|
Read the cells in chunks. |
None
|
seed
|
int
|
Seed for the null signatures and the kNN search. |
42
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
VisionAutocorRes
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the embedding or the cached kNN is missing or stale. |
References
DeTomaso, et al., Nat. Commun., 2019.
Examples:
generate_null_perm_gs
¶
generate_null_perm_gs(
gs_list: Signatures,
expr_genes: Sequence[str],
*,
n_perm: int = 500,
n_comp: int = 5,
seed: int = 42,
) -> tuple[list[list[dict[str, list[str]]]], ndarray]
Random signatures for the VISION autocorrelation null.
Signatures are clustered by log10 size and share of positive genes;
per cluster centre n_perm random signatures of that size and balance
are drawn from expr_genes. With no more signatures than n_comp, each
is its own cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gs_list
|
Signatures
|
The signatures, as for |
required |
expr_genes
|
Sequence[str]
|
The gene ids to draw from. |
required |
n_perm
|
int
|
Random signatures per cluster. |
500
|
n_comp
|
int
|
Number of clusters. |
5
|
seed
|
int
|
Seed for the clustering and the draws. |
42
|
Returns:
| Type | Description |
|---|---|
list[list[dict[str, list[str]]]]
|
|
ndarray
|
|
tuple[list[list[dict[str, list[str]]]], ndarray]
|
signature. |
Examples:
TF activity from a network¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
LmActivityRes
dataclass
¶
LmActivityRes(
es: ScMatrixRes, pvals: ScMatrixRes, fdr: ScMatrixRes
)
ULM / MLM scores with p-values.
Attributes:
| Name | Type | Description |
|---|---|---|
es |
ScMatrixRes
|
The activity scores. |
pvals |
ScMatrixRes
|
Two-sided p-values. |
fdr |
ScMatrixRes
|
Benjamini-Hochberg adjusted per cell across the sources, as decoupler does. |
lm_activity
¶
lm_activity(
sc: ScOrMc,
net: DataFrame,
*,
lm_params: LmActivityParams | None = None,
verbose: Verbose = True,
) -> ScMatrixRes | LmActivityRes | None
ULM / MLM activity scores (decoupler style).
Per cell the normalised expression of every gene is regressed on the weights of each source's targets (ULM: one model per source, MLM: all sources jointly); the t value (or the slope) is the activity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells. |
required |
net
|
DataFrame
|
|
required |
lm_params
|
LmActivityParams | None
|
The parameters. |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScMatrixRes | LmActivityRes | None
|
The scores as a |
ScMatrixRes | LmActivityRes | None
|
|
ScMatrixRes | LmActivityRes | None
|
come in sorted order. |
References
Badia-i-Mompel, et al., Bioinform. Adv., 2022.
Examples:
prep_lm_network
¶
prep_lm_network(
net: DataFrame, features: Sequence[str], tmin: int
) -> dict[str, tuple[ndarray, ndarray]] | None
A source-target network as weighted gene sets.
Targets outside features are dropped, then sources with fewer than
tmin targets; duplicated source-target pairs keep the first with a
warning. A missing weight column means weight 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
DataFrame
|
|
required |
features
|
Sequence[str]
|
The gene ids, in index order. |
required |
tmin
|
int
|
Minimum targets per source. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[ndarray, ndarray]] | None
|
Source (sorted) to |
dict[str, tuple[ndarray, ndarray]] | None
|
warning if no source survives. |
Raises:
| Type | Description |
|---|---|
ValueError
|
On missing columns or non-finite weights. |
Examples:
HotSpot gene modules¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
Hotspot
dataclass
¶
Hotspot(
z: ndarray,
cor: ndarray,
genes: tuple[str, ...],
params: dict[str, object],
module_membership: DataFrame | None = None,
)
HotSpot gene-gene local correlations.
Attributes:
| Name | Type | Description |
|---|---|---|
z |
ndarray
|
|
cor |
ndarray
|
The local correlation coefficients, same layout. |
genes |
tuple[str, ...]
|
The gene ids. |
params |
dict[str, object]
|
|
module_membership |
DataFrame | None
|
|
hotspot_autocor
¶
hotspot_autocor(
sc: ScOrMc,
*,
embd_to_use: str = "pca",
use_knn: bool = True,
hotspot_params: HotspotParams | None = None,
no_embd_to_use: int | None = None,
cells_to_take: Sequence[str] | None = None,
genes_to_take: Sequence[str] | None = None,
streaming: bool | None = None,
seed: int = 42,
verbose: Verbose = True,
) -> DataFrame
HotSpot gene autocorrelation.
How much each gene's expression varies smoothly over the kNN graph of the embedding. Meta cells model their raw counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells, with the embedding. |
required |
embd_to_use
|
str
|
The embedding for the kNN, e.g. |
'pca'
|
use_knn
|
bool
|
Take the cached kNN rather than searching the embedding.
Ignored when |
True
|
hotspot_params
|
HotspotParams | None
|
The parameters. |
None
|
no_embd_to_use
|
int | None
|
Leading embedding dimensions to use. |
None
|
cells_to_take
|
Sequence[str] | None
|
Cell (meta cell) ids to use. |
None
|
genes_to_take
|
Sequence[str] | None
|
Gene ids to test. |
None
|
streaming
|
bool | None
|
Stream the genes. |
None
|
seed
|
int
|
Seed for the kNN search. |
42
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the embedding or the cached kNN is missing or stale. |
References
DeTomaso, et al., Cell Syst., 2021.
Examples:
hotspot_gene_cor
¶
hotspot_gene_cor(
sc: ScOrMc,
*,
embd_to_use: str = "pca",
use_knn: bool = True,
hotspot_params: HotspotParams | None = None,
no_embd_to_use: int | None = None,
cells_to_take: Sequence[str] | None = None,
genes_to_take: Sequence[str] | None = None,
streaming: bool | None = None,
working_mem_gb: float = 4.0,
seed: int = 42,
verbose: Verbose = True,
) -> Hotspot
HotSpot gene-gene local correlations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells, with the embedding. |
required |
embd_to_use
|
str
|
The embedding for the kNN, e.g. |
'pca'
|
use_knn
|
bool
|
Take the cached kNN rather than searching the embedding.
Ignored when |
True
|
hotspot_params
|
HotspotParams | None
|
The parameters. |
None
|
no_embd_to_use
|
int | None
|
Leading embedding dimensions to use. |
None
|
cells_to_take
|
Sequence[str] | None
|
Cell (meta cell) ids to use. |
None
|
genes_to_take
|
Sequence[str] | None
|
Gene ids to correlate. |
None
|
streaming
|
bool | None
|
Stream the genes. |
None
|
working_mem_gb
|
float
|
Memory for the resident gene panels of the streaming path, excluding the two output matrices. |
4.0
|
seed
|
int
|
Seed for the kNN search. |
42
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
Hotspot
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the embedding or the cached kNN is missing or stale. |
References
DeTomaso, et al., Cell Syst., 2021.
Examples:
generate_hotspot_membership
¶
generate_hotspot_membership(
x: Hotspot,
*,
fdr_threshold: float = 0.05,
min_size: int = 10,
) -> Hotspot
Gene modules from the pair Z-scores.
Average-linkage clustering of the Z-scores, cut as HotSpot's
compute_modules does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Hotspot
|
The |
required |
fdr_threshold
|
float
|
BH level at which a pair counts as significant. |
0.05
|
min_size
|
int
|
Minimum genes per module. |
10
|
Returns:
| Type | Description |
|---|---|
Hotspot
|
A copy with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
get_hotspot_membership
¶
get_hotspot_membership(x: Hotspot) -> DataFrame | None
The module membership.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Hotspot
|
The HotSpot result. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
|
DataFrame | None
|
|
SCENIC network inference¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
ScenicGrn
dataclass
¶
ScenicGrn(
importance_matrix: ndarray,
gene_ids: tuple[str, ...],
tf_ids: tuple[str, ...],
params: ScenicParams,
tf_to_gene_results: DataFrame = DataFrame(),
cis_targets_results: DataFrame = DataFrame(),
)
SCENIC GRN inference results.
Attributes:
| Name | Type | Description |
|---|---|---|
importance_matrix |
ndarray
|
|
gene_ids |
tuple[str, ...]
|
The target genes, the rows. |
tf_ids |
tuple[str, ...]
|
The TFs, the columns. |
params |
ScenicParams
|
The parameters of the run. |
tf_to_gene_results |
DataFrame
|
The TF to gene links once
|
cis_targets_results |
DataFrame
|
The CisTarget motif enrichment once
|
scenic_gene_filter
¶
scenic_gene_filter(
sc: ScOrMc,
*,
scenic_params: ScenicParams | None = None,
cells_to_take: Sequence[str] | None = None,
verbose: Verbose = True,
) -> list[str]
Genes with enough counts and enough expressing cells.
A gene passes with at least min_counts total counts and a share of at
least min_cells expressing cells. Meta cells are filtered on their raw
counts in memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells. |
required |
scenic_params
|
ScenicParams | None
|
The parameters. |
None
|
cells_to_take
|
Sequence[str] | None
|
Cell (meta cell) ids to use. |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The passing gene ids, in gene order. |
Examples:
scenic_grn
¶
scenic_grn(
sc: ScOrMc,
tf_ids: Sequence[str],
*,
scenic_params: ScenicParams | None = None,
genes_to_take: Sequence[str] | None = None,
cells_to_take: Sequence[str] | None = None,
streaming: bool | None = None,
seed: int = 42,
verbose: Verbose = True,
) -> ScenicGrn
GRN inference, the GENIE3 / GRNBoost2 step of SCENIC.
Regresses every target gene on the TFs with tree ensembles and keeps the
feature importances. TFs must also pass as targets. On meta cells a
min_samples_leaf of 20 or more is lowered to 10.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sc
|
ScOrMc
|
The experiment, a subset or meta cells. |
required |
tf_ids
|
Sequence[str]
|
The TF gene ids; ids not in the object drop, with a warning
when |
required |
scenic_params
|
ScenicParams | None
|
The parameters. |
None
|
genes_to_take
|
Sequence[str] | None
|
Target gene ids. |
None
|
cells_to_take
|
Sequence[str] | None
|
Cell (meta cell) ids. |
None
|
streaming
|
bool | None
|
Stream the targets. |
None
|
seed
|
int
|
Seed for the learners. |
42
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScenicGrn
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no TF is in the object or none passes as a target. |
References
Aibar, et al., Nat. Methods, 2017; Moerman, et al., Bioinformatics, 2019.
Examples:
get_params
¶
get_params(
x: ScenicGrn | Hotspot,
) -> ScenicParams | dict[str, object]
The parameters of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ScenicGrn | Hotspot
|
A SCENIC GRN result or a HotSpot result. |
required |
Returns:
| Type | Description |
|---|---|
ScenicParams | dict[str, object]
|
The |
identify_tf_to_genes
¶
identify_tf_to_genes(
x: ScenicGrn,
*,
method: Literal["threshold", "top_k"] = "threshold",
k_tfs: int | None = None,
k_genes: int | None = None,
n_sd: float = 2.0,
min_importance: float | None = None,
verbose: Verbose = True,
) -> ScenicGrn
TF to gene links from the importances.
"threshold" keeps, per target gene, the TFs at or above mean + n_sd *
sd of its importances. "top_k" keeps the k_tfs strongest regulators
per gene and / or the k_genes strongest targets per TF. Duplicate links
are dropped, the first kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ScenicGrn
|
The |
required |
method
|
Literal['threshold', 'top_k']
|
|
'threshold'
|
k_tfs
|
int | None
|
Regulators per gene for |
None
|
k_genes
|
int | None
|
Targets per TF for |
None
|
n_sd
|
float
|
Standard deviations above the mean for |
2.0
|
min_importance
|
float | None
|
Optional floor on the importance, in |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScenicGrn
|
A copy with |
Raises:
| Type | Description |
|---|---|
ValueError
|
On |
Examples:
tf_to_genes_correlations
¶
tf_to_genes_correlations(
x: ScenicGrn,
sc: ScOrMc,
*,
rho_threshold: float = 0.03,
mode: Mode = "activating",
remove_self: bool = True,
spearman: bool = True,
verbose: Verbose = True,
) -> ScenicGrn
Sign the TF to gene links by correlation.
Correlates each TF with its target over the kept cells (the normalised
counts on meta cells), signs the link +1 above rho_threshold, -1
below its negative and 0 between, and keeps the signs mode asks
for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ScenicGrn
|
The result with TF to gene links. |
required |
sc
|
ScOrMc
|
The object the GRN ran on. |
required |
rho_threshold
|
float
|
Correlation band around zero counted as unsigned. |
0.03
|
mode
|
Mode
|
Which links to keep. |
'activating'
|
remove_self
|
bool
|
Drop TF to itself links. |
True
|
spearman
|
bool
|
Spearman rather than Pearson. |
True
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScenicGrn
|
A copy whose links gain |
ScenicGrn
|
itself with a warning if there are no links. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Motif enrichment¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
run_cistarget
¶
run_cistarget(
gs_list: Mapping[str, Sequence[str]],
rankings: ndarray,
rank_genes: Sequence[str],
rank_motifs: Sequence[str],
annot_data: DataFrame,
*,
cis_target_params: CistargetParams | None = None,
verbose: Verbose = True,
) -> DataFrame
CisTarget motif enrichment of gene sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gs_list
|
Mapping[str, Sequence[str]]
|
Gene set name to gene ids. |
required |
rankings
|
ndarray
|
|
required |
rank_genes
|
Sequence[str]
|
The genes of the rows. |
required |
rank_motifs
|
Sequence[str]
|
The motifs of the columns. |
required |
annot_data
|
DataFrame
|
|
required |
cis_target_params
|
CistargetParams | None
|
The parameters. |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
sorted by gene set and descending NES. The TF lists are sorted in C |
DataFrame
|
order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
On a malformed ranking or annotation. |
References
Aibar, et al., Nat. Methods, 2017.
Examples:
tf_to_genes_motif_enrichment
¶
tf_to_genes_motif_enrichment(
x: ScenicGrn,
rankings: ndarray,
rank_genes: Sequence[str],
rank_motifs: Sequence[str],
annot_data: DataFrame,
*,
cis_target_params: CistargetParams | None = None,
gene_id_to_symbol: Mapping[str, str] | None = None,
only_high_conf_tf: bool = True,
verbose: Verbose = True,
) -> ScenicGrn
Motif support for the TF to gene links.
Runs run_cistarget on each TF's targets and flags a link
in_leading_edge when a motif annotated to that TF (high confidence, or
also low with only_high_conf_tf = False) has the gene in its leading
edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ScenicGrn
|
The result with TF to gene links. |
required |
rankings
|
ndarray
|
|
required |
rank_genes
|
Sequence[str]
|
The genes of the rows. |
required |
rank_motifs
|
Sequence[str]
|
The motifs of the columns. |
required |
annot_data
|
DataFrame
|
|
required |
cis_target_params
|
CistargetParams | None
|
The parameters. |
None
|
gene_id_to_symbol
|
Mapping[str, str] | None
|
Gene id to the symbol the database uses; links without a symbol are left out of the enrichment. |
None
|
only_high_conf_tf
|
bool
|
Count only high confidence annotations. |
True
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
ScenicGrn
|
A copy with |
ScenicGrn
|
|
Examples:
Regulons¶
Gene set scores, HotSpot gene modules and SCENIC regulons.
Three jobs. Score every cell against gene sets (module scores, AUCell, VISION, ULM / MLM), find gene modules that vary smoothly over the kNN graph (HotSpot), and infer TF regulons and score those (SCENIC).
Start with aucell for gene sets; vision takes signed signatures,
lm_activity a weighted TF-target network. For modules call hotspot_autocor,
then hotspot_gene_cor on the genes that score, then
generate_hotspot_membership. For regulons run scenic_grn,
identify_tf_to_genes, tf_to_genes_correlations, optionally
tf_to_genes_motif_enrichment, then build_regulons and score them with
aucell. Each SCENIC step takes the ScenicGrn of the last and returns an
updated copy; the input is never modified.
What lands where. Nothing here writes to obs, var, sc.map or sc.cache.
Scores come back as an ScMatrixRes (cells by gene sets) and get_data turns
one into an obs frame for sc.add_obs. The HotSpot, VISION autocorrelation
and SCENIC functions return their own result objects and data frames. All of
them take a SingleCells, a SingleCellsSubset or a MetaCells (the meta
cells compute on their in-memory counts), except module_scores, which takes
no meta cells.
genes = sc.gene_ids().tolist()
gene_sets = {"set_a": genes[:20], "set_b": genes[20:50]}
res = bv.pathways.aucell(sc, gene_sets)
sc.add_obs(bv.pathways.get_data(res))
HotSpot reads the PCA and, by default, the cached kNN graph:
bv.pp.find_hvg(sc, hvg_no=500)
bv.pp.calculate_pca(sc, no_pcs=20)
bv.graph.find_neighbours(sc)
autocor = bv.pathways.hotspot_autocor(sc)
top = autocor.sort("z_score", descending=True)["gene_id"].head(100).to_list()
hs = bv.pathways.hotspot_gene_cor(sc, genes_to_take=top)
hs = bv.pathways.generate_hotspot_membership(hs, min_size=5)
modules = bv.pathways.get_hotspot_membership(hs)
The SCENIC chain, without the motif step:
tf_ids = genes[:30] # your TF list, as gene ids
grn = bv.pathways.scenic_grn(sc, tf_ids)
grn = bv.pathways.identify_tf_to_genes(grn, n_sd=1.5)
grn = bv.pathways.tf_to_genes_correlations(grn, sc)
regulons = bv.pathways.build_regulons(grn, use_leading_edge=False, min_genes=5)
auc = bv.pathways.aucell(sc, regulons)
on_off = bv.pathways.binarise_regulon_activity(auc)
Gotchas. Gene sets, TFs and networks use the gene ids of var, not symbols.
Unknown ids drop; for the TFs in scenic_grn you only hear about it with
verbose on. hotspot_autocor and hotspot_gene_cor raise if the
embedding or the cached kNN is stale after a change of the cell filter, and the
gene by gene output of hotspot_gene_cor grows with the square of
genes_to_take, so cut it down by autocorrelation first. cells_to_take drops
the cached kNN and searches again. The motif ranking database and the
motif-to-TF annotation are yours to supply: run_cistarget and
tf_to_genes_motif_enrichment take the ranks as a genes by motifs integer
matrix and the annotation as a frame with motif, TF and
annotationSource, and build_regulons keeps only links with motif support
unless you pass use_leading_edge=False. build_regulons and lm_activity
return None with a warning when nothing survives their size filters.
RegulonBinarisation
dataclass
¶
On/off regulon calls.
Attributes:
| Name | Type | Description |
|---|---|---|
binary |
DataFrame
|
|
thresholds |
DataFrame
|
|
build_regulons
¶
build_regulons(
x: ScenicGrn,
*,
use_leading_edge: bool = True,
add_tf: bool = True,
min_genes: int = 10,
mode: Mode = "activating",
verbose: Verbose = True,
) -> dict[str, list[str]] | None
Regulons from the TF to gene links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ScenicGrn
|
The result with TF to gene links. |
required |
use_leading_edge
|
bool
|
Keep only links with motif support; skipped with a
warning before |
True
|
add_tf
|
bool
|
Put the TF itself first in its regulon. |
True
|
min_genes
|
int
|
Minimum regulon size. |
10
|
mode
|
Mode
|
Which correlation signs to keep, if the links are signed. With
|
'activating'
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
dict[str, list[str]] | None
|
Regulon name (sorted) to gene ids, or |
dict[str, list[str]] | None
|
nothing survives. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
binarise_regulon_activity
¶
binarise_regulon_activity(
auc: ScMatrixRes,
*,
binarise_params: ScenicBinariseParams | None = None,
verbose: Verbose = True,
) -> RegulonBinarisation
On/off calls per regulon.
Per regulon a two-component Gaussian mixture is compared against one
Gaussian by BIC; if the mixture wins the threshold is the density trough
between the means, else mean + 2 * sd. A cell is on strictly above it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auc
|
ScMatrixRes
|
The AUCell scores of the regulons, at least two cells. |
required |
binarise_params
|
ScenicBinariseParams | None
|
The parameters. |
None
|
verbose
|
Verbose
|
|
True
|
Returns:
| Type | Description |
|---|---|
RegulonBinarisation
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
With fewer than two cells. |
References
Aibar, et al., Nat. Methods, 2017.
Examples: