In accordance with the Measures for Ethical Review of Life Science and Medical Research Involving Human Subjects promulgated in China on February 18, 2023, research using publicly available data may meet the criteria for exemption from ethical review. This study used only publicly available, de-identified secondary transcriptomic data and did not involve new human participant recruitment, human sample collection, or animal experiments. Therefore, additional institutional ethical approval was not required. No animal experiments were performed in this study. Therefore, approval from the institutional animal care and use committee was not applicable.
Data sources for endoplasmic reticulum stress-related genes in atrial fibrillation
In this study, publicly available AF-related transcriptomic datasets were retrieved from the GEO database, including GSE41177, GSE79768, GSE115574, GSE14975, and GSE165838. Detailed information on the GSE datasets is provided in Supplementary File 1—Supplementary Table S1. GSE41177 and GSE79768 were used to construct the integrated bulk transcriptomic training cohort, whereas GSE115574 and GSE14975 were used as two independent external validation cohorts. GSE165838 was used for single-cell transcriptomic analysis. Because these datasets were generated on different platforms and may differ in tissue source, clinical background, and sample composition, each dataset was preprocessed separately according to its platform characteristics prior to integration or validation. Batch-effect correction was then performed using the sva R package for the merged training cohort. The endoplasmic reticulum stress-related gene set was retrieved from the GeneCards database with a relevance score ≥ 3 and, after deduplication, formed the target gene list used in this study.
Analysis of differentially expressed genes
After data standardization and normalization, the R package limma was used to identify differentially expressed genes (DEGs) in the integrated training set. DEGs were defined using the following significance criteria: false discovery rate-adjusted P value (adj.P.Val) < 0.05 and |log2FC| > 0.58510. To visualize the expression patterns of DEGs, volcano plots and heatmaps were generated using the ggplot2 and pheatmap packages, respectively.
WGCNA analysis
To elucidate potential mechanisms of coordinated gene regulation, define the association patterns between co-expression modules and clinical trait variables, and identify core biomarkers or therapeutic targets with translational potential, WGCNA was applied11.
A weighted co-expression network was constructed using the WGCNA package in R. The soft-thresholding power (β) was selected according to the scale-free topology criterion; the corresponding β value was chosen for subsequent analyses when the scale-free topology fit index (R2) reached and remained above 0.8512. During module identification, parameters related to dynamic tree cutting and module detection sensitivity were optimized to improve module boundary resolution and stability. Finally, modules significantly associated with the target trait were extracted, and intramodular hub genes were identified as candidate gene sets for downstream analyses.
Enrichment analysis of AF-related DEGs
To precisely identify hub genes, the DEGs were first intersected with genes from the key WGCNA modules to define a set of genes implicated in AF pathogenesis. Next, this AF gene set was further intersected with ERS-related genes, and the resulting overlapping genes were retained for subsequent analyses.
Functional enrichment of the screened genes was evaluated using Gene Ontology (GO) and Kyoto Encyclopedia of Genes and Genomes (KEGG) analyses. GO terms were analyzed with the R package clusterProfiler to summarize enrichment across biological process (BP), cellular component (CC), and molecular function (MF) categories13. KEGG analysis was then used to identify enriched pathways associated with the target genes14. Enrichment results with an adjusted P value < 0.05 were considered statistically significant. The leading GO terms and KEGG pathways were displayed as bar plots and bubble plots using ggplot2.
Protein-protein interaction (PPI) analysis
PPI analysis was performed by uploading the intersected gene set to the STRING database, with the organism restricted to Homo sapiens. Disconnected nodes were removed, and interactions were retrieved using a medium confidence score threshold (combined score ≥ 0.4). The resulting PPI network was then imported into a network visualization and analysis tool for topological analysis to identify key nodes.
Construction of a candidate AF-ERS classification model based on 12 machine-learning algorithms
In this study, an ensemble classification framework based on twelve conventional machine-learning algorithms was developed to screen ERS-related candidate signature genes associated with AF and to optimize classification performance. For data partitioning, after standardization and normalization, GSE41177 and GSE79768 were merged to generate the training cohort expression matrix. GSE115574 was used as an independent external validation cohort to evaluate model generalizability. Specifically, DEGs were first identified in the training cohort (|log2FC| >0.585, adjusted p < 0.05). These DEGs were then intersected with genes from the key WGCNA modules and ERS-related genes, and the resulting gene set was used as the input features for model construction.
To link ERS-related genes with the AF phenotype, a candidate classification model was developed using 12 machine-learning approaches: Lasso, Ridge, stepwise generalized linear model (Stepglm), extreme gradient boosting (XGBoost), random forest (RF), elastic net (Enet), partial least squares regression for generalized linear models (plsRglm), generalized boosted regression modeling (GBM), naive Bayes, linear discriminant analysis (LDA), glmBoost, and support vector machine (SVM). A systematic combinatorial modeling strategy was adopted by adding a second algorithm to the first and integrating them via the tuning parameter α, yielding 113 combinations of feature selection and model fitting that were comprehensively evaluated. Model discrimination was assessed by calculating the area under the receiver operating characteristic curve (AUC). According to previously reported model-selection criteria, the final candidate framework was defined as the model with the best overall performance, as assessed by the mean AUC across the training and validation cohorts.
This combinatorial modeling strategy was informed by prior studies in biomedical machine learning15,16,17. Collectively, these studies indicate that no single algorithm consistently outperforms others across datasets and analytical tasks. Based on this premise, adopting an ensemble learning and combinatorial modeling framework can increase the likelihood of obtaining a high-performing candidate model with more stable generalizability and improve the robustness of model selection.
Subsequently, SHapley Additive exPlanations (SHAP) values were applied to interpret the machine-learning model by visualizing the key features driving AF classification, thereby quantifying the contribution of each feature to the predicted outcome and illustrating how individual signature genes influence the final model output18.
Evaluation of model performance and external validation of the optimal model
The performance of the optimal model was evaluated in the training cohort and in the independent external validation cohort (GSE115574). At the model level, a confusion matrix was constructed based on the predicted class labels, and the corresponding classification metrics were reported. Receiver operating characteristic (ROC) curves were generated using the R package pROC, and the AUC was calculated to quantify discriminative performance.
At the biomarker level, single-gene ROC curves were plotted for each key gene in the optimal model, and the corresponding AUCs were computed to assess their individual discriminatory ability. In addition, differential expression of the key genes was summarized using a volcano plot, and boxplots were used to depict their expression distributions in disease versus healthy samples. To further evaluate the generalizability of the previously defined optimal model-derived gene signature, an additional independent external validation was performed using GSE14975. GSE14975 contains transcriptomic data from left atrial appendage samples, including five atrial fibrillation samples and five sinus rhythm/control samples. All genes included in the locked signature were available in this dataset. To maintain consistency with the original cross-cohort analytical workflow, the development cohort and GSE14975 were harmonized using ComBat with the dataset source as the batch variable. This harmonization was performed in an unsupervised manner. Importantly, disease/control labels from GSE14975 were not used for feature selection, coefficient estimation, threshold determination, or hyperparameter tuning.
The optimal model-derived scoring model was fitted using the development cohort only and then applied to GSE14975 for external validation. Model performance in GSE14975 was assessed using receiver operating characteristic curve analysis, area under the curve, 95% confidence interval (CI), sensitivity, specificity, accuracy, positive and negative predictive values, and Brier score. In addition, single-gene ROC curves were generated for all optimal model-derived genes in GSE14975 to illustrate their individual discriminatory ability. To further assess potential overfitting in the development cohort, repeated 10-fold cross-validation and bootstrap optimism correction were performed using the gene signature derived from the locked optimal model. For repeated cross-validation, the development cohort was repeatedly partitioned into 10 folds, and model discrimination was summarized across all iterations. For bootstrap validation, 1,000 bootstrap resamples were generated to estimate the optimism of the apparent development-set performance and to calculate the optimism-corrected AUC. Because the final signature was derived from the optimal model, the contribution of each gene was interpreted primarily according to the absolute magnitude and direction of the model coefficients. In addition, single-gene ROC analyses were performed in GSE14975 to illustrate the individual discriminatory ability of each component gene. For visualization purposes, single-gene ROC curves were oriented to reflect discriminatory ability regardless of whether higher or lower expression was associated with AF.
Gene set enrichment analysis (GSEA)
To explore the functional implications of the key genes, GSEA was performed using samples from the disease group19. For each key gene, samples were stratified into high- and low-expression subgroups using the median expression value in the disease group as the cutoff. The mean expression difference between the two subgroups for each gene was calculated, and a ranked gene list was generated in descending order as input for enrichment analysis. GSEA was conducted using the R package clusterProfiler, with gene sets obtained from the MSigDB collection c2.cp.kegg.Hs.symbols.gmt. Statistical significance was defined as p < 0.05. Enrichment direction was determined by the sign of the normalized enrichment score (NES), and enrichment plots were generated for representative pathways.
Assessment of immune cell subtype abundance and differential expression
The CIBERSORT deconvolution algorithm was applied to estimate the relative abundance of infiltrating immune cell subsets and their interrelationships across samples. Based on the LM22 leukocyte signature matrix, immune cell composition was quantitatively inferred from gene expression profiles using the R package CIBERSORT20. A threshold of p < 0.05 was used to filter results, and only samples passing this criterion were retained for subsequent analyses. Boxplots were generated to compare the estimated relative fractions of immune-cell subsets between the AF and control groups. In addition, Spearman's correlation analysis was performed to assess associations between immune cell infiltration levels and hub gene expression.
Single-cell analysis
Single-cell transcriptomic analysis was performed using the GEO dataset GSE165838. Raw gene-cell count matrices were imported into R and processed using Seurat v4.4.0. For each sample, a Seurat object was generated using CreateSeuratObject with min.cells = 5 and min.features = 300. Quality-control metrics, including the number of detected genes, total unique molecular identifier (UMI) counts, mitochondrial gene percentage, ribosomal gene percentage, and hemoglobin gene percentage, were calculated for each cell. Cells were retained if they had more than 500 detected genes, fewer than 5,000 UMI counts, mitochondrial gene percentage < 25%, ribosomal gene percentage > 3%, and hemoglobin gene percentage < 1%. Genes detected in fewer than three cells were removed. MALAT1 and mitochondrial genes were also excluded before downstream analysis. DoubletFinder was used to detect and exclude potential doublets. Briefly, cells were split by sample identity, and doublet detection was performed separately for each sample using principal components 1–30.
The pN parameter was set to 0.25, and the optimal pK value was selected according to the maximal BC metric obtained from parameter sweeping. The expected doublet rate was estimated according to the number of recovered cells in each sample, with rates of 2.5%, 5%, and 6.5% used for samples with relatively low, intermediate, and high cell numbers, respectively. Only cells classified as singlets were retained. Ambient RNA contamination was further estimated using DecontX, and cells with a contamination score ≥ 0.2 were excluded. After quality control, doublet removal, and ambient RNA filtering, 40,886 cells and 23,947 genes were retained for downstream analysis. The filtered single-cell dataset was normalized with the LogNormalize method using a scale factor of 10,000, followed by identification of highly variable genes. The data were then scaled before principal component analysis.
To reduce sample-specific batch effects, Harmony was applied using orig.ident as the batch variable. Uniform Manifold Approximation and Projection (UMAP) visualization and nearest-neighbor graph construction were performed using the first 15 Harmony-corrected dimensions21. Clustering was performed using the Louvain algorithm, and multiple clustering resolutions were evaluated. The final major cell-type annotation was based on the clustering result at resolution 0.05. Cell clusters were manually annotated according to canonical marker-gene expression. This marker-based annotation strategy is consistent with prior single-cell immune-profiling studies22. T cells were identified by CD3D, CD3E, and TRAC; natural killer (NK) cells by NKG7, GNLY, NCAM1, and KLRG1; monocyte-macrophage cells by LYZ, CD14, FCGR3A, CD68, CD163, FCN1, TYROBP, S100A8, and S100A9; B cells by MS4A1 and CD79A; plasma cells by MZB1 and XBP1; endothelial cells by PECAM1, VWF, and CDH5; vascular smooth muscle cells by ACTA2, TAGLN, MYH11, and MYL9; fibroblasts by DCN, LUM, COL1A1, COL1A2, and PDGFRA; neutrophil-like cells by FCGR3B, CXCR2, S100A8, and MPO; mast cells by TPSB2; and dendritic cells by LILRA4, CD1C, and XCR1. Marker-gene expression across clusters was visualized using dot plots, and the expression distribution of the final ERS-related hub genes was visualized on UMAP embeddings.
To quantify ERS-related transcriptional activity at the single-cell level, the final hub-gene set was used to calculate cell-wise signature scores using AUCell, single-sample gene set enrichment analysis, and Seurat AddModuleScore. For AUCell, cell rankings were constructed from the normalized RNA expression matrix, and AUC scores were calculated using the hub-gene set with the top 10% of ranked genes as the maximum ranking threshold. For ssGSEA, enrichment scores were calculated using the GSVA package. The three scoring outputs were centered and scaled, then min-max normalized, and finally summed to generate an integrated ERS-related composite score for each cell. The distribution of the composite score was compared across annotated cell populations to evaluate cell-type heterogeneity of the ERS-related program. Because the monocyte-macrophage lineage exhibited prominent ERS-related signature enrichment and was closely associated with immune-inflammatory remodeling, it was selected for subsequent within-lineage analyses. Monocyte-macrophage cells were divided into high- and low-score groups according to the median ERS-related composite score. Pseudotime trajectory analysis was then performed on monocyte-macrophage cells using Monocle.
For pseudotime analysis, a CellDataSet object was created from the raw count matrix using a negative binomial expression model. Size factors and dispersions were then estimated. Ordering genes were selected using a mean expression threshold of ≥ 0.1 and empirical dispersion greater than the fitted dispersion. Dimensionality was reduced with the DDRTree algorithm, and cells were ordered along the inferred trajectory. The dynamic expression patterns of ERS-related hub genes along pseudotime were visualized. Cell-cell communication analysis was performed using CellChat to explore potential ligand-receptor interactions involving monocyte-macrophage cells with different ERS-related scores. For this analysis, monocyte-macrophage cells were labeled as high-score or low-score according to the median composite score, while other cells retained their original cell-type labels. The normalized RNA expression matrix and corresponding cell-group annotations were used to create the CellChat object. For cell-cell communication analysis, the human CellChatDB database was selected, and only secreted signaling interactions were evaluated. Overexpressed genes and ligand-receptor pairs were detected before calculating communication probabilities. Cell groups containing fewer than 10 cells were excluded from the interaction analysis. Pathway-level communication probabilities were subsequently estimated and aggregated to compare the number and strength of interactions among cell populations. To facilitate reproducibility, a checkpoint table is provided below linking each protocol step to its corresponding expected output figure or table (Supplementary File 1—Supplementary Table S2).