單因素差異分析
對(duì)于DESeq來(lái)說(shuō),常用的單因素的差異分析已經(jīng)比較多了,

一般來(lái)說(shuō),對(duì)于基因的表達(dá)矩陣,放在前面的為對(duì)照組,后面的為處理組,所以結(jié)果為后面的比較前面的
并且對(duì)于control組或者treat組這樣的組來(lái)說(shuō),組內(nèi)各樣本的表達(dá)譜姑且認(rèn)為是相同的
雙因素差異分析
那么,對(duì)于雙因素差異分析

所謂雙因素,是指一個(gè)為主因素,另一個(gè)為次要因素,我們除了考慮treat與control的差異以外,分別在這兩個(gè)組內(nèi),不同genotype也會(huì)造成彼此之間的差異
雙因素差異分析的交互項(xiàng):
如果不考慮交互項(xiàng),那么意味著在 genotype I ,genotype II 和 genotype III 中 treat 比較于 control 的差異值都是相等的;而事實(shí)并非如此,在 genotype I ,genotype II 和 genotype III 中 treat 比較于 control 的差異值很可能是不一樣的,因此需要引入交互項(xiàng)來(lái)評(píng)價(jià)在 genotype I ,genotype II 和 genotype III 中 treat 比較于 control 差異值的不同

交互項(xiàng)的意義是當(dāng)控制第二個(gè)變量時(shí),我們討論 control 與treat 的差異,那么效應(yīng)值為 a2,這意味著在第二個(gè)變量 genotype I ,genotype II 和 genotype III 中 control 與treat 的差異都是 a2。可是不是在第二個(gè)變量 genotype I ,genotype II 和 genotype III 類中的差異都是 a2?需要引入交互項(xiàng)來(lái)區(qū)分這種差異
因此引入交互項(xiàng)來(lái)區(qū)分在第二個(gè)變量 genotype I ,genotype II 和 genotype III 中 control 與treat 的差異,如上圖 y2 和 y3,同樣描述 control 與treat 的差異(效應(yīng)值為 a2)但在第二個(gè)變量 genotype II 和 genotype III 中是不同的,在 genotype II 類中 control 與 treat 的差異為 a2+d5,在 genotype III 中 control 與 treat 的差異為a2+d6
交互項(xiàng)顯著代表 control 與 treat 的差異在不同的 genotype 是不同的;否則相同
雙因素差異分析結(jié)構(gòu)

這就是各個(gè)因素之間的結(jié)構(gòu)和內(nèi)在聯(lián)系,一般我們把設(shè)計(jì)矩陣的前面那幾列作為對(duì)照
雙因素實(shí)例
若不帶交互項(xiàng)
dds <- makeExampleDESeqDataSet(n=100,m=18)
dds$genotype <- factor(rep(rep(c("I","II","III"),each=3),2))
#我們把主要因素condition寫(xiě)在后面,genotype為次要因素寫(xiě)在前面,“:”表示交互項(xiàng)
design(dds) <- ~ genotype + condition
dds <- DESeq(dds)
resultsNames(dds)

我們可以發(fā)現(xiàn),若沒(méi)有交互項(xiàng),各組的比較僅停留在單因素兩兩進(jìn)行比較。
設(shè)計(jì)矩陣的因子水平如下:

