spateo.alignment.morpho_alignment

Functions

morpho_align(→ Tuple[List[anndata.AnnData], ...)

Continuous alignment of spatial transcriptomic coordinates based on Morpho.

morpho_align_transformation(models[, models_path, ...])

Continuous alignment of spatial transcriptomic coordinates based on Morpho, and return the transformation matrix.

morpho_align_apply_transformation(models[, ...])

Apply the transformation to the models.

morpho_align_ref(→ Tuple[List[anndata.AnnData], ...)

Continuous alignment of spatial transcriptomic coordinates with the reference models based on Morpho.

remove_all_files_in_directory(directory_path)

Module Contents

spateo.alignment.morpho_alignment.morpho_align(models: List[anndata.AnnData], rep_layer: str | List[str] = 'X', rep_field: str | List[str] = 'layer', genes: List[str] | 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 | List[str] = 'kl', max_iter: int = 200, dtype: str = 'float32', device: str = 'cpu', verbose: bool = True, **kwargs) Tuple[List[anndata.AnnData], 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. If iter_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. If vecfld_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.

dtype

The floating-point number type. Only float32 and float64.

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_transformation(models: List[anndata.AnnData | str], models_path: str | None = None, save_transformation: bool = False, transformation_path: str | None = './Spateo_transformation', resume: bool = False, rep_layer: str | List[str] = 'X', rep_field: str | List[str] = 'layer', genes: List[str] | 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', dissimilarity: str | List[str] = 'kl', max_iter: int = 200, dtype: str = 'float32', device: str = 'cpu', verbose: bool = True, **kwargs)[source]

Continuous alignment of spatial transcriptomic coordinates based on Morpho, and return the transformation matrix.

Parameters:
models List[AnnData]

_description_

Returns:

_description_

Return type:

_type_

spateo.alignment.morpho_alignment.morpho_align_apply_transformation(models: List[anndata.AnnData | str], models_path: str | None = None, transformation: List[dict] = None, transformation_path: str | None = './Spateo_transformation', spatial_key: str = 'spatial', key_added: str = 'align_spatial', save_models_path: str | None = None, verbose: bool = True)[source]

Apply the transformation to the models.

Parameters:
models List[AnnData]

_description_

transformation List[dict]

_description_

Returns:

_description_

Return type:

_type_

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 = 'random', rep_layer: str | List[str] = 'X', rep_field: str | List[str] = 'layer', 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 | List[str] = 'kl', max_iter: int = 200, dtype: str = 'float32', device: str = 'cpu', verbose: bool = True, **kwargs) Tuple[List[anndata.AnnData], List[anndata.AnnData], 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. If iter_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. If vecfld_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 and float64.

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

spateo.alignment.morpho_alignment.remove_all_files_in_directory(directory_path)[source]