scsplice.pp¶
Preprocessing functions. Event-level filters and selection methods applied before dimensionality reduction.
pp
¶
scsplice.pp — preprocessing (per-event filters, HVE/HVG selection).
highly_variable_events
¶
highly_variable_events(adata: AnnData, *, min_row_sum: float = 50.0, n_top: int | None = None, n_threads: int = 1, sample_key: str = 'sample_id', key_added: str = 'highly_variable', inplace: bool = True) -> AnnData | None
Identify highly variable splicing events via ratio binomial deviance.
For every event, compute the per-library deviance of the (M1, M2) ratio
against its library-aggregate p_hat, then sum across libraries. Events
that fail the row-sum filter (M1.sum > min_row_sum AND M2.sum > min_row_sum)
receive NaN deviance and are excluded from the top-N selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adata
|
AnnData
|
Splicing AnnData with |
required |
min_row_sum
|
float
|
Minimum row sum required on both M1 and M2 (computed on the full data, before per-library splitting). Events failing the filter are excluded from deviance computation entirely. |
50.0
|
n_top
|
int | None
|
If set, mark the top-N events by |
None
|
n_threads
|
int
|
OpenMP thread count. Per-row work is independent so output is bit-identical regardless of n_threads. |
1
|
sample_key
|
str
|
|
'sample_id'
|
key_added
|
str
|
Boolean column in |
'highly_variable'
|
inplace
|
bool
|
Mutate |
True
|
Returns:
| Type | Description |
|---|---|
``None`` when ``inplace=True``; otherwise a copy.
|
|
Notes
Writes var['sum_deviance'] (float64, NaN for filtered-out events)
and var[key_added] (bool). Stores call params under
uns['scsplice']['params']['highly_variable_events'].
Source code in src/scsplice/pp/_hve.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
highly_variable_genes
¶
highly_variable_genes(adata: AnnData, *, layer: str | None = None, method: str = 'vst', loess_span: float = 0.3, n_top: int | None = None, n_threads: int = 1, key_added: str = 'highly_variable', inplace: bool = True) -> AnnData | None
Identify highly variable genes via Seurat-style variance-stabilizing transformation.
Fits a mean-variance trend (log10(variance) ~ log10(mean), degree-2
local regression with tricube weights, span=loess_span) across genes,
then computes each gene's clipped, standardized residual variance —
Hafemeister & Satija (2019)'s VST, as implemented by R splikit's
find_variable_genes(method = "vst") /
standardizeSparse_variance_vst().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adata
|
AnnData
|
Gene-expression AnnData, e.g. from :func: |
required |
layer
|
str | None
|
Read counts from |
None
|
method
|
str
|
Only |
'vst'
|
loess_span
|
float
|
Span (neighborhood fraction) passed to the loess fit. Matches R
splikit's hardcoded |
0.3
|
n_top
|
int | None
|
If set, mark the top-N genes by |
None
|
n_threads
|
int
|
OpenMP thread count for the two C++ passes (row mean/variance and
standardization). The loess fit itself is single-threaded (it runs
in Python via |
1
|
key_added
|
str
|
Boolean column in |
'highly_variable'
|
inplace
|
bool
|
Mutate |
True
|
Returns:
| Type | Description |
|---|---|
``None`` when ``inplace=True``; otherwise a copy.
|
|
Notes
Writes var["standardize_variance"] (float64; this is R splikit's own
column name, kept verbatim for direct comparison) and var[key_added]
(bool). Stores call params under
uns['scsplice']['params']['highly_variable_genes'].
Genes that fail the mean > 0 and variance > 0 filter (constant or
all-zero genes) do not receive NaN: R splikit computes their
standardized variance using a hardcoded fallback trend (sd = 1.0),
and this port replicates that behaviour exactly rather than "fixing" it,
so results match R splikit row-for-row. Such genes are excluded from
var[key_added] selection when n_top is None.
Numerical equivalence with R
The row mean/variance pass and the standardization pass are plain
floating-point arithmetic ported from
splikit/src/hvf_gene_expression.cpp and are np.allclose-tight
(not bit-exact) vs. R, the same as scsplice's other ported kernels — see
the C++ header comments in hvg_vst.hpp. The loess step uses
skmisc.loess, which wraps the same netlib/Cleveland-Grosse loess
Fortran/C implementation that R's stats::loess() calls (both default
to degree=2, family="gaussian", surface="interpolate",
cell=0.2), so this is genuine — not merely approximate — parity with
R, modulo ordinary cross-platform floating-point differences.
Source code in src/scsplice/pp/_hvg.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |