0
$\begingroup$

Hi there I am brand new to using RStudio and trying to run DESeq2 analysis on my featureCounts output counts table.

I ran the following code:

library("DESeq2")
samplefile<-"C:/Users/RGB King/Documents/R/~/R/DESeq2_analysis/sample_table.txt"
coldata<-read.table(file=samplefile, sep="\t", header=FALSE, col.names = as.factor(c("","treatment")), row.names=1)
countfile<-"C:/Users/RGB King/Documents/R/~/R/DESeq2_analysis/feature_counts_test_AvABC.txt"
countdata<-read.table(file=countfile, sep="\t", header=FALSE, row.names = 1)
countdata<-countdata[-c(1:5)]
dds <- DESeqDataSetFromMatrix(
countData = countdata,
colData = coldata,
design = ~ treatment)

I then get the following error:

Warning message:

In DESeqDataSet(se, design = design, ignoreRank) :

  some variables in design formula are characters, converting to factors

The countdata table looks as follows:

|------|Variable1|Variable2|Variable3|Variable4|Variable5|Variable6|Variable7|Variable8|
|GeneID|A_1.bam--|A_2.bam--|A_3.bam--|A_4.bam--|AB_1.bam-|AB_2.bam-|AB_3.bam-|AB_4.bam-|
|THI3--|:12:-----|:34:-----|:8:------|:15:-----|:6:------|:22:-----|:41:-----|:33:-----|
|THI7--|:17:-----|:78:-----|:9:------|:23:-----|:11:-----|:54:-----|:19:-----|:7:------|

The coldata looks like this:

|--------|treatment|
|A_1.bam-|:A:------|
|A_2.bam-|:A:------|
|A_3.bam-|:A:------|
|A_4.bam-|:A:------|
|AB_1.bam|:B:------|
|AB_2.bam|:B:------|
|AB_3.bam|:B:------|
|AB_4.bam|:B:------|

So after I got the error I found posts on a forum that stated that DESeq2 only recognises "integer" class input values for the analyses. Therefore, I ran the following code:

sapply(countdata,class)

This then showed me that the data in the countdata table was in "character" class, so to fix this I ran the following:

chars <- sapply(countdata, is.character)
countdata[ , chars] <- as.data.frame(apply(countdata[ , chars], 2, as.integer))

But this then caused the values in the GeneID row to become "NA". So my questions are how can I change the class of just the GeneID row back to what it was? Will this then allow the analysis to run correctly? And in my code for the countdata I do specify "row.names =1" so why does this not keep my values in the GeneID row separate from the rest of the table?

I really apologize if this is a poorly crafted question, but I have been trying to figure this out for weeks now and I don't know what else to do and I really just need the results of this analysis to move forward with my work urgently. Any help please would really appreciate it.

$\endgroup$
7
  • $\begingroup$ If the first column is GeneID and your data.frame was called df then do df[,2:ncol(df)] or move GeneID to rownames and then convert to numeric class. $\endgroup$
    – ATpoint
    Jul 31 at 14:39
  • $\begingroup$ Hi there, @ATpoint thanks for taking the time to answer I appreciate it. Could you maybe explain how to move the GeneID to row.names in my code? If I can explain better, I need to just keep the cells in GeneID row i.e. "A_1.bam" as a "character" class and change the rest of the cells that contain the DE gene counts to "integer" class. I am not sure if this will work though, but I just want to try it and see if that is why I am getting the error I mentioned in post. $\endgroup$
    – Justin1609
    Jul 31 at 15:19
  • $\begingroup$ Cause when I run sapply(countdata,class) I still get the following output V7 V8 V9 V10 V11 V12 V13 V14 "character" "character" "character" "character" "character" "character" "character" "character" $\endgroup$
    – Justin1609
    Jul 31 at 15:44
  • $\begingroup$ Why are you importing your count data with header = false when you clearly have a header? $\endgroup$
    – swbarnes2
    Jul 31 at 16:39
  • $\begingroup$ Yes apologies I corrected that, however, I still can't resolve the issue of the data in the counts table I input being in "character" class. Is this a common error that one gets when working with featureCounts generated counts tables? It might be worth mentioning, I changed the file from what I got directly as the output file i.e. a file in ASCII text format to a text document in notepad on windows. I am not sure if that maybe caused DESeq2 to recognise the integers as "character" class as well? Would it be better to convert the output of featureCounts to a .csv file format in excel? $\endgroup$
    – Justin1609
    Jul 31 at 21:24
1
$\begingroup$

There is nothing wrong with your colData. It is encoded as character rather than factor, and DESeq2 is turning it into factors, that is all that the warning (warning != error) tells. I never needed to convert my matrix to load featureCounts output into DESeq2. Just load the output with the header, use rownames() to move the gene column to rownames, remove all the non-relevant columns (that is usually 1-7) and then feed the remaining one into DESeq2. I have no featureCounts output at hand right now. If you need code then please provide suitable example data via the dput function for easy copy/pasting.

$\endgroup$
1
  • $\begingroup$ Hey @ATpoint sorry your suggestion on my other question reminded me about this. I got assistance from a friend who works as a bioinformaticist at a private company. He noted that there was an annotation step missing in my data and interestingly even with his code he wrote for me I still got the warning message I mentioned, which he attributed to using RStudio in Windows. I still would like to send examples of my data through to you though, as although I did get an output from his code I am unsure if it is correct. $\endgroup$
    – Justin1609
    Aug 18 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.