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"
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.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?
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.
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/