Question: How to subset data
gravatar for sarah.whiteley
4 months ago by
sarah.whiteley0 wrote:

Hi there,

I am having trouble figuring out how to subset my data to look at gene expression within particular groups. I have 38 samples with two factors - temperature with 2 levels (28 and 36), and stage with 3 levels (s1, s2, and s3). While I can readily contrast within each factor

res <- results(dds, contrast=c("stage","s1","s3"), alpha=0.05, lfcThreshold=1) res <- results(dds, contrast=c("temp","28","36"), alpha=0.05, lfcThreshold=1)

I want to be able to look at genes that are differentially expressed between the two temperatures within each stage. I have tried creating a new factor containing only values for a single stage stage3 <- factor(c( "s3", "s3", "s3", "s3", "s3", "s3", "s3","s3" ,"s3","s3" , "s3","s3","s3","s3"))

test <- results(dds, contrast=c("stage3","28","36"), alpha=0.05, lfcThreshold=1)

And get an error message that 28 and 36 should be levels of stage 3, which of course indicates that the way I'm trying to set this up is fundamentally wrong.

Any suggestions would be greatly appreciated!

Session info R version 3.5.3 (2019-03-11) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 17134)

deseq2 • 149 views
ADD COMMENTlink modified 4 months ago by swbarnes2330 • written 4 months ago by sarah.whiteley0
Answer: How to subset data
gravatar for Michael Love
4 months ago by
Michael Love25k
United States
Michael Love25k wrote:

Check out the vignette section on interactions, we have example code of how to combine two factors into one so that you can make these comparisons.

ADD COMMENTlink written 4 months ago by Michael Love25k
Answer: How to subset data
gravatar for swbarnes2
4 months ago by
swbarnes2330 wrote:

It's a little hard to find in the vignette, but you want to do this:

dds$group <- factor(paste0(dds$genotype, dds$condition))
design(dds) <- ~ group
dds <- DESeq(dds)
results(dds, contrast=c("group", "IB", "IA"))

This is how you compare one subset of samples to another subset of samples

ADD COMMENTlink written 4 months ago by swbarnes2330

Hi, thanks so much for your suggestion. I tried the following (trying to assess DGE between 28 and 36 for stage 3 samples only)

dds$stage <-factor(paste0(dds$s3, dds$"28", dds$"36")) design(dds)<- ~ s3 dds3 <- DESeq(dds) resultsNames(dds3) results(dds3, contrast=c("s3", "28", "36"))

Weird thing is that this actually worked the first time I ran it, and then for some reason when I try to run it again it throws up the following error message for the first line

Error in [[<-(*tmp*, name, value = integer(0)) : 0 elements in value to replace 38 elements

I have changed nothing in my code, checked that all of the factors are properly defined in the dds object, but have had no luck. It's particularly perplexing given that it did run (I have proof in a CSV file I export and subsequent graph I made).

I have also tested with the other two stages (s1 and s2) and get the same error.

Do you have any idea why this might be happening?

ADD REPLYlink modified 4 months ago • written 4 months ago by sarah.whiteley0

You need to walk through the example from the vignette, because you aren't following the example at all.

ADD REPLYlink written 4 months ago by swbarnes2330
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 231 users visited in the last hour