Answers.Body: <p>As the warning message is suggesting, you should convert the <code>class</code> of your <code>treatment</code> column in <code>coldata</code> from <code>character</code> to <code>factor</code>.</p>
  <p>Use this:<br />
  <code>coldata$treatment = factor(coldata$treatment)</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-24T17:27:43.310Z
Answers.Text: Thank you, I will give that a try
Answers.UserDisplayName: Justin1609
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-18T07:22:50.807Z
Answers.LastActivityDate: 2022-08-18T07:22:50.807Z
Answers.UserDisplayName: Nitesh Shriwash
Body: <p>I am trying to run DESeq2 analysis on my featureCounts output counts table.</p>
  <p>I ran the following code:</p>
  <pre><code>library(&quot;DESeq2&quot;)
  
  samplefile&lt;-&quot;C:/Users/RGB King/Documents/R/~/R/DESeq2_analysis/sample_table.txt&quot;
  
  coldata&lt;-read.table(file=samplefile, sep=&quot;\t&quot;, header=FALSE, col.names = as.factor(c(&quot;&quot;,&quot;treatment&quot;)), row.names=1)
  
  countfile&lt;-&quot;C:/Users/RGB King/Documents/R/~/R/DESeq2_analysis/feature_counts_test_AvABC.txt&quot;
  countdata&lt;-read.table(file=countfile, sep=&quot;\t&quot;, header=FALSE, row.names = 1)
  
  countdata&lt;-countdata[-c(1:5)]
  
  dds &lt;- DESeqDataSetFromMatrix(
      countData = countdata,
      colData = coldata,
      design = ~ treatment
  )
  </code></pre>
  <p>I then get the following error:</p>
  <pre><code>Warning message:
  
  In DESeqDataSet(se, design = design, ignoreRank) :
  
    some variables in design formula are characters, converting to factors
  </code></pre>
  <p>The countdata table looks as follows:</p>
  <pre><code>|------|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:------|
  </code></pre>
  <p>The coldata looks like this:</p>
  <pre><code>|--------|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:------|
  
  </code></pre>
  <p>So after I got the error I found posts on a forum that stated that DESeq2 only recognises &quot;integer&quot; class input values for the analyses. Therefore, I ran the following code:</p>
  <pre><code>sapply(countdata,class)
  </code></pre>
  <p>This then showed me that the data in the countdata table was in &quot;character&quot; class, so to fix this I ran the following:</p>
  <pre><code>chars &lt;- sapply(countdata, is.character)
  countdata[ , chars] &lt;- as.data.frame(apply(countdata[ , chars], 2, as.integer))
  </code></pre>
  <p>But this then caused the values in the GeneID row to become &quot;NA&quot;. 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 &quot;row.names =1&quot; so why does this not keep my values in the GeneID row separate from the rest of the table?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-31T15:19:28.867Z
Comments.Text: 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.
Comments.UserDisplayName: Justin1609
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-31T15:44:40.173Z
Comments.Text: 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"
Comments.UserDisplayName: Justin1609
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-31T16:39:21.713Z
Comments.Text: Why are you importing your count data with header = false when you clearly have a header?
Comments.UserDisplayName: swbarnes2
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-07-31T21:24:36.990Z
Comments.Text: 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?
Comments.UserDisplayName: Justin1609
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-01T01:14:03.797Z
Comments.Text: Are you sure you cant use the feature counts file without manipulating it in windows at all?  The warning you quote above (not an error) is about your coldata, not your count data.
Comments.UserDisplayName: swbarnes2
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-01T07:01:05.890Z
Comments.Text: @swbarnes2 I will give that a try then thank you. Could you maybe explain what is wrong with my coldata file please? And how should I correct it so that the analysis can run without the error?
Comments.UserDisplayName: Justin1609
Tags: <rna-seq><differential-expression><deseq2>
Title: Beginner with DESeq2 having issue with analysis
ThreadText: # Beginner with DESeq2 having issue with analysis
  
  (Asked by: username_0 on 2021-07-31)
  
  I am 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?
  
  **Tags:** rna-seq, differential-expression, deseq2
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_0**: 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"  
  > **username_1**: Why are you importing your count data with header = false when you clearly have a header?  
  > **username_0**: 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?  
  > **username_1**: Are you sure you cant use the feature counts file without manipulating it in windows at all?  The warning you quote above (not an error) is about your coldata, not your count data.  
  > **username_0**: @username_1 I will give that a try then thank you. Could you maybe explain what is wrong with my coldata file please? And how should I correct it so that the analysis can run without the error?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-08-18. Score: 1
  
  As the warning message is suggesting, you should convert the `class` of your `treatment` column in `coldata` from `character` to `factor`.
  
  Use this:  
  `coldata$treatment = factor(coldata$treatment)`
  
  > **Comments:**
  > **username_0**: Thank you, I will give that a try  
  
  ---
  
  