第一種情況:
dat = counts(dds, normalized=TRUE)
dds_result = data.frame(results(dds, contrast=c("condition","B","A")))
這樣的差異表達(dá)方式只考慮condition B和A的差異,而不區(qū)分是哪一種genotype
我們挑選前三個(gè)基因手動(dòng)計(jì)算它們的log2(FC)值:
# dat 的 10-18列包括了所有 genotype I-III 的 conditionB 的 sample
# dat 的 1-9列包括了所有 genotype I-III 的 conditionA 的 sample
## Gene 1
log2(mean(dat[1,10:18])/mean(dat[1,1:9]))
[1] -0.5054413
## Gene 2
log2(mean(dat[2,10:18])/mean(dat[2,1:9]))
[1] -0.09992514
## Gene 3
log2(mean(dat[3,10:18])/mean(dat[3,1:9]))
[1] -0.2876421
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.495586066
- Gene 2: log2(FC) 為 -0.103780171
- Gene 3: log2(FC) 為 -0.322288959
第二種情況:
dat = counts(dds, normalized=TRUE)
dds_result = data.frame(results(dds, contrast=c("genotype","II","I")))
這樣的差異表達(dá)方式只考慮genotype II 和 I 之間的差異,而不區(qū)分是哪一種condition
我們挑選前三個(gè)基因手動(dòng)計(jì)算它們的log2(FC)值:
# dat 的 4-6列和13-15列包括了所有 condition 的 genotype II 的 sample
# dat 的 1-3列和10-12列包括了所有 condition 的 genotype I 的 sample
## Gene 1
log2(mean(dat[1,c(4:6,13:15)])/mean(dat[1,c(1:3,10:12)]))
[1] -0.3342552
# Gene 2
log2(mean(dat[2,c(4:6,13:15)])/mean(dat[2,c(1:3,10:12)]))
[1] 0.4529269
# Gene 3
log2(mean(dat[3,c(4:6,13:15)])/mean(dat[3,c(1:3,10:12)]))
[1] -0.1632169
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.3179995795
- Gene 2: log2(FC) 為 0.4551878042
- Gene 3: log2(FC) 為 -0.2035258259
第三種情況:
dat = counts(dds, normalized=TRUE)
dds_result = data.frame(results(dds, contrast=c("genotype","III","I")))
這樣的差異表達(dá)方式只考慮genotype III 和 I 之間的差異,而不區(qū)分是哪一種condition
我們挑選前三個(gè)基因手動(dòng)計(jì)算它們的log2(FC)值:
# dat 的 7-9列和16-18列包括了所有 condition 的 genotype III 的 sample
# dat 的 1-3列和10-12列包括了所有 condition 的 genotype I 的 sample
## Gene 1
log2(mean(dat[1,c(7:9,16:18)])/mean(dat[1,c(1:3,10:12)]))
[1] -0.5673898
# Gene 2
log2(mean(dat[2,c(7:9,16:18)])/mean(dat[2,c(1:3,10:12)]))
[1] 0.7163037
# Gene 3
log2(mean(dat[3,c(7:9,16:18)])/mean(dat[3,c(1:3,10:12)]))
[1] -0.2464887
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.5515813451
- Gene 2: log2(FC) 為 0.7185941762
- Gene 3: log2(FC) 為 -0.3108995692
第四種情況:
dat = counts(dds, normalized=TRUE)
dds_result = data.frame(results(dds, contrast=c("genotype","III","II")))
這樣的差異表達(dá)方式只考慮genotype III 和 II 之間的差異,而不區(qū)分是哪一種condition
我們挑選前三個(gè)基因手動(dòng)計(jì)算它們的log2(FC)值:
# dat 的 7-9列和16-18列包括了所有 condition 的 genotype III 的 sample
# dat 的 4-6列和13-15列包括了所有 condition 的 genotype II 的 sample
## Gene 1
log2(mean(dat[1,c(7:9,16:18)])/mean(dat[1,c(4:6,13:15)]))
[1] -0.2331346
# Gene 2
log2(mean(dat[2,c(7:9,16:18)])/mean(dat[2,c(4:6,13:15)]))
[1] 0.2633768
# Gene 3
log2(mean(dat[3,c(7:9,16:18)])/mean(dat[3,c(4:6,13:15)]))
[1] -0.08327181
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.23358177
- Gene 2: log2(FC) 為 0.26340637
- Gene 3: log2(FC) 為 -0.10737374
若帶有交互項(xiàng)
我們用幫助文檔中的例子作為說(shuō)明
dds <- makeExampleDESeqDataSet(n=100,m=18)
dds$genotype <- factor(rep(rep(c("I","II","III"),each=3),2))
#我們把主要因素condition寫(xiě)在后面,genotype為次要因素寫(xiě)在前面,“:”表示交互項(xiàng)
design(dds) <- ~ genotype + condition + genotype:condition
dds <- DESeq(dds)
resultsNames(dds)

