From 876c2e622da13887f318c43a535536f62d251398 Mon Sep 17 00:00:00 2001 From: tanliwei Date: Fri, 20 Oct 2023 14:18:10 +0800 Subject: [PATCH] update some documents. --- docs/source/Tutorials/Cell_Segmentation.ipynb | 4 +- docs/source/content/032_API_StPipeline.rst | 5 ++ .../algorithm/spatial_alignment/__init__.py | 1 + stereo/algorithm/spatial_alignment/methods.py | 78 +++++++++---------- .../spatial_alignment/spatial_alignment.py | 2 + 5 files changed, 46 insertions(+), 44 deletions(-) diff --git a/docs/source/Tutorials/Cell_Segmentation.ipynb b/docs/source/Tutorials/Cell_Segmentation.ipynb index 8bffb3ce..666974b5 100644 --- a/docs/source/Tutorials/Cell_Segmentation.ipynb +++ b/docs/source/Tutorials/Cell_Segmentation.ipynb @@ -46,7 +46,7 @@ "\n", "All processes of cell segmentation will perform tissue segmentation beforehand. You could specify the method by `tissue_seg_method` and the path to tissue segmentation model file by `tissue_seg_model_path`. We strongly recommend setting `tissue_seg_method=1` which is based on deep learning and is more effective, while 0 is based on OpenCV.\n", "\n", - "Download the [Tissue Segmentation Model](https://pan.genomics.cn/ucdisk/s/ai22e2).\n", + "Download the [Tissue Segmentation Model](http://116.6.21.110:8090/share/dd965cba-7c1f-40b2-a275-0150890e005f).\n", "\n", "More detail about [Tissue Segmentation](https://stereopy.readthedocs.io/en/latest/Tutorials/Tissue_Segmentation.html)." ] @@ -372,7 +372,7 @@ "metadata": {}, "outputs": [], "source": [ - "from stereo.algorithm import Cellpose as cp \n", + "from stereo.algorithm import cell_pose as cp \n", "\n", "image=\"./Cellpose_DemoImage.tif\"\n", "output=\"./Cellpose_DemoImage_mask.tif\"\n", diff --git a/docs/source/content/032_API_StPipeline.rst b/docs/source/content/032_API_StPipeline.rst index 1a355aa4..3ab041e3 100644 --- a/docs/source/content/032_API_StPipeline.rst +++ b/docs/source/content/032_API_StPipeline.rst @@ -39,10 +39,15 @@ which is compromised of basic preprocessing, embedding, clustering, and so on. core.StPipeline.gaussian_smooth core.StPipeline.annotation algorithm.single_r.SingleR.main + algorithm.batch_qc.BatchQc.main + algorithm.spatial_alignment.SpatialAlignment.main + algorithm.spatial_alignment.pairwise_align + algorithm.spatial_alignment.center_align algorithm.get_niche.GetNiche.main algorithm.gen_ccc_micro_envs.GenCccMicroEnvs.main algorithm.cell_cell_communication.CellCellCommunication.main algorithm.regulatory_network_inference.RegulatoryNetworkInference.main algorithm.co_occurrence.CoOccurrence.main algorithm.community_detection.CommunityDetection.main + algorithm.time_series_analysis.TimeSeriesAnalysis.main algorithm.dendrogram.Dendrogram.main \ No newline at end of file diff --git a/stereo/algorithm/spatial_alignment/__init__.py b/stereo/algorithm/spatial_alignment/__init__.py index 6c1b07bc..2d53a9d7 100644 --- a/stereo/algorithm/spatial_alignment/__init__.py +++ b/stereo/algorithm/spatial_alignment/__init__.py @@ -1,2 +1,3 @@ # flake8: noqa from .spatial_alignment import SpatialAlignment +from .methods import pairwise_align, center_align diff --git a/stereo/algorithm/spatial_alignment/methods.py b/stereo/algorithm/spatial_alignment/methods.py index 5a8cbe34..59181606 100644 --- a/stereo/algorithm/spatial_alignment/methods.py +++ b/stereo/algorithm/spatial_alignment/methods.py @@ -44,29 +44,23 @@ def pairwise_align( """ Calculates and returns optimal alignment of two slices. - Args: - sliceA: Slice A to align. - sliceB: Slice B to align. - alpha: Alignment tuning parameter. Note: 0 <= alpha <= 1. - dissimilarity: Expression dissimilarity measure: ``'kl'`` or ``'euclidean'``. - use_rep: If ``None``, uses ``slice.X`` to calculate dissimilarity between spots, otherwise uses the representation given by ``slice.obsm[use_rep]``. - G_init (array-like, optional): Initial mapping to be used in FGW-OT, otherwise default is uniform mapping. - a_distribution (array-like, optional): Distribution of sliceA spots, otherwise default is uniform. - b_distribution (array-like, optional): Distribution of sliceB spots, otherwise default is uniform. - numItermax: Max number of iterations during FGW-OT. - norm: If ``True``, scales spatial distances such that neighboring spots are at distance 1. Otherwise, spatial distances remain unchanged. - backend: Type of backend to run calculations. For list of backends available on system: ``ot.backend.get_backend_list()``. - use_gpu: If ``True``, use gpu. Otherwise, use cpu. Currently we only have gpu support for Pytorch. - return_obj: If ``True``, additionally returns objective function output of FGW-OT. - verbose: If ``True``, FGW-OT is verbose. - gpu_verbose: If ``True``, print whether gpu is being used to user. - - Returns: - - Alignment of spots. - - If ``return_obj = True``, additionally returns: - - - Objective function output of FGW-OT. + :param sliceA: Slice A to align. + :param sliceB: Slice B to align. + :param alpha: Alignment tuning parameter. Note: 0 <= alpha <= 1. + :param dissimilarity: Expression dissimilarity measure: ``'kl'`` or ``'euclidean'``. + :param use_rep: If ``None``, uses ``slice.X`` to calculate dissimilarity between spots, otherwise uses the representation given by ``slice.obsm[use_rep]``. + :param G_init (array-like, optional): Initial mapping to be used in FGW-OT, otherwise default is uniform mapping. + :param a_distribution (array-like, optional): Distribution of sliceA spots, otherwise default is uniform. + :param b_distribution (array-like, optional): Distribution of sliceB spots, otherwise default is uniform. + :param numItermax: Max number of iterations during FGW-OT. + :param norm: If ``True``, scales spatial distances such that neighboring spots are at distance 1. Otherwise, spatial distances remain unchanged. + :param backend: Type of backend to run calculations. For list of backends available on system: ``ot.backend.get_backend_list()``. + :param use_gpu: If ``True``, use gpu. Otherwise, use cpu. Currently we only have gpu support for Pytorch. + :param return_obj: If ``True``, additionally returns objective function output of FGW-OT. + :param verbose: If ``True``, FGW-OT is verbose. + :param gpu_verbose: If ``True``, print whether gpu is being used to user. + + :return: Alignment of spots. If ``return_obj = True``, additionally returns objective function output of FGW-OT. """ # noqa # Determine if gpu or cpu is being used @@ -203,26 +197,26 @@ def center_align( """ Computes center alignment of slices. - Args: - initial_slice: Slice to use as the initialization for center alignment; Make sure to include gene expression and spatial information. - slices: List of slices to use in the center alignment. - lmbda (array-like, optional): List of probability weights assigned to each slice; If ``None``, use uniform weights. - alpha: Alignment tuning parameter. Note: 0 <= alpha <= 1. - n_components: Number of components in NMF decomposition. - threshold: Threshold for convergence of W and H during NMF decomposition. - max_iter: Maximum number of iterations for our center alignment algorithm. - dissimilarity: Expression dissimilarity measure: ``'kl'`` or ``'euclidean'``. - norm: If ``True``, scales spatial distances such that neighboring spots are at distance 1. Otherwise, spatial distances remain unchanged. - random_seed: Set random seed for reproducibility. - pis_init: Initial list of mappings between 'A' and 'slices' to solver. Otherwise, default will automatically calculate mappings. - distributions (List[array-like], optional): Distributions of spots for each slice. Otherwise, default is uniform. - backend: Type of backend to run calculations. For list of backends available on system: ``ot.backend.get_backend_list()``. - use_gpu: If ``True``, use gpu. Otherwise, use cpu. Currently we only have gpu support for Pytorch. - verbose: If ``True``, FGW-OT is verbose. - gpu_verbose: If ``True``, print whether gpu is being used to user. - - Returns: + :param initial_slice: Slice to use as the initialization for center alignment; Make sure to include gene expression and spatial information. + :param slices: List of slices to use in the center alignment. + :param lmbda (array-like, optional): List of probability weights assigned to each slice; If ``None``, use uniform weights. + :param alpha: Alignment tuning parameter. Note: 0 <= alpha <= 1. + :param n_components: Number of components in NMF decomposition. + :param threshold: Threshold for convergence of W and H during NMF decomposition. + :param max_iter: Maximum number of iterations for our center alignment algorithm. + :param dissimilarity: Expression dissimilarity measure: ``'kl'`` or ``'euclidean'``. + :param norm: If ``True``, scales spatial distances such that neighboring spots are at distance 1. Otherwise, spatial distances remain unchanged. + :param random_seed: Set random seed for reproducibility. + :param pis_init: Initial list of mappings between 'A' and 'slices' to solver. Otherwise, default will automatically calculate mappings. + :param distributions (List[array-like], optional): Distributions of spots for each slice. Otherwise, default is uniform. + :param backend: Type of backend to run calculations. For list of backends available on system: ``ot.backend.get_backend_list()``. + :param use_gpu: If ``True``, use gpu. Otherwise, use cpu. Currently we only have gpu support for Pytorch. + :param verbose: If ``True``, FGW-OT is verbose. + :param gpu_verbose: If ``True``, print whether gpu is being used to user. + + :return: - Inferred center slice with full and low dimensional representations (W, H) of the gene expression matrix. + - List of pairwise alignment mappings of the center slice (rows) to each input slice (columns). """ # noqa diff --git a/stereo/algorithm/spatial_alignment/spatial_alignment.py b/stereo/algorithm/spatial_alignment/spatial_alignment.py index 073a51cc..9d9958d3 100644 --- a/stereo/algorithm/spatial_alignment/spatial_alignment.py +++ b/stereo/algorithm/spatial_alignment/spatial_alignment.py @@ -27,6 +27,8 @@ def main( :param method: pairwise or center, defaults to 'pairwise' :param initial_slice: slice to use as the initialization for center alignment, defaults to None :param slices: list of slices to align, defaults to None + + Other parameters refer to `algorithm.paste.pairwise_align` and `algorithm.paste.center_align` """ if method not in ('pairwise', 'center'): raise ValueError(f'Error method({method}), it must be one of pairwise and center')