This is a test version of Biostars. For the public version, visit https://www.biostars.org.
DESeq2 comparisons using contrast

Hi all, I recently started analyzing some bacterial RNAseq data. So, I have 4 different strains and for each strain I have 2 conditions. Let's say strains are A, B, C and D while conditions are X and Y. I have a total of 24 samples (3 replicate per strain and condition, for example strain A in condition X has 3 replicates and so on). I made a count matrix with the raw read counts from all my samples and coldata with 2 columns : strain and condition. I made each column as a factor.

I have a few questions:

  1. I am primarily interested in getting differences between the strains keeping the condition in mind. So, is using design~ condition+strain sufficient? (Note, after doing PCA I found out that most of my variance actually comes from the different conditions and not the different strains but I'm interested in the difference between the strains).

  2. Next, I know how to get results between different factor levels inside a variable using contrast. Like, If I wanted to get results between strain A and strain B, I would go like results(dds, contrast=c("strain","A","B")) while if I wanted to compare just my conditions it would be results(dds, contrast=c("condition","X","Y")).

Now the first code would give me differences between strain A and B for both conditions combined (all 6 samples of strain A vs all 6 samples of strain B). What if I just wanted to get differences between strain A and B in just condition X (3 samples of strain A in condition X vs 3 samples of strain B in condition X) or just condition Y. How do I do that using results?

Or do I need to make 2 separate dds objects for each condition and do it?

Any help will be appreciated. Thanks!!

deseq2

2 answers

What if I just wanted to get differences between strain A and B in just condition X (3 samples of strain A in condition X vs 3 samples of strain B in condition X) or just condition Y.

The simpler and more readable way to do this is to make a new column in colData which is strain concatenated with condition. Make that column alone your design, then specify the contracts you want in results.

http://bioconductor.org/packages/devel/bioc/vignettes/DESeq2/inst/doc/DESeq2.html#interactions

Okay, so if I got this correctly, I want to do something like

dds$group <- factor(paste0(dds$strain, dds$condition))

design(dds) <- ~ group

dds <- DESeq(dds)

results(dds, contrast=c("group", "BX", "AX"))

and this should give me the results table for strain B vs strain A for condition X? Right?

If so, this should be simple enough and I can use this to get all the comparisons I need.

Thanks a lot.

To account for condition-specific strain effect, you need to change your design by including the interaction term:

design~ condition+strain+condition:strain

or more briefly:

design~ condition*strain

Then you can measure the impact of strain in condition X by extracting the following contrast (asuming that X is the first level of the condition factor):

results(dds, contrast=c("strain","B","A"))

For the other condition levels, you will need to add the interaction term:

results(dds, list( c("strain_B_vs_A","condtionY.strainB")))

More info on how to specify contrasts: ?results

Log in to answer this question.