在R中运行GDCprepare函数时遇到报错问题求助
TCGAbiolinks运行GDCprepare时的列索引错误解决
问题背景
复制视频代码使用TCGAbiolinks包查询下载TCGA-BRCA项目RNA-Seq数据时,执行tcga_brca_data <- GDCprepare(query_TCGA)触发错误,同时出现3条解析警告,提示调用problems()查看详情。
报错信息
Error in `map()`: i In index: 1. i With name: 1. Caused by error in `y[, 2:4]`: ! Can't subset columns past the end. i Locations 2, 3, and 4 don't exist. i There is only 1 column. Run `rlang::last_error()` to see where the error occurred.
复现代码
library(TCGAbiolinks) library(tidyverse) library(maftools) library(pheatmap) library(SummarizedExperiment) # 获取项目列表 gdcprojects <- getGDCprojects() # 构建初始查询 query_TCGA <- GDCquery(project = 'TCGA-BRCA', data.category = 'Transcriptome Profiling') output_query_TCGA <- getResults(query_TCGA) # 构建基因表达数据查询 query_TCGA <- GDCquery(project = 'TCGA-BRCA', data.category = 'Transcriptome Profiling', experimental.strategy = 'RNA-Seq', workflow.type = 'STAR - Counts', access = 'open', barcode = c('TCGA-LL-A73Y-01A-11R-A33J-07', 'TCGA-E2-A1IU-01A-11R-A14D-07','TCGA-AO-A03U-01B-21R-A10J-07')) getResults(query_TCGA) # 下载数据 GDCdownload(query_TCGA) # 预处理数据 tcga_brca_data <- GDCprepare(query_TCGA)
错误原因
- TCGAbiolinks版本与当前GDC数据库的元数据结构不兼容,旧版本包无法解析新的返回格式
- 查询参数未明确指定
data.type,导致返回的文件结构不符合预期(仅包含1列数据,而包预期有2-4列) - 本地缓存的下载文件损坏,导致解析时出错
解决方案
1. 更新TCGAbiolinks到最新版本
BiocManager::install("TCGAbiolinks", update = TRUE, force = TRUE)
重启R会话后重新加载包。
2. 优化查询参数,明确指定数据类型
在查询中添加data.type = 'Gene Expression Quantification',确保返回的是标准的基因表达计数文件:
query_TCGA <- GDCquery(project = 'TCGA-BRCA', data.category = 'Transcriptome Profiling', data.type = 'Gene Expression Quantification', # 新增参数 experimental.strategy = 'RNA-Seq', workflow.type = 'STAR - Counts', access = 'open', barcode = c('TCGA-LL-A73Y-01A-11R-A33J-07', 'TCGA-E2-A1IU-01A-11R-A14D-07','TCGA-AO-A03U-01B-21R-A10J-07'))
3. 强制重新下载数据,覆盖缓存
GDCdownload(query_TCGA, overwrite = TRUE)
4. 查看解析警告详情
运行problems()函数,确认具体是哪些文件解析失败,针对性调整barcode或查询条件:
problems()
验证
完成上述步骤后,重新运行GDCprepare(query_TCGA),应能正常生成SummarizedExperiment对象,可通过class(tcga_brca_data)验证结果类型。
内容的提问来源于stack exchange,提问作者DevelopingHippo
相关产品推荐
相关产品推荐

