Tools (sdq.tl)#
sdq.tl.annotate_cell_state
- scdiffeq.tools._annotate_cell_state.annotate_cell_state(adata_sim: AnnData, kNN: kNN, obs_key: str = 'state', use_key: str = 'X', silent: bool = False) None[source]
Use a kNN Graph to annotate simulated cell states.
- Parameters:
adata_sim (AnnData) – Simulated data object in the format of
anndata.AnnData, the (annotated) single-cell data matrix of shapen_obs × n_vars. Rows correspond to cells and columns to genes. For more: [1](https://anndata.readthedocs.io/en/latest/).kNN (kNN) – k-nearest neighbor graph.
obs_key (str, optional) – Observation key. Default is “state”.
use_key (str, optional) – Key to use for the basis. Default is “X”.
silent (bool, optional) – If True, suppresses informational messages. Default is False.
- Return type:
None
References
sdq.tl.annotate_cell_fate
- scdiffeq.tools._annotate_cell_fate.annotate_cell_fate(adata_sim: AnnData, state_key: str = 'state', key_added: str = 'fate', time_key: str = 't', sim_key: str = 'sim', silent: bool = False, *args, **kwargs) None[source]
Annotate the fate of a simulated cell trajectory, given annotated states.
- Parameters:
adata_sim (AnnData) –
Simulated AnnData object.
- state_key (str)
Key in
adata_sim.obscorresponding to annotated states.- key_added (str)
Key added to
adata_sim.obsto indicate the fate of each trajectory. Default: “fate”- time_key (str)
Key in
adata_sim.obscorresponding to time.- sim_key (str)
Key in
adata_sim.obscorresponding to each individual simulation.- silent (bool)
If
True, suppresses informational messages.
- Return type:
None
sdq.tl.kNN
- scdiffeq.tools._knn.kNN(adata: AnnData, use_key: str = 'X_pca', n_neighbors: int = 20, metric: str = 'euclidean', space: Space | None = None)[source]
k-Nearest Neighbors container using voyager backend.
This class provides a kNN graph interface for single-cell data stored in AnnData objects. It uses voyager (Spotify’s HNSW implementation) for efficient approximate nearest neighbor search.
- Parameters:
adata – AnnData object containing the data.
use_key – Key to fetch data from adata (e.g., “X_pca”). Default: “X_pca”.
n_neighbors – Number of neighbors to return in queries. Default: 20.
metric – Distance metric to use. One of “euclidean”, “cosine”, “inner_product”. Default: “euclidean”.
space – Alternative to metric - directly specify voyager.Space. If provided, overrides metric parameter.
- scdiffeq.tools._knn.adata
The AnnData object.
- scdiffeq.tools._knn.use_key
Key used to fetch data.
- scdiffeq.tools._knn.n_neighbors
Number of neighbors for queries.
- scdiffeq.tools._knn.space
The voyager.Space used for distance computation.
sdq.tl.simulate
- scdiffeq.tools._simulation.simulate(adata: AnnData, diffeq: LightningModule, idx: Index | None = None, use_key: str = 'X_pca', time_key: str = 'Time point', N: int | None = 1, t: Tensor | None = None, dt: float | None = 0.1, device: device | None = device(type='cpu'), *args, **kwargs) AnnData[source]
Simulate trajectories by sampling from an scDiffEq model.
- Parameters:
adata (AnnData) – Input AnnData object.
idx (pd.Index) – Cell indices (corresponding to adata) from which the model should initiate sampled trajectories.
diffeq (lightning.LightningModule) – The differential equation model.
use_key (str, optional) – adata accession key for the input data. Default is “X_pca”.
N (int, optional) – Number of trajectories to sample from the model. Default is 2000.
device (device, optional) – Device to run the simulation on. Default is True.
- Returns:
AnnData object encapsulating scDiffEq model simulation.
- Return type: