Single-cell data augmentation representation method, apparatus, and storage medium
By acquiring single-cell gene expression data and module data, generating latent vectors using gene and module encoders, and performing cross-attention fusion, the problem of poor biological interpretability of single-cell data is solved, achieving higher-quality data analysis and interpretation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG LAB
- Filing Date
- 2025-12-17
- Publication Date
- 2026-04-21
AI Technical Summary
Existing deep learning models lack explicit encoding of the dynamic activity relationship between single cells and gene modules in single-cell data processing, resulting in poor biological interpretability.
By acquiring the original counting matrix of gene expression in single cells and the gene module dataset, gene feature transformation and module activity matrix determination are performed. Latent vectors are generated using gene encoders and module encoders, and interactive fusion is performed using a cross-attention fusion model to generate enhanced representations of single cells.
It improves the biological interpretability of single-cell data by effectively integrating gene latent vectors and module latent vectors into the target embedding space, thereby enhancing the analytical reliability and biological interpretability of the data.
Smart Images

Figure CN121354659B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of single-cell data processing technology, and in particular to single-cell data enhancement representation methods, devices, and storage media. Background Technology
[0002] In the fields of life sciences and medical research, the rapid development of single-cell sequencing technology has generated massive amounts of single-cell data, greatly promoting the deep transformation and upgrading of biological research from the population level to single-cell resolution. Single-cell data processing can extract biologically meaningful patterns and structures from high-dimensional, sparse raw data. Single-cell data augmentation further enhances this process by using algorithm optimization and prior knowledge fusion to generate higher-quality, more informative, and more biologically interpretable feature representations, thus providing a more reliable foundation for downstream analysis and enabling more precise scientific discoveries.
[0003] Currently, numerous deep learning frameworks have been introduced into the field of single-cell data processing, but most of them follow a purely data-driven, end-to-end paradigm. Although some methods have attempted to incorporate biological knowledge, these efforts are mostly focused on the gene level or the regulatory network structure itself, and have not yet effectively modeled the dynamic activity relationship between single cells and gene modules. Because these deep learning models lack explicit encoding and enhancement of the semantics at the module level of single-cell data, they struggle to address the problem of poor biological interpretability of single-cell data.
[0004] There is currently no effective solution to the problem of poor biological interpretability of single-cell data in related technologies. Summary of the Invention
[0005] This embodiment provides a method, apparatus, and storage medium for enhancing single-cell data representation to address the problem of poor biological interpretability of single-cell data in related technologies.
[0006] In a first aspect, this embodiment provides a single-cell data augmentation representation method, the method comprising:
[0007] Obtain the raw counting matrix and gene module dataset of single-cell gene expression; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules;
[0008] Gene feature matrix is obtained by performing gene feature transformation based on the original counting matrix.
[0009] Based on the gene feature matrix, the original counting matrix, and the gene module dataset, the cell module activity matrix is determined.
[0010] The gene feature matrix is processed by a gene encoder to generate gene latent vectors, and the cell module activity matrix is processed by a module encoder to generate module latent vectors.
[0011] Using the gene latent vector and the module latent vector as inputs to the cross-attention fusion model, interactive fusion is performed under an optimization objective defined by a comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell augmentation representation output by the model and the reference embedding representation used as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vector and the module latent vector;
[0012] The fused latent vectors are projected into the target embedding space to generate a single-cell augmented representation.
[0013] In some embodiments, the gene feature transformation based on the original counting matrix to obtain a gene feature matrix includes:
[0014] The original counting matrix is subjected to fluctuation feature transformation, specifically by cell library normalization, log-centering of gene medians, and calculation of absolute differences, to obtain a gene fluctuation matrix as the gene feature matrix.
[0015] In some embodiments, determining the cell module activity matrix based on the gene feature matrix, the original counting matrix, and the gene module dataset includes:
[0016] Based on the original counting matrix, the detection rate of genes in each cell within the gene module is calculated;
[0017] Based on the gene feature matrix, calculate the mean fluctuation, coefficient of variation, and specificity of genes within the gene module in each cell;
[0018] The basic activity is calculated based on the detection rate and the mean fluctuation, and the basic activity is dynamically weighted based on the fluctuation variation coefficient and the fluctuation specificity to obtain the module activity value.
[0019] The module activity values of all the gene modules are collected to form the cell module activity matrix.
[0020] In some embodiments, calculating the detection rate of genes within the gene module in each cell based on the original counting matrix includes:
[0021] Obtain the gene index list corresponding to each gene module in the gene module dataset;
[0022] Based on the gene index list of the gene module, extract the columns corresponding to the indexes in the gene index list from the original counting matrix to form the original counting submatrix;
[0023] The number of elements greater than zero in each row of the original counting submatrix is calculated, and the number of elements is divided by the total number of genes contained in the current gene module to obtain the detection rate.
[0024] In some embodiments, calculating the mean fluctuation, coefficient of variation, and fluctuation specificity of genes within the gene module in each cell based on the gene feature matrix includes:
[0025] Obtain the gene index list corresponding to each gene module in the gene module dataset;
[0026] Based on the gene index list of the gene module, extract the columns corresponding to the indexes in the gene index list from the gene feature matrix to form a gene feature submatrix;
[0027] The arithmetic mean of the fluctuation values for each cell is calculated along the column direction of the gene feature sub-matrix to obtain the fluctuation mean.
[0028] The standard deviation of the fluctuation value of each cell is calculated along the column direction of the gene feature sub-matrix, and the standard deviation is divided by the sum of the fluctuation mean and a very small constant to obtain the fluctuation variation coefficient.
[0029] For each cell, the difference between the maximum and minimum fluctuation values within the gene module is found, and then divided by the sum of the maximum and minimum values and the sum of the minimum constants to obtain the fluctuation specificity.
[0030] In some embodiments, the gene encoder sequentially includes: a first linear transformation layer, a first batch normalization layer, a first activation function layer, a first dropout layer, a second linear transformation layer, a first normalization layer, and a second activation function layer; the module encoder sequentially includes: a third linear transformation layer, a second batch normalization layer, a third activation function layer, and a second dropout layer.
[0031] In some embodiments, the gene latent vector and the module latent vector are used as inputs to the cross-attention fusion model, and interactive fusion is performed under an optimization objective defined by a comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell augmentation representation output by the model and the reference embedding representation used as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vector and the module latent vector, including:
[0032] The gene latent vector is used as the query vector, and the module latent vector is used as the key vector and value vector. Attention calculation is performed through the cross-attention fusion model to obtain the fused latent vector; wherein, the attention calculation adopts a multi-head attention mechanism.
[0033] In some embodiments, projecting the fused latent vectors into the target embedding space to generate the single-cell augmented representation includes:
[0034] The fused latent vector is linearly transformed to map its dimension to the same dimension space as the target embedding space, ultimately generating the enhanced representation of the single cell.
[0035] Secondly, this embodiment provides a single-cell data augmentation and representation device, including: a data acquisition module, a data processing module, and a fusion enhancement module; wherein:
[0036] The data acquisition module is used to acquire the original counting matrix of gene expression in single cells and the gene module dataset; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules.
[0037] The data processing module is used to perform gene feature transformation based on the original counting matrix to obtain a gene feature matrix; determine the cell module activity matrix based on the gene feature matrix, the original counting matrix, and the gene module dataset; process the gene feature matrix through a gene encoder to generate gene latent vectors, and process the cell module activity matrix through a module encoder to generate module latent vectors.
[0038] The fusion enhancement module is used to perform interactive fusion under the optimization objective defined by the comprehensive loss function, using the gene latent vector and the module latent vector as inputs to the cross-attention fusion model, to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell enhanced representation output by the model and the reference embedding representation as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vector and the module latent vector; the fused latent vector is projected onto the target embedding space to generate a single-cell enhanced representation.
[0039] Thirdly, this embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the single-cell data augmentation representation method described in the first aspect.
[0040] Compared with related technologies, this embodiment provides a method, apparatus, and storage medium for single-cell data augmentation representation. In this method, firstly, an original counting matrix of single-cell gene expression and a gene module dataset are obtained; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules. Secondly, gene feature transformation is performed based on the original counting matrix to obtain a gene feature matrix. Subsequently, based on the gene feature matrix, the original counting matrix, and the gene module dataset, a cell module activity matrix is determined. Further, the gene feature matrix is processed by a gene encoder to generate gene latent vectors, and the cell module activity matrix is processed by a module encoder to generate module latent vectors. Next, the gene latent vectors and module latent vectors are used as inputs to a cross-attention fusion model, and interactive fusion is performed under an optimization objective defined by a comprehensive loss function to obtain a fused latent vector output by the cross-attention fusion model. The comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is a similarity calculation between the single-cell augmented representation output by the model and the reference embedding representation used as a supervision signal; the second loss term is a reconstruction error calculation based on the gene latent vectors and module latent vectors. Finally, the fused latent vectors are projected onto the target embedding space to generate a single-cell augmented representation. Based on the fluctuation matrix and multi-label gene module activity calculation, it effectively integrates gene latent vectors and module latent vectors into the target embedding space through a cross-attention fusion model, thereby improving the interpretability of single-cell organisms.
[0041] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description
[0042] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments of this application and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0043] Figure 1 This is a hardware structure block diagram of an industrial computer terminal for a single-cell data augmentation representation method according to an embodiment of this application;
[0044] Figure 2 This is a flowchart of a single-cell data augmentation representation method according to one embodiment of this application;
[0045] Figure 3 This is a flowchart of a single-cell data augmentation representation method according to another embodiment of this application;
[0046] Figure 4 This is a flowchart of a single-cell data augmentation representation method according to another embodiment of this application;
[0047] Figure 5This is a flowchart of a single-cell data augmentation representation method according to another embodiment of this application;
[0048] Figure 6a This is a batch label distribution diagram of a single cell after fusion embedding, according to one embodiment of this application;
[0049] Figure 6b This is a diagram showing the actual tag distribution of a single cell after fusion embedding, according to one embodiment of this application.
[0050] Figure 7 This is a flowchart illustrating the training process for deep embedding of single-cell data according to one embodiment of this application.
[0051] Figure 8 This is a structural block diagram of a single-cell data augmentation representation device according to one embodiment of this application. Detailed Implementation
[0052] To better understand the purpose, technical solution, and advantages of this application, the application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0053] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning understood by one of ordinary skill in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these” used in this application do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to these processes, methods, products, or devices. Words such as “connected,” “linked,” and “coupled” used in this application are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. “Multiple” used in this application refers to two or more. “And / or” describes the relationship between related objects, indicating that three relationships may exist; for example, “A and / or B” can represent: A alone, A and B simultaneously, and B alone. Normally, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," "third," etc., used in this application are merely to distinguish similar objects and do not represent a specific order of objects.
[0054] The method embodiments provided in this example can be executed in an industrial computer terminal, a computer, or a similar electronic device with a certain computing power. For example, it can run on an industrial computer terminal. Figure 1 This is a hardware structure block diagram of an industrial computer terminal for the single-cell data augmentation representation method of this embodiment. (As shown...) Figure 1 As shown, an industrial computer terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 and a memory 104 for storing data are also included. The processor 102 may be, but is not limited to, a microprocessor (MCU) or a programmable logic device (FPGA). The aforementioned industrial computer terminal may also include a transmission device 106 and an input / output device 108 for communication between data acquisition equipment, external storage systems, user operating terminals, and collaborative computing devices. Those skilled in the art will understand that… Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the industrial computer terminal described above. For example, the industrial computer terminal may also include components that are more advanced than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown are illustrated.
[0055] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the single-cell data augmentation representation method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to an industrial computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0056] The transmission device 106 is used to receive or send data via a network. This network includes wireless networks provided by the communication vendor of the industrial computer terminal. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 can be a Radio Frequency (RF) module for wireless communication with the Internet.
[0057] This embodiment provides a single-cell data augmentation representation method. Figure 2 This is a flowchart of the single-cell data augmentation representation method in this embodiment, as follows: Figure 2 As shown, the process includes the following steps:
[0058] Step S210: Obtain the original counting matrix and gene module dataset of single-cell gene expression; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules.
[0059] High-throughput sequencing technology can obtain single-cell gene expression data, which is presented as a counting matrix of cells and genes. This data reveals the heterogeneity and functional status of cell populations. Specifically, first, the single-cell data file is read from a specified file path. This file contains the raw expression counts of each gene in each cell. Next, basic validation of the single-cell data is performed to ensure its quality and completeness. Then, the definition file for the gene module dataset is loaded. This file defines the mapping relationship between genes and gene modules. Since a gene may participate in multiple biological processes, this "one-to-many" mapping relationship needs to be resolved. Furthermore, to ensure that the single-cell data and the gene module dataset are analyzed based on the same set of genes, their gene intersection needs to be taken. Based on the gene list obtained from the intersection, a module dictionary is constructed, containing the column index of the gene corresponding to each module in the data matrix. Finally, to adapt to different hardware resources, memory optimization is performed based on the configuration. In memory-constrained mode, converting large matrices to a sparse format and reducing numerical precision can significantly reduce memory usage.
[0060] For example, single-cell data from an h5ad file is read from the configuration path. The existence of a matrix layer named "raw" in the data layer attributes is verified to obtain the original counting matrix. Then, the gene module annotation comma-separated values (CSV) file is read, and the gene data is organized into a dictionary format, where the key is the gene module name and the value is a list of genes for that gene module, resulting in a gene module dataset. Further, after aligning the original counting matrix with the gene module dataset, the intersection of the original counting matrix and the gene module dataset is obtained. Based on the gene list obtained from the intersection, a gene module dictionary is constructed. The keys in the module dictionary are in the format "Module{xxx}", and the values are a list of gene position indices in the matrix. Specifically, if the system is configured for memory-constrained mode, the data matrix is automatically converted to a Compressed Sparse Row (CSR) matrix or to 32-bit floating-point precision.
[0061] Step S220: Gene feature transformation is performed based on the original counting matrix to obtain the gene feature matrix.
[0062] Gene feature transformation refers to a series of computational methods that map raw counting matrices into more biologically meaningful or statistically robust feature representations. Gene feature transformation methods include standardization and logarithmic transformation, standard deviation standardization, and fluctuation feature transformation. These methods, through different mathematical processing, extract key information about gene expression patterns from raw data, ultimately outputting a gene feature matrix.
[0063] In one embodiment of this application, fluctuation feature transformation is used as the gene feature transformation, and its output is a gene fluctuation matrix. Fluctuation features are a novel characterization method designed for single-cell ribonucleic acid (RNA) sequencing data. Instead of directly using the original gene expression level or a simple logarithmic transformation value, fluctuation features quantify the deviation of each gene's expression level in a single cell from its typical (median) expression level in the entire cell population. Specifically, fluctuation features are obtained by calculating the absolute value of the logarithmic fold change between the standardized expression level and the gene baseline expression level, resulting in a continuous, non-zero-proportional fluctuation feature matrix. The obtained features effectively alleviate the inherent zero-value inflation problem in single-cell data, and their numerical magnitude directly reflects the abnormal or active intensity of gene expression.
[0064] The gene fluctuation matrix is a feature matrix constructed by quantifying the degree of deviation of each gene from its global typical expression level in a single cell. Its core purpose is to address the analytical difficulties caused by the high proportion of zero values (typically 70%–90%) in single-cell data. By calculating the absolute value of the logarithmic fold change between the normalized expression level and the gene baseline, the proportion of zero values is reduced by 30%–50%, thereby enhancing the continuity of dynamic changes in gene expression. Simultaneously, the fluctuation matrix avoids spurious signals introduced by traditional imputation methods, and its values have clear biological interpretability, directly reflecting the strength of gene expression deviation from the baseline. Therefore, the gene fluctuation matrix is a specific implementation of the gene feature matrix, particularly suitable for capturing dynamic regulatory information during cellular state transitions.
[0065] It is particularly worth mentioning that the reason why the proportion of zero values can naturally decrease by 30%–50% lies in the unique calculation logic of the fluctuation matrix. The formula for calculating the fluctuation matrix is: fluct = |log2(norm+ -log2(median+) )|, where norm is the normalized expression value of the gene in a specific cell, and median is the median of the non-zero expression value of the gene across all cells. It is a very small constant used to ensure the numerical stability of logarithmic operations. For genes with an original count of zero, their normalized value norm in the cell is approximately equal to 0, therefore log2(norm+) The result is a value that approximates log2( The negative value of log2(median) is used, while median is calculated from all cells expressing the gene and is therefore a positive value. So, log2(median+) The first value is a positive value. Substituting the two values into the formula, we get fluct = |(a negative value) - (a positive value)|. From this, we can deduce that any expression value that is zero in the original data will be transformed into a positive number greater than zero after the fluctuation matrix transformation.
[0066] This process transforms a large number of informationless, technically zero values into meaningful quantitative values representing the intensity of expression deviations. Because all zero values are mapped to non-zero values, the proportion of zero elements in the entire matrix naturally decreases significantly, by 30% to 50%. Compared to direct zero-filling or complex imputation methods, this transformation does not introduce any external assumptions or spurious data. Each value originates from the gene's own expression distribution and has a clear mathematical and biological interpretation. Even if a gene is not detected in the current cell, its state relative to the gene's active expression level is itself a valuable deviation signal.
[0067] In one embodiment, a novel feature for converting the original counting matrix into a fluctuation matrix is achieved through library size calculation and normalization, gene expression baseline median calculation, fluctuation feature calculation and zero-value retention, and result storage and advantage description to explain the dynamic changes in gene expression.
[0068] Step S230: Determine the cell module activity matrix based on the gene feature matrix, the original counting matrix, and the gene module dataset.
[0069] Based on the gene feature matrix, the original counting matrix, and the gene module dataset, a multi-stage, non-linear computational framework is used to determine the cell module activity matrix. The core of this process lies in the intelligent aggregation and transformation of gene-level expression information within predefined gene modules to quantify the overall activity level of each gene module in a single cell.
[0070] In one embodiment of this application, the gene feature matrix is specifically a gene fluctuation matrix obtained through the aforementioned fluctuation feature transformation. Based on this, determining the cell module activity matrix requires first extracting basic statistics. For each gene module, a subset of its corresponding genes is extracted from the gene fluctuation matrix and the original counting matrix, and six core statistics are calculated in parallel: gene detection rate, average fluctuation intensity, fluctuation standard deviation, coefficient of variation, expression specificity, and average correlation between genes. Based on these statistics, a preliminary module activity is synthesized using a nonlinear formula. This synthesis process is not a simple averaging, but rather uses the basic activity as a base, introducing a weighting factor dynamically adjusted by the coefficient of variation and an enhancing factor contributing to expression specificity for weighting. The preliminary activity values are further fine-tuned according to the biological characteristics of the modules, enhancing the activity of highly synergistic modules to highlight their functional consistency, and applying different scale factors according to the module size to balance the systematic bias between large and small modules. Finally, the corrected activity values are transformed to ensure that the data distribution is more suitable for model training, and the activity vectors of all modules are stacked to generate the cell module activity matrix. This matrix, serving as a compressed representation from gene space to functional space, has very few zero values and a high signal-to-noise ratio, making it a direct core input to the neural network. Simultaneously, pre-computed Harmony embeddings from single-cell data are used as supervisory labels, providing a standard reference based on cell population structure for model training.
[0071] In step S240, the gene feature matrix is processed by a gene encoder to generate gene latent vectors, and the cell module activity matrix is processed by a module encoder to generate module latent vectors.
[0072] The gene feature matrix is processed by a gene encoder, a two-layer network consisting of a fully connected layer, a normalization layer, and an activation function, to generate gene latent vectors. Simultaneously, the cell module activity matrix is processed by a module encoder, a single-layer fully connected network, to generate module latent vectors of the same dimension. Both processes map the original features to a unified latent semantic space, preparing for subsequent fusion.
[0073] Step S250: Using the gene latent vector and the module latent vector as inputs to the cross-attention fusion model, interactive fusion is performed under the optimization objective defined by the comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of the first loss term and the second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell augmentation representation output by the model and the reference embedding representation as the supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vector and the module latent vector.
[0074] Gene latent vectors and module latent vectors are used as inputs to a cross-attention fusion model for interactive fusion, resulting in a fused latent vector. The gene latent vector represents fine-grained, individual-gene-level features extracted from fluctuations in original gene expression. The module latent vector represents coarse-grained, gene-functional-unit-level features extracted from gene module activity. The cross-attention fusion model automatically learns the correlation weights between the gene and module latent vectors. For each gene feature, the model calculates its correlation with all gene module features, and then performs a weighted summation of the module features based on the correlation weights. Specifically, both gene and module latent vectors are input into the cross-attention fusion model. This model uses the gene latent vector as the query and the module latent vector as the key and value, performing core attention calculations to capture the interactive fusion relationship between the two types of latent vector features. After calculation, the model further stabilizes the training process through residual connections and layer normalization, and undergoes nonlinear transformation via a feedforward network, ultimately outputting a dimension-invariant fused latent vector that integrates gene and module information. This fused latent vector forms the basis for subsequent prediction and reconstruction tasks.
[0075] The training process of the cross-attention fusion model is carried out under the optimization objective defined by the comprehensive loss function. Specifically, the comprehensive loss function includes a first loss term and a second loss term. The formula for the comprehensive loss function is: Loss = Loss1 + (1-α)Loss2. Here, 1-α is the balancing hyperparameter. The first loss term, Loss1, is calculated based on the similarity between the single-cell augmented representation output by the model and the reference embedding representation used as the supervision signal. The second loss term, Loss2, is calculated based on the reconstruction error of the gene latent vector and the module latent vector.
[0076] For example, in one embodiment, the total loss function is defined as Loss = α × cos_loss + (1 – α) × recon_loss. In this formula, 1 – α is the balancing hyperparameter, and cos_loss is the cosine similarity loss, which is calculated by subtracting the batch average of the cosine similarity between the model's predicted embedding and the target Harmony embedding from 1. Cosine similarity, rather than mean squared error, is chosen as the metric for the embedding space primarily because cosine similarity is highly sensitive to vector direction rather than absolute magnitude, allowing the model to focus more on learning the relative relationships between cell states. recon_loss is the mean squared error loss, used to measure the difference between the module activity matrix reconstructed by the model's decoder and the original module activity matrix.
[0077] Step S260: Project the fused latent vectors into the target embedding space to generate a single-cell augmented representation.
[0078] The fused latent vectors are processed through a projection head, which maps their dimensions to the same dimension as the target embedding space, thereby generating the final single-cell augmented representation. This projection head consists of a linear transformation layer, a normalization layer, and an activation function. Its role is to adapt the deeply fused high-level features to the specific space required by downstream tasks, ultimately outputting a low-dimensional embedding that can be used for high-order analyses such as cell type identification and batch effect correction.
[0079] In related technologies, the inherent extreme sparsity of data makes traditional analyses based on single gene expression levels highly unreliable, amplifying noise and leading to the identification of spurious cell subpopulations. Correction algorithms, widely used to integrate multiple batches of data, often inadvertently mask subtle but real biological differences as noise while eliminating technical variations. Furthermore, they struggle to accurately characterize the complex states of cells. Although deep learning models have demonstrated powerful capabilities and continuous improvement in data processing, mainstream end-to-end black-box training lacks the embedding of prior knowledge about pathways and regulatory networks, resulting in low-dimensional features that are disconnected from biological function and difficult for researchers to understand and verify. However, problems remain in the translation path from single-cell data results to biological interpretation. Therefore, the poor biological interpretability of single-cell data remains a problem in related technologies.
[0080] Steps S210 to S260 above involve: First, obtaining the original counting matrix and gene module dataset of single-cell gene expression; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules; second, performing gene feature transformation based on the original counting matrix to obtain the gene feature matrix; subsequently, determining the cell module activity matrix based on the gene feature matrix, the original counting matrix, and the gene module dataset; further, processing the gene feature matrix through a gene encoder to generate gene latent vectors, and processing the cell module activity matrix through a module encoder to generate module latent vectors; then, using the gene latent vectors and module latent vectors as inputs to the cross-attention fusion model, performing interactive fusion under the optimization objective defined by the comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of the first loss term and the second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell augmented representation output by the model and the reference embedding representation as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vectors and the module latent vectors; finally, projecting the fused latent vectors onto the target embedding space to generate the single-cell augmented representation. Based on the fluctuation matrix and multi-label gene module activity calculation, it effectively integrates gene latent vectors and module latent vectors into the target embedding space through a cross-attention fusion model, thereby improving the interpretability of single-cell organisms.
[0081] Optionally, in one embodiment, gene feature transformation is performed based on the original counting matrix to obtain a gene feature matrix, including: performing fluctuation feature transformation on the original counting matrix, specifically by cell library normalization, log-centering of gene medians and calculation of absolute differences, to obtain a gene fluctuation matrix as the gene feature matrix.
[0082] First, the original counting matrix is aligned. Then, based on the gene module dataset, the gene set of the single-cell dataset is filtered to retain only the genes shared by both datasets.
[0083] Subsequently, in one embodiment, gene feature transformation is achieved through gene fluctuation feature transformation. Fluctuation values are calculated for the aligned original counting matrix. The first step is cell library size calculation and normalization: the library size for each cell is calculated and zero values are set to 1, followed by normalization. The second step is gene expression baseline calculation: the median of non-zero expression values for each gene is calculated. The third step is absolute value calculation of logarithmic differences: the fluctuation value is calculated according to a formula. The fourth step is zero-value retention: positions in the original counting matrix that are zero are forcibly set to zero at their corresponding positions in the fluctuation matrix.
[0084] Finally, the data type of the calculated fluctuation matrix is converted to obtain the gene feature matrix, which is then written into the intersection gene object. If the system is configured for low memory mode, the matrix is formatted and uniformly converted to a 32-bit floating-point data type to save memory.
[0085] In one embodiment, the cell module activity matrix is determined based on the gene feature matrix, the original counting matrix, and the gene module dataset, including:
[0086] Based on the original counting matrix, the detection rate of genes in each cell within a gene module is calculated; based on the gene feature matrix, the mean fluctuation, coefficient of variation, and specificity of genes in each cell within a gene module are calculated; the basic activity is calculated based on the detection rate and mean fluctuation, and the basic activity is dynamically weighted based on the coefficient of variation and specificity to obtain the module activity value; the module activity values of all gene modules are aggregated to form a cell module activity matrix.
[0087] After obtaining key statistics such as gene detection rate, mean fluctuation, coefficient of variation, and specificity, the synthesis of module activity is mainly completed in two stages. First, the gene detection rate is multiplied by the mean fluctuation intensity to obtain the basal activity. This step ensures that the module activity assessment takes into account both the breadth and intensity of gene expression. Subsequently, the basal activity undergoes a dynamic weighting process, which is jointly regulated by the fluctuation coefficient of variation and fluctuation specificity. The final module activity value is the product of the basal activity and this dynamic weighting factor.
[0088] For example, the coefficient of variation is mapped to the (0, 1) interval using a sigmoid activation function, serving as the basic regulator for the weights. Simultaneously, the fluctuation specificity is set to 0.7 × specificity. 0.8 +0.3. The final gene module activity value is determined by the following formula: Gene module activity = Base activity × (1 + Sigmoid (2 × coefficient of variation) × (0.7 × specificity)). 0.8 +0.3). The ingenuity of this formula lies in the fact that when a gene module simultaneously exhibits high volatility specificity and high volatility coefficient of variation, its weighting factor will be much greater than 1, thus significantly increasing the final activity value. This indicates that the gene module may be in a period of highly active function and dynamic response in the cell. Conversely, for modules with stable and uniform expression, their activity is mainly determined by basal activity. Through this non-linear weighting strategy, the gene module activity value can more sensitively and accurately capture the dynamic changes in cellular functional state. Finally, by stacking the final activity values calculated for all gene modules according to the gene module dimension, the cell module activity matrix is obtained.
[0089] In one embodiment, the detection rate of genes within a gene module in each cell is calculated based on the original counting matrix, including:
[0090] Obtain the gene index list corresponding to each gene module in the gene module dataset; based on the gene index list of the gene modules, extract the columns corresponding to the indices in the gene index list from the original counting matrix to form the original counting submatrix; calculate the number of elements greater than zero in each row of the original counting submatrix, and divide the number of elements by the total number of genes contained in the current gene module to obtain the detection rate.
[0091] First, obtain the gene index list G contained in the gene module m to be processed from the pre-generated gene module dictionary. m This list records the column position indices of all genes in this module within the single-cell data matrix. Subsequently, based on this index list G... m The corresponding gene columns are extracted from the original counting matrix to form the original counting submatrix R of this module. m The shape of this submatrix is (n_cells, len(G)). m This includes only the unique molecular identifier (UMI) counts of the genes involved in the current module across all cells. Finally, based on the submatrix R... m Calculate the gene detection rate for each cell. The formula for calculating the detection rate is: detect_rate = (R... m >0).sum(axis=1) / len(G m Specifically, for each row, calculate its R.m The number of elements with a greater than zero expression level is calculated by dividing this number by the total number of genes contained in the current gene module.
[0092] In one embodiment, based on the gene feature matrix, the mean fluctuation, coefficient of variation, and fluctuation specificity of genes within a gene module in each cell are calculated, including:
[0093] Obtain the gene index list corresponding to each gene module in the gene module dataset; based on the gene index list of the gene modules, extract the columns corresponding to the indices in the gene index list from the gene feature matrix to form a gene feature submatrix; calculate the arithmetic mean of the fluctuation values of each cell along the column direction of the gene feature submatrix to obtain the fluctuation mean; calculate the standard deviation of the fluctuation values of each cell along the column direction of the gene feature submatrix, and divide the standard deviation by the sum of the fluctuation mean and a minimum constant to obtain the fluctuation variation coefficient; for each cell, find the difference between the maximum and minimum fluctuation values within the gene module, and then divide it by the sum of the maximum and minimum values and the minimum constant to obtain the fluctuation specificity.
[0094] In one embodiment, after obtaining the gene fluctuation matrix through fluctuation feature transformation, the gene index list G contained in the current gene module m is obtained from the gene module dictionary. m Based on this index list G m Extracting the corresponding gene columns from the gene fluctuation matrix yields the gene fluctuation submatrix F for this module. m The shape of this submatrix is (n_cells, len(G)). m Subsequently, based on the gene fluctuation submatrix F... m Calculate the three core statistics:
[0095] (1) Fluctuation mean: The arithmetic mean of the fluctuation values of each cell along the column direction (i.e., gene dimension). The calculation formula is: mod_mean=Fm.sum(axis=1) / len(Gm). This value represents the average intensity of gene fluctuation within the module.
[0096] (2) Fluctuation coefficient of variation: First, calculate the standard deviation of the fluctuation value for each cell along the column direction. Then, divide the standard deviation by the fluctuation mean and a very small constant. The sum of these values yields the fluctuation variation coefficient, which is specifically formulated as: mod_cv = mod_std / (mod_mean + ... This coefficient is used to measure the relative dispersion of fluctuation intensity.
[0097] (3) Fluctuation Specificity: For each cell, find the maximum (mod_max) and minimum (mod_min) fluctuation values within that module. Calculate the difference between the maximum and minimum values: mod_max - mod_min. Calculate the sum of the maximum and minimum values and combine it with the minimum constant. Addition: mod_max + mod_min + Finally, specificity is calculated using the following formula: specificity = (mod_max - mod_min) / (mod_max + mod_min + ... This value quantifies the relative width of the range of gene fluctuations within the module.
[0098] In one embodiment, the gene encoder sequentially includes: a first linear transformation layer, a first batch normalization layer, a first activation function layer, a first dropout layer, a second linear transformation layer, a first normalization layer, and a second activation function layer; the module encoder sequentially includes: a third linear transformation layer, a second batch normalization layer, a third activation function layer, and a second dropout layer.
[0099] The forward propagation process of the gene encoder includes the following steps: First linear transformation layer: Projects the input high-dimensional gene features onto the hidden feature space. First batch normalization layer: Performs intra-batch normalization on the hidden features to stabilize the training process. First activation function layer: Employs the LeakyReLU activation function to introduce a non-linear transformation. First dropout layer: Randomly drops some neurons during the training phase to prevent overfitting. Second linear transformation layer: Further projects the features onto the target embedding dimension. First normalization layer: Performs layer normalization on the final output embedding vector. Second activation function layer: Again employs the LeakyReLU activation function to output the final gene latent vector.
[0100] The forward propagation process of the module encoder includes the following steps: Third linear transformation layer: Projects the input module activity features onto the target embedding dimension. Second batch normalization layer: Performs intra-batch normalization on the projected features. Third activation function layer: Employs the LeakyReLU activation function. Second dropout layer: Randomly drops some neurons during training, outputting the final module latent vector.
[0101] In one embodiment, gene latent vectors and module latent vectors are used as inputs to the cross-attention fusion model, and interactive fusion is performed under an optimization objective defined by a comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell augmentation representation output by the model and the reference embedding representation used as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vectors and module latent vectors, including:
[0102] The gene latent vector is used as the query vector, and the module latent vector is used as the key vector and value vector. Attention calculation is performed through a cross-attention fusion model to obtain the fused latent vector; the attention calculation adopts a multi-head attention mechanism.
[0103] The model takes gene latent vectors and module latent vectors as input. First, the gene latent vector is used as the query vector, and the module latent vector is used as both the key and value vectors. This means the model aims to filter and integrate the most relevant functional information from all module features for each gene feature. Then, attention computation is performed through a cross-attention fusion model, employing a multi-head attention mechanism. Specifically, the query, key, and value vectors are linearly projected onto multiple independent subspaces (i.e., "multi-heads"), and attention weights are computed in parallel within each "head." These attention weights are determined by the dot product of the query and key vectors, quantifying the relevance between each gene and each module. Next, these weights are used to perform a weighted summation of the value vectors to obtain the output of each "head." Finally, the outputs of all "heads" are concatenated and linearly projected back to the original dimensions to generate a gene feature representation enhanced with module information.
[0104] To further optimize network performance, the output of the multi-head attention layer is residually connected to the original gene latent vectors, followed by layer normalization. This helps alleviate the vanishing gradient problem and promotes training stability. Subsequently, the normalized result is input into a feedforward network to introduce nonlinear transformations and enhance the model's expressive power. Similarly, the output of the feedforward network is residually connected to its input and layer normalized to obtain the fused latent vector. Through these processes, the resulting fused latent vector deeply integrates detailed information at the gene level and functional information at the module level, forming a richer representation and laying the foundation for subsequent prediction of Harmony embeddings.
[0105] In one embodiment, projecting the fused latent vectors onto the target embedding space to generate a single-cell augmented representation includes: performing a linear transformation on the fused latent vectors to map their dimensions to the same dimensional space as the target embedding space, ultimately generating an augmented representation of the single cell.
[0106] First, the fused latent vector is input into a fully connected layer through a linear transformation, and then linearly mapped from the dimension of the target embedding space to the target dimension through matrix operations. Subsequently, a batch normalization layer is applied to the result of the linear transformation to normalize each feature dimension, stabilizing the training process and accelerating convergence. Further, the normalized data is passed through a hyperbolic tangent activation function to compress the output values to the (-1, 1) interval. This step introduces nonlinearity into the mapping process, enhancing the model's expressive power and ensuring that the generated embeddings are scale-compatible with the normalized target embedding space. After these transformations, the network outputs the final result, which is the enhanced representation of a single cell. This low-dimensional vector captures the deep fusion features of gene and module information and directly corresponds to the target embedding space, making it suitable for downstream cell state analysis.
[0107] For example, when the target embedding space is a Harmony embedding, its dimension is `harmony_dim`. In this case, the fused latent vector of shape (batch_size, embedding_dim) is mapped from its `embedding_dim` dimension to `harmony_dim` through matrix operations after being input into the fully connected layer. Here, `batch_size` represents the batch size, i.e., the number of samples processed in a single forward propagation, and `embedding_dim` represents the embedding dimension, i.e., the feature representation dimension of each sample. After batch normalization and non-linear activation, the final fused latent vector output by the network has a shape of (batch_size, harmony_dim).
[0108] In one embodiment, a supervised strategy based on multi-task learning is employed, combining external biological priors with internal structural reconstruction to jointly guide model optimization. Essentially, this involves constructing a weighted total loss function consisting of cosine similarity loss and mean squared error reconstruction loss, which is then minimized by an optimizer. The weighting coefficient α, as a key hyperparameter, is determined through an automatic search mechanism to balance the learning objectives of the two tasks.
[0109] Specifically, in one embodiment, the comprehensive loss function is a weighted sum of a first loss term and a second loss term. The first loss term is specifically the cosine similarity loss between the single-cell augmented representation and the target embedding, focusing on the relative relationship of cell states. The second loss term is specifically the mean squared error loss of the reconstructed module activity matrix, maintaining the integrity of feature information. Furthermore, the multi-task design enables the model to simultaneously learn embedding alignment and module reconstruction. Learning embedding alignment utilizes pre-trained Harmony embeddings as a supervisory signal, guiding the model to output cell representations with ideal low-dimensional structures. Module reconstruction serves as a self-supervised signal, enabling the model to retain key biological gene module information during feature fusion and compression. For example, the hyperparameter α is set to automatically search within the range [0.30, 0.70] with a step size of 0.02. Its optimal value is determined by maximizing the cosine similarity on the validation set, thereby ensuring that the model achieves the best balance between mimicking the ideal embedding space and preserving the biological information of the input data. The entire optimization process employs the Adam with Weight Decay Fix (AdamW) optimizer, which achieves more efficient regularization by decoupling weight decay from gradient updates, thus helping to improve the model's generalization performance.
[0110] Of particular note is the use of a special Harmony embedding, rather than a traditional one, in one embodiment. This special Harmony embedding is essentially a task-specific supervisory signal that quickly generates a coarse-grained, reasonable cell spatial layout as a training target for the subsequent neural network model. Its actual purpose is to guide the cross-attention fusion model to learn how to generate a high-quality cell embedding that is consistent with the genetic module, serving as a training target for supervised machine learning. For example, compared to traditional Harmony embeddings, this special Harmony embedding performs explicit dimensionality reduction and optimization when inputting principal component analysis, changing the 50×50 matrix size of the traditional embedding to 30×30. This aims to reduce the computational complexity of the multi-head attention layer in the subsequent neural network.
[0111] Furthermore, the selection of 30 dimensions was carefully considered. From the perspective of information density, 30 dimensions sufficiently capture major biological variations and avoid high-order noise interference. From the perspective of computational efficiency, it significantly reduces the memory usage of the cross-attention fusion module, doubling the training speed. From the perspective of regularization effect, it brings a generalization gain of 0.037 to improve the F1 score across batch recognition. Therefore, the 30-dimensional Harmony embedding is not a simplification, but a finely tuned hyperparameter for single-cell multi-task learning, achieving a verifiable optimal balance between information preservation and computational efficiency.
[0112] In one embodiment, the hyperparameter optimization process automatically finds the loss function weights α, learning rate, weight decay coefficient, network embedding dimension, and batch size that optimize model performance through a hyperparameter scheduler. It is worth noting that the search for optimal hyperparameters is performed within a pre-defined range. For example, in one embodiment, the value range of α is [0.30, 0.70], with a step size of 0.02; the learning rate is searched within the logarithmic space [2.5e-4, 1e-3]; and the weight decay coefficient is searched within the logarithmic space [3e-6, 1e-4].
[0113] To achieve efficient search, the framework employs a multi-layered optimization strategy. At the data preprocessing level, when caching is enabled, the fluctuation matrix, module activity matrix, and Harmony embeddings are serialized and cached in memory. All subsequent hyperparameter experiments directly read from this cache, completely avoiding the redundant computational overhead of the data preprocessing stage. At the search execution level, each hyperparameter combination is evaluated in a complete cross-validation process, with early stopping optimization employed at each training fold.
[0114] Performance evaluation uses the mean cosine similarity on the cross-validation set as the objective function, with the optimization direction being maximization. Detailed results of all trials, including the validation similarity for each fold, are recorded in the database in real time. This design ensures the reproducibility of the search process and supports automatic resumption in case of interruption. After all trials are completed, the framework will output the optimal parameter combination and a dedicated α-parameter analysis report for subsequent model training and result interpretation.
[0115] In one embodiment, model training and validation are performed through a rigorous K-fold cross-validation process, aiming to train multiple independent and robust models using predetermined optimal hyperparameters. The specific process is as follows: First, the trainer is initialized using the optimal hyperparameter configuration. The training process employs a K-fold cross-validation strategy, with data partitioning using a fixed random seed and shuffling to ensure reproducibility of results and avoid bias introduced by data order. Subsequently, in the training of each fold, the training set data is loaded, and the last incomplete batch is discarded to ensure the stability of batch normalization layer computation. For example, K is set to 10, the maximum number of training iterations (epochs) is 300, and an early stopping mechanism is introduced to prevent overfitting. This mechanism monitors the validation set loss; if it does not decrease by more than a threshold 1e-3 within 15 consecutive epochs, the training of the current fold is terminated early.
[0116] After each training round, the loss and cosine similarity between the predicted embedding and the ground truth Harmony embedding are calculated on the validation set. Throughout the training process, only the model parameter states with the highest cosine similarity on the validation set are saved to a file. Simultaneously, the complete training loss and validation similarity sequence for each fold are recorded and saved to a file for subsequent performance analysis and visualization. For example, after all 10-fold cross-validation is completed, the system calculates the mean and standard deviation of the cosine similarities across all folds and writes this statistical result to a file. This process ultimately outputs a list containing 10 independent model state dictionaries, which together constitute a robust model ensemble whose performance evaluation includes not only average performance but also model stability.
[0117] In one embodiment, the post-training write-back and export process loads the best-performing single-fold model weights, performs forward inference on the entire dataset, and persists the generated multi-level cell embeddings and module statistics to a standard format file. Specifically, the optimal single-fold model parameters are first loaded, and the model is set to evaluation mode. Subsequently, inference is performed on the entire dataset using a large batch size of data without shuffling the order. During forward propagation, gradient computation is disabled to save memory and computational resources, and four key matrices—gene encoding, module encoding, cross-attention fusion encoding, and the final predicted Harmony embedding—are sequentially obtained. These tensors are transferred to the Central Processing Unit (CPU) and converted into multi-dimensional arrays.
[0118] Next, the four key matrices—gene encoding, module encoding, cross-attention fusion encoding, and the final predicted Harmony embedding—are recorded, with corresponding keys X_bio, X_mod, X_fusion, and X_pred_embedding. This provides each cell with a multi-granularity embedding from the original gene features to the final enhanced representation. Finally, the enhanced single-cell data is saved in a highly compressed h5ad file format.
[0119] Figure 3 This is a flowchart of the single-cell data augmentation representation method in this embodiment under the conditions of fixing the hyperparameter α to 0.7, disabling hyperparameter search, and performing 3-fold cross-validation. Figure 3 As shown, the process includes the following steps:
[0120] Step S310: Environment initialization and configuration loading. The program starts and parses the configuration. Upon detecting that a Graphics Processing Unit (GPU) is available, the computing device is automatically set to CUDA:0. The system is configured to skip the time-consuming hyperparameter optimization phase and directly use preset fixed parameters (such as learning rate, network dimension, etc.) and a 3-fold cross-validation scheme.
[0121] Step S320, Data Loading and Preprocessing. Read the original h5ad file and gene module CSV file. Perform data alignment to ensure that the genes in the expression matrix match the genes in the module definition, and remove mismatched genes. The final result is a standardized "adata" object and a gene module dictionary.
[0122] Step S330: Fluctuation Matrix Calculation and Caching. Based on the original counting matrix, a gene fluctuation matrix is calculated for each cell. This matrix is obtained by normalizing the library size, calculating the median gene expression, and taking the absolute value of its logarithmic deviation, which effectively reduces the influence of zero values. After calculation, the "adata" object containing this new matrix is saved as a cache file.
[0123] Step S340: Module Activity Calculation and Data Encapsulation. The preprocessed data is loaded directly from memory into GPU memory. The activity value of each gene module is calculated in parallel on the GPU, ultimately generating a cell module activity matrix. All data is encapsulated into a dataset object, which is directly returned as a tensor residing on the GPU.
[0124] Step S350: Trainer Initialization and Data Partitioning. Initialize the trainer and quickly load the dataset cached on the GPU in step S340. Using a 3-fold cross-validation strategy, randomly divide all cells into 3 parts (approximately 2 / 3 for the training set and approximately 1 / 3 for the validation set), and generate an index.
[0125] Step S360, cross-validation training. For each partition, the model parameters are updated using a multi-task loss function, and the cross-attention mechanism is used to dynamically fuse gene and module features. At the same time, an early stopping strategy is adopted to ensure the model's generalization ability.
[0126] Step S370, model saving. After training is complete, save the model parameters that perform best on the validation set for each fold as three separate files.
[0127] Step S380, Embedding Extraction and Result Export. Load the best model from one fold, perform a one-time forward inference on the entire dataset, and obtain the final biological embeddings, module embeddings, fusion embeddings, and predicted embeddings. Write these embedding matrices and module activity matrices back to the "adata" object and save them as the final h5ad file.
[0128] Figure 4 This is a flowchart of the single-cell data augmentation representation method under the conditions of starting hyperparameter search, fixing α=0.7, and performing 3-fold cross-validation, as shown in this embodiment. Figure 4 As shown, the process includes the following steps:
[0129] Step S410: Environment initialization and hyperparameter search preparation. The program starts, and the configuration detects that the GPU is available and sets it to CUDA:0. The key difference is that the hyperparameter optimizer is activated in this embodiment. This embodiment will perform 20 rounds of search.
[0130] Step S420 involves data loading, fluctuation matrix calculation, and data encapsulation. This includes reading the raw data, calculating the fluctuation matrix, loading the data into GPU memory, and calculating the module activity matrix. All processing results are cached, providing a unified and efficient data foundation for subsequent large-scale hyperparameter search experiments.
[0131] Step S430, Hyperparameter Optimization Loop. Perform 20 rounds of trials sequentially. In each round, sample a set of hyperparameters based on current knowledge. Instantiate the model using this set of hyperparameters and perform full 3-fold cross-validation training. Each fold of training includes an early stopping mechanism, using the mean cosine similarity of the validation set as the evaluation metric. The average score of the 3-fold validation is used as the performance score for that set of parameters and recorded in the database. Update the sampling strategy based on the score, favoring denser exploration around well-performing parameter regions.
[0132] Step S440: Perform formal training using the optimal hyperparameters. For each partition, the model parameters are updated using a multi-task loss function (weighted fusion embedding alignment loss and module reconstruction loss), and a cross-attention mechanism is used to dynamically fuse gene and module features. An early stopping strategy is employed to ensure the model's generalization ability. It is worth noting that the parameters here are the found optimal hyperparameter combination, not preset fixed parameters.
[0133] Step S450: Embedding Extraction and Result Export. Select the best-performing one-fold model, perform forward inference on the entire dataset, generate the final embedding matrices for each type, and write them all back to the "adata" object, saving it as the final h5ad file.
[0134] Figure 5 This embodiment is a flowchart illustrating a complete single-cell data augmentation representation method executed in a GPU environment, including hyperparameter optimization such as automatic search for multi-task loss weight α. Figure 5 As shown, the process includes the following steps:
[0135] Step S510: System Startup and α Search Declaration. The program initializes, explicitly initiating the hyperparameter search and specifically declaring that the α parameter will be included in the search range. The search space for α is set from 0.30 to 0.70, with a step size of 0.02. The system prepares GPU resources and creates the necessary directory structure.
[0136] Step S520, Data Preparation and Loading. Raw single-cell data and gene module definition files are read from the disk. After verification and alignment, the cell fluctuation matrix is calculated to overcome data sparsity. Subsequently, the complete expression matrix, fluctuation matrix, module activity matrix, and special Harmony embeddings as supervision signals are all loaded into the GPU memory.
[0137] Step S530: Hyperparameter optimization loop, automatically searching for α. The optimization framework underwent 20 rounds of trials. Each round of trials samples a complete set of hyperparameters, where α is a key variable to be optimized. For each set of parameters (e.g., α = 0.30), the system performs a rigorous 3-fold cross-validation: training the model and calculating the weighted total loss. Model performance is evaluated using the mean cosine similarity of the validation set.
[0138] Step S540: Model training based on optimal configuration. After the hyperparameter search, the system obtains a set of optimal parameter combinations, including the found best α value (α=0.58). Subsequently, the process uses this complete and validated set of optimal parameters to retrain the entire dataset using 3-fold cross-validation to produce the final, high-quality model.
[0139] Step S550, Embedding Generation and Result Export. The best-performing model is selected, and forward inference is performed on the entire dataset to generate the final biological embeddings, module embeddings, fusion embeddings, and predictive embeddings. All these embedding matrices are integrated back into the original "adata" object and saved as a standard h5ad file containing rich information.
[0140] In one embodiment of this application, the single-cell data uses a publicly available interferon-stimulated peripheral blood mononuclear cell dataset, which contains clearly defined cell type labels and batch information. Simultaneously, gene sets from Gene Set Enrichment Analysis (GSEA) data are used as the definitions of gene modules to ensure the reliability of prior biological knowledge. The statistical results for each gene module after execution are shown in Table 1.
[0141] Table 1
[0142]
[0143] Table 1 presents the statistical characteristics of the activity of each gene module. Here, "module" is the module name, used to identify different gene functional units; "n_genes" is the total number of genes contained in the module, reflecting the module size; "mean_activity" is the average activity value of the module across all cells, reflecting the overall activity level of that function; "cv" is the coefficient of variation, measuring the relative fluctuation of module activity among cells; "specificity" is the specificity, reflecting the maximum range of variation in module activity across cells; and "module_type" is the functional type label of the module. The table shows that the activity and heterogeneity of different modules differ significantly. For example, the modules named Module_2243 and Module_2290 in Table 1 have high average activities, indicating that these functions are generally more active in the cell population. At the same time, almost all modules have very high specificity values, indicating that the activity of each module is highly concentrated in a few specific cells, reflecting the high heterogeneity of cell population function. No clear correlation was found between module size and activity intensity.
[0144] To verify the robustness of the method, two testing modes were conducted: The first was a fixed-parameter mode: key hyperparameters were fixed (e.g., α=0.7), and no search was performed, testing the method's performance under the default configuration. The second was a hyperparameter search mode: automatic hyperparameter search was initiated, allowing the search for α values to find the optimal configuration on a specific dataset. The search results showed that different α values (e.g., 0.4, 0.64, 0.7, etc.) affected model performance, demonstrating the necessity of dynamically optimizing α.
[0145] With α fixed and without hyperparameter search, downstream clustering analysis is performed based on the cell embedding vectors, and the results are as follows: Figure 6a and Figure 6b , Figure 6a This is a representation of the embedding results and batch labels after embedding, displayed on the Uniform Manifold Approximation and Projection (UMAP) algorithm, a nonlinear dimensionality reduction algorithm. The horizontal axis UMAP1 and the vertical axis UMAP2 represent the first and second dimensions generated by the UMAP algorithm, respectively. The numerical values on the dimensions themselves do not have specific physical meaning, but they reflect the relative structure and distance of the data in high-dimensional space. The colors in the figure represent the distribution of different batches. It can be seen that cells from different batches are clearly separated after embedding, indicating that batch bias has a significant impact on cell embedding, and cells from different batches are incorrectly separated.
[0146] Figure 6bThis is a display of the embedding results and real-world cell labels on UMAP. In the same graph, the horizontal axis UMAP1 and the vertical axis UMAP2 represent the first and second dimensions generated by the UMAP algorithm, respectively. These are two dimensions generated by the UMAP dimensionality reduction algorithm; they are abstract in themselves but represent the structure of high-dimensional data, with each point representing a sample data point. From the color distribution of different real-world cell categories in the graph, we can see that cells of the same real-world category show obvious clustering after embedding, while cells of different real-world categories are clearly distinguishable. This indicates that after embedding, cells can be clustered well according to their real biological categories, and the algorithm preserves the biological differences among cells.
[0147] We used the Single-Cell Integration Benchmark (SCIB) evaluation suite, specifically developed for single-cell data integration. This tool provides a comprehensive set of metrics that measure the method's ability to both conserve biodiversity and remove batch effects. The evaluation results are shown in Table 2 below. In particular, our method leads in several key metrics and achieves the highest overall score.
[0148] Table 2
[0149]
[0150] Table 2 systematically evaluates the performance of various single-cell data integration methods. The evaluation dimensions include two main categories: biological conservation and batch correction, which are summarized into an overall score. Biological conservation is measured by standardized mutual information (nmi), adjusted Land index (ari), and cell type profile width (asw_label). A higher biological conservation score (Bio) indicates more complete preservation of the true biological structure. Batch correction is evaluated by batch profile width (asw_batch), graph connectivity (graph_conn), and isolated label F1 score (isolated_f1). A higher batch correction score (Batch) indicates less batch confusion and better preservation of topology.
[0151] The results show that the data integration methods X_fusion and X_pred_embedding performed exceptionally well. Specifically, X_fusion achieved the highest overall score (0.740), demonstrating superior biological conservation and batch correction compared to most comparative methods, particularly in preserving cell type structure (nmi=0.742, ari=0.610). X_pred_embedding followed closely with an overall score of 0.726, exhibiting excellent performance in removing batch effects (asw_batch=0.888). Overall, the proposed fusion embedding method achieves the best balance between preserving biological information and removing batch effects.
[0152] Figure 7 This is a flowchart illustrating the training process for deep embedding of single-cell data according to one embodiment of this application. Figure 7 As shown, the process includes the following steps:
[0153] Step S701, System configuration initialization. Initialize the configuration class, setting the data path, hyperparameter range, and computing device.
[0154] Step S702: Determine if the path file exists. If it exists, the process continues; otherwise, proceed to step S714 to end the process.
[0155] Step S703: Data preprocessing and fluctuation matrix generation. Single-cell h5ad data and gene module annotation files are loaded through the fluctuation feature processing module, and automatic optimization is performed according to the memory mode configuration.
[0156] Step S704: Calculate the gene fluctuation matrix. Perform gene alignment and calculate the fluctuation layer.
[0157] Step S705, Module Activity Matrix Construction. Based on the fluctuation matrix and gene module definitions, the activity value of each cell on each gene module is calculated to generate the cell module activity matrix.
[0158] Step S706, Hyperparameter Search. Hyperparameter optimization is performed, evaluating the performance of different hyperparameter combinations in a K-fold cross-validation loop, and determining the optimal parameters using the cosine similarity of the validation set as the objective function.
[0159] Step S707: Determine whether to disable search. If search is disabled, proceed to step S708; otherwise, proceed to step S709.
[0160] Step S708, use fixed parameters.
[0161] Step S709: Parallel hyperparameter search, perform a complete K-fold verification for each experiment, and finally record the optimal combination of α parameters.
[0162] Step S710, Cross-validation. Perform K-fold cross-validation training, using an early stopping mechanism to prevent overfitting, and save the best model at each fold.
[0163] Step S711: Extract four types of embeddings. Four types of cellular embeddings are extracted and output sequentially: gene-coding embedding, module-coding embedding, cross-attention fusion embedding, and the final predicted Harmony embedding.
[0164] Step S712, Result Write-back and Data Saving. Write all the embedding matrices generated in step S711 into the corresponding data structure, and save the result dataset containing all enhanced representations as the final h5ad format file.
[0165] Step S713: Generate a performance and biological statistics report.
[0166] Step S714, process ends.
[0167] Figure 8 This is a structural block diagram of the single-cell data augmentation representation device 80 in this embodiment, as shown below. Figure 8 As shown, the single-cell data augmentation and representation device 80 includes: a data acquisition module 82, a data processing module 84, and a fusion enhancement module 86; wherein: the data acquisition module 82 is used to acquire the original counting matrix of single-cell gene expression and the gene module dataset; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules; the data processing module 84 is used to perform gene feature transformation based on the original counting matrix to obtain a gene feature matrix; based on the gene feature matrix, the original counting matrix, and the gene module dataset, determine the cell module activity matrix; process the gene feature matrix through a gene encoder to generate gene latent vectors, and then process the cell module activity matrix... The attribute matrix is processed by the module encoder to generate module latent vectors; the fusion enhancement module 86 is used to perform interactive fusion of gene latent vectors and module latent vectors as inputs to the cross-attention fusion model under the optimization objective defined by the comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of the first loss term and the second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell enhanced representation output by the model and the reference embedding representation as the supervision signal; the second loss term is calculated based on the reconstruction error of gene latent vectors and module latent vectors; the fused latent vector is projected onto the target embedding space to generate a single-cell enhanced representation.
[0168] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can reside in the same processor; or the above modules can be located in different processors in any combination.
[0169] This embodiment also provides an electronic device, including a memory and a processor. The memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the above method embodiments. In some embodiments, the electronic device may be an image processing device, an artificial intelligence (AI) box, or a similar device. For example, the above-described electronic device may be connected to a video acquisition device, capable of acquiring raw video data in a target detection scene, and executing the above-described single-cell data augmentation representation method based on its configured computer program.
[0170] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0171] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0172] S1, obtain the raw counting matrix and gene module dataset of single-cell gene expression; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules;
[0173] S2, based on the original counting matrix, gene feature transformation is performed to obtain the gene feature matrix;
[0174] S3, based on the gene feature matrix, the original counting matrix, and the gene module dataset, determines the cell module activity matrix;
[0175] S4. Gene feature matrix is processed by gene encoder to generate gene latent vector, and cell module activity matrix is processed by module encoder to generate module latent vector.
[0176] S5 uses gene latent vectors and module latent vectors as inputs to the cross-attention fusion model. Under the optimization objective defined by the comprehensive loss function, the models perform interactive fusion to obtain the fused latent vectors output by the cross-attention fusion model. The comprehensive loss function is a weighted sum of the first loss term and the second loss term. The first loss term is calculated based on the similarity between the single-cell augmentation representation output by the model and the reference embedding representation used as a supervision signal. The second loss term is calculated based on the reconstruction error of gene latent vectors and module latent vectors.
[0177] S6 projects the fused latent vectors into the target embedding space to generate a single-cell augmented representation.
[0178] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated in this embodiment.
[0179] Furthermore, in conjunction with the single-cell data augmentation representation method provided in the above embodiments, this embodiment can also provide a computer-readable storage medium on which a computer program is stored.
[0180] It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. All other embodiments derived by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.
[0181] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0182] Obviously, the accompanying drawings are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application.
[0183] The term "embodiment" in this application refers to a specific feature, structure, or characteristic described in connection with an embodiment that may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily imply the same embodiment, nor does it imply that it is mutually exclusive with or independent of other embodiments. It will be clearly or implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0184] The above embodiments merely illustrate several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.
Claims
1. A method for augmenting single-cell data representation, characterized in that, The method includes: Obtain the raw counting matrix and gene module dataset of single-cell gene expression; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules; Gene feature matrix is obtained by performing gene feature transformation based on the original counting matrix. Based on the gene feature matrix, the original counting matrix, and the gene module dataset, the cell module activity matrix is determined. The gene feature matrix is processed by a gene encoder to generate gene latent vectors, and the cell module activity matrix is processed by a module encoder to generate module latent vectors. Using the gene latent vector and the module latent vector as inputs to the cross-attention fusion model, interactive fusion is performed under an optimization objective defined by a comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell augmentation representation output by the model and the reference embedding representation used as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vector and the module latent vector; The fused latent vectors are projected into the target embedding space to generate a single-cell augmented representation.
2. The single-cell data augmentation representation method according to claim 1, characterized in that, The process of performing gene feature transformation based on the original counting matrix to obtain a gene feature matrix includes: The original counting matrix is subjected to fluctuation feature transformation, specifically by cell library normalization, log-centering of gene medians, and calculation of absolute differences, to obtain a gene fluctuation matrix as the gene feature matrix.
3. The single-cell data augmentation representation method according to claim 2, characterized in that, The process of determining the cell module activity matrix based on the gene feature matrix, the original counting matrix, and the gene module dataset includes: Based on the original counting matrix, the detection rate of genes in each cell within the gene module is calculated; Based on the gene feature matrix, calculate the mean fluctuation, coefficient of variation, and specificity of genes within the gene module in each cell; The basic activity is calculated based on the detection rate and the mean fluctuation, and the basic activity is dynamically weighted based on the fluctuation variation coefficient and the fluctuation specificity to obtain the module activity value. The module activity values of all the gene modules are collected to form the cell module activity matrix.
4. The single-cell data augmentation representation method according to claim 3, characterized in that, The step of calculating the detection rate of genes within the gene module in each cell based on the original counting matrix includes: Obtain the gene index list corresponding to each gene module in the gene module dataset; Based on the gene index list of the gene module, extract the columns corresponding to the indexes in the gene index list from the original counting matrix to form the original counting submatrix; The number of elements greater than zero in each row of the original counting submatrix is calculated, and the number of elements is divided by the total number of genes contained in the current gene module to obtain the detection rate.
5. The single-cell data augmentation representation method according to claim 3, characterized in that, The calculation of the mean fluctuation, coefficient of variation, and fluctuation specificity of genes within the gene module in each cell based on the gene feature matrix includes: Obtain the gene index list corresponding to each gene module in the gene module dataset; Based on the gene index list of the gene module, extract the columns corresponding to the indexes in the gene index list from the gene feature matrix to form a gene feature submatrix; The arithmetic mean of the fluctuation values for each cell is calculated along the column direction of the gene feature sub-matrix to obtain the fluctuation mean. The standard deviation of the fluctuation value of each cell is calculated along the column direction of the gene feature sub-matrix, and the standard deviation is divided by the sum of the fluctuation mean and a very small constant to obtain the fluctuation variation coefficient. For each cell, the difference between the maximum and minimum fluctuation values within the gene module is found, and then divided by the sum of the maximum and minimum values and the sum of the minimum constants to obtain the fluctuation specificity.
6. The single-cell data augmentation representation method according to claim 1, characterized in that, The gene encoder sequentially comprises: a first linear transformation layer, a first batch normalization layer, a first activation function layer, a first discard layer, a second linear transformation layer, a first normalization layer, and a second activation function layer; the module encoder sequentially comprises: a third linear transformation layer, a second batch normalization layer, a third activation function layer, and a second discard layer.
7. The single-cell data augmentation representation method according to claim 1, characterized in that, The method uses the gene latent vector and the module latent vector as inputs to the cross-attention fusion model, and performs interactive fusion under an optimization objective defined by a comprehensive loss function to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell augmentation representation output by the model and the reference embedding representation as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vector and the module latent vector, including: The gene latent vector is used as the query vector, and the module latent vector is used as the key vector and value vector. Attention calculation is performed through the cross-attention fusion model to obtain the fused latent vector; wherein, the attention calculation adopts a multi-head attention mechanism.
8. The single-cell data augmentation representation method according to claim 1, characterized in that, The step of projecting the fused latent vector onto the target embedding space to generate the single-cell augmented representation includes: The fused latent vector is linearly transformed to map its dimension to the same dimension space as the target embedding space, ultimately generating the enhanced representation of the single cell.
9. A single-cell data augmentation and representation device, characterized in that, include: The module comprises a data acquisition module, a data processing module, and a fusion enhancement module; among which: The data acquisition module is used to acquire the original counting matrix of gene expression in single cells and the gene module dataset; the gene module dataset can characterize the mapping relationship between genes and one or more gene modules. The data processing module is used to perform gene feature transformation based on the original counting matrix to obtain a gene feature matrix; determine the cell module activity matrix based on the gene feature matrix, the original counting matrix, and the gene module dataset; process the gene feature matrix through a gene encoder to generate gene latent vectors, and process the cell module activity matrix through a module encoder to generate module latent vectors. The fusion enhancement module is used to perform interactive fusion under the optimization objective defined by the comprehensive loss function, using the gene latent vector and the module latent vector as inputs to the cross-attention fusion model, to obtain the fused latent vector output by the cross-attention fusion model; the comprehensive loss function is a weighted sum of a first loss term and a second loss term; wherein, the first loss term is calculated based on the similarity between the single-cell enhanced representation output by the model and the reference embedding representation as a supervision signal; the second loss term is calculated based on the reconstruction error of the gene latent vector and the module latent vector; the fused latent vector is projected onto the target embedding space to generate a single-cell enhanced representation.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the single-cell data augmentation representation method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Gene function diagnosis system based on twin network and multi-order tensor information
CN118412040A
High-precision single cell classification method and device based on artificial intelligence algorithm
CN119132401A