Search
Question: Limma: how to get same output as topTable but for all the genes ?
1
gravatar for Daren Tan
9.0 years ago by
Daren Tan150
Daren Tan150 wrote:

Apology this question is very general, and no codes to illustrate. How can I emulate topTable to output all the genes, as topTable is not suitable for outputting all genes.

ADD COMMENTlink modified 3 months ago by Gordon Smyth32k • written 9.0 years ago by Daren Tan150

Hope this helps others

After I sent out the earlier email, realized that there is write.fit. My solution is to modify it such that

fit2tablefunction (fit, results = NULL, file, digits = 3, adjust =
"none",    sep = "\t", ...){    if (!is(fit, "MArrayLM"))
stop("fit should be an MArrayLM object")    if (!is.null(results) &&
!is(results, "TestResults"))        stop("results should be a
TestResults object")    if (is.null(fit$t) || is.null(fit$p.value))
fit <- eBayes(fit)    p.value <- as.matrix(fit$p.value)    for (j in
1:ncol(p.value)) p.value[, j] <- p.adjust(p.value[,        j], method
= adjust)    rn <- function(x, digits = digits) if (is.null(x))
NULL    else {        if (is.matrix(x) && ncol(x) == 1)            x
<- x[, 1]        round(x, digits = digits)    }    tab <- list()
tab$A <- rn(fit$Amean, digits = digits - 1)    tab$Coef <-
rn(fit$coef, digits = digits)    tab$t <- rn(fit$t, digits = digits -
1)    tab$p.value <- rn(p.value, digits = digits + 2)    tab$F <-
rn(fit$F, digits = digits - 1)    tab$F.p.value <- rn(fit$F.p.value,
digits = digits + 2)    tab$Res <- unclass(results)    tab$Genes <-
fit$genes    return(data.frame(tab, check.names = FALSE))}
ADD REPLYlink modified 9 months ago by Gordon Smyth32k • written 9.0 years ago by Daren Tan150
1
gravatar for Jenny Drnevich
9.0 years ago by
Jenny Drnevich1.9k
United States
Jenny Drnevich1.9k wrote:

HI Daren,

Actually, after requests from many of us who do want the all the results from topTable to use in R (and not just written out to a file using write.fit), Gordon kindly made some changes to the newest version of limma out with R 2.8.0 (currently limma_2.16.3). Here's a snippet from the help file:

Toptable output for all probes in original (unsorted) order can be obtained by topTable(fit,sort="none",n=Inf). However write.fit or write may be preferable if the intention is to write the results to a file. A related method is as.data.frame(fit) which coerces an MArrayLM object to a data.frame.

However, this will only give the adjusted p-values for one contrast at a time, or the over F-stat and adjusted p-values if more than one coefficient is given to topTable. You code below may be better if you want results for all the coefficients together in one object.

Cheers,
Jenny


Jenny Drnevich, Ph.D.

Functional Genomics Bioinformatics Specialist
W.M. Keck Center for Comparative and Functional Genomics
Roy J. Carver Biotechnology Center
University of Illinois, Urbana-Champaign

330 ERML
1201 W. Gregory Dr.
Urbana, IL 61801
USA

ph: 217-244-7355
fax: 217-265-5066
e-mail: drnevich@illinois.edu

ADD COMMENTlink modified 9 months ago by Gordon Smyth32k • written 9.0 years ago by Jenny Drnevich1.9k

The as.data.frame(fit) call mentioned in the help file snippet does collate results for all coefficients in one data frame.

ADD REPLYlink modified 3 months ago • written 3 months ago by Gordon Smyth32k
0
gravatar for lindsaynhayes
3 months ago by
lindsaynhayes0 wrote:

This was super useful. I didn't know you could call each of these variables out of the limma fit output. Thanks for sharing.

Lindsay

ADD COMMENTlink written 3 months ago by lindsaynhayes0
0
gravatar for Gordon Smyth
3 months ago by
Gordon Smyth32k
Walter and Eliza Hall Institute of Medical Research, Melbourne, Australia
Gordon Smyth32k wrote:

Actually, topTable() has always been able to output results for all genes if necessary. As Jenny, points out, you could simply use:

tab <- topTable(fit, n=Inf, coef=2)

to get results for all genes for coefficient 2.

If you wanted to create a data.frame with results for all coefficients, you could use:

tab <- as.data.frame(fit)

and your fit2table function is essentially the same as that. There's no need to write you own code to do this stuff. As Jenny's quote shows, there are hints about this in the topTable help page.

ADD COMMENTlink modified 3 months ago • written 3 months ago by Gordon Smyth32k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 148 users visited in the last hour