运行FGSEA报错:pathways格式不符合要求的问题求助
问题:运行FGSEA时出现pathways格式错误
错误信息
fgseaRes <- fgsea(gmt.file, res, minSize=15, maxSize=500) #need to load GOCC_RIBOSOME pathway Error in preparePathwaysAndStats(pathways, stats, minSize, maxSize, gseaParam, : pathways should be a list with each element containing names of the stats argument here
我的代码
##loading ranks res <- read.delim("Rank_fgsea_data.rnk", header=T, colClasses = c("numeric", "character")) #removing decimals res$Gene.ID <- gsub("\\..*", "", res$Gene.ID) #read as list/data frame as.data.frame(res) res <- setnames(res$log2FoldChange, res$Gene.ID) str(res) ## Loading pathways from msigDB pathways <- gmtPathways(gmt.file) str(head(pathways)) as.data.frame(pathways) ##running FGSEA fgseaRes <- fgsea(gmt.file, res, minSize=15, maxSize=500) #need to load GOCC_RIBOSOME pathway head(fgseaRes)
解决建议
- 修正fgsea函数参数:
fgsea()的第一个参数需要传入gmtPathways()读取后的通路列表(也就是你定义的pathways对象),而不是gmt文件路径字符串gmt.file。 - 确保stats参数是正确的命名数值向量:
- 若未加载
data.table包,setnames()会报错,改用base R方式生成命名向量:# 替换原res赋值代码 res_vec <- res$log2FoldChange names(res_vec) <- res$Gene.ID # 移除NA值(可选但推荐) res_vec <- na.omit(res_vec) - 运行
str(res_vec)检查格式,输出应类似:num [1:XXX] ... - attr(*, "names")= chr [1:XXX] "基因名1" "基因名2" ...
- 若未加载
- 确认pathways格式:
gmtPathways()读取后的pathways必须是列表类型,每个元素是对应通路的基因名向量。运行str(pathways)验证,输出应为List of X,每个子元素是chr类型的基因向量。 - 匹配基因名格式:确保通路中的基因名和
res_vec中的基因名完全一致(比如大小写、是否包含后缀等,你已经处理了Gene.ID的小数部分,要确认通路里的基因名也是相同格式)。
修改后的完整代码示例
##loading ranks res <- read.delim("Rank_fgsea_data.rnk", header=T, colClasses = c("numeric", "character")) #removing decimals res$Gene.ID <- gsub("\\..*", "", res$Gene.ID) # 生成正确的命名数值向量 res_vec <- res$log2FoldChange names(res_vec) <- res$Gene.ID res_vec <- na.omit(res_vec) str(res_vec) ## Loading pathways from msigDB pathways <- gmtPathways(gmt.file) str(head(pathways)) ##running FGSEA fgseaRes <- fgsea(pathways = pathways, stats = res_vec, minSize=15, maxSize=500) head(fgseaRes)
内容的提问来源于stack exchange,提问作者Nicola
相关产品推荐
相关产品推荐

