spateo.alignment.morpho_alignment
#
Module Contents#
Functions#
|
Continuous alignment of spatial transcriptomic coordinates based on Morpho. |
|
Continuous alignment of spatial transcriptomic coordinates based on Morpho. |
|
Continuous alignment of spatial transcriptomic coordinates with the reference models based on Morpho. |
- spateo.alignment.morpho_alignment.morpho_align(models: List[anndata.AnnData], layer: str = 'X', genes: list | numpy.ndarray | None = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: str | None = 'iter_spatial', vecfld_key_added: str = 'VecFld_morpho', mode: Literal[SN - N, SN - S] = 'SN-S', dissimilarity: str = 'kl', max_iter: int = 100, SVI_mode: bool = True, dtype: str = 'float32', device: str = 'cpu', verbose: bool = True, **kwargs) Tuple[List[anndata.AnnData], List[numpy.ndarray], List[numpy.ndarray]] [source]#
Continuous alignment of spatial transcriptomic coordinates based on Morpho.
- Parameters:
- models
List of models (AnnData Object).
- layer
If
'X'
, uses.X
to calculate dissimilarity between spots, otherwise uses the representation given by.layers[layer]
.- genes
Genes used for calculation. If None, use all common genes for calculation.
- spatial_key
The key in
.obsm
that corresponds to the raw spatial coordinate.- key_added
.obsm
key under which to add the aligned spatial coordinate.- iter_key_added
.uns
key under which to add the result of each iteration of the iterative process. Ifiter_key_added
is None, the results are not saved.- vecfld_key_added
The key that will be used for the vector field key in
.uns
. Ifvecfld_key_added
is None, the results are not saved.- mode
The method of alignment. Available
mode
are:'SN-N'
, and'SN-S'
.'SN-N'
: use both rigid and non-rigid alignment to keep the overall shape unchanged, while including local non-rigidity, and finally returns a non-rigid aligned result;'SN-S'
: use both rigid and non-rigid alignment to keep the overall shape unchanged, while including local non-rigidity, and finally returns a rigid aligned result. The non-rigid is used here to solve the optimal mapping, thus returning a more accurate rigid transformation. The default is'SN-S'
.
- dissimilarity
Expression dissimilarity measure:
'kl'
or'euclidean'
.- max_iter
Max number of iterations for morpho alignment.
- SVI_mode
Whether to use stochastic variational inferential (SVI) optimization strategy.
- dtype
The floating-point number type. Only
float32
andfloat64
.- device
Equipment used to run the program. You can also set the specified GPU for running.
E.g.: '0'
.- verbose
If
True
, print progress updates.- **kwargs
Additional parameters that will be passed to
BA_align
function.
- Returns:
List of models (AnnData Object) after alignment. pis: List of pi matrices. sigma2s: List of sigma2.
- Return type:
align_models
- spateo.alignment.morpho_alignment.morpho_align_sparse(models: List[anndata.AnnData], layer: str = 'X', genes: list | numpy.ndarray | None = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: str | None = 'iter_spatial', vecfld_key_added: str = 'VecFld_morpho', mode: Literal[SN - N, SN - S] = 'SN-S', dissimilarity: str = 'kl', max_iter: int = 100, SVI_mode: bool = True, use_label_prior: bool = False, label_key: str | None = 'cluster', label_transfer_prior: dict | None = None, dtype: str = 'float32', device: str = '0', verbose: bool = True, **kwargs) Tuple[List[anndata.AnnData], List[numpy.ndarray], List[numpy.ndarray]] [source]#
Continuous alignment of spatial transcriptomic coordinates based on Morpho.
- Parameters:
- models
List of models (AnnData Object).
- layer
If
'X'
, uses.X
to calculate dissimilarity between spots, otherwise uses the representation given by.layers[layer]
.- genes
Genes used for calculation. If None, use all common genes for calculation.
- spatial_key
The key in
.obsm
that corresponds to the raw spatial coordinate.- key_added
.obsm
key under which to add the aligned spatial coordinate.- iter_key_added
.uns
key under which to add the result of each iteration of the iterative process. Ifiter_key_added
is None, the results are not saved.- vecfld_key_added
The key that will be used for the vector field key in
.uns
. Ifvecfld_key_added
is None, the results are not saved.- mode
The method of alignment. Available
mode
are:'SN-N'
, and'SN-S'
.'SN-N'
: use both rigid and non-rigid alignment to keep the overall shape unchanged, while including local non-rigidity, and finally returns a non-rigid aligned result;'SN-S'
: use both rigid and non-rigid alignment to keep the overall shape unchanged, while including local non-rigidity, and finally returns a rigid aligned result. The non-rigid is used here to solve the optimal mapping, thus returning a more accurate rigid transformation. The default is'SN-S'
.
- dissimilarity
Expression dissimilarity measure:
'kl'
or'euclidean'
.- max_iter
Max number of iterations for morpho alignment.
- SVI_mode
Whether to use stochastic variational inferential (SVI) optimization strategy.
- dtype
The floating-point number type. Only
float32
andfloat64
.- device
Equipment used to run the program. You can also set the specified GPU for running.
E.g.: '0'
.- verbose
If
True
, print progress updates.- **kwargs
Additional parameters that will be passed to
BA_align_sparse
function.
- Returns:
List of models (AnnData Object) after alignment. pis: List of pi matrices. sigma2s: List of sigma2.
- Return type:
align_models
- spateo.alignment.morpho_alignment.morpho_align_ref(models: List[anndata.AnnData], models_ref: List[anndata.AnnData] | None = None, n_sampling: int | None = 2000, sampling_method: str = 'trn', layer: str = 'X', genes: list | numpy.ndarray | None = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: str | None = 'iter_spatial', vecfld_key_added: str | None = 'VecFld_morpho', mode: Literal[SN - N, SN - S] = 'SN-S', dissimilarity: str = 'kl', max_iter: int = 100, SVI_mode: bool = True, return_full_assignment: bool = False, dtype: str = 'float32', device: str = 'cpu', verbose: bool = True, **kwargs) Tuple[List[anndata.AnnData], List[anndata.AnnData], List[numpy.ndarray], List[numpy.ndarray], List[numpy.ndarray]] [source]#
Continuous alignment of spatial transcriptomic coordinates with the reference models based on Morpho.
- Parameters:
- models
List of models (AnnData Object).
- models_ref
Another list of models (AnnData Object).
- n_sampling
When
models_ref
is None, new data containing n_sampling coordinate points will be automatically generated for alignment.- sampling_method
The method to sample data points, can be one of
["trn", "kmeans", "random"]
.- layer
If
'X'
, uses.X
to calculate dissimilarity between spots, otherwise uses the representation given by.layers[layer]
.- genes
Genes used for calculation. If None, use all common genes for calculation.
- spatial_key
The key in
.obsm
that corresponds to the raw spatial coordinate.- key_added
.obsm
key under which to add the aligned spatial coordinate.- iter_key_added
.uns
key under which to add the result of each iteration of the iterative process. Ifiter_key_added
is None, the results are not saved.- vecfld_key_added
The key that will be used for the vector field key in
.uns
. Ifvecfld_key_added
is None, the results are not saved.- mode
The method of alignment. Available
mode
are:'SN-N'
, and'SN-S'
.'SN-N'
: use both rigid and non-rigid alignment to keep the overall shape unchanged, while including local non-rigidity, and finally returns a non-rigid aligned result;'SN-S'
: use both rigid and non-rigid alignment to keep the overall shape unchanged, while including local non-rigidity, and finally returns a rigid aligned result. The non-rigid is used here to solve the optimal mapping, thus returning a more accurate rigid transformation. The default is'SN-S'
.
- dissimilarity
Expression dissimilarity measure:
'kl'
or'euclidean'
.- max_iter
Max number of iterations for morpho alignment.
- SVI_mode
Whether to use stochastic variational inferential (SVI) optimization strategy.
- dtype
The floating-point number type. Only
float32
andfloat64
.- device
Equipment used to run the program. You can also set the specified GPU for running.
E.g.: '0'
.- verbose
If
True
, print progress updates.- **kwargs
Additional parameters that will be passed to
BA_align
function.
- Returns:
List of models (AnnData Object) after alignment. align_models_ref: List of models_ref (AnnData Object) after alignment. pis: List of pi matrices for models. pis_ref: List of pi matrices for models_ref. sigma2s: List of sigma2.
- Return type:
align_models