:py:mod:`spatialtis_core` ========================= .. py:module:: spatialtis_core Subpackages ----------- .. toctree:: :titlesonly: :maxdepth: 3 spatial_de/index.rst Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 cell_interaction/index.rst geo_analysis/index.rst io/index.rst neighbors/index.rst shape_ops/index.rst spatial_analysis/index.rst types/index.rst utils/index.rst Package Contents ---------------- .. py:class:: CellCombs(types: List[str], order: bool = False) Profile cell-cell interaction using permutation test :param types: All the type of cells in your research :param order: bool (False); If False, A->B and A<-B is the same .. py:method:: bootstrap(types: List[str], neighbors: spatialtis_core.types.Neighbors, labels: spatialtis_core.types.Labels, times: int = 1000, pval: float = 0.05, method: str = 'pval') -> List[Tuple[str, str, float]] Bootstrap functions 1.0 means association, -1.0 means avoidance, 0.0 means insignificance. :param types: The type of all the cells :param neighbors: List of neighbors :param labels: List of labels :param times: How many times to perform bootstrap :param pval: The threshold of p-value :param method: 'pval' or 'zscore' :returns: List of tuples, eg.('a', 'b', 1.0), the type a and type b has a relationship as association .. py:function:: bbox_neighbors(bbox: List[spatialtis_core.types.BoundingBox], labels: spatialtis_core.types.Labels, expand: float = -1.0, scale: float = 1.3) -> List[List[int]] Get neighbors for each bounding box :param bbox: A list of bounding box :param labels: Integer to label your bounding box :param expand: Expand the bounding box to search for neighbors :param scale: Scale the bounding box to search for neighbors :returns: A list of neighbors .. py:function:: comb_bootstrap(exp_matrix: numpy.ndarray, markers: List[str], neighbors: spatialtis_core.types.Neighbors, labels: spatialtis_core.types.Labels, pval: float = 0.05, times: int = 1000) -> List[Tuple[str, str, float]] Bootstrap between two types If you want to test co-localization between protein X and Y, first determine if the cell is X-positive and/or Y-positive. True is considered as positive and will be counted. :param exp_matrix: The expression matrix, each row should be a marker :param markers: Match to the row of exp_matrix :param neighbors: List of neighbors :param labels: List of labels :param pval: The threshold of p-value :param times: How many times to perform bootstrap :returns: The significance between markers List of (marker1, marker2, p-value) .. py:function:: dumps_points_wkt(points: spatialtis_core.types.Points) -> List[str] Dumps points into wkt format :param points: A list of 2D points :returns: A list of wkt string .. py:function:: dumps_polygons_wkt(polygons: List[spatialtis_core.types.Points]) -> List[str] Dumps points into wkt format :param polygons: A list of polygons :returns: A list of wkt string .. py:function:: fast_corr(data1: numpy.ndarray, data2: numpy.ndarray, method: Optional[str] = 'pearson') -> numpy.ndarray Parallel pairwise correlation Compute pairwise (combination with replacement) correlation between two 2D array with same shape. Faster than scipy's implementation. :param data1: 2D Array :param data2: 2D Array :param method: "pearson" or "spearman" .. py:function:: getis_ord(points: spatialtis_core.types.Points, bbox: spatialtis_core.types.BoundingBox, search_level: int = 3, quad: Optional[Tuple[int, int]] = None, rect_side: Optional[Tuple[float, float]] = None, pval: float = 0.05, min_cells: int = 10) -> List[bool] Getis-ord analysis to find hot cells :param points: A list of points :param bbox: The bounding box :param search_level: The level of outer-ring to search for :param quad: eg.(X, Y) Use X * Y grid to perform analysis :param rect_side: eg.(X, Y) Use X * Y rectangle to perform analysis :param pval: The threshold for p-value :param min_cells: The minimum number of cells to perform analysis :returns: A list of bool .. py:function:: multipoints_bbox(points_collections: Sequence[spatialtis_core.types.Points]) -> Sequence[spatialtis_core.types.BoundingBox] A utility function to return minimum bounding box list of polygons :param points_collections: List of 2d points collections :returns: A list of bounding box (minx, miny, maxx, maxy) .. py:function:: multipolygons_area(points_collections: Sequence[spatialtis_core.types.Points]) -> Sequence[float] Calculate the area of polygons using shoelace formula :param points_collections: List of 2d points collections, represents a list of polygons :returns: The area of the polygons in list .. py:function:: neighbor_components(neighbors: spatialtis_core.types.Neighbors, labels: spatialtis_core.types.Labels, types: List[str]) -> (List[str], List[List[int]]) Compute the number of different cells at neighbors :param neighbors: The neighbors dict :param labels: Integer to label points :param types: A list of types match to points :returns: can be used to construct dataframe :rtype: (header, data) .. py:function:: points_bbox(points: spatialtis_core.types.Points) -> spatialtis_core.types.BoundingBox Return minimum bounding box of points :param points: A list of points :returns: The bounding box (minx, miny, maxx, maxy) or (minx, miny, minz, maxx, maxy, maxz) .. py:function:: points_neighbors(points: spatialtis_core.types.Points, labels: spatialtis_core.types.Labels, r: Optional[float] = None, k: Optional[int] = None, method: str = 'kdtree') -> List[List[int]] Get neighbors for each points When search with KD-tree, you can use either `r` or `k`. If r = 5, it will search for all points within 5; If k = 5, it will search for the 5 nearest neighbors; If combined, r = 5 and k = 5, it will search for at most 5 neighbors within 5; When search with Delaunay triangulation, there is no parameter. The return list follow the order of labels. For example, if serach for points of [100, 101, 102], the result may look like [[100, 102], [101, 102], [102, 100, 101]] :param points: A list of points :param labels: Integer to labels your points :param r: Radius range to search for neighbors :param k: Number of nearest neighbors :param method: "kdtree" or "delaunay" :returns: A list of neighbors .. py:function:: points_shapes(polygons: List[spatialtis_core.types.Points], method: str = 'convex', concavity: float = 1.5) -> spatialtis_core.types.Points Acquire multipoints (shapes) that describe the points :param polygons: A list of polygons :param method: "convex" or "concave" :param concavity: Determine the concavity in concave hull :returns: A list of points .. py:function:: polygons_area(points: spatialtis_core.types.Points) -> float Calculate the area of polygons using shoelace formula :param points: A list of points represents a polygon :returns: The area of the polygon .. py:function:: reads_wkt_points(wkt_strings: List[str]) -> spatialtis_core.types.Points Reads wkt points into python object :param wkt_strings: A list of wkt string represents points :returns: A list of 2D points .. py:function:: reads_wkt_polygons(wkt_strings: List[str]) -> List[spatialtis_core.types.Points] Reads wkt points into python object :param wkt_strings: A list of wkt string represents polygons :returns: A list of 2D polygons .. py:function:: spatial_autocorr(x: numpy.ndarray, neighbors: spatialtis_core.types.Neighbors, labels: spatialtis_core.types.Labels, two_tailed: bool = True, pval: float = 0.05, method: str = 'moran_i') -> List[Tuple[float, float]] Compute spatial auto-correlation value for a 2D array in parallel The p-value is under the assumption of normal distribution Return is tuples of (spatial_autocorr value, p value) :param x: Gene expression matrix, each row is the expression of a gene :param neighbors: A list of neighbors :param labels: A list of labels :param two_tailed: Determine the p value :param pval: The p-value threshold :param method: "moran_i" or "geary_c" :returns: A list of (value, p_value) .. py:function:: spatial_distribution_pattern(points_collections: List[spatialtis_core.types.Points], bbox: spatialtis_core.types.BoundingBox, method: str = 'id', r: Optional[float] = None, resample: int = 1000, quad: Optional[Tuple[int, int]] = None, rect_side: Optional[Tuple[float, float]] = None, pval: float = 0.05, min_cells: int = 10, dims: int = 2) -> List[Tuple[float, float, int]] Compute the distribution index and determine the pattern for different cells in a ROI in parallel If data is 3D, only method="id" is supported :param points_collections: A list of list of points :param bbox: The bounding box :param method: "id" for index of dispersion, "morisita" for morisita index, "clark_evans" for clark evans' index :param r: If method == "id"; The sample windows' radius :param resample: If method == "id"; The number of sampling times :param quad: If method == "morisita"; eg.(X, Y) Use X * Y grid to perform analysis :param rect_side: If method == "morisita"; eg.(X, Y) Use X * Y rectangle to perform analysis :param pval: The threshold for p-value :param min_cells: The minimum number of cells to perform analysis :param dims: The dimension of data :returns: A list of (index_value, p_value, pattern) .. py:function:: spatial_entropy(points_collections: List[spatialtis_core.types.Points], types_collections: List[List[str]], method: str = 'leibovici', d: Optional[float] = None, cut: int = 3, dims: int = 2) -> List[float] Compute spatial entropy value of multiple ROIs in parallel :param points_collections: A list of list of points :param types_collections: A list of list of types :param bbox: The bounding box :param method: "leibovici" or "altieri" :param d: If method == "leibovici"; The distance threshold to determine co-occurrence :param cut: If method == "altieri"; The distance interval to determine co-occurrence :param dims: The dimension of data :returns: A list of spatial entropy .. py:function:: spatial_weight(neighbors: types.Neighbors, labels: types.Labels) -> scipy.sparse.csr_matrix Build a neighbors sparse matrix from neighbors data :param neighbors: List of neighbors :param labels: List of neighbors :returns: A scipy sparse matrix in csr format .. py:data:: Labels .. py:data:: Neighbors