Reputation: 91
I would like to do rna seq data for several genes, tested in control and treatment. To do fisher.test I need a contingency table for each gene, is there a way to do this in R instead of computing a contingency table for each gene? I am new to this so any advice can be helpful.
I have the count data and the sample Info data,
control1 treated1 control2 treat2 control3 treat3
ENSG00000000003 723 486 904 445 1170 1097
ENSG00000000005 0 0 0 0 0 0
ENSG00000000419 467 523 616 371 582 781
Where ENSG are the genes
Upvotes: 0
Views: 415
Reputation: 226911
Reading in your data:
dd <- read.table(header=TRUE,text="
control1 treated1 control2 treat2 control3 treat3
ENSG00000000003 723 486 904 445 1170 1097
ENSG00000000005 0 0 0 0 0 0
ENSG00000000419 467 523 616 371 582 781
")
Running a for
loop, with some safeguards:
results <- list()
for (i in 1:nrow(dd)) {
m <- matrix(unlist(dd[i,]),nrow=2)
if (any(m>0)) {
results[[i]] <- fisher.test(m)
} else {
results[[i]] <- NA
}
}
names(results) <- rownames(dd)
Upvotes: 1