This is a test version of Biostars. For the public version, visit https://www.biostars.org.
DESeq2 Error: some variables in design formula are characters, converting to factors

Hi to you all, I'm a beginner in R and my task is to perform a Differential Expression Analysis on different tissues coming from an individual. I have already trimmed my raw reads (TrimGalore), mapped (Hisat2), assembled transcripts and estimated transcript abundances with StringTie. Then I tried to perform DEA following this pipeline (https://ccb.jhu.edu/software/stringtie/index.shtml?t=manual). I have generated the .csv file with the prepDE.py and I have tried to import these data on DESeq2. In general the pipeline works but then i get an error:

>setwd("C:/Users/hp/Desktop")
>library("DESeq2")
>countData <- as.matrix(read.csv("gene_count_matrix.csv", row.names = "gene_id"))
> head(countData)
                      Adrenal_Cortex Cerebellum_Vermis Cornea Spleen
DNALI1|DNALI1                          0                 0      0      0
MSTRG.852|RAB3B                        0                 0     64      4
MSTRG.10382                         3933              2809   2078   3393
PRAM1|PRAM1                            0                 0      0      0
MSTRG.13828|NBAS                       6                58      9      3
LOC105373404|LOC105373404              0                 0      0      0
>colData <- read.csv("Pheno_data.csv", header = T)
>str(colData) 'data.frame': 4 obs. of  3 variables:  
 $ id    : chr  "Adrenal_Cortex" "Cerebellum_Vermis" "Cornea" "Spleen" 
 $ Tissue: chr  "Adrenal Cortex" "Cerebellum vermis" "Cornea" "Spleen"  
 $ Sex   : chr "Female" "Female" "Female" "Female"
>colData <- read.csv("Pheno_data.csv", header = T, row.names = 1)
>str(colData) 'data.frame': 4 obs. of  2 variables:  
 $ Tissue: chr  "Adrenal Cortex" "Cerebellum vermis" "Cornea" "Spleen"  
 $ Sex   : chr   "Female" "Female" "Female" "Female"
>all(rownames(colData) %in% colnames(countData)) 
 [1] TRUE
>countData <- countData[, rownames(colData)]
>all(rownames(colData) == colnames(countData)) 
 [1] TRUE
>dds <- DESeqDataSetFromMatrix(countData = countData, colData = colData, design = ~ Tissue)
Warning message:
In DESeqDataSet(se, design = design, ignoreRank) :
some variables in design formula are characters, converting to factors

How can I solve my problem??

Thank you in advance for your suggestions!!

rna-seq

1 answer

It is a warning message, not an error. It gives an explanation:

some variables in design formula are characters, converting to factors

In this case, it can be inferred that this warning is produced due to the fact that colData$Tissue is encoded as a character vector, not a categorical variable ('factor').

You need to encode your variables properly. Try something like:

colData$Tissue <- factor(colData$Tissue, levels = c('PBMC', 'NK', 'tcell'))

Here, PBMC is the reference level.

Kevin

Thank you Kevin for your very fast reply! I'm not able to understand your suggestion, I mean this one:

colData$Tissue <- factor(colData$Tissue, levels = c('PBMC', 'NK', 'tcell'))

I have no levels because I have just different types of tissues and I have to perform DEA on them.

By default in R, converting a character vector to a factor will set the factor levels in alphabetical order. That means your first factor level will be NK, and the default contrast will be comparing your PBMC and tcell samples to the NK sample. You can of course set your own contrasts in edgeR or DESeq2, but it's something to keep in mind.

Log in to answer this question.