spateo.alignment.methods.deprecated_morpho¶
Functions¶
|
con_K constructs the Squared Exponential (SE) kernel, where K(i,j)=k(X_i,Y_j)=exp(-beta*||X_i-Y_j||^2). |
|
Calculating the generating probability matrix P. |
|
Calculating the generating probability matrix P. |
|
Align two spatial transcriptomics AnnData objects using the Spateo alignment algorithm. |
Module Contents¶
- spateo.alignment.methods.deprecated_morpho.con_K(X: numpy.ndarray | torch.Tensor, Y: numpy.ndarray | torch.Tensor, beta: int | float = 0.01, use_chunk: bool = False) numpy.ndarray | torch.Tensor [source]¶
con_K constructs the Squared Exponential (SE) kernel, where K(i,j)=k(X_i,Y_j)=exp(-beta*||X_i-Y_j||^2).
- Parameters:
- Returns:
The kernel Kinmathbb{R}^{N imes M}
- Return type:
K
- spateo.alignment.methods.deprecated_morpho.get_P(XnAHat: numpy.ndarray | torch.Tensor, XnB: numpy.ndarray | torch.Tensor, sigma2: int | float | numpy.ndarray | torch.Tensor, beta2: int | float | numpy.ndarray | torch.Tensor, alpha: numpy.ndarray | torch.Tensor, gamma: float | numpy.ndarray | torch.Tensor, Sigma: numpy.ndarray | torch.Tensor, GeneDistMat: numpy.ndarray | torch.Tensor, SpatialDistMat: numpy.ndarray | torch.Tensor, samples_s: List[float] | None = None, outlier_variance: float = None) Tuple[Any, Any, Any] [source]¶
Calculating the generating probability matrix P.
- Parameters:
- XAHat
Current spatial coordinate of sample A. Shape: N x D.
- XnB
spatial coordinate of sample B (reference sample). Shape: M x D.
- sigma2
The spatial coordinate noise.
- beta2
The gene expression noise.
- alpha
A vector that encoding each probability generated by the spots of sample A. Shape: N x 1.
- gamma
Inlier proportion of sample A.
- Sigma
The posterior covariance matrix of Gaussian process. Shape: N x N or N x 1.
- GeneDistMat
The gene expression distance matrix between sample A and sample B. Shape: N x M.
- SpatialDistMat
The spatial coordinate distance matrix between sample A and sample B. Shape: N x M.
- samples_s
The space size of each sample. Area size for 2D samples and volume size for 3D samples.
- Returns:
Generating probability matrix P. Shape: N x M.
- Return type:
P
- spateo.alignment.methods.deprecated_morpho.get_P_chunk(XnAHat: numpy.ndarray | torch.Tensor, XnB: numpy.ndarray | torch.Tensor, X_A: numpy.ndarray | torch.Tensor, X_B: numpy.ndarray | torch.Tensor, sigma2: int | float | numpy.ndarray | torch.Tensor, beta2: int | float | numpy.ndarray | torch.Tensor, alpha: numpy.ndarray | torch.Tensor, gamma: float | numpy.ndarray | torch.Tensor, Sigma: numpy.ndarray | torch.Tensor, samples_s: List[float] | None = None, outlier_variance: float = None, chunk_size: int = 1000, dissimilarity: str = 'kl') numpy.ndarray | torch.Tensor [source]¶
Calculating the generating probability matrix P.
- Parameters:
- XAHat
Current spatial coordinate of sample A. Shape
- spateo.alignment.methods.deprecated_morpho.BA_align(sampleA: anndata.AnnData, sampleB: anndata.AnnData, rep_layer: str | List[str] = 'X', rep_field: str | List[str] = 'layer', genes: List[str] | torch.Tensor | None = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: str | None = None, save_concrete_iter: bool = False, vecfld_key_added: str | None = None, dissimilarity: str | List[str] = 'kl', probability_type: str | List[str] = 'gauss', probability_parameters: float | List[float] | None = None, label_transfer_dict: dict | List[dict] | None = None, nn_init: bool = True, allow_flip: bool = False, init_layer: str = 'X', init_field: str = 'layer', max_iter: int = 200, SVI_mode: bool = True, batch_size: int = 1000, pre_compute_dist: bool = True, sparse_calculation_mode: bool = False, lambdaVF: int | float = 100.0, beta: int | float = 0.01, K: int | float = 15, sigma2_init_scale: int | float | None = 0.1, partial_robust_level: float = 25, normalize_c: bool = True, normalize_g: bool = True, dtype: str = 'float32', device: str = 'cpu', verbose: bool = True, guidance_pair: List[numpy.ndarray] | numpy.ndarray | None = None, guidance_effect: bool | str | None = False, guidance_epsilon: float = 1) Tuple[Tuple[anndata.AnnData, anndata.AnnData], numpy.ndarray] [source]¶
Align two spatial transcriptomics AnnData objects using the Spateo alignment algorithm.
- Parameters:
- sampleA AnnData
The first AnnData object that acts as the reference.
- sampleB AnnData
The second AnnData object to be aligned.
- rep_layer Union[str, List[str]], optional
Representation layer(s) in AnnData to be used for alignment. Defaults to “X”.
- rep_field Union[str, List[str]], optional
Representation layer field(s) in AnnData to be used for alignment. “layer” means gene expression, “obsm” means embdedding like pca or VAE, “obs” means discrete label annotation. Note that Spateo only accept one label annotation. Defaults to “layer”.
- genes Optional[Union[List[str], torch.Tensor]], optional
List or tensor of genes to be used for alignment. For example, you can input the genes you are interested or spatially variabe genes here. Defaults to None.
- spatial_key str, optional
Key in .obsm of AnnData corresponding to the spatial coordinates. Defaults to “spatial”.
- key_added str, optional
Key under which the aligned spatial coordinates are added in .obsm. Defaults to “align_spatial”.
- iter_key_added Optional[str], optional
Key under which to store intermediate iteration results in .uns. Defaults to None.
- vecfld_key_added Optional[str], optional
Key under which to store vector field results in .uns. Defaults to None.
- dissimilarity Union[str, List[str]], optional
Measure(s) of pairwise dissimilarity of each observation to be used. Defaults to “kl”.
- probability_type Union[str, List[str]], optional
Type(s) of probability distribution used. Defaults to “gauss”.
- probability_parameters Optional[Union[float, List[float]]], optional
Parameters for the probability distribution. Defaults to None.
- label_transfer_dict Optional[Union[dict, List[dict]]], optional
Dictionary that stores the label transfer probability. Defaults to None.
- nn_init bool, optional
Whether to use nearest neighbor initialization. Defaults to True.
- allow_flip bool, optional
Whether to allow flipping of coordinates. Defaults to False.
- init_layer str, optional
Layer for init alignment. Defaults to “X”.
- init_field str, optional
Layer field for init alignment. Defaults to ‘layer’.
- max_iter int, optional
Maximum number of iterations. Defaults to 200.
- SVI_mode bool, optional
Whether to use Stochastic Variational Inference mode. Defaults to True.
- batch_size int, optional
Size of the mini-batch for SVI. Defaults to 1000.
- pre_compute_dist bool, optional
Whether to pre-compute the gene similarity matrix. Defaults to True.
- sparse_calculation_mode bool, optional
Whether to use sparse matrix calculations. Defaults to False.
- lambdaVF Union[int, float], optional
Regularization parameter for vector field. Defaults to 1e2.
- beta Union[int, float], optional
Length-scale of the SE kernel. Defaults to 0.01.
- K Union[int, float], optional
Number of sparse inducing points for Nyström approximation. Defaults to 15.
- sigma2_init_scale Optional[Union[int, float]], optional
Initial spatial dispersion scale. Defaults to 0.1.
- partial_robust_level float, optional
Robust level for partial alignment. Defaults to 25.
- normalize_c bool, optional
Whether to normalize spatial coordinates. Defaults to True.
- normalize_g bool, optional
Whether to normalize gene expression. Defaults to True.
- dtype str, optional
Data type for computations. Defaults to “float32”.
- device str, optional
Device for computation, e.g., “cpu” or “0” for GPU. Defaults to “cpu”.
- inplace #
Whether to modify adata inplace. Defaults to True.
- verbose bool, optional
Whether to print verbose messages. Defaults to True.
- guidance_pair Optional[Union[List[np.ndarray], np.ndarray]], optional
Guidance pairs for alignment. Defaults to None.
- guidance_effect Optional[Union[bool, str]], optional
Effect of guidance. Defaults to False.
- guidance_epsilon float, optional
Epsilon value for guidance. Defaults to 1.
- Returns:
A tuple containing the aligned AnnData objects and assignment matrix.
- Return type:
Tuple[Tuple[AnnData, AnnData], np.ndarray]