在進行數(shù)據(jù)分析時,limma作為一個功能十分強大的存在,而且3步(1.ImFit; 2.eBayes; 3.topTable)就能完成差異分析。但是在做差異分析的時候limma需要的有3樣?xùn)|西。
表達矩陣
分組矩陣
差異比較矩陣
本人就在做contract martix時過于隨意,誰比誰沒有搞清楚導(dǎo)致發(fā)生了小意外。故事發(fā)生在最近論文的復(fù)現(xiàn),用到了GSE19804.
load('changedID_19804.Rdata') #此數(shù)據(jù)是我自己進行了ID轉(zhuǎn)換的表達矩陣,其他東西沒有改變
library(limma)
design <- model.matrix(~0+factor(group_list))
colnames(design)=levels(factor(group_list))
rownames(design)=colnames(sf)
design
contrast.matrix<-makeContrasts(Cancer-Normal,levels = design)
contrast.matrix
fit <- lmFit(sf,design)
fit2 <- contrasts.fit(fit, contrast.matrix)
fit2 <- eBayes(fit2)
tempOutput = topTable(fit2, coef=1, n=Inf)
library(ggpubr)
df=nrDEG
df$v= -log10(P.Value)
ggscatter(df, x = "logFC", y = "v",size=0.5)
df$g=ifelse(df$P.Value>0.01,'stable',
ifelse( df$logFC >1,'up',
ifelse( df$logFC < -1,'down','stable') ))
table(df$g)
df$name=rownames(df)
head(df)
ggscatter(df, x = "logFC", y = "v",size=0.5,color = 'g',title = 'GSE19804_DEGs')
可以看到,制作差異比較矩陣的時候,是Cancer組比Normal,Cancer寫在前面。
contrast.matrix<-makeContrasts(Cancer-Normal,levels = design)
那如果寫反了呢?


up 和 down 都會反過來。連數(shù)據(jù)也部分顛倒。


也不算錯得很離譜吧。。就是全部東西都顛倒了而已。如果記性好的話,還是問題不算太多。可是我就是記性不好那個。所以說還是規(guī)范起來,Cancer寫左,Normal寫右吧。
最后附上JM大神寫的關(guān)于limma包是否需要比較矩陣的帖子https://github.com/bioconductor-china/basic/blob/master/makeContrasts.md