在做完GO富集之后,我们可以得到这样的富集分析结果,在结果里可以看到有两列是GeneRatio和BgRatio。
![](https://img.haomeiwen.com/i15771939/d007b2f58b3d3d66.png)
GeneRatio:是一个分数,分子是富集到这个GO条目上的gene的数目,分母是所有输入的做富集分析的gene的数目,可以是差异表达分析得到的gene。
BgRatio(Background Ratio):这里也是一个分数,分母是人的所有编码蛋白的基因中有GO注释的gene的数目,BP是18866个,CC是19559个。分子是这18866/19559个gene中注释到这个GO条目上面的gene的数目。
而富集倍数Fold Enrichment就是GeneRatio / BgRatio。
此前还写过另一个评价富集程度的指标zscore。
富集倍数的计算方法:
- 利用eval直接做计算
go=read.csv("enrichGO_all.csv",stringsAsFactors = F)
enrichment_fold=apply(go,1,function(x){
GeneRatio=eval(parse(text=x["GeneRatio"]))
BgRatio=eval(parse(text=x["BgRatio"]))
enrichment_fold=round(GeneRatio/BgRatio,2)
enrichment_fold
})
go$EF <- enrichment_fold
View(go)
![](https://img.haomeiwen.com/i15771939/678e2d041bca24ef.png)
- 利用strsplit按/分割成分子和分母
go=read.csv("enrichGO_all.csv",stringsAsFactors = F)
fenshu2xiaoshu<-function(ratio){
sapply(ratio,function(x) as.numeric(strsplit(x,"/")[[1]][1])/as.numeric(strsplit(x,"/")[[1]][2]))
}
enrichment_fold=fenshu2xiaoshu(go$GeneRatio)/fenshu2xiaoshu(go$BgRatio)
enrichment_fold=as.numeric(enrichment_fold)
go$EF <- enrichment_fold
View(go)
![](https://img.haomeiwen.com/i15771939/cc0e2e4c593f2e03.png)
- 利用gsub替换,得到分子和分母
go=read.csv("enrichGO_all.csv",stringsAsFactors = F)
fenshu2xiaoshu2<-function(ratio){
sapply(ratio,function(x) as.numeric(gsub("/.*$","",x))/as.numeric(gsub("^.*/","",x)))
}
enrichment_fold=fenshu2xiaoshu2(go$GeneRatio)/fenshu2xiaoshu2(go$BgRatio)
enrichment_fold=as.numeric(enrichment_fold)
go$EF <- enrichment_fold
View(go)
得到的富集倍数可以用来做图
网友评论