如果帶有交互項(xiàng),那么我們就可以比較雙因素共同作用下兩組的差異了;也可以限定一個(gè)因素,比較某單因素作用下兩組的差異
注意事項(xiàng)
DESeq2的建模原理是利用廣義線性模型去擬合高維數(shù)據(jù),然后再做差異比較
值得注意的是,不帶有交互項(xiàng)(design(dds) <- ~ genotype + condition)對(duì)高維數(shù)據(jù)的擬合的方程是線性的(兩個(gè)維度,其中一個(gè)維度是genotype,另一個(gè)維度是condition);帶有交互項(xiàng)(design(dds) <- ~ genotype + condition + genotype:condition)對(duì)高維數(shù)據(jù)的擬合的方程是非線性的(兩個(gè)維度,其中一個(gè)維度是genotype,另一個(gè)維度是condition ,再帶有一個(gè)非線性交互項(xiàng) genotype:condition);因此兩個(gè)模型計(jì)算出來(lái)的基因表達(dá)估計(jì)值是不一樣的,因此計(jì)算出來(lái)的log2(FC)是不一樣的,但是不會(huì)影響上下調(diào)的方向

上面是沒(méi)有交互項(xiàng)的;下面是有交互項(xiàng)的
那么DESeq的原理是哪一個(gè)sample放前面,哪一個(gè)就為對(duì)照組,在該例子里面,對(duì)于condition,condition_A為對(duì)照,對(duì)于genotype,genotype I為對(duì)照組
當(dāng)然我們也可以自行設(shè)定:
# to compare A vs B, make B the reference level,
# and select the last coefficient
condition <- relevel(condition, "B")
- genotype_II_vs_I 表示的是在condition_A的條件下,genotype II 與genotype I 相比較下的差異
- genotype_III_vs_I 表示的是在condition_A的條件下,genotype III 與genotype I 相比較下的差異
- condition_B_vs_A 表示對(duì)于genotype I 來(lái)說(shuō),在condition_B與condition_A相比較下的差異
- genotypeII.conditionB 表示雙因素交互項(xiàng),目的是檢測(cè)在不同genotype中,condition的效果是否會(huì)不同,即先計(jì)算condition_B的genotype II 與condition_A的genotype II 相比較下的差異和condition_B的genotype I 與condition_A的genotype I 的差異,兩者再進(jìn)行差異比較(前者比后者)
- genotypeIII.conditionB 表示雙因素交互項(xiàng),目的是檢測(cè)在不同genotype中,condition的效果是否會(huì)不同,即先計(jì)算condition_B的genotype III 與condition_A的genotype III 相比較下的差異和condition_B的genotype I 與condition_A的genotype I 的差異,兩者再進(jìn)行差異比較(前者比后者)
接下來(lái)我們介紹下參數(shù) contrast:

