Help with droplevels in Deseq2
1
0
Entering edit mode
bjen731 • 0
Last seen 6 days ago
United Kingdom

Hi, I am currently using the DEseq2 package to carry out differential gene expression. When i try to drop levels it gives me an error message saying " no applicable method for 'droplevels' applied to an object of class "character". Can you please explain how I can fix this please? Also I would like some more info on the function 'droplevels' and how to correctly use it in an example please as I am still not sure if I am using it in the correct context.

Thank you!

dds1 <- DESeqDataSetFromMatrix(countData = countdata,
colData = colData,
design = ~ Celltype+Treatment+Celltype:Treatment)

#subset the  relevant columsn from full dataset, Call it dds1a

dds1a <- dds1[,dds1$Subset == "classical"] # quick check to see we have the correct samples extracted as.data.frame(colData(dds1a)) # Droplevels dds1a$Celltype <- droplevels( dds1a\$Celltype)

#Error in UseMethod("droplevels") :
no applicable method for 'droplevels' applied to an object of class "character"
droplevels DESeq2 • 194 views
2
Entering edit mode
ATpoint ▴ 970
@atpoint-13662
Last seen 16 hours ago
Germany

It means that this column of the data.frame is a character and not a factor, and only factors have levels. Actually, if the colData are not factorial you do not have to do anything after the filtering because DESeq2 will convert to factors when running DESeq() DESeqDataSet()(or its derivates when starting from matrix or other input formats) automatically. it will print a message when doing so.

1
Entering edit mode

The conversion is at the dataset creation step, e.g. DESeqDataSetFrom....

Any variables in the design which are characters will be converted to factors at that step.

I would check what class() the variables are before and after. You can always just make sure you provide factors to DESeq2, and avoid the character variable problem on your end.

0
Entering edit mode

That makes more sense, thank you very much!

Also, as I am still very new to this field, how would I ensure that the variables are provided as a factor to deseq2 to avoid any issues later on?

1
Entering edit mode

DESeq2 and Bioconductor assume some familiarity with basic R functions, I'd recommend watching a few videos on basics of R, in particular reading about characters and factors. This will be a more efficient way to go forward.

0
Entering edit mode

This here is what you should read, from Hadley Wickham (that's the RStudio/tidyverse/ggplot/magrittr/reshape2 dude) -- short enough to read in a few hours, yet extensive enough to get most essentials: