How to save different coefficients as different outputs using topTable in limma
2
0
Entering edit mode
newbie_R • 0
@newbie_r-13299
Last seen 7.0 years ago

I have a limma output with 50 different coefficients. I am saving the each coefficient as one individual file by using the following command manually. Is there anyway to automatically save all 50 coefficients with their names? thanks

 

tab1 <- topTable(fit, n=Inf, coef=1)

write.table(tab1, file="tissue1.txt")

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

write.table(tab2, file="tissue2.txt")

.....
limma toptable coef • 1.6k views
ADD COMMENT
2
Entering edit mode
@gordon-smyth
Last seen 3 hours ago
WEHI, Melbourne, Australia

Does write.fit() do what you want?

write.fit(fit, file="everything.txt")
ADD COMMENT
0
Entering edit mode

yes! thank you very much. @Gordon Smyth

@Gordon Smyth One more thing: The values in the write.fit saved file are p-values? because I need both logFC and p values.

ADD REPLY
1
Entering edit mode

If you type help("write.fit") you still find that it does write both logFC and p-values. It writes everything that is in the fit object.

ADD REPLY
0
Entering edit mode

@Gordon Smyth : For some reason, I am getting coeff, t and p-values but not the logFC values. 

ADD REPLY
1
Entering edit mode

The coeff are the logFC values.

ADD REPLY
0
Entering edit mode

@Gordon Smyth: Thank you. It has what I needed but I just notice there are no gene names in the saved file. Is there anyway i can keep them? thanks

ADD REPLY
0
Entering edit mode
fit$genes$GeneName <- row.names(fit)
write.fit(fit, file="everything.txt")
ADD REPLY
0
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 7 hours ago
The city by the bay

Clarification: you are saving the results of testing each coefficient to file, not just the values of the coefficients.

To easily save results for all 50 coefficients, you can do something called a for loop. Just google it.

ADD COMMENT

Login before adding your answer.

Traffic: 962 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