Search
Question: DESeq2 Subsetting gives error in contrasts - can be applied only to factors with 2 or more levels
0
gravatar for russell.stewart.j
5 months ago by
russell.stewart.j0 wrote:

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.

ADD COMMENTlink modified 5 months ago • written 5 months ago by russell.stewart.j0
1
gravatar for Michael Love
5 months ago by
Michael Love20k
United States
Michael Love20k wrote:

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 COMMENTlink written 5 months ago by Michael Love20k

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 REPLYlink written 5 months ago by russell.stewart.j0
Please log in to add an answer.

Help
Access

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