gravatar for orzech_mag

2 hours ago by

Poland/Łódź

Dear Collegues,

I am trying to perform analysis of differentially expressed genes between multiple groups. For that I found some tutorial (jef.works/blog/2017/05/31/multiclass-diffential-expression-analysis/). I am interested in t-test only between one group vs rest. This is corresponding code part:

pv.sig <- lapply(levels(groups), function(g){
  ingroup <- names(groups)[groups %in% g]
  outgroup <- names(groups)[!(groups %in% g)]
  pv <- sapply(1:M, function(i) {
    t.test(x[i,ingroup], x[i,outgroup])$p.value
  })
  names(pv) <- rownames(x)
  pv.sig <- names(pv)[pv < 0.05/M/G] ## bonferonni
  pv.sig
})

When I run it on data created in the tutorial everything is fine. When I run it on my data each time I get such error:

Error in 'x[i, ingroup]': subscript out of bounds

This is how my data looks like: my data

My example file may be downloaded here: example data

This is how my code looks like:

x = read.table("~/Desktop/DAT.txt", sep = "t", dec = ".", header = T)
groups = c(rep("B", 505), rep("C", 304), rep("O", 301), rep("U", 370))
groups = as.factor(groups)

rownames(x) = x$X
x$X = NULL
x = as.matrix(x)
names(groups) <- colnames(x)

M = 1480
G = 4
pv.sig <- lapply(levels(groups), function(g){
  ingroup <- names(groups)[groups %in% g]
  outgroup <- names(groups)[!(groups %in% g)]
  pv <- sapply(1:M, function(i) {
    t.test(x[i,ingroup], x[i,outgroup])$p.value
  })
  names(pv) <- rownames(x)
  pv.sig <- names(pv)[pv < 0.05/M/G] ## bonferonni
  pv.sig
})

I've already tested many different combinations, but I am too weak in writing functions to solve what is wrong. So, I ask you as pros for help and I'll appreciate it much.

Best regards!

link

modified 2 hours ago

written
2 hours ago
by

orzech_mag210



Source link