How to subset data
2
0
Entering edit mode
@sarahwhiteley-20870
Last seen 4.9 years ago

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 • 655 views
ADD COMMENT
0
Entering edit mode
@mikelove
Last seen 1 hour ago
United States

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 COMMENT
0
Entering edit mode
swbarnes2 ★ 1.3k
@swbarnes2-14086
Last seen 23 hours ago
San Diego

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)
resultsNames(dds)
results(dds, contrast=c("group", "IB", "IA"))

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

ADD COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 934 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6