這個(gè)參數(shù)目的是指定要從對(duì)象中提取哪些比較以構(gòu)建結(jié)果表
簡(jiǎn)而言之,這個(gè)參數(shù)控制著提取誰(shuí)與誰(shuí)比較的結(jié)果
第一種情況:
那么:
dat = counts(dds, normalized=TRUE)
res = results(dds, list( c("genotype_II_vs_I")))
這個(gè)表示對(duì)于condition_A 來(lái)說(shuō),在genotype II 與genotype I 相比較下的差異
FC=(genotype II in condition_A) / (genotype I in condition_A)
我們用代碼計(jì)算下:
# dat 的 4-6列代表 genotype II in condition_A 的 sample
# dat 的 1-3列代表 genotype I in condition_A 的 sample
## Gene 1
log2(mean(dat[1,4:6])/mean(dat[1,1:3]))
[1] 0.3768983
## Gene 2
log2(mean(dat[2,4:6])/mean(dat[2,1:3]))
[1] 0.3134871
## Gene 3
log2(mean(dat[3,4:6])/mean(dat[3,1:3]))
[1] -0.5114681
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 0.367333
- Gene 2: log2(FC) 為 0.313593
- Gene 3: log2(FC) 為 -0.506202
第二種情況:
那么:
dat = counts(dds, normalized=TRUE)
res = results(dds, list( c("genotype_III_vs_I")))
這個(gè)表示對(duì)于condition_A 來(lái)說(shuō),在genotype III 與genotype I 相比較下的差異
FC=(genotype III in condition_A) / (genotype I in condition_A)
我們用代碼計(jì)算下:
# dat 的 7-9列代表 genotype III in condition_A 的 sample
# dat 的 1-3列代表 genotype I in condition_A 的 sample
## Gene 1
log2(mean(dat[1,7:9])/mean(dat[1,1:3]))
[1] -0.3639434
## Gene 2
log2(mean(dat[2,7:9])/mean(dat[2,1:3]))
[1] -0.03030897
## Gene 3
log2(mean(dat[3,7:9])/mean(dat[3,1:3]))
[1] -0.6220792
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.364814
- Gene 2: log2(FC) 為 -0.029441
- Gene 3: log2(FC) 為 -0.610125
第三種情況:
那么:
dat = counts(dds, normalized=TRUE)
# the condition effect for genotype I (the main effect)
results(dds, contrast=c("condition","B","A"))
這個(gè)表示對(duì)于genotype I 來(lái)說(shuō),在condition_B與condition_A相比較下的差異
FC=(genotype I in condition_B) / (genotype I in condition_A)
我們用代碼計(jì)算下:
# dat 的 10-12列代表 genotype I in condition_B 的 sample
# dat 的 1-3列代表 genotype I in condition_A 的 sample
## Gene 1
log2(mean(dat[1,10:12])/mean(dat[1,1:3]))
[1] -0.6302513
## Gene 2
log2(mean(dat[2,10:12])/mean(dat[2,1:3]))
[1] -0.1265862
## Gene 3
log2(mean(dat[3,10:12])/mean(dat[3,1:3]))
[1] 0.3226792
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.633304150
- Gene 2: log2(FC) 為 -0.129958993
- Gene 3: log2(FC) 為 0.321771376
第四種情況:
dat = counts(dds, normalized=TRUE)
# the condition effect for genotype III.
# this is the main effect *plus* the interaction term
# (the extra condition effect in genotype III compared to genotype I).
results(dds, list( c("condition_B_vs_A","genotypeIII.conditionB")))
表示主要考察在genotype III 這個(gè)因素下,condition_B 與condition_A 相比帶來(lái)的差異。
也就是說(shuō),condition_B的genotype III 與 condition_A的genotype III 相比較所帶來(lái)的差異
這里的extra condition effect應(yīng)該理解為在genotype III 的條件下,某兩個(gè)condition相比較下的差異
FC = (genotype III in condition_B) / (genotype III in condition_A)
# dat 的 16-18列代表 genotype III in condition_B 的 sample
# dat 的 7-9列代表 genotype III in condition_A 的 sample
## Gene 1
log2(mean(dat[1,16:18])/mean(dat[1,7:9]))
[1] -0.4690318
## Gene 2
log2(mean(dat[2,16:18])/mean(dat[2,7:9]))
[1] -0.0880866
## Gene 3
log2(mean(dat[3,16:18])/mean(dat[3,7:9]))
[1] -0.8147309
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.46013841
- Gene 2: log2(FC) 為 -0.08729557
- Gene 3: log2(FC) 為 -0.81238535
第五種情況:
dat = counts(dds, normalized=TRUE)
# the condition effect for genotype II.
# this is the main effect *plus* the interaction term
# (the extra condition effect in genotype II compared to genotype I).
results(dds, list( c("condition_B_vs_A","genotypeII.conditionB")))
表示主要考察在genotype II 這個(gè)因素下,condition_B 與condition_A 相比帶來(lái)的差異。
也就是說(shuō),condition_B的genotype II 與 condition_A的genotype II 相比較所帶來(lái)的差異
這里的extra condition effect應(yīng)該理解為在genotype II 的條件下,某兩個(gè)condition相比較下的差異
FC = (genotype II in condition_B) / (genotype II in condition_A)
# dat 的 13-15列代表 genotype II in condition_B 的 sample
# dat 的 4-6列代表 genotype II in condition_A 的 sample
## Gene 1
log2(mean(dat[1,13:15])/mean(dat[1,4:6]))
[1] 1.375654
## Gene 2
log2(mean(dat[2,13:15])/mean(dat[2,4:6]))
[1] -0.3227521
## Gene 3
log2(mean(dat[3,13:15])/mean(dat[3,4:6]))
[1] 0.08036955
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 1.3656608
- Gene 2: log2(FC) 為 -0.3305137
- Gene 3: log2(FC) 為 0.0780536
第六種情況:
dat = counts(dds, normalized=TRUE)
# the interaction term for condition effect in genotype III vs genotype I.
# this tests if the condition effect is different in III compared to I
results(dds, name="genotypeIII.conditionB")
這一項(xiàng)是交互項(xiàng),即目的是檢測(cè)在不同genotype中,condition的效果是否會(huì)不同,即先計(jì)算condition_B的genotype III 與condition_A的genotype III 相比較下的差異和condition_B的genotype I 與condition_A的genotype I 的差異,兩者再進(jìn)行差異比較(前者比后者),英文的解釋為:This tests if the condition effect is different in III compared to I:
FC = (genotype III in condition_B / genotype III in condition_A) / (genotype I in condition_B / genotype I in condition_A)
這個(gè) FC 主要考察的是 condition 的改變對(duì) genotype III 產(chǎn)生的變化倍數(shù)是否和 condition 的改變對(duì) genotype I 產(chǎn)生的變化倍數(shù)相同;如果相同 FC的值為1;如果前者變化倍數(shù)比后者小,那么 FC 介于0到1,如果前者變化倍數(shù)比后者大,那么 FC 大于1
代碼如下:
# dat 的 16-18列代表 genotype III in condition_B 的 sample
# dat 的 7-9列代表 genotype III in condition_A 的 sample
# dat 的 10-12列代表 genotype I in condition_B 的 sample
# dat 的 1-3列代表 genotype I in condition_A 的 sample
## Gene 1
log2((mean(dat[1,16:18])/mean(dat[1,7:9]))/(mean(dat[1,10:12])/mean(dat[1,1:3])))
[1] 0.1612196
## Gene 2
log2((mean(dat[2,16:18])/mean(dat[2,7:9]))/(mean(dat[2,10:12])/mean(dat[2,1:3])))
[1] 0.03849963
## Gene 3
log2((mean(dat[3,16:18])/mean(dat[3,7:9]))/(mean(dat[3,10:12])/mean(dat[3,1:3])))
[1] -1.13741
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 0.17316574
- Gene 2: log2(FC) 為 0.04266342
- Gene 3: log2(FC) 為 -1.13415673
這里在插播一下name這個(gè)參數(shù):

通常只提取一項(xiàng)的話,用 name 比較好
第七種情況:
dat = counts(dds, normalized=TRUE)
# the interaction term for condition effect in genotype III vs genotype II.
# this tests if the condition effect is different in III compared to II
results(dds, contrast=list("genotypeIII.conditionB", "genotypeII.conditionB"))
這個(gè)是兩個(gè)交互項(xiàng)的比較,其英文解釋為:This tests if the condition effect is different in III compared to II
目的是檢測(cè)在不同genotype中,condition的效果是否會(huì)不同,即先計(jì)算condition_B的genotype III 與condition_A的genotype III 相比較下的差異和condition_B的genotype II 與condition_A的genotype II 的差異,兩者再進(jìn)行差異比較(前者比后者)
FC = (genotype III in condition_B / genotype III in condition_A) / (genotype II in condition_B / genotype II in condition_A)
這個(gè) FC 主要考察的是 condition 的改變對(duì) genotype III 產(chǎn)生的變化倍數(shù)是否和 condition 的改變對(duì) genotype II 產(chǎn)生的變化倍數(shù)相同;如果相同 FC的值為1;如果前者變化倍數(shù)比后者小,那么 FC 介于0到1,如果前者變化倍數(shù)比后者大,那么 FC 大于1
# dat 的 16-18列代表 genotype III in condition_B 的 sample
# dat 的 7-9列代表 genotype III in condition_A 的 sample
# dat 的 13-15列代表 genotype II in condition_B 的 sample
# dat 的 4-6列代表 genotype II in condition_A 的 sample
## Gene 1
log2((mean(dat[1,16:18])/mean(dat[1,7:9]))/(mean(dat[1,13:15])/mean(dat[1,4:6])))
[1] -0.08777481
## Gene 2
log2((mean(dat[2,16:18])/mean(dat[2,7:9]))/(mean(dat[2,13:15])/mean(dat[2,4:6])))
[1] 0.006579703
## Gene 3
log2((mean(dat[3,16:18])/mean(dat[3,7:9]))/(mean(dat[3,13:15])/mean(dat[3,4:6])))
[1] -0.3210265
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.072876535
- Gene 2: log2(FC) 為 0.007112289
- Gene 3: log2(FC) 為 -0.321480534
第八種情況:
dat = counts(dds, normalized=TRUE)
res = results(dds, list( c("genotype_III_vs_I","genotypeIII.condition_B")))
這個(gè)比較的是在condition_B的條件下,genotype III 和genotype I 相比較下的差異
即condition_B的genotype III 與condition_B的genotype I 相比較下的差異
FC = (genotype III in condition_B) / (genotype I in condition_B)
手動(dòng)計(jì)算代碼:
# dat 的 16-18列代表 genotype III in condition_B 的 sample
# dat 的 10-12列代表 genotype I in condition_B 的 sample
## Gene 1
log2(mean(dat[1,16:18])/mean(dat[1,10:12]))
[1] -0.4716114
## Gene 2
log2(mean(dat[2,16:18])/mean(dat[2,10:12]))
[1] 0.7362693
## Gene 3
log2(mean(dat[3,16:18])/mean(dat[3,10:12]))
[1] -0.8629554
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.46202782
- Gene 2: log2(FC) 為 0.73984754
- Gene 3: log2(FC) 為 -0.86640184
第九種情況:
dat = counts(dds, normalized=TRUE)
res = results(dds, list( c("genotype_II_vs_I","genotypeII.conditionB")))
這個(gè)比較的是在condition_B的條件下,genotype II 和genotype I 相比較下的差異
即condition_B的genotype II 與condition_B的genotype I 相比較下的差異
FC = (genotype II in condition_B) / (genotype I in condition_B)
手動(dòng)計(jì)算代碼:
# dat 的 13-15列代表 genotype II in condition_B 的 sample
# dat 的 10-12列代表 genotype I in condition_B 的 sample
## Gene 1
log2(mean(dat[1,13:15])/mean(dat[1,10:12]))
[1] -0.9762591
## Gene 2
log2(mean(dat[2,13:15])/mean(dat[2,10:12]))
[1] -0.4114295
## Gene 3
log2(mean(dat[3,13:15])/mean(dat[3,10:12]))
[1] 1.126437
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.972029
- Gene 2: log2(FC) 為 -0.412843
- Gene 3: log2(FC) 為 1.132502
第十種情況:
dat = counts(dds, normalized=TRUE)
# 注意要分為兩個(gè) c() 來(lái)寫(xiě)
res = results(dds, list( c("genotype_III_vs_I","genotypeIII.conditionB"),c("genotype_II_vs_I","genotypeII.conditionB")))
這個(gè)比較的是在condition_B的條件下,genotype III 和genotype II 相比較下的差異
即condition_B的genotype III 與condition_B的genotype II 相比較下的差異
FC = (genotype III in condition_B) / (genotype II in condition_B)
手動(dòng)計(jì)算代碼:
# dat 的 16-18列代表 genotype III in condition_B 的 sample
# dat 的 13-15列代表 genotype II in condition_B 的 sample
## Gene 1
log2(mean(dat[1,16:18])/mean(dat[1,13:15]))
[1] 0.2984419
## Gene 2
log2(mean(dat[2,16:18])/mean(dat[2,13:15]))
[1] -0.1667908
## Gene 3
log2(mean(dat[3,16:18])/mean(dat[3,13:15]))
[1] -0.02535796
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 0.3033151
- Gene 2: log2(FC) 為 -0.1632627
- Gene 3: log2(FC) 為 -0.0172830
如果我們想要計(jì)算跨condition和跨genotype的差異
第十一種情況:
dds <- makeExampleDESeqDataSet(n=100,m=18)
dds$genotype <- factor(rep(rep(c("I","II","III"),each=3),2))
dds$genotype <- relevel(dds$genotype, "III")
#我們把主要因素condition寫(xiě)在后面,genotype為次要因素寫(xiě)在前面,“:”表示交互項(xiàng)
design(dds) <- ~ genotype + condition + genotype:condition
dds <- DESeq(dds)
resultsNames(dds)
dat = counts(dds, normalized=TRUE)
res = results(dds, list(c("condition_B_vs_A"),c("genotype_I_vs_III")))
這里計(jì)算的是condition_B的genotype III 與condition_A的genotype I 相比較下的差異
FC = (genotype III in condition_B) / (genotype I in condition_A)
手動(dòng)計(jì)算代碼:
# dat 的 16-18列代表 genotype III in condition_B 的 sample
# dat 的 1-3列代表 genotype I in condition_A 的 sample
## Gene 1
log2(mean(dat[1,16:18])/mean(dat[1,1:3]))
[1] -0.2684356
## Gene 2
log2(mean(dat[2,16:18])/mean(dat[2,1:3]))
[1] 0.6341815
## Gene 3
log2(mean(dat[3,16:18])/mean(dat[3,1:3]))
[1] 0.111087
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 -0.267888
- Gene 2: log2(FC) 為 0.638842
- Gene 3: log2(FC) 為 0.108176
第十二種情況:
dds <- makeExampleDESeqDataSet(n=100,m=18)
dds$genotype <- factor(rep(rep(c("I","II","III"),each=3),2))
dds$genotype <- relevel(dds$genotype, "III")
#我們把主要因素condition寫(xiě)在后面,genotype為次要因素寫(xiě)在前面,“:”表示交互項(xiàng)
design(dds) <- ~ genotype + condition + genotype:condition
dds <- DESeq(dds)
resultsNames(dds)
dat = counts(dds, normalized=TRUE)
res = results(dds, list(c("condition_B_vs_A"),c("genotype_II_vs_III")))
這里計(jì)算的是condition_B的genotype III 與condition_A的genotype II 相比較下的差異
FC = (genotype III in condition_B) / (genotype II in condition_A)
手動(dòng)計(jì)算代碼:
# dat 的 16-18列代表 genotype III in condition_B 的 sample
# dat 的 4-6列代表 genotype II in condition_A 的 sample
## Gene 1
log2(mean(dat[1,16:18])/mean(dat[1,4:6]))
[1] 0.07651671
## Gene 2
log2(mean(dat[2,16:18])/mean(dat[2,4:6]))
[1] 0.966533
## Gene 3
log2(mean(dat[3,16:18])/mean(dat[3,4:6]))
[1] -0.1500791
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 0.0778375
- Gene 2: log2(FC) 為 0.9659273
- Gene 3: log2(FC) 為 -0.1501982
第十三種情況:
dds <- makeExampleDESeqDataSet(n=100,m=18)
dds$genotype <- factor(rep(rep(c("I","II","III"),each=3),2))
dds$genotype <- relevel(dds$genotype, "II")
#我們把主要因素condition寫(xiě)在后面,genotype為次要因素寫(xiě)在前面,“:”表示交互項(xiàng)
design(dds) <- ~ genotype + condition + genotype:condition
dds <- DESeq(dds)
resultsNames(dds)
dat = counts(dds, normalized=TRUE)
res = results(dds, list(c("condition_B_vs_A"),c("genotype_I_vs_II")))
這里計(jì)算的是condition_B的genotype II 與condition_A的genotype I 相比較下的差異
FC = (genotype II in condition_B) / (genotype I in condition_A)
手動(dòng)計(jì)算代碼:
# dat 的 13-15列代表 genotype II in condition_B 的 sample
# dat 的 1-3列代表 genotype I in condition_A 的 sample
## Gene 1
log2(mean(dat[1,13:15])/mean(dat[1,1:3]))
[1] 1.852217
## Gene 2
log2(mean(dat[2,13:15])/mean(dat[2,1:3]))
[1] 0.9619238
## Gene 3
log2(mean(dat[3,13:15])/mean(dat[3,1:3]))
[1] -0.5547154
而軟件計(jì)算的log2(FC)值如下(忽略矯正的情況):
- Gene 1: log2(FC) 為 1.812546
- Gene 2: log2(FC) 為 0.959211
- Gene 3: log2(FC) 為 -0.553264
關(guān)于contract的注意事項(xiàng)
contract這個(gè)參數(shù)后面接contract = c("..." , "..."),contract = list(c("..." , "..."))和contract = list(c("..."),c("..."))這幾個(gè)所對(duì)比的是不一樣的
第一個(gè)要求的向量長(zhǎng)度為3,那么只適用于某一個(gè)因素不同的兩組進(jìn)行對(duì)比
例如:

