I trying to add some interactions to my DESeq2 design matrix. My 12 samples are divided into two batches. There are two strains. These samples are coming from 6 individuals, so it's also a paired experiment with two treatments. Please see the metadata for clarity. As mentioned in the vignette, I have put the ind.n variable in the metadata to make the design paired. The question I am interested in is "Is the treatment effect different across strains?" Following the examples provided in ?results, I believe the contrast name will be "strainsstrainA.conditionstreated". But I have more variables, so I wanted to make sure my design can correctly address the question and that it is taking batches and ind.n variables into account.
no_of_genes <- 10000
no_of_samples <- 12
dds <- makeExampleDESeqDataSet(m = no_of_samples, n = no_of_genes, betaSD = 1)
rawcounts <- counts(dds)
colnames(rawcounts) <- c(paste0("sample", 1:no_of_samples))
rownames(rawcounts) <- c(paste0("gene", 1:no_of_genes))
# Create metadata for the dataset
batches <- c("a","a","a","a","a","b","b","b","b","b","b","b")
conditions <- c("treated","untreated","treated","untreated","treated","untreated",
"treated","untreated","treated","untreated","treated","untreated") #input
strains <- c("strainA","strainA","strainA","strainA","strainA","strainA",
"strainB","strainB","strainB","strainB","strainB","strainB")
animals <- factor(rep(1:6,each=2))
ind.n <- factor(rep(rep(1:3,each=2),2))
metadata <- data.frame(batches, strains, animals, ind.n, conditions)
rownames(metadata) <- c(paste0("sample", 1:no_of_samples))
# Create DESeq object
dds <- DESeqDataSetFromMatrix(countData = rawcounts,
colData = metadata, design = ~ batches +
strains:ind.n + strains + conditions +
strains:conditions)
# Set levels
dds$strains<- relevel(dds$strains, ref = "strainB")
dds$conditions<- relevel(dds$conditions, ref = "untreated")
# Run analysis
dds <- DESeq(dds)
resultsNames(dds)
> resultsNames(dds)
[1] "Intercept" "batches_b_vs_a"
[3] "strains_strainA_vs_strainB" "conditions_treated_vs_untreated"
[5] "strainsstrainB.ind.n2" "strainsstrainA.ind.n2"
[7] "strainsstrainB.ind.n3" "strainsstrainA.ind.n3"
[9] "strainsstrainA.conditionstreated"
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)