Hi Dariober
Thanks!! I got the same results using your code without contrast; I will check later if the model provides the real significant differential genes in the matrix as you suggested!!
Cheers
I am rookie to using limma package. My data looks like this in excel: first column is the gene name, first raw is sample name, and under each sample name is the gene expression value (4 replicates per sample, I have sample wt and mu). I want to find out the significant expressed genes between mu vs wt.
and I write code like this:
sample=read.csv("sample.csv",header=T,row.names=1)
logsample=log2(sample)
design=model.matrix(~0+c(rep('wt',4),rep('mu',4)))
colnames(design)=c("wt","mu")
cm=makeContrasts(mu-wt,levels=design)
fit=lmFit(logsample,design)
fit2=contrasts.fit(fit,cm)
fit3=eBayes(fit2)
result=topTable(fit3,number=Inf,adjust="BH",sort.by="none")
I am not sure I did it correctly. Please help me to check, many thanks!! I log2 transformed the intensity. The data is already normalized by other software; I am not sure I should use makeContrasts or not.
Thanks!!
Your code looks good to me to find genes differentially expressed between the 4 WT and 4 mu, which I guess it is what you want.
As Devon Ryan suggested, you can leave the intercept and skip the contrasts. This should be equivalent to your code:
design=model.matrix(~1+c(rep('wt',4),rep('mu',4)))
colnames(design)=c("wt","mu")
fit=lmFit(logsample,design)
fit<- eBayes(fit)
results<- topTable(fit,number=Inf,adjust="BH",sort.by="none", coef= 2)
However, I don't see any harm in explicitly fitting contrasts, actually I find it clearer.
I think in general it's good to look at a couple of genes from the output of topTable() and make sure the model is doing what you expect by comparing to the values in the normalized matrix. E.g. in your case:
results$logFC[1]
Should be equal to (given rounding errors):
mean(logsample[1, 1:4]) - mean(logsample[1, 5:8])
Hi Dariober
Thanks!! I got the same results using your code without contrast; I will check later if the model provides the real significant differential genes in the matrix as you suggested!!
Cheers
Log in to answer this question.
What exactly does sample.csv contain?
BTW, if you don't remove the intercept from the design then you can skip looking at the contrast.
Hi Devon, thanks for reply, the
sample.csvlooks like this: