Lecture3_One-hundred-software-in-bioinformatics098_Gostats
Jimmy(jmzeng1314@outlook.com)
Keywords: hyperGTest
需要加载包,用包自带的函数做富集分析
library(GOstats)
用别人的程序做富集分析
hyperG.params = new("KEGGHyperGParams", geneIds=****, universeGeneIds=NULL, annotation=annotationPKG,
categoryName="KEGG", pvalueCutoff=1, testDirection = "over")
KEGG.hyperG.results = hyperGTest(hyperG.params);
htmlReport(KEGG.hyperG.results, file="kegg.enrichment.html", summary.args=list("htmlLinks"=TRUE))
自己写一个富集分析程序如下:
tmp=toTable(org.Hs.egPATH)
GeneID2Path=tapply(tmp[,2],as.factor(tmp[,1]),function(x) x)
Path2GeneID=tapply(tmp[,1],as.factor(tmp[,2]),function(x) x)
#phyper(k-1,M, N-M, n, lower.tail=F)
#n*M/N
diff_gene_has_path=intersect(diff_gene,names(GeneID2Path))
n=length(diff_gene_has_path)
N=length(GeneID2Path)
for (i in names(Path2GeneID)){
M=length(Path2GeneID[[i]])
exp_count=n*M/N
k=0
for (j in diff_gene_has_path){
if (i %in% GeneID2Path[[j]]) k=k+1
}
OddsRatio=k/exp_count
p=phyper(k-1,M, N-M, n, lower.tail=F)
print(paste(i,p,OddsRatio,exp_count,k,M,sep=" "))
}
useful links :