Index
Data loading and formula utilities.
AnnDataStandardScaler
Standardize numerical columns of adata.obs using sklearn's StandardScaler.
Categorical and object-typed columns are detected automatically and left unchanged. The API mirrors the familiar sklearn fit / transform pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**scaler_kwargs
|
Keyword arguments forwarded to :class: |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
numeric_cols_ |
list[str]
|
Names of |
categorical_cols_ |
list[str]
|
Names of |
scaler_ |
StandardScaler
|
The fitted scaler instance. |
Examples:
>>> scaler = AnnDataStandardScaler()
>>> adata_scaled = scaler.fit_transform(adata) # returns a copy
>>> scaler.fit_transform(adata, inplace=True) # modifies in place
Source code in scdesigner/src/scdesigner/data/preprocessing.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 | |
fit(adata)
Fit the scaler on the numerical columns of adata.obs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adata
|
AnnData
|
Annotated data matrix whose |
required |
Returns:
| Type | Description |
|---|---|
self
|
|
Source code in scdesigner/src/scdesigner/data/preprocessing.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
fit_transform(adata, inplace=False)
Fit the scaler and transform adata.obs in one step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adata
|
AnnData
|
Annotated data matrix to fit and transform. |
required |
inplace
|
bool
|
Passed through to :meth: |
False
|
Returns:
| Type | Description |
|---|---|
AnnData or None
|
See :meth: |
Source code in scdesigner/src/scdesigner/data/preprocessing.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
transform(adata, inplace=False)
Scale the numerical columns of adata.obs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adata
|
AnnData
|
Annotated data matrix to transform. |
required |
inplace
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
AnnData or None
|
Modified copy when |
Source code in scdesigner/src/scdesigner/data/preprocessing.py
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 | |
GPBasis
Bases: SpatialBasis
Gaussian-process basis with an RBF kernel (Nystrom).
Regularizes the landmark kernel with eps * I before SVD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length_scale
|
float
|
RBF length scale :math: .. math::
Smaller values allow more rapidly varying functions. If |
None
|
length_fraction
|
float
|
Fraction :math: .. math::
taken over the fitted coordinates :math: |
0.17
|
**kwargs
|
Forwarded to :class: |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
length_scale_ |
float
|
Length scale of the fitted basis. Set by :meth: |
Source code in scdesigner/src/scdesigner/data/basis.py
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
SpatialBasis
Bases: ABC
Low-rank 2D spatial basis with stateful fit / transform.
Subclasses define _kernel and _regularize (applied to the
landmark kernel before SVD). fit picks landmarks, stores the
projection U_m[:, :df] / s_m[:df], training column std (if
standardize), and the penalty diagonal s_0 / s_j (capped).
transform reuses that state on new coordinates. fit evaluates the
kernel on at most chunk_size coordinates at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
int
|
Basis columns to retain. |
15
|
n_landmarks
|
int
|
Landmark count for the Nystrom approximation. |
200
|
eps
|
float
|
Numerical floor for kernel and column-std. |
1e-06
|
max_penalty_ratio
|
float
|
Cap on |
1000.0
|
standardize
|
bool
|
Divide columns by training std. |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
landmarks_, projection_, col_sd_, penalty_diag |
Set by :meth: |
Source code in scdesigner/src/scdesigner/data/basis.py
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 | |
fit(coords, chunk_size=None)
Fit on coords; chunk_size=None evaluates all rows at once.
Source code in scdesigner/src/scdesigner/data/basis.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
SpatialTerm
dataclass
Unfitted spatial basis and optional penalty on its coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basis
|
SpatialBasis
|
Template |
required |
penalty
|
QuadraticPenalty
|
|
None
|
Source code in scdesigner/src/scdesigner/data/spatial.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
TPSBasis
Bases: SpatialBasis
Thin-plate spline basis (Nystrom).
Projects out the TPS penalty null space (intercept + linear terms over
landmarks) before SVD; drops singular values below eps.
Source code in scdesigner/src/scdesigner/data/basis.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
adata_loader(adata, formula, chunk_size=None, batch_size=1024, shuffle=False, num_workers=0, device=None, partition_keys=None, **kwargs)
Create a :class:~torch.utils.data.DataLoader over an AnnData dataset.
The resulting loader yields tuples (X_batch, obs_batch) where:
X_batchis a float tensor of shape (batch_size, n_genes)obs_batchis a dict mapping each formula key to a float tensor of shape (batch_size, n_covariates) for that key's design matrix
For backed AnnData objects, the underlying dataset uses chunk caching to limit memory usage. Chunks are read in the order stored on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adata
|
AnnData
|
Input AnnData object. |
required |
formula
|
dict[str, str] or Design
|
A fitted :class: |
required |
chunk_size
|
int
|
Rows per chunked read. |
None
|
batch_size
|
int
|
Mini-batch size returned by the loader. |
1024
|
shuffle
|
bool
|
Whether to shuffle observations each epoch. Not allowed for backed reads. |
False
|
num_workers
|
int
|
Number of DataLoader workers. |
0
|
partition_keys
|
set of str
|
Formula used to partition observations, usually used for copula
covariance groups. Ignored when |
None
|
**kwargs
|
Additional keyword arguments filtered via |
{}
|
Returns:
| Type | Description |
|---|---|
DataLoader
|
DataLoader over the dataset. |
Source code in scdesigner/src/scdesigner/data/loader.py
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
obs_loader(obs, formula, **kwargs)
Create a loader that yields design matrices for an observation table.
This is a convenience wrapper for prediction-time batching: it creates a
dummy AnnData with a placeholder X and uses :func:adata_loader to
construct batches of covariates derived from obs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs
|
DataFrame
|
Observation metadata used to build design matrices. |
required |
formula
|
dict[str, str] or Design
|
See :func: |
required |
**kwargs
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
DataLoader
|
Loader yielding |
Source code in scdesigner/src/scdesigner/data/loader.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |