spateo.alignment.morpho_alignment ================================= .. py:module:: spateo.alignment.morpho_alignment Functions --------- .. autoapisummary:: spateo.alignment.morpho_alignment.morpho_align spateo.alignment.morpho_alignment.morpho_align_transformation spateo.alignment.morpho_alignment.morpho_align_apply_transformation spateo.alignment.morpho_alignment.morpho_align_ref spateo.alignment.morpho_alignment.remove_all_files_in_directory Module Contents --------------- .. py:function:: morpho_align(models: List[anndata.AnnData], rep_layer: Union[str, List[str]] = 'X', rep_field: Union[str, List[str]] = 'layer', genes: Optional[Union[List[str], numpy.ndarray]] = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: Optional[str] = 'iter_spatial', vecfld_key_added: str = 'VecFld_morpho', mode: Literal['SN-N', 'SN-S'] = 'SN-S', dissimilarity: Union[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]] Continuous alignment of spatial transcriptomic coordinates based on Morpho. :param models: List of models (AnnData Object). :param layer: If ``'X'``, uses ``.X`` to calculate dissimilarity between spots, otherwise uses the representation given by ``.layers[layer]``. :param genes: Genes used for calculation. If None, use all common genes for calculation. :param spatial_key: The key in ``.obsm`` that corresponds to the raw spatial coordinate. :param key_added: ``.obsm`` key under which to add the aligned spatial coordinate. :param 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. :param 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. :param 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'``. :param dissimilarity: Expression dissimilarity measure: ``'kl'`` or ``'euclidean'``. :param max_iter: Max number of iterations for morpho alignment. :param dtype: The floating-point number type. Only ``float32`` and ``float64``. :param device: Equipment used to run the program. You can also set the specified GPU for running. ``E.g.: '0'``. :param verbose: If ``True``, print progress updates. :param \*\*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. :rtype: align_models .. py:function:: morpho_align_transformation(models: List[Union[anndata.AnnData, str]], models_path: Optional[str] = None, save_transformation: bool = False, transformation_path: Optional[str] = './Spateo_transformation', resume: bool = False, rep_layer: Union[str, List[str]] = 'X', rep_field: Union[str, List[str]] = 'layer', genes: Optional[Union[List[str], numpy.ndarray]] = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: Optional[str] = 'iter_spatial', vecfld_key_added: str = 'VecFld_morpho', dissimilarity: Union[str, List[str]] = 'kl', max_iter: int = 200, dtype: str = 'float32', device: str = 'cpu', verbose: bool = True, **kwargs) Continuous alignment of spatial transcriptomic coordinates based on Morpho, and return the transformation matrix. :param models: _description_ :type models: List[AnnData] :returns: _description_ :rtype: _type_ .. py:function:: morpho_align_apply_transformation(models: List[Union[anndata.AnnData, str]], models_path: Optional[str] = None, transformation: List[dict] = None, transformation_path: Optional[str] = './Spateo_transformation', spatial_key: str = 'spatial', key_added: str = 'align_spatial', save_models_path: Optional[str] = None, verbose: bool = True) Apply the transformation to the models. :param models: _description_ :type models: List[AnnData] :param transformation: _description_ :type transformation: List[dict] :returns: _description_ :rtype: _type_ .. py:function:: morpho_align_ref(models: List[anndata.AnnData], models_ref: Optional[List[anndata.AnnData]] = None, n_sampling: Optional[int] = 2000, sampling_method: str = 'random', rep_layer: Union[str, List[str]] = 'X', rep_field: Union[str, List[str]] = 'layer', genes: Optional[Union[list, numpy.ndarray]] = None, spatial_key: str = 'spatial', key_added: str = 'align_spatial', iter_key_added: Optional[str] = 'iter_spatial', vecfld_key_added: Optional[str] = 'VecFld_morpho', mode: Literal['SN-N', 'SN-S'] = 'SN-S', dissimilarity: Union[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]] Continuous alignment of spatial transcriptomic coordinates with the reference models based on Morpho. :param models: List of models (AnnData Object). :param models_ref: Another list of models (AnnData Object). :param n_sampling: When ``models_ref`` is None, new data containing n_sampling coordinate points will be automatically generated for alignment. :param sampling_method: The method to sample data points, can be one of ``["trn", "kmeans", "random"]``. :param layer: If ``'X'``, uses ``.X`` to calculate dissimilarity between spots, otherwise uses the representation given by ``.layers[layer]``. :param genes: Genes used for calculation. If None, use all common genes for calculation. :param spatial_key: The key in ``.obsm`` that corresponds to the raw spatial coordinate. :param key_added: ``.obsm`` key under which to add the aligned spatial coordinate. :param 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. :param 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. :param 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'``. :param dissimilarity: Expression dissimilarity measure: ``'kl'`` or ``'euclidean'``. :param max_iter: Max number of iterations for morpho alignment. :param SVI_mode: Whether to use stochastic variational inferential (SVI) optimization strategy. :param dtype: The floating-point number type. Only ``float32`` and ``float64``. :param device: Equipment used to run the program. You can also set the specified GPU for running. ``E.g.: '0'``. :param verbose: If ``True``, print progress updates. :param \*\*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. :rtype: align_models .. py:function:: remove_all_files_in_directory(directory_path)