DESeq2 Subsetting gives error in contrasts - can be applied only to factors with 2 or more levels
1
0
Entering edit mode
@russellstewartj-14292
Last seen 4.8 years ago

I'm running DESeq2 on a small RNA seq experiment. The coldata has 87 samples total and begins like this:

Sample

BMI

Diagnosis

Particle

1

Obese

PCOS

MP

10

Obese

PCOS

MP

11

Obese

PCOS

EV

12

Obese

PCOS

FFD

14

Obese

PCOS

MP

15

Obese

PCOS

EV

16

Obese

PCOS

FFD

18

Lean

PCOS

MP

19

Lean

PCOS

EV

2

Obese

PCOS

EV

20

Lean

PCOS

FFD

21

Lean

PCOS

MP

22

Lean

PCOS

EV

23

Lean

PCOS

FFD

24

Lean

PCOS

MP

25

Lean

PCOS

EV

26

Lean

PCOS

FFD

27

Lean

PCOS

MP

28

Lean

PCOS

EV

29

Lean

PCOS

FFD

3

Obese

PCOS

FFD

My two main comparisons, Lean vs Obese and PCOS vs non-PCOS work fine, which I can summarize with this:

dds <- DESeqDataSetFromMatrix(countData = cts_df_ordered,
  colData = coldata_ordered_trim,
  design = ~ Particle + BMI + Diagnosis)
dds$Diagnosis <- factor(dds$Diagnosis, levels = c("PCOS","non-PCOS"))
dds$BMI <- factor(dds$BMI, levels = c("Lean","Obese"))
dds$Particle <- factor(dds$Particle, levels = c("MP","FFD","EV"))
dds <- DESeq(dds)

resDIAG <- results(dds)
resresOrdered <- resDIAG[order(resDIAG$pvalue),]
summary(resDIAG)
sum(resDIAG$padj < 0.05, na.rm=TRUE)

resBMI <- results(dds, contrast=c("BMI","Lean","Obese"))
summary(resBMI)
sum(resBMI$padj < 0.05, na.rm=TRUE)

Then I tried to subset the dds to make these same two comparisons but within each particle, starting with MP:

dds_MP <- dds[, dds$Particle %in% c("MP")]
dds_MP$Particle <- droplevels(dds_MP$Particle)
dds_MP <- DESeq(dds_MP)

Giving the error:

using pre-existing size factors
estimating dispersions
found already estimated dispersions, replacing these
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

I'm also looking to make PCAs which only include the particle type of interest, which I was doing for the complete dataset using the below code:

vsd <- vst(dds, blind=FALSE)
plotPCA(vsd, intgroup=c("BMI","Diagnosis"))

How can I subset the 3 particle types (MP, FFD, EV) and compare PCOS v non-PCOS and Lean vs Obese within particle type followed by PCA? Thanks in advance for your time and help.

deseq2 multiple factor design contrast • 2.4k views
ADD COMMENT
1
Entering edit mode
@mikelove
Last seen 1 day ago
United States

From quickly scanning your code, it looks like you need to change the design(dds) before you re-run DESeq() on the subset. You still have a factor in there even though that factor only has one level, and so it doesn’t make sense for building coefficients. DESeq2 does some things (mostly checks) on the user’s behalf, but it doesn’t change the design(dds) for you, as this is a important user-defined part of the analysis.

ADD COMMENT
0
Entering edit mode

Thanks Michael, I rebuilt my dds and ran again without that factor like so and it worked:

dds_Particle <- DESeqDataSetFromMatrix(countData = cts_df_ordered,
  colData = coldata_ordered_trim,
  design = ~ BMI + Diagnosis)

dds_MP <- dds_Particle[, dds_Particle$Particle %in% c("MP")]
dds_MP$Particle <- droplevels(dds_MP$Particle)
dds_MP <- DESeq(dds_MP)

Your hard work and continued support on this package is amazing, much appreciated!

Stewart

ADD REPLY
0
Entering edit mode

Is there any way of subset the 3 particles without rebuilding dds, like just modifying the design of the original dds?

ADD REPLY
0
Entering edit mode

No, to have the entire analysis only consider a subset of samples you have to subset the dds.

ADD REPLY
0
Entering edit mode

Is there any way of subset the 3 particles without rebuilding dds, like just modifying the design of the original dds?

ADD REPLY

Login before adding your answer.

Traffic: 388 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