atlas.tl.PalantirExtension#
- class atlas.tl.PalantirExtension(mudata)#
Trajectory inference using the Palantir algorithm on
MuDataobjects.This class provides a high-level interface to run Palantir-based trajectory inference on multimodal single-cell data stored in a
MuDataobject. It operates directly on the input object and stores all intermediate and final results within it.- Parameters:
mudata (
MuData) – Annotated multimodal data object containing precomputed neighborhood graphs and embeddings.
Notes
This implementation is adapted from the original Palantir algorithm [SKL+19], with modifications to operate on
MuDataobjects.
Attributes table#
Underlying |
Methods table#
|
Compute diffusion maps from a precomputed kernel. |
|
Compute an adaptive Gaussian kernel from a kNN graph. |
|
Compute the multiscale diffusion distance. |
|
Trajectory inference using Palantir ([SKL+19]). |
Attributes#
- PalantirExtension.mudata#
Underlying
MuDataobject.Represents multimodal single-cell data containing the weighted nearest neighbor graph.
Methods#
- PalantirExtension.compute_diffusion_maps(kernel_key='DM_Kernel', sim_key='DM_Similarity', eigval_key='DM_EigenValues', eigvec_key='DM_EigenVectors', n_components=10, seed=42)#
Compute diffusion maps from a precomputed kernel.
This function computed the diffusion operator from the kernel stored in
mudata.obsp. Results are stored back into theMuDataobject.- Parameters:
kernel_key (
str(default:'DM_Kernel')) – Key inmudata.obspwhere the kernel matrix is stored.sim_key (
str(default:'DM_Similarity')) – Key inmudata.obspwhere the diffusion operator is stored.eigval_key (
str(default:'DM_EigenValues')) – Key inmudata.unswhere eigenvalues are stored.eigvec_key (
str(default:'DM_EigenVectors')) – Key inmudata.obsmwhere the eigenvectors are stores.n_components (
int(default:10)) – Number of diffusion components to compute.seed (
int(default:42)) – Random seed for reproducibility.
- Return type:
- Returns:
Updates the original
MuDataobject:Sparse similarity matrix of shape
(n_cells, n_cells)in.obsp[sim_key]Eigenvectors,
pandas.DataFrameornumpy.ndarrayof shape(n_cells, n_components)in.obsm[eigval_key].Eigenvalues, numpy.ndarray of shape
(n_components,)in.uns[eigvec_key].
- Raises:
KeyError – if
kernel_keyis not present inmudata.obsp.
- PalantirExtension.compute_kernel(knn_key='wnn', distance_key='wnn_distances', knn=None, alpha=0, kernel_key='DM_Kernel')#
Compute an adaptive Gaussian kernel from a kNN graph.
This function builds a symmetric affinity matrix using an adaptive bandwidth scheme, following the approach described in [SKL+19]. The kernel is constructed from a k-nearest neighbors distance graph stored in
mudata.obsp.- Parameters:
knn_key (
str(default:'wnn')) – Key inmudata.unswhere neighborhood parameters are stored. Must contain['params']['n_neighbors']. Default is"wnn".distance_key (
str(default:'wnn_distances')) – Key inmudata.obspwhere the kNN distance matrix is stored. Default is"wnn_distances".knn (
int|None(default:None)) – Number of nearest neighbors used to define the adaptive bandwidth. IfNoneor larger than the number of neighbors stored inmudata.uns[knn_key]['params']['n_neighbors'], it is set to that value.alpha (
float(default:0)) – Normalization parameter for the diffusion operator. Ifalpha > 0, applies degree normalization to the kernel. Default is0.kernel_key (
str(default:'DM_Kernel')) – Key inmudata.obspwhere the resulting kernel matrix is stored. Default is"DM_Kernel".
- Return type:
- Returns:
Updates the original
MuDataobject.Anisotropic kernel, scipy.sparse.csr_matrix of shape
(n_cells, n_cells)inobsp[kernel_key].
- Raises:
KeyError – If
distance_keyis not present inmudata.obsporknn_keyis not present inmudata.uns.
Notes
The kernel is computed using an adaptive bandwidth defined as the distance to the
floor(knn / 3)-th nearest neighbor for each cell. The resulting affinity matrix is symmetrized and optionally normalized.
- PalantirExtension.compute_multiscale_space(n_eigs=None, eigval_key='DM_EigenValues', eigvec_key='DM_EigenVectors', out_key='DM_EigenVectors_multiscaled')#
Compute the multiscale diffusion distance.
This function rescales diffusion components using their associated eigenvalues to obtain a multiscale representation of the data.
- Parameters:
n_eigs (
int|None(default:None)) – Number of eigenvalues to use. IfNone, the eigengap heuristic is used to obtain a multiscale representation of the data.eigval_key (
str(default:'DM_EigenValues')) – Key inmudata.unswhere diffusion eigenvalues are stored.eigvec_key (
str(default:'DM_EigenVectors')) – Key inmudata.obsmwhere diffusion eigenvectors are stored.out_key (
str(default:'DM_EigenVectors_multiscaled')) – Key inmudata.obsmwhere the multiscale representation is stored.
- Return type:
- Returns:
Updates the original MuData object:
Multiscaled distances,
pandas.DataFrameof shape(n_cells, n_eigs)inobsm[out_key].
- Raises:
- PalantirExtension.run(early_cell, cluster_key=None, terminal_states=None, knn=30, num_waypoints=1200, n_jobs=-1, scale_components=True, use_early_cell_as_start=False, max_iterations=25, eigvec_multi_key='DM_EigenVectors_multiscaled', eigvec_key='DM_EigenVectors', pseudotime_key='pseudotime', fate_prob_key='fate_probabilities', waypoints_key='palantir_waypoints', random_state=42)#
Trajectory inference using Palantir ([SKL+19]).
- This function:
Computes the anisotropic kernel from the weighted nearest neighbor graph connectivites.
Derives diffusion components and multiscale space if not available.
Runs the original Palantir algorithm.
Computed entropy as defined in [LBK+22].
- Parameters:
early_cell (
str) – Barcode identifier of the initial cell for pseudotime inference.cluster_key (
str|None(default:None)) – Identifier inobscontaining information about cells, optional.terminal_states (
Sequence[str] |Mapping[str,Sequence[str]] |Series|None(default:None)) – Terminal states can be defined by the user. WhenNone, terminal states are automatically inferred by the algorithm.knn (
int(default:30)) – Number of nearest neighbors for graph construction in the multiscale space.num_waypoints (
int(default:1200)) – Number of waypoints for trajectory inference. See the original Palantir algorithm for an accurate description of the parameter.n_jobs (
int(default:-1)) – Parameter for parallelization.scale_components (
bool(default:True)) – When set to True diffusion components are scaled.use_early_cell_as_start (
bool(default:False)) – If True ther early cell is used as start.max_iterations (
int(default:25)) – Maximum number of iterations for pseudotime convergence.eigvec_multi_key (
str(default:'DM_EigenVectors_multiscaled')) – Identifier of the multiscale space matrix in.obsm.pseudotime_key (
str(default:'pseudotime')) – Key in.obswhere pseudotime results are stored.fate_prob_key (
str(default:'fate_probabilities')) – Key in.obsmwhere fate probabilities are stored.waypoints_key (
str(default:'palantir_waypoints')) – Key in.unswhere waypoints are stored if provided.random_state (
int(default:42)) – Seed for reproducibility.
- Return type:
- Returns:
Updates the
MuDataobject:Pseudotime is added in
.obs[pseudotime_key].Fate probabilites, a
pandas.DataFrameof shape(n_cells, n_terminal_states)inobsm[fate_prob_key].List of inferred waypoints in
.uns[waypoints_key].Shannon entropy and KL-divergence values, respectively, in
.obs["shannon_entropy"]and.obs["kl_divergence"].Initial and terminal cell identifiers, respectively, in
.uns["initial_states"]anduns["terminal_states"].
Notes
If the multiscale space identified by
eigvec_multi_keyis not present, the anisotropc kernel, the diffusion components and the multiscaled distances are inferred using the default parameters on the graph stored as “wnn_distances” in.obsp.