This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Using data.matrix while reading raw counts from a csv file for DESeq2 analysis

Hi all, I have my raw read counts in a csv file and while doing DESEq2 I read it like-

  calidata<-read.csv("/Users/XXX/Desktop/xxx/TT48.csv", header=TRUE, row.names = 1)
 mat_data <- data.matrix(calidata)

and then proceeded with DESeq2. If I use same input file but in a tab delim text format and read it using read.table and as.matrix like-

calidata <- read.table("/Users/XXX/Desktop/xxx/TT48.txt", row.names = 1, header=TRUE)
mat_data <-as.matrix(calidata)

then the values get changed and so as MAplot and normalized counts. I understand that function 'data.matrix' changes input according to internal factors but my question is which one to use? Is using data.matrix not right here as my output gets changed or is it okay ? I get better norm counts using data.matrix function but result is not same. I am so confused about it. Kindly help me out.

rna-seq

1 answer

They should produce the same data, as evidenced by this simple example:

x <- data.frame(replicate(10,sample(0:1,10,rep=TRUE)))

table(x==data.matrix(x))
TRUE 
 100 

table(x==as.matrix(x))
TRUE 
 100 

table(data.matrix(x)==as.matrix(x))
TRUE 
 100

You will have to explore the reason why they are giving different results.

I prefer to use read.table because read.csv is a wrapper function that can read malformed data without giving any warnings. Use read.table like this:

read.table(FILE, row.names=1, header=TRUE, sep="\t", stringsAsFactors=FALSE, dec=".")

dec specifies the decimal point. stringsAsFactors will prevent any text from being converted into factors.

Also look out for trailing white-space after your numerical data. If even 1 value is like this, "1.5 ", then the entire data that's read can be misinterpreted as characters, and then the conversion into data-matrix will be unreliable.

Kevin

Problem solved. Thanks a lot

Log in to answer this question.