Gene Set Enrichment between two dataset
1
0
Entering edit mode
5.7 years ago
gracie ▴ 20

Dear all,

I want to perform gene set enrichment analysis between two datasets. There are packages for GO or KEGG pathway enrichment but I could not find one to calculate enrichment score between user given geneset and genelist. Is there any package for that?

Thank you

GSEA RNA-Seq R language • 3.1k views
ADD COMMENT
0
Entering edit mode
ADD REPLY
0
Entering edit mode
5.7 years ago
ewre ▴ 250

Here you go if you want to use fisher's exact test.

enrich.test = function(PathGenes, interestGenes, totalGenes) {
    ################################################
    ###           | inPath | not inPath |
    ###-------------------------------------------
    ###   Predict |  a     |   b        | nPredict
    ###notPredict |  c     |   d        |
    ###-------------------------------------------
    ###           |  nPath |            | nAll
    ################################################
      ##remove genes not included in reference gene set
      PathGenes = intersect(PathGenes,totalGenes)
      interestGenes = intersect(interestGenes, totalGenes)

      nPath <- length(PathGenes)
      nPredict <- length(interestGenes)
      a <- length(intersect(PathGenes,interestGenes))
      b <- nPredict - a
      c <- nPath - a
      nAll = length(totalGenes)
      d <- nAll - (a + b + c)
      m <- matrix(c(a,b,c,d), ncol=2,byrow=T)
      colnames(m) <- c('inPath','notInPath');rownames(m) <- c('Predict','notPredict')
      p <- fisher.test(m,alternative='greater')$p.value

      ##using phyper for hypergeometric test
      p1 <- phyper(a-1,nPath, nAll-nPath,nPredict,lower.tail=F)
      p2 <-1 - phyper(a-1,nPath, nAll-nPath,nPredict)
      tmp <- c(a,b,c,d,p,p1,p2)


      res = list(mat=m,p=list('fisher.exact'=p,
                              'phyper1'=p1,
                              'phyper2'=p2),
                overlapped=intersect(PathGenes, interestGenes))
      res
    }
ADD COMMENT

Login before adding your answer.

Traffic: 2541 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6