Spatial group data clustering method and device, electronic equipment and storage medium
By calculating the transfer probability between single cells and spatial group cells and combining spatial position information, the problem of unsatisfactory spatial data clustering results in the prior art is solved, and the accurate clustering of spatial data is achieved.
Patent Information
- Application Number
- CN202311423548.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-30
- Publication Date
- 2025-05-02
AI Technical Summary
The prior art fails to effectively consider the spatial position characteristics of cells in spatial data clustering, resulting in unsatisfactory clustering results and the inability to achieve accurate spatial data clustering.
By calculating the transfer probability between single cells and spatial group cells, combining single cell data and spatial group position information, the initial clustering type of spatial group cells is determined, and iterated through a preset clustering algorithm to calculate the loss function to adjust the clustering results.
Accurate clustering of spatial data is achieved, and the accuracy and effectiveness of clustering results are improved by combining cell type and spatial location information.
Smart Images

Figure CN119920327A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of spatial group data clustering, and in particular to a method and device, electronic device and storage medium for spatial group data clustering. Background Art
[0002] Due to the low capture rate and resolution of spatial groups, spatial group clustering has become a major difficulty in the field of spatiotemporal technology research. At present, the Seurat algorithm is usually used in existing technologies to achieve spatial data clustering. By using canonical correlation analysis to reduce the dimensionality of single-cell and spatial group data sets to the same low-dimensional space, the transcript feature correlation of the data is retained.
[0003] Although the above-mentioned Seurat algorithm can realize spatial data clustering, the Seurat algorithm only retains and uses the transcript feature correlation of the data, and does not take into account the spatial location characteristics of the cells, resulting in the final result being unsatisfactory in many cases and being unable to achieve accurate clustering of spatial data. Summary of the invention
[0004] The present disclosure provides a method, device, electronic device and storage medium for clustering spatial group data, the main purpose of which is to achieve accurate clustering of spatial data.
[0005] According to a first aspect of the present disclosure, a method for clustering spatial group data is provided, comprising:
[0006] Calculate the transmission transfer probability between single cells and spatial group cells; where single cells have cell group labels,
[0007] The cell group label is used to identify the cell type of a single cell;
[0008] Determining the initial clustering type of the space group cells according to the transmission transfer probability and the group of single cells corresponding to the space group cells;
[0009] The initial clustering type of the space group cells is iterated according to a preset clustering algorithm, a first iterative loss function is calculated, and after the first iterative loss function meets a preset condition, the iteration is stopped and a target clustering result is output.
[0010] Optionally, before calculating the transmission transfer probability of each spatial group data and each single cell group, the
[0011] The method also includes:
[0012] The single cell data and the spatial group are preprocessed respectively, and the preprocessing includes at least one of data filtering, data normalization and principal component dimensionality reduction.
[0013] Optionally, determining the initial clustering type of the space group cells according to the transmission transition probability and the group of single cells corresponding to the space group cells includes:
[0014] Calculating the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each of the space group data and the gene expression rate of each of the single cell groups;
[0015] Calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs;
[0016] Calculate the average transmission transfer probability of each single-cell category within the same single-cell group;
[0017] Determine the group of each of the spatial group data within the single cell group as the single cell group corresponding to the highest average transmission transfer probability.
[0018] Optionally, determining the initial clustering type of the space group cells according to the transmission transition probability and the group of single cells corresponding to the space group cells includes:
[0019] Calculating the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each of the space group data and the gene expression rate of each of the single cell groups;
[0020] Calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs;
[0021] Determine the group of each of the spatial group data within the single cell group as the single cell group corresponding to the highest transmission transfer probability.
[0022] Optionally, before iterating the initial clustering type according to a preset clustering algorithm, the method further includes:
[0023] The initial loss function between the data of each space group in each group is calculated respectively, wherein the initial loss function is the sum of the gene expression distance and the physical space position distance.
[0024] Optionally, iterating the initial clustering result according to a preset clustering algorithm, calculating a first iterative loss function, stopping iteration after the first iterative loss function satisfies a preset condition, and outputting a target clustering result includes:
[0025] Using the initial clustering type as initial information, recalculating the clustering information of each space group data according to the K-means clustering algorithm, and obtaining each first iterative clustering result;
[0026] Calculating the first iterative loss function of each spatial group in each of the first iterative clustering results respectively, and comparing the first iterative loss function with the initial loss function, wherein the first iterative loss function is the sum of the gene expression clustering, the physical space position distance and the Weissenstein distance;
[0027] Determine whether the first iterative loss function is greater than the initial loss function;
[0028] If the first iterative loss function is less than the initial loss function, the first iterative clustering result is used as initial information, the iterative calculation is continued to obtain the second iterative clustering result, and the second iterative loss function is recalculated;
[0029] The second iterative loss function is compared with the first iterative loss function until the second iterative loss function is greater than the first iterative loss function, the iterative calculation is stopped, the second iterative clustering result obtained in the current iterative round is determined to be the target clustering result, and the target clustering result is output.
[0030] According to a second aspect of the present disclosure, there is provided a device for clustering spatial group data, comprising:
[0031] A first calculation unit is used to calculate the transmission transfer probability between a single cell and cells in a space group; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell;
[0032] A determination unit, configured to determine an initial clustering type of the space group cells according to the transmission transfer probability and the group of single cells corresponding to the space group cells;
[0033] The output unit is used to iterate the initial clustering type of the space group cells according to a preset clustering algorithm, calculate a first iterative loss function, stop iterating after the first iterative loss function meets a preset condition, and output a target clustering result.
[0034] Optionally, the device further comprises:
[0035] The preprocessing unit is used to preprocess the single-cell data and the spatial group data respectively before the first calculation unit calculates the transmission transfer probability of each spatial group data and each single-cell group respectively, and the preprocessing includes at least one of data filtering, data normalization and principal component dimensionality reduction.
[0036] Optionally, the determining unit includes:
[0037] A first calculation module is used to calculate the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each single cell data and the gene expression rate of each of the space group groups;
[0038] A second calculation module is used to calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs;
[0039] The third calculation module is used to calculate the average transmission transfer probability of each single cell category in the same single cell group;
[0040] The determination module is used to respectively determine that the group of each of the spatial group data in the single cell group is the single cell group corresponding to the highest average transmission transfer probability.
[0041] Optionally, the determining unit includes:
[0042] The first calculation module is further used to calculate the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each space group data and the gene expression rate of each of the single cell groups;
[0043] The second calculation module is further used to calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs;
[0044] The determination module is also used to determine that the group of each of the spatial group data within the single cell group is the single cell group corresponding to the highest transmission transfer probability.
[0045] Optionally, the device further comprises:
[0046] The second calculation unit is used to calculate the initial loss function between each spatial group data in each group before the output unit iterates the initial clustering result according to the preset clustering algorithm, wherein the initial loss function is the sum of the gene expression distance and the physical space position distance.
[0047] Optionally, the output unit includes:
[0048] A fourth calculation module, configured to use the initial clustering type as initial information, and recalculate the clustering information of each space group data according to a K-means clustering algorithm to obtain each first iterative clustering result;
[0049] A comparison module, used to respectively calculate the first iterative loss function of each spatial group in each of the first iterative clustering results, and compare the first iterative loss function with the initial loss function, wherein the first iterative loss function is the sum of the gene expression clustering, the physical space position distance and the Weissenstein distance;
[0050] A judging module, used to judge whether the first iterative loss function is greater than the initial loss function;
[0051] a fifth calculation module, configured to, when the first iterative loss function is less than the initial loss function, use the first iterative clustering result as initial information, continue iterative calculation, obtain a second iterative clustering result, and recalculate the second iterative loss function;
[0052] An output module is used to compare the second iterative loss function with the first iterative loss function until the second iterative loss function is greater than the first iterative loss function, stop the iterative calculation, determine that the second iterative clustering result obtained in the current iterative round is the target clustering result, and output the target clustering result.
[0053] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0054] at least one processor; and
[0055] a memory communicatively connected to the at least one processor; wherein,
[0056] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect.
[0057] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described in the first aspect.
[0058] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method as described in the first aspect above.
[0059] The method, device, electronic device and storage medium for clustering spatial group data provided by the present disclosure mainly include: calculating the transmission transfer probability between a single cell and a spatial group cell; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell; determining the initial clustering type of the spatial group cell according to the transmission transfer probability and the group of single cells corresponding to the spatial group cell; iterating the initial clustering type of the spatial group cell according to a preset clustering algorithm, calculating the first iterative loss function, and stopping the iteration after the first iterative loss function meets the preset conditions, and outputting the target clustering result. Compared with the related art, the embodiment of the present application clusters the spatial group data by combining the single cell data with the spatial group position information, and adjusts the spatial group data clustering result by comparing the loss function, thereby achieving accurate clustering of the spatial data.
[0060] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0062] Figure 1 A schematic flow chart of a method for clustering spatial group data provided by an embodiment of the present disclosure;
[0063] Figure 2 A schematic flow chart of another method for clustering spatial group data provided by an embodiment of the present disclosure;
[0064] Figure 3 A schematic flow chart of another method for clustering spatial group data provided by an embodiment of the present disclosure;
[0065] Figure 4 A schematic flow chart of a method for clustering spatial group data provided by an embodiment of the present disclosure;
[0066] Figure 5 A schematic flow chart of another method for clustering spatial group data provided by an embodiment of the present disclosure;
[0067] Figure 6 A schematic block diagram of an exemplary electronic device provided for an embodiment of the present disclosure. DETAILED DESCRIPTION
[0068] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0069] The following describes the method, device, electronic device and storage medium for clustering spatial group data according to the embodiments of the present disclosure with reference to the accompanying drawings.
[0070] Figure 1 A schematic flow chart of a method for clustering spatial group data provided in an embodiment of the present disclosure.
[0071] like Figure 1 As shown, the method comprises the following steps:
[0072] Step 101, calculating the transmission transfer probability between a single cell and cells in a space group; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell.
[0073] In one implementable method of the embodiment of the present application, the single-cell data and the spatial group groups are in matrix form, wherein the horizontal coordinate of the single-cell data matrix is cells, and the vertical coordinate is genes, indicating the expression of each gene in different cells; the horizontal coordinate of the spatial group group matrix is cells, and the vertical coordinate is genes, indicating the expression of each gene in cells of different spatial groups.
[0074] Step 102: determining the initial clustering type of the space group cells according to the transmission transition probability and the group of single cells corresponding to the space group cells.
[0075] The transmission transfer probability is used to characterize the similarity between single-cell gene expression and spatial group gene expression. The higher the similarity of gene expression, the higher the transmission transfer probability, that is, the higher the probability that the spatial group data belongs to the single-cell group. In one implementable method of an embodiment of the present application, the group with the highest transmission transfer probability of each spatial group data is determined to be the group of the spatial group data.
[0076] Each spatial group data corresponds to a cell type. Within the same single cell group, the transmission transfer probabilities corresponding to the spatial group data of the same cell type are added and averaged to obtain the average transmission transfer probability. Specifically, the embodiment of the present application does not limit the calculation method of the average transfer rate.
[0077] After calculating the average transfer probability of each group, the initial cluster type of each group is determined based on the cell type with the highest average transfer probability.
[0078] Step 103, iterating the initial clustering type of the space group cells according to a preset clustering algorithm, calculating a first iterative loss function, stopping the iteration after the first iterative loss function meets a preset condition, and outputting a target clustering result.
[0079] In one implementable manner of an embodiment of the present application, the preset clustering algorithm may be k-means, hierarchical clustering or other algorithms; specifically, the embodiment of the present application is not limited to this; in each iteration, the cluster center is updated, each single-cell data is assigned to the nearest cluster center, and the loss function is calculated. When the loss function does not meet the preset conditions, the next iteration is continued. If it meets the preset conditions, the iteration is stopped and the target clustering result is output; the target clustering result is the cluster center and the allocation result updated for the last time during the iteration process; the preset conditions may be the convergence of the loss function, reaching a certain threshold or other suitable stopping conditions, specifically, the embodiment of the present application is not limited to this.
[0080] The method for clustering spatial group data provided by the present disclosure mainly includes the following technical solutions: calculating the transmission transfer probability between a single cell and a spatial group cell; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell; determining the initial clustering type of the spatial group cell according to the transmission transfer probability and the group of the single cell corresponding to the spatial group cell; iterating the initial clustering type of the spatial group cell according to a preset clustering algorithm, calculating the first iterative loss function, and stopping the iteration after the first iterative loss function meets the preset conditions, and outputting the target clustering result. Compared with the related art, the embodiment of the present application clusters the spatial group data by combining the single cell data with the spatial group position information, and adjusts the spatial group data clustering result by comparing the loss function, thereby achieving accurate clustering of the spatial data.
[0081] In an implementable manner of the embodiment of the present application, before executing step 101, the single cell data and the space group group must first be preprocessed separately, and the preprocessing includes at least one of data filtering, data normalization and principal component dimensionality reduction; the single cell data and the space group data are RNA transcriptome data collected from two adjacent sections of an organization. Because they are adjacent sections, we assume that the single cell and the space group can correspond in terms of cell type. Among them, the single cell has completed self-clustering (this step requires the user to complete it in advance), and there are clustering results and cell type labels. After data filtering and normalization, the genes of the single cell data and the space group data are intersected, so that an m*p single cell data set and an n*p space group data set are obtained. Where m represents m single cells, n represents n space group units, in practical applications, the user can determine the size and shape of the space group unit according to actual needs, for example, it can be set to the size corresponding to one cell or the size corresponding to multiple cells, set to a circular unit or a rectangular unit, specifically, the embodiment of the present application does not limit this; in addition, the space group data also has a data set of n*2, representing a two-dimensional physical space position. This data set will be used below. PCA dimension reduction is performed on the single cell and space group data respectively, and the first k dimensions are taken for subsequent calculations. The user can customize the k value, such as setting it to 20 or 30, etc. Specifically, the embodiment of the present application does not limit this. Filter useless data in the data, normalize the gene data of each cell, make the gene data conform to the normal distribution, and perform principal component dimension reduction, reduce the data dimension, shorten the time required for calculation, and reduce the demand for computer computing power. The detailed implementation process of data filtering, normalization and principal component dimension reduction can refer to any implementation method in the prior art, and the embodiment of the present application will not be repeated here.
[0082] When confirming the cluster type of each spatial group, it is necessary to determine it based on the transmission transfer probability of each cell type, see Figure 2 , Figure 2 A schematic flow chart of a method for clustering spatial group data provided by an embodiment of the present disclosure includes:
[0083] Step 201, calculating the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each of the single cell data and the gene expression rate of each of the space group groups.
[0084] In one implementable method of an embodiment of the present application, the spatial group data matrix is input into the single-cell group matrix, and the transmission transfer cost between each cell and each group is calculated to obtain a transmission transfer cost matrix. The more similar the gene expression rate of the single-cell data is to the gene expression rate of each group in the spatial group, the smaller the transmission transfer cost. For a detailed method of calculating the transmission transfer cost, please refer to any implementation method in the prior art, and the embodiments of the present application will not be described one by one here.
[0085] The Euclidean distance corresponding to each space group is calculated based on the single cell data (m*30) and the space group data (n*30), and the Euclidean distance matrix (m*n) is obtained, which is the transfer cost matrix. Each data represents the similarity between the cells in this space group and this single cell in terms of gene expression level.
[0086] Step 202, calculating the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs.
[0087] In one possible implementation of the embodiment of the present application, the transmission transition probability calculation formula is:
[0088]
[0089] stγ1=a
[0090] γ T 1 = b
[0091] γ≥0
[0092] Where M is the cost matrix calculated above. Ω is the entropy regularization term, Ω(γ) = ∑ i ,γ i,j log(γ i,j ). a and b are the weights of the source cell and the target cell
[0093] Unless otherwise specified, we assume that the weights of the source cells and the target cells are equal, that is, a is an n*1 vector, and the value of each element is 1 / n; b is a 1*n vector, and the value of each element is 1 / n. The sum of all elements in vector a and vector b is 1.
[0094] γ={γ i,j}m×n γ i,j represents the transition probability between cell i and cell j
[0095] reg represents the coefficient of the entropy regularization term. Generally, reg>0, and we set it to 1e-1.
[0096] The transmission transfer cost is taken as input, and the transmission transfer probability of each spatial group data and each group is calculated based on a preset formula to obtain a transmission transfer probability matrix, wherein the transmission transfer probability is inversely proportional to the transmission transfer cost, that is, the higher the transmission transfer cost, the lower the transmission transfer probability.
[0097] In one possible implementation of the embodiment of the present application, the mathematical optimization model can be exemplarily expressed as:
[0098]
[0099] stγ1=a,
[0100] 1 T γ T =b,
[0101] γ ≥ 0,
[0102] in, represents the objective function of the mathematical optimization model, st represents subject to, and st is followed by the three constraints of the mathematical optimization model.
[0103] Specifically, in the objective function: γ={γ i,j} n×n represents the optimal transition probability matrix to be solved, γ i,j represents the transition probability between cell i and cell j, and γ i,j =γ j,i , γ i,j The value range of is (0,1), and n represents the total number of multiple cells in the single chip; represents the function that minimizes the Frobenius norm (inner product) between the optimal transition probability matrix γ and the transition cost matrix M; entropy regularization term Ω(γ) = ∑ i,j γ i,j log(γ i,j );reg represents the coefficient of the entropy regularization term, reg>0, for example, it can be set to e-1.
[0104] In the constraint condition: γ1 = a, a represents an n×1 dimensional vector in which the value of each element is 1 / n, where 1 represents an n×1 dimensional vector in which all elements are 1; 1 T γ T= b, b represents a 1×n dimensional vector and the value of each element is 1 / n, where 1 T Represents a 1×n dimensional vector whose elements are all 1s.
[0105] In one embodiment, reg represents the coefficient of the entropy regularization term, which can be used to balance and minimizing the entropy regularization term Ω(γ). When reg is larger, the model's penalty for the entropy regularization term Ω(γ) is stronger, so the optimization result is more inclined to minimize entropy. On the contrary, when reg is smaller, the model's penalty for the entropy regularization term is smaller, so the optimization result is more inclined to minimize entropy. It is usually necessary to determine a suitable reg value through methods such as cross-validation to obtain better generalization performance.
[0106] In one embodiment, in the above constraints, a can be understood as the weight vector of the source cell (or source point) in the optimal transmission theory, and b can be understood as the weight vector of the target cell (or target point). Assuming that the weight values of the source cell and the target cell are equal, since a single chip contains n cells, the value of each element in vector a and vector b can be set to 1 / n respectively, and the sum of all elements in vector a and vector b is 1 respectively.
[0107] In one embodiment, the objective function includes multiple parameters, namely, the elements γ in the optimal transition probability matrix γ. i,j , by solving the value of the parameter that minimizes the objective function, the optimal transition probability matrix can be obtained.
[0108] Step 203, calculating the average transmission transfer probability of each single cell category in the same single cell group.
[0109] For a spatial group data, sort it and the transmission transfer probability of each group in order from large to small, and repeat the above operation until the transmission transfer probability of all spatial group data is sorted; it should be noted that when sorting the transmission transfer probability, it can be sorted from large to small, or it can be sorted from small to large, or it can be sorted in a histogram, etc. Specifically, the embodiment of the present application does not limit the sorting method.
[0110] Following the description of the above application embodiment, it is assumed that the cells are divided into q categories.
[0111] Since the transfer probability of a single cell to a cell point in a spatial group has been calculated, we have obtained an m*n transfer probability matrix, where n spatial groups are divided into q categories. We add the transfer matrices of the same category and calculate the average to obtain a q*n matrix.
[0112] For each cell, we get q transition probabilities. We take the maximum transition probability and assign the cell type corresponding to the maximum transition probability to this cell as the initial spatial clustering type of this cell. In this way, we get the spatial group data of n cells, where each cell corresponds to one of the q cell types.
[0113] Step 204, determining the group of each of the spatial group data within the single cell group as the single cell group corresponding to the highest average transmission transfer probability.
[0114] The group of spatial group data in single cells is determined to be the single cell group corresponding to the highest average transmission transfer probability.
[0115] In one possible implementation of the embodiment of the present application, when determining the initial clustering type of the space group cells in step 102, the following method can also be used for determination:
[0116] Calculating the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each of the space group data and the gene expression rate of each of the single cell groups;
[0117] Calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs;
[0118] Determine the group of each of the spatial group data within the single cell group as the single cell group corresponding to the highest transmission transfer probability.
[0119] Following the description of the above-mentioned application embodiment, after calculating the transmission transfer probability of the spatial group data and each of the single cell groups, the transmission transfer probability corresponding to each single cell can be arranged in order from large to small, and the single cell group corresponding to the maximum transmission transfer probability is determined to determine the group of the spatial group data within the single cell group. In an implementable manner of the embodiment of the present application, other transmission transfer probabilities in the arrangement sequence can also be taken, such as taking the median value in the arrangement sequence, etc. Specifically, the embodiment of the present application does not limit this.
[0120] In one possible implementation of the present application, after determining the cell type corresponding to each group in step 102, the initial loss function between the data of each spatial group in each group is calculated respectively, wherein the initial loss function is the sum of the gene expression distance and the physical space position distance. The calculation of the gene expression distance and the physical space position distance can be calculated using the Euclidean distance, which is not limited in the present application.
[0121] The purpose of calculating the loss function is that the grouping of cell data at this time is determined based on the gene expression distance between each cell. Therefore, the distance between spatial group data in the same group may be far in physical space. Therefore, the loss function uses the sum of physical space distance and gene expression distance, which can take into account both the physical space distance and gene expression distance between spatial group data in the same group.
[0122] The initial clustering results are only based on the gene expression distance. The initial clustering results need to be tested by the physical space distance between the spatial groups through an iterative algorithm; please refer to Figure 3 , Figure 3 A schematic flow chart of a method for clustering spatial group data provided by an embodiment of the present disclosure includes:
[0123] Step 301 : using the initial clustering type as initial information, and recalculating the clustering information of each space group data according to the K-means clustering algorithm, to obtain each first iterative clustering result.
[0124] According to the physical space clustering between the spatial group data in each group in the initial clustering type, the center position of each group is calculated; after obtaining the center position of each group, the physical space distance from each spatial group data to each of the center point positions is calculated respectively, and the group of the spatial group data is determined to be the group corresponding to the center point with the closest physical space distance; after the calculation is completed, the cell type of each group is re-determined to obtain the first iterative clustering result; for the method of determining the clustering category, please refer to step 102, and the embodiments of the present application will not be described one by one here.
[0125] Step 302, respectively calculate the first iterative loss function of each single cell group in each of the first iterative clustering results, and compare the first iterative loss function with the initial loss function, wherein the first iterative loss function is the sum of the gene expression clustering, the physical space position distance and the Weissenstein distance.
[0126] The Wiesenstein distance is used to make the iterative clustering type as close as possible to the initial clustering type while taking into account the physical space distance between single-cell data; wherein, the Wiesenstein clustering is calculated based on the iteratively calculated gene expression clustering and the physical space position distance and the initial loss function. For the detailed calculation process, please refer to any implementation method in the prior art, and the embodiments of the present application will not be described one by one here.
[0127] For n cells, q cell types. We extract the spatial group data of each cell type and calculate the sum of the gene expression distance and the spatial position distance. For example: suppose that a certain cell type among the q cell types contains 3 spatial group cells (a, b, c). We take out these three cells and calculate the gene expression distance (Euclidean distance) and physical space distance (Euclidean distance) between each cell, so we get 3 types of gene expression distances and physical space distances (ab, ac, bc) respectively. Add these distances and sum them. (Among them, the gene expression distance and physical space distance can be scaled by alpha1 and alpha2 to achieve the desired effect of user clustering. Alpha1 and alpha2 take values between 0-1. The larger the value, the greater the proportion of the corresponding distance considered in subsequent clustering.) We use the above method to calculate the distance for all cell types, and finally get the value of the sum of q distances. Add these q distances to get the initial loss function value.
[0128] The label assigned to each cell by the initial clustering result is used as the initialization information of kmeans for iterative clustering. Based on this, kmeans can calculate the center point of each group of cells and perform subsequent calculations.
[0129] Similarly, gene expression distance, physical space location distance and Weissenstein distance can be scaled using alpha1, alpha2 and alpha3. Alpha1, alpha2 and alpha3 values are between 0 and 1. The larger the value, the greater the proportion of the corresponding distance considered in subsequent clustering.
[0130] Step 303: Determine whether the first iterative loss function is greater than the initial loss function.
[0131] If the first iteration loss function is smaller than the initial loss function, it means that the first iteration clustering result is better than the initial clustering result, then execute step 304 and continue to perform the iterative calculation. If the first iteration loss function is larger than the initial loss function, it means that the initial clustering result is better than the first iteration clustering result, indicating that the clustering result is good enough, then execute step 305 and stop the iterative calculation.
[0132] Step 304: If the first iterative loss function is less than the initial loss function, the first iterative clustering result is used as initial information, and the iterative calculation is continued to obtain the second iterative clustering result, and the second iterative loss function is recalculated.
[0133] For the calculation process of the second iterative clustering result and the second iterative loss function, please refer to step 301, which will not be described in detail in the embodiment of the present application.
[0134] Step 305: compare the second iterative loss function with the first iterative loss function until the second iterative loss function is greater than the first iterative loss function, stop the iterative calculation, determine that the second iterative clustering result obtained in the current iteration round is the target clustering result, and output the target clustering result.
[0135] It should be noted that after each iteration and calculation of the iterative loss function, the iterative loss function is compared with the iterative loss function of the previous round to determine whether the iterative loss function of the current round is greater than the iterative loss function of the previous round.
[0136] If the iterative loss function no longer decreases, it means that the iterative clustering result obtained by the previous round of iterative calculation is good enough. It is determined as the target clustering result and output to achieve clustering of the spatial group.
[0137] Compared with the related art, the method for clustering spatial group data provided in the embodiment of the present application also includes the following advantages:
[0138] The computing resource requirements are small and the computing speed is faster.
[0139] Corresponding to the above-mentioned method for clustering spatial group data, the present invention also provides a device for clustering spatial group data. Since the device embodiment of the present invention corresponds to the above-mentioned method embodiment, details not disclosed in the device embodiment can be referred to the above-mentioned method embodiment, and will not be repeated in the present invention.
[0140] Figure 4 A schematic diagram of a device for clustering spatial group data provided by an embodiment of the present disclosure is shown in FIG. Figure 4 As shown, including:
[0141] A first calculation unit 41 is used to calculate the transmission transfer probability between a single cell and cells in a space group; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell;
[0142] A determination unit 42, configured to determine an initial clustering type of the space group cells according to the transmission transfer probability and the group of single cells corresponding to the space group cells;
[0143] The output unit 43 is used to iterate the initial clustering type of the space group cells according to a preset clustering algorithm, calculate a first iterative loss function, stop iterating after the first iterative loss function meets a preset condition, and output a target clustering result.
[0144] The device for clustering spatial group data provided by the present disclosure has the following main technical solutions: calculating the transmission transfer probability between a single cell and a spatial group cell; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell; determining the initial clustering type of the spatial group cell according to the transmission transfer probability and the group of the single cell corresponding to the spatial group cell; iterating the initial clustering type of the spatial group cell according to a preset clustering algorithm, calculating the first iterative loss function, and stopping the iteration after the first iterative loss function meets the preset conditions, and outputting the target clustering result. Compared with the related art, the embodiment of the present application clusters the spatial group data by combining the single cell data with the spatial group position information, and adjusts the spatial group data clustering result by comparing the loss function, thereby achieving accurate clustering of the spatial data.
[0145] Furthermore, in a possible implementation of this embodiment, Figure 5 As shown, the device also includes:
[0146] The preprocessing unit 44 is used to preprocess the single-cell data and the spatial group data respectively before the first calculation unit 41 calculates the transmission transfer probability of each spatial group data and each single-cell group respectively, and the preprocessing includes at least one of data filtering, data normalization and principal component dimensionality reduction.
[0147] Furthermore, in a possible implementation of this embodiment, Figure 5 As shown, the determining unit 42 includes:
[0148] The first calculation module 421 is used to calculate the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each single cell data and the gene expression rate of each of the space group groups;
[0149] A second calculation module 422 is used to calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs;
[0150] The third calculation module 423 is used to calculate the average transmission transfer probability of each single cell category in the same single cell group;
[0151] The determination module 424 is used to respectively determine that the group of each of the spatial group data in the single cell group is the single cell group corresponding to the highest average transmission transfer probability.
[0152] Optionally, the determining unit 42 includes:
[0153] The first calculation module 421 is further used to calculate the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each space group data and the gene expression rate of each of the single cell groups;
[0154] The second calculation module 422 is further used to calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs;
[0155] The determination module 424 is further used to determine that the group of each of the spatial group data within the single cell group is the single cell group corresponding to the highest transmission transfer probability.
[0156] Furthermore, in a possible implementation of this embodiment, Figure 5 As shown, the device also includes:
[0157] The second calculation unit 45 is used to calculate the initial loss function between each spatial group data in each group before the output unit 43 iterates the initial clustering result according to the preset clustering algorithm, wherein the initial loss function is the sum of the gene expression distance and the physical space position distance.
[0158] Furthermore, in a possible implementation of this embodiment, Figure 5 As shown, the output unit 43 includes:
[0159] A fourth calculation module 431 is used to use the initial clustering type as initial information, and recalculate the clustering information of each space group data according to the K-means clustering algorithm to obtain each first iterative clustering result;
[0160] A comparison module 432 is used to respectively calculate the first iterative loss function of each spatial group in each of the first iterative clustering results, and compare the first iterative loss function with the initial loss function, wherein the first iterative loss function is the sum of the gene expression clustering, the physical space position distance and the Weissenstein distance;
[0161] A judging module 433 is used to judge whether the first iterative loss function is greater than the initial loss function;
[0162] A fifth calculation module 434 is configured to, when the first iterative loss function is less than the initial loss function, use the first iterative clustering result as initial information, continue iterative calculation, obtain a second iterative clustering result, and recalculate the second iterative loss function;
[0163] The output module 435 is used to compare the second iterative loss function with the first iterative loss function until the second iterative loss function is greater than the first iterative loss function, stop the iterative calculation, determine that the second iterative clustering result obtained in the current iterative round is the target clustering result, and output the target clustering result.
[0164] It should be noted that the above explanation of the method embodiment is also applicable to the device of this embodiment, and the principle is the same, which is not limited in this embodiment.
[0165] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0166] Figure 6 A schematic block diagram of an example electronic device 500 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0167] like Figure 6 As shown, the device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 502 or a computer program loaded from a storage unit 508 to a RAM (Random Access Memory) 503. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An I / O (Input / Output) interface 505 is also connected to the bus 504.
[0168] A number of components in the device 500 are connected to the I / O interface 505, including: an input unit 506, such as a keyboard, a mouse, etc.; an output unit 507, such as various types of displays, speakers, etc.; a storage unit 508, such as a disk, an optical disk, etc.; and a communication unit 509, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 509 allows the device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0169] The computing unit 501 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, a DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 501 performs the various methods and processes described above, such as a method for clustering spatial group data. For example, in some embodiments, the method for clustering spatial group data may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 500 via the ROM 502 and / or the communication unit 509. When the computer program is loaded into the RAM 503 and executed by the computing unit 501, one or more steps of the method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to execute the aforementioned spatial group data clustering method in any other appropriate manner (for example, by means of firmware).
[0170] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0171] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0172] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0173] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball), through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0174] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.
[0175] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0176] It should be noted that artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), and includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0177] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0178] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for clustering spatial group data, characterized in that: include: Calculating the transmission transfer probability between a single cell and cells in a spatial group; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell; Determining the initial clustering type of the space group cells according to the transmission transfer probability and the group of single cells corresponding to the space group cells; The initial clustering type of the space group cells is iterated according to a preset clustering algorithm, a first iterative loss function is calculated, and after the first iterative loss function meets a preset condition, the iteration is stopped and a target clustering result is output.
2. The method according to claim 1, characterized in that Before respectively calculating the transmission transfer probability of each spatial group of cells and each single cell group of cells, the method further includes: The single cell data and the spatial group are preprocessed respectively, and the preprocessing includes at least one of data filtering, data normalization and principal component dimensionality reduction.
3. The method according to claim 1, characterized in that The determining the initial clustering type of the space group cells according to the transmission transfer probability and the group of single cells corresponding to the space group cells comprises: Calculating the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each of the space group data and the gene expression rate of each of the single cell groups; Calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs; Calculate the average transmission transfer probability of each single-cell category within the same single-cell group; Determine the group of each of the spatial group data within the single cell group as the single cell group corresponding to the highest average transmission transfer probability.
4. The method according to claim 1, characterized in that: The determining the initial clustering type of the space group cells according to the transmission transfer probability and the group of single cells corresponding to the space group cells comprises: Calculating the transmission transfer cost of each of the space group data and each of the single cell groups according to the gene expression rate of each of the space group data and the gene expression rate of each of the single cell groups; Calculate the transmission transfer probability of each of the spatial group data and each of the single cell groups based on each of the transmission transfer costs; Determine the group of each of the spatial group data within the single cell group as the single cell group corresponding to the highest transmission transfer probability.
5. The method according to claim 1, characterized in that Before iterating the initial clustering type according to a preset clustering algorithm, the method further includes: The initial loss function between the data of each space group in each group is calculated respectively, wherein the initial loss function is the sum of the gene expression distance and the physical space position distance.
6. The method according to claim 5, characterized in that The iterating the initial clustering result according to the preset clustering algorithm, calculating the first iterative loss function, stopping the iteration after the first iterative loss function meets the preset condition, and outputting the target clustering result includes: Using the initial clustering type as initial information, recalculating the clustering information of each single cell data according to the K-means clustering algorithm, and obtaining each first iteration clustering result; Calculating the first iterative loss function of each spatial group in each of the first iterative clustering results respectively, and comparing the first iterative loss function with the initial loss function, wherein the first iterative loss function is the sum of the gene expression clustering, the physical space position distance and the Weissenstein distance; Determine whether the first iterative loss function is greater than the initial loss function; If the first iterative loss function is less than the initial loss function, the first iterative clustering result is used as initial information, the iterative calculation is continued to obtain the second iterative clustering result, and the second iterative loss function is recalculated; The second iterative loss function is compared with the first iterative loss function until the second iterative loss function is greater than the first iterative loss function, the iterative calculation is stopped, the second iterative clustering result obtained in the current iterative round is determined to be the target clustering result, and the target clustering result is output.
7. A device for clustering spatial group data, characterized in that: include: A first calculation unit is used to calculate the transmission transfer probability between a single cell and cells in a space group; wherein the single cell has a cell group label, and the cell group label is used to identify the cell type of the single cell; A determination unit, configured to determine an initial clustering type of the space group cells according to the transmission transfer probability and the group of single cells corresponding to the space group cells; The output unit is used to iterate the initial clustering type of the space group cells according to a preset clustering algorithm, calculate a first iterative loss function, stop iterating after the first iterative loss function meets a preset condition, and output a target clustering result.
8. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-6.
10. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 6.