lgeistlinger / EnrichmentBrowser

Seamless navigation through combined results of set-based and network-based enrichment analysis
19 stars 11 forks source link

Multiple factor experiments (non-binary). #28

Open grabearummc opened 3 years ago

grabearummc commented 3 years ago

What if I have a multi-factor experiment with more than 2 conditions? How can I use EnrichmentBrowser?

> design <- model.matrix(~ 0+factor(c(1,1,1,2,2,3,3,3,4,4,4,5,5,5,6,6,6)))
> colnames(design) <- c("group1", "group2", "group3", "group4", "group5", "group6")
> contrast.matrix <- makeContrasts((group2+group3)-(group4+group5), levels=design)
> fit2 <- contrasts.fit(fit, contrast.matrix)
> fit2 <- eBayes(fit2)            
> design
   group1 group2 group3 group4 group5 group6
1       1      0      0      0      0      0
2       1      0      0      0      0      0
3       1      0      0      0      0      0
4       0      1      0      0      0      0
5       0      1      0      0      0      0
6       0      0      1      0      0      0
7       0      0      1      0      0      0
8       0      0      1      0      0      0
9       0      0      0      1      0      0
10      0      0      0      1      0      0
11      0      0      0      1      0      0
12      0      0      0      0      1      0
13      0      0      0      0      1      0
14      0      0      0      0      1      0
15      0      0      0      0      0      1
16      0      0      0      0      0      1
17      0      0      0      0      0      1
attr(,"assign")
[1] 1 1 1 1 1 1
attr(,"contrasts")
attr(,"contrasts")$`factor(c(1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6))`
[1] "contr.treatment"

> contrast.matrix
        Contrasts
Levels   (group2 + group3) - (group4 + group5)
  group1                                     0
  group2                                     1
  group3                                     1
  group4                                    -1
  group5                                    -1
  group6        
grabearummc commented 3 years ago

Let's say I've already done the differential gene expression analysis. How can I continue with EnrichmentBrowser::import/sbea/nbea?

lgeistlinger commented 3 years ago

Question 1: Most GSA methods only support two groups comparisons. That means, you'll need to break down multi-group comparisons into the atomic unit of several 2-group comparisons.

Question 2: let's say you would like to do a GO enrichment analysis with your results from limma (assuming you have human data):

se <- import(el, res)
go.gs <- getGenesets(org = "hsa", db = "go", onto = "BP")
sbea.res <- sbea("ora", se, go.gs, perm = 0)
gsRanking(sbea.res, signif.only = FALSE)
lgeistlinger commented 3 years ago

I think import would then need to allow to specify which two groups you would like to compare / for which DE results should be imported. Good point.

grabearummc commented 3 years ago

I think import would then need to allow to specify which two groups you would like to compare / for which DE results should be imported. Good point.

Nice! I was thinking this through earlier, and that crossed my mind, but I wasn't 100% sure if that was the right thing to do. So should I filter out samples based on my intended comparison? So (using my example) should I remove group1 and group6 and then combine everything else?

lgeistlinger commented 3 years ago

Exactly. This is how you could produce an index vector that allows you to subset to the relevant samples for comparison (would make samples in groups 2 and 3 your reference group, ie group 0; change accordingly if you want samples in groups 4 and 5 to be the reference).

group <- c(1,1,1,2,2,3,3,3,4,4,4,5,5,5,6,6,6)
group[group %in% 2:3] <- 0
group[group %in% 4:5] <- 1
rel.samples <- group %in% 0:1
grabearummc commented 3 years ago

Good deal. Much appreciated @lgeistlinger!