2

Here is an example:

cts<-matrix(sample(1:1000, 600, replace = T), ncol=6)
rownames(cts)<-paste0("Gene", 1:100)
colnames(cts)<-paste0("sample", 1:6)

coldat<-data.frame(B=c(1,2,1,2,1,2),
                   C=c(1,1,1,2,2,2))
rownames(coldat)<-colnames(cts)

library(DESeq2)
batch="B"
condition="C"
dds <- DESeqDataSetFromMatrix(countData = cts,
                              colData = coldat,
                              design= ~ batch + condition)
dds <- DESeq(dds)
Error in DESeqDataSet(se, design = design, ignoreRank) : 
all variables in design formula must be columns in colData

My question is how to index batch="B" and condition="C" in the design formula.

David Z
  • 6,641
  • 11
  • 50
  • 101

2 Answers2

2

Just figured out:

dds <- DESeqDataSetFromMatrix(countData = cts,
                              colData = coldat,
                              design= as.formula(paste0("~", batch, "+", condition)))
David Z
  • 6,641
  • 11
  • 50
  • 101
1

The issue is that batch and condition are not esplicitly declared in coldat. If B=batch and C=condition, then you can simply ~ B+C. Otherwise you will need to add (or rename) the 2 columns.

coldat$batch <- coldat$B
coldat$condition <- coldat$C

or, if they differ

coldat$batch <- c(1,2,3,4,5,6)
coldat$condition <- c(1,1,1,2,2,2)
fra
  • 832
  • 6
  • 14