error while making a DegList object on R using edgeR package (Error in colSums(counts) : 'x' must be numeric)
2
0
Entering edit mode
5.8 years ago
deeksha3696 ▴ 10

hey, I am doing an RNAseq analysis (using edgeR) I am loading my data for differential analysis, my data is of read counts. I am now just trying to make DEGList object but, it is showing "Error in colSums(counts): 'x' must be numeric. Please suggest what should I do. thank you!! command used:

rawCountTable <- read.table(file.choose(),header=TRUE)
sampleInfo <- read.table(file.choose(), header=TRUE)
library(edgeR)
dgeFull <- DGEList(rawCountTable, group=sampleInfo$condition)

Error in colSums(counts) : 'x' must be numeric

RNA-Seq R • 16k views
ADD COMMENT
2
Entering edit mode
5.7 years ago
Gordon Smyth ★ 7.6k

This is frequently asked question that arises because many R users don't appreciate the difference between a matrix and a data.frame in R.

I assume that you have a tab-delimited file of read counts. The first field of your file probably contains the Gene Ids and the other columns probably contain read counts. When you read the rawCountTable using read.table you get a data.frame where the first column is a factor with the Gene Ids as levels and the other columns contain integers.

However DGEList is expecting to get a matrix rather than a data.frame. DGEList tries to convert the data.frame to a matrix but finds that the first column of rowCountTable is not numeric and hence issues an error message.

Assuming that your file counts only one column of Gene Ids, then you can fix the problem by

rawCountTable <- read.delim(file.choose(), row.names=1)

This will ensure that the Gene Ids are stored as row.names instead of as a column.

ADD COMMENT
0
Entering edit mode

Hi Gordon, I had the same problem and I tried to fix it following your post here. However, edgeR still gave the error message. Here is the code I used

rawCountTable <- read.delim("featureCount_counts", header = FALSE, sep = "\t", row.names = 1)

rawCountTable <- rawCountTable[-c(1,2), -c(1,2,3,4,5)] 

rawCountTable <- as.matrix(rawCountTable)

And after running head(rawCountTable), this is what I got

head(rawCountTable)
           V7    V8    V9    V10   V11  V12  V13   V14   V15   V16   V17  V18
TG_00001 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00002 "0"   "0"   "7"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_20621 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00003 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00004 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00005 "490" "221" "111" "138" "84" "34" "258" "128" "189" "146" "80" "2"

I am struggling with R and edgeR, I'd really appreciate it if you could take a look at this and help me out. Thanks a lot!

ADD REPLY
0
Entering edit mode

I realized the numbers in my matrix were characters. It looks like I have fixed it by

class(rawCountTable) <- "numeric"

Thanks!!

ADD REPLY
0
Entering edit mode
5.8 years ago
h.mon 35k

Please show the result of:

head( rawCountTable )

rawCountTable is probably a data frame with a non-numeric column corresponding to gene names. You want to make this column into the row names of rawCountTable, then remove this column, to keep only numeric values.

ADD COMMENT

Login before adding your answer.

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