Help with droplevels in Deseq2
1
0
Entering edit mode
bjen731 ▴ 10
@2586ad17
Last seen 2.1 years 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 • 1.8k views
ADD COMMENT
2
Entering edit mode
ATpoint ★ 4.0k
@atpoint-13662
Last seen 13 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.

ADD COMMENT
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.

ADD REPLY
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?

ADD REPLY
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.

ADD REPLY
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:

http://adv-r.had.co.nz/

ADD REPLY

Login before adding your answer.

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