> dds <- DESeqDataSetFromMatrix(countData = cts, colData = coldata, design = ~ condition)
> dds
class: DESeqDataSet
dim: 59368 18
metadata(1): version
assays(1): counts
rownames(59368): DDX11L1 WASH7P ... MT-TT MT-TP
rowData names(0):
colnames(18): KO1_P1_L001.Counts KO1_P1_L002.Counts ... WT_P3_L001.Counts WT_P3_L002.Counts
colData names(4): cell_type condition sample run
> ddsColl <- collapseReplicates(dds, dds$sample, dds$run)
> ddsColl
class: DESeqDataSet
dim: 59368 9
metadata(1): version
assays(1): counts
rownames(59368): DDX11L1 WASH7P ... MT-TT MT-TP
rowData names(0):
colnames(9): l1 l2 ... w2 w3
colData names(5): cell_type condition sample run runsCollapsed
> colData(ddsColl)
DataFrame with 9 rows and 5 columns
cell_type condition sample run runsCollapsed
<character> <factor> <character> <character> <character>
l1 human longKO l1 long_P1_L001 long_P1_L001,long_P1_L002
l2 human longKO l2 long_P2_L001 long_P2_L001,long_P2_L002
l3 human longKO l3 long_P3_L001 long_P3_L001,long_P3_L002
s1 human shortKO s1 short_P1_L001 short_P1_L001,short_P1_L002
s2 human shortKO s2 short_P2_L001 short_P2_L001,short_P2_L002
s3 human shortKO s3 short_P3_L001 short_P3_L001,short_P3_L002
w1 human WT w1 wt_P1_L001 wt_P1_L001,wt_P1_L002
w2 human WT w2 wt_P2_L001 wt_P2_L001,wt_P2_L002
w3 human WT w3 wt_P3_L001 wt_P3_L001,wt_P3_L002
> matchFirstLevel <- dds$sample == levels(dds$sample)[1]
> matchFirstLevel
logical(0)
> stopifnot(all(rowSums(counts(dds[,matchFirstLevel])) == counts(ddsColl[,1])))
Error: all(rowSums(counts(dds[, matchFirstLevel])) == counts(ddsColl[, .... is not TRUE
From the output of dds
and ddsColl
, it seems the number of columns decreased from 18 to 9, as expected. The only difference I see between my DESeq2 workflow output is the result of matchFirstLevel
(see below for expected result). Why might this be for my dataset, but not the example dataset?
> dds <- makeExampleDESeqDataSet(m=12)
> dds$sample <- factor(sample(paste0("sample",rep(1:9, c(2,1,1,2,1,1,2,1,1)))))
> dds$run <- paste0("run",1:12)
> ddsColl <- collapseReplicates(dds, dds$sample, dds$run)
> colData(ddsColl)
DataFrame with 9 rows and 4 columns
condition sample run runsCollapsed
<factor> <factor> <character> <character>
sample1 B sample1 run10 run10,run11
sample2 A sample2 run5 run5
sample3 A sample3 run6 run6
sample4 A sample4 run1 run1,run4
sample5 B sample5 run7 run7
sample6 B sample6 run9 run9
sample7 A sample7 run3 run3,run12
sample8 B sample8 run8 run8
sample9 A sample9 run2 run2
> colnames(ddsColl)
[1] "sample1" "sample2" "sample3" "sample4" "sample5" "sample6" "sample7" "sample8" "sample9"
> matchFirstLevel <- dds$sample == levels(dds$sample)[1]
> matchFirstLevel
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE
> stopifnot(all(rowSums(counts(dds[,matchFirstLevel])) == counts(ddsColl[,1])))