對(duì)于上圖的condition_B_vs_A,這是一個(gè)條件,所以有:
results(dds, contrast=c("condition","B","A"))
那么對(duì)于多因素的情況,比如下面的情況
results(dds, contrast=list( c("condition_B_vs_A","genotypeIII.conditionB") ))
主要考察在genotype III 這個(gè)因素下,condition_B 與condition_A 相比帶來(lái)的差異。
也就是說(shuō),condition_B的genotype III 與 condition_A的genotype III 相比較所帶來(lái)的差異
那么下面的這種情況:
results(dds, contrast=list( c("genotype_III_vs_I","genotypeIII.conditionB"),c("genotype_II_vs_I","genotypeII.conditionB")))
前一個(gè)c()作分子,后一個(gè)c()作分母;
表示的是在condition_B條件下,genotype III 與genotype I 相比較下的差異(分子)和condition_B條件下,genotype II 與genotype I 相比較下的差異(分母),兩者再進(jìn)行比較下的差異(再相除)
FC = [(genotype III in condition_B) / (genotype I in condition_B)] / (genotype II in condition_B) / (genotype I in condition_B)] = (genotype III in condition_B) / (genotype II in condition_B),相當(dāng)于約分
參考:《DESeq2說(shuō)明文檔》
https://www.bioconductor.org/packages/release/bioc/vignettes/DESeq2/inst/doc/DESeq2.html
Bioconductor issue:
https://support.bioconductor.org/p/121674/
主要解釋:
https://rstudio-pubs-static.s3.amazonaws.com/329027_593046fb6d7a427da6b2c538caf601e1.html
