snapatac2.tl.diff_test#
- snapatac2.tl.diff_test(data, cell_group1, cell_group2, features=None, covariates=None, direction='both', min_log_fc=0.25, min_pct=0.05, solver='lbfgs')[source]#
Test regions for differential accessibility between two cell groups.
Use this function to compare two explicit cell sets with logistic-regression likelihood-ratio tests after filtering by detection fraction and fold change.
Anti-Patterns#
Do NOT pass group names directly; pass cell indices, cell barcodes, or a Boolean mask for each group.
Do NOT use
covariates; the parameter is currently not implemented.Do NOT expect features failing
min_pctormin_log_fcto appear in the output table.
- param data:
Annotated data object with cells in observations and regions in variables.
- type data:
AnnData | AnnDataSet
- param cell_group1:
Cells in group 1 as indices, barcodes, or a Boolean mask.
- type cell_group1:
list[int] | list[str]
- param cell_group2:
Cells in group 2 as indices, barcodes, or a Boolean mask.
- type cell_group2:
list[int] | list[str]
- param features:
Region names or indices to test. If None, test all regions that pass filtering.
- type features:
list[str] | list[int] | None
- param covariates:
Reserved for covariates; currently raises
NameErrorwhen provided.- type covariates:
list[str] | None
- param direction:
Direction of enrichment to retain.
"positive"keeps regions enriched in group 1,"negative"keeps regions enriched in group 2, and"both"keeps either direction.- type direction:
Literal[‘positive’, ‘negative’, ‘both’]
- param min_log_fc:
Minimum absolute or directional log2 fold change required before testing.
- type min_log_fc:
float
- param min_pct:
Minimum fraction of cells with nonzero accessibility in either group.
- type min_pct:
float
- param solver:
Solver passed to
sklearn.linear_model.LogisticRegression.- type solver:
str
- returns:
Differential accessibility table sorted by adjusted p-value, with columns
"feature name","log2(fold_change)","p-value", and"adjusted p-value".- rtype:
polars.DataFrame
Examples
>>> import snapatac2 as snap >>> adata = snap.datasets.pbmc5k(type="annotated_h5ad") >>> group1 = list(range(50)) >>> group2 = list(range(50, 100)) >>> result = snap.tl.diff_test(adata, group1, group2, features=list(range(20))) >>> set(result.columns) <= {"feature name", "log2(fold_change)", "p-value", "adjusted p-value"} True