Hello,
I often use DESeq2 for DE analysis and prefer to automate the processing using an Rscript.
The function would look like this:
deseq2 <- function(counts, sampleInfo) {
suppressMessages(library(DESeq2))
deseqdata <- DESeqDataSetFromMatrix(countData=counts, colData=sampleInfo, design=~condition)
dds <- deseqdata[rowSums(counts(deseqdata)) > 1,]
dds$condition <- relevel(dds$condition, ref="CON")
res <- results(DESeq(dds))
...
...
}
I would like to be able to deduce the design formula based on the sample info file I provide.For example, I sometimes should take batch effects into account or other group variables. Therefore, it would be the best if I can specify the design formula based on the columns (and their relative order) in the sample info. e.g. ‘sample’ ‘batch’ ‘condition’ would result in ~batch + condition and ‘sample’ ‘condition’ would result just in ~condition (etc.)
I don’t see an obvious way to achieve this. I tried to just use a variable in the design formula e.g
Mydesign <- colnames(sampleInfo)[2:]
design=~mydesign
This is perhaps due to my quite limited knowledge of R, since I just started using R for writing scripts and have more experience with Python. Could someone point me in the direction to accomplish this goal?
Thanks in advance.
Kind regards,
Wouter De Coster

Thanks for your reply. I understand that this part is not automated by design, but I would in my case use the order of the column in my sample info file to make the formula, without having to hard-code anything a priori.
Perhaps I could have "~batch+condition" hard-coded, and when no batch effect is to be corrected just use the same value in sampleInfo$batch? I will have a look at the matrix and formula() options to specify the design.