counts matrix should be numeric, currently it has mode: character when using a csv file in R for DESeq2
2
0
Entering edit mode
12 months ago
Sara ▴ 260

I have a csv files and columns are separated by ; and decimal part of numbers are separated by ,. I open the file using this command:

counts_data <- read.csv('normalized.csv', sep=';', check.names = FALSE , stringsAsFactors=FALSE)

and here is how it looks:

       4780008_S1_R1_001 4780008_S6_R1_001 4780009_S2_R1_001 4780009_S7_R1_001 4780020_S12_R1_001 4780020_S17_R1_001 4780021_S13_R1_001 4780021_S18_R1_001
HOPX         25,11928758       17,76365784       19,69619514       11,96904427        35,09723338        28,27082618        10,90948573        20,44938677
THAP6        12,05145011        6,92481577       10,74337917       5,459564054        7,019446675         11,0943282        10,38998641         8,89366821
MTRF1        15,82660316       20,17228942       13,87686476       8,399329314        22,66278498        17,90861101        11,77531793         13,2497506
CXCR3         19,7469544       11,74207891       17,45799115       20,78834005        17,84945012        20,27389925        19,22147486        22,50642568
MRPL39        14,6650176       13,24747365       10,29573837       13,85889337        12,03333716        13,57224922        14,54598097         9,74068423
GCNT4        17,56898148        17,4625789       12,08630156       10,49916164        10,83000344        18,47177487        13,85331521        14,52027463
       4780024_S3_R1_001 4780024_S8_R1_001 4780033_S14_R1_001 4780033_S19_R1_001 4780034_S20_R1_001 4780037_S15_R1_001 4780045_S16_R1_001 4780045_S21_R1_001
HOPX           14,849565       12,38366402        11,74245904        5,285433701        9,164738495        20,00683332        42,91645904        27,96661055
THAP6         12,4736346         5,8221704        10,70198798        5,162516638        6,612532838        8,594484736        10,11963664        6,279927518
MTRF1         15,4435476       7,947724673        19,32303386        11,06253565        13,45708437        10,98966901        20,88325017        11,30386953
CXCR3         18,4134606       12,19883322        26,30905379        17,70005705        25,40604722        18,31611501        25,85107179        28,80393422
MRPL39        15,4435476       9,241540317        14,41795603        11,92295509         11,6009348        10,42609624        14,94946322        9,043095626
GCNT4         12,4736346       3,696616127        27,79544101        9,341696774        16,70534612        9,158057506        16,60540377        6,782321719

When I do follow up analysis on the data from this file, I keep getting this error:

Error in DESeqDataSet(se, design = design, ignoreRank) : 
  counts matrix should be numeric, currently it has mode: character

I think the reason is that I have commas in the file. if so, do you know how fix the issue? if not , do you know what the problem is?

DESeq2 • 1.3k views
ADD COMMENT
2
Entering edit mode
12 months ago
Darked89 4.6k

You can try:

counts_data  <- read.csv2("normalized.csv", header = TRUE)

But as far as I know DESeq2 requires raw counts as input, so the normalized counts will not work properly.

ADD COMMENT
0
Entering edit mode
12 months ago
ATpoint 83k

You have commas as decimal delimiters which interpreted as text. Just replace by dot and make numeric:

d <- data.frame(A=c("1,2", "3,2"), B=c("3,4", "10,2"), row.names = c("GeneA", "GeneB"))
d
#>         A    B
#> GeneA 1,2  3,4
#> GeneB 3,2 10,2

dx <- apply(d, 2, function(x) as.numeric(gsub(",", ".", x)))
rownames(dx) <- rownames(d)

dx
#>         A    B
#> GeneA 1.2  3.4
#> GeneB 3.2 10.2

mode(dx)
#> [1] "numeric"

What are these floating numbers, it's not the typical "raw" counts, or is it from tximport?

ADD COMMENT
0
Entering edit mode

Since the input file is named normalized.csv and the values look like floats most likely the counts have been already normalized somehow.

ADD REPLY

Login before adding your answer.

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