You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用clusterProfiler的gseWP函数出现No gene can be mapped错误求助

问题:clusterProfiler包gseWP函数基因映射失败

使用clusterProfiler包(版本4.2.2)的gseWP函数时,出现check_gene_id(geneList, geneSets)无法正常工作的问题,运行后提示---> No gene can be mapped....。尝试禁用该函数但未成功,而gseKEGG函数可以正常运行。

复现代码

> library(clusterProfiler); packageVersion("clusterProfiler") 
[1] ‘4.2.2’

> data(geneList, package="DOSE")

> gseWP(geneList, organism = "Homo sapiens")

错误信息

preparing geneSet collections...
---> Expected input gene ID:
Error in check_gene_id(geneList, geneSets) :
---> No gene can be mapped....

相关函数定义

check_gene_id <- function(geneList, geneSets) {
    if (all(!names(geneList) %in% unique(unlist(geneSets)))) {
        sg <- unlist(geneSets[1:10])
        sg <- sample(sg, min(length(sg), 6))
        message("---> Expected input gene ID: ", paste0(sg, collapse=','))
        stop("---> No gene can be mapped....")
    }}

 geneSets <- getGeneSet(USER_DATA)
 
 getGeneSet <- function(USER_DATA) {
    if (inherits(USER_DATA, "environment")) { 
        res <- get("PATHID2EXTID", envir = USER_DATA)
    } else if (inherits(USER_DATA, "GSON")) {
        gsid2gene <- USER_DATA@gsid2gene
        res <- split(gsid2gene$gene, gsid2gene$gsid) 
    } else {
        stop("not supported")
    }
    return(res)
 }
 
  USER_DATA <- build_Anno(TERM2GENE, TERM2NAME)

sessionInfo

> sessionInfo()

R version 4.1.3 (2022-03-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggridges_0.5.4        RCy3_2.14.2           RColorBrewer_1.1-3    GSEABase_1.56.0       graph_1.72.0         
 [6] annotate_1.72.0       XML_3.99-0.11         GO.db_3.14.0          jsonlite_1.8.2        rWikiPathways_1.14.0 
[11] DOSE_3.20.1           org.Mm.eg.db_3.14.0   org.Dr.eg.db_3.14.0   org.Hs.eg.db_3.14.0   AnnotationDbi_1.56.2 
[16] IRanges_2.28.0        S4Vectors_0.32.4      Biobase_2.54.0        BiocGenerics_0.40.0   enrichplot_1.14.2    
[21] clusterProfiler_4.2.2 plyr_1.8.7            forcats_0.5.2         stringr_1.4.1         dplyr_1.0.10         
[26] purrr_0.3.5           readr_2.1.3           tidyr_1.2.1           tibble_3.1.8          ggplot2_3.3.6        
[31] tidyverse_1.3.2       

loaded via a namespace (and not attached):
  [1] utf8_1.2.2                  tidyselect_1.1.2            RSQLite_2.2.18              grid_4.1.3                 
  [5] BiocParallel_1.28.3         Rtsne_0.16                  scatterpie_0.1.8            munsell_0.5.0               
  [9] base64url_1.4               codetools_0.2-18            interp_1.1-3                pbdZMQ_0.3-7               
 [13] withr_2.5.0                 colorspace_2.0-3            GOSemSim_2.20.0             phyloseq_1.38.0            
 [17] knitr_1.40                  uuid_1.1-0                  rstudioapi_0.14             MatrixGenerics_1.6.0       
 [21] repr_1.1.4                  GenomeInfoDbData_1.2.7      hwriter_1.3.2.1             polyclip_1.10-0            
 [25] bit64_4.0.5                 farver_2.1.1                rhdf5_2.38.1                downloader_0.4              
 [29] vctrs_0.4.2                 treeio_1.18.1               generics_0.1.3              xfun_0.33                   
 [33] R6_2.5.1                    GenomeInfoDb_1.30.1         graphlayouts_0.8.2          RJSONIO_1.3-1.6            
 [37] bitops_1.0-7                rhdf5filters_1.6.0          microbiome_1.17.41          cachem_1.0.6               
 [41] fgsea_1.20.0                gridGraphics_0.5-1          DelayedArray_0.20.0         assertthat_0.2.1           
 [45] scales_1.2.1                googlesheets4_1.0.1         ggraph_2.1.0                gtable_0.3.1               
 [49] tidygraph_1.2.2             rlang_1.0.6                 splines_4.1.3               lazyeval_0.2.2              
 [53] gargle_1.2.1                broom_1.0.1                 modelr_0.1.9                reshape2_1.4.4              
 [57] backports_1.4.1             qvalue_2.26.0               tools_4.1.3                 ggplotify_0.1.0            
 [61] ellipsis_0.3.2              biomformat_1.22.0           sessioninfo_1.2.2           Rcpp_1.0.9                 
 [65] base64enc_0.1-3             zlibbioc_1.40.0             RCurl_1.98-1.9              deldir_1.0-6               
 [69] viridis_0.6.2               haven_2.5.1                 SummarizedExperiment_1.24.0 ggrepel_0.9.1               
 [73] cluster_2.1.4               fs_1.5.2                    magrittr_2.0.3              data.table_1.14.2          
 [77] DO.db_2.9                   reprex_2.0.2                googledrive_2.0.0           matrixStats_0.62.0         
 [81] hms_1.1.2                   patchwork_1.1.2             evaluate_0.17               xtable_1.8-4               
 [85] jpeg_0.1-9                  readxl_1.4.1                gridExtra_2.3               compiler_4.1.3              
 [89] crayon_1.5.2                shadowtext_0.1.2            htmltools_0.5.3             tzdb_0.3.0                 
 [93] ggfun_0.0.7                 mgcv_1.8-40                 aplot_0.1.8                 RcppParallel_5.1.5         
 [97] lubridate_1.8.0             DBI_1.1.3                   tweenr_2.0.2                dbplyr_2.2.1               
[101] MASS_7.3-58.1               ShortRead_1.52.0            Matrix_1.5-1                ade4_1.7-19                
[105] permute_0.9-7               cli_3.4.1                   uchardet_1.1.0              parallel_4.1.3              
[109] igraph_1.3.5                GenomicRanges_1.46.1        pkgconfig_2.0.3             GenomicAlignments_1.30.0   
[113] IRdisplay_1.1               xml2_1.3.3                  foreach_1.5.2               ggtree_3.2.1               
[117] multtest_2.50.0             XVector_0.34.0              rvest_1.0.3                 yulab.utils_0.0.5          
[121] digest_0.6.29               vegan_2.6-2                 dada2_1.22.0                Biostrings_2.62.0          
[125] cellranger_1.1.0            fastmatch_1.1-3             tidytree_0.4.1              Rsamtools_2.10.0           
[129] rjson_0.2.21                lifecycle_1.0.3             nlme_3.1-158                Rhdf5lib_1.16.0            
[133] viridisLite_0.4.1           fansi_1.0.3                 pillar_1.8.1                lattice_0.20-45            
[137] KEGGREST_1.34.0             fastmap_1.1.0               httr_1.4.4                  survival_3.4-0              
[141] glue_1.6.2                  png_0.1-7                   iterators_1.0.14            bit_4.0.4                   
[145] ggforce_0.4.1               stringi_1.7.8               blob_1.2.3                  latticeExtra_0.6-30        
[149] memoise_2.0.1               IRkernel_1.3                ape_5.6-2  

解决方案

1. 确认基因ID类型不匹配

gseWP基于WikiPathways数据库,其默认使用的基因ID类型(如Ensembl ID、Entrez ID)和你输入的geneList中的ID类型不匹配,这是核心问题。gseKEGG能正常运行,说明你的基因ID符合KEGG的要求,但不匹配WikiPathways的ID系统。

先查看当前geneList的ID类型:

head(names(geneList))

2. 转换基因ID格式

使用clusterProfiler的bitr函数将基因ID转换为WikiPathways支持的类型(以Entrez ID为例):

library(clusterProfiler)
# 提取geneList中的基因名
gene_symbols <- names(geneList)
# 转换为Entrez ID,需确保org.Hs.eg.db已加载
gene_entrez <- bitr(gene_symbols, fromType="SYMBOL", toType="ENTREZID", OrgDb=org.Hs.eg.db)
# 构建新的geneList,保留原有的排序和表达量
new_geneList <- geneList[gene_entrez$SYMBOL]
names(new_geneList) <- gene_entrez$ENTREZID
# 去除转换失败的NA值
new_geneList <- new_geneList[!is.na(names(new_geneList))]

转换完成后重新运行gseWP:

gseWP(new_geneList, organism = "Homo sapiens")

3. 查看WikiPathways支持的ID类型

如果不确定WikiPathways使用的ID格式,可通过rWikiPathways包查询:

library(rWikiPathways)
# 获取人类通路列表
pathways <- listPathways("Homo sapiens")
# 取第一个通路查看基因ID格式
sample_pathway <- getPathway(pathways[1])
gene_ids <- pathwayGenes(sample_pathway)$id
head(gene_ids)

根据输出调整bitr函数中的toType参数。

4. 绕过检查函数(不推荐)

若需临时跳过检查,可重新定义check_gene_id函数覆盖原函数:

check_gene_id <- function(geneList, geneSets) {
  invisible()
}

但这种方法只是跳过了错误提示,基因不匹配的问题依然存在,可能导致后续分析结果无效,不建议使用。

内容的提问来源于stack exchange,提问作者vollkorrn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 05:05:55