This is a test version of Biostars. For the public version, visit https://www.biostars.org.
data.matrix returns txt file packed into a single column

I am trying to convert my txt file into a data.matrix before generating a heatmap out of it bur when I try data.matrix function, resulting matrix only consists of two columns; sample numbers and all the other information (basemean, log2foldchange, pvalue etc.) packed into a single column. How do I fix this?

Thank you so much,

this is where you can find the .txt file I am using. https://www.dropbox.com/s/n13ny5ropeg8p83/deseq2uaa.txt?dl=0

commands I used;

install.packages("gplots")
library(gplots)
x <- read.csv("deseq2uaa.txt", check.names= FALSE)
y <- data.matrix(x)
r

Please post your actual code

Hello, Here is the trunk of command lines I have used.

Thank you!

> install.packages("gplots")
> library(gplots)
> x <- read.csv("deseq2uaa.txt", check.names= FALSE)
> y <- data.matrix(x)

deseq2.uaa is my text file.

1 answer

Something like this ? You were close with your code above, just set a separator (sep="\t") and chose the first line of your file as column names (header=TRUE)

df <- read.csv(file="deseq2uaa.txt", header=TRUE, sep="\t")
matrix <- as.matrix(df)

thank you so much! this helped. :)

Hello,

I now have another problem. After I converted my data frame into a matrix, I wanted to generate a heatmap but I don't know how to only use the data from "log2foldchange" column to generate the heatmap. I would also like to exclude any "NA" within that specific column. How do I do this? Do you have an idea?

Thanks so much.

I suggest you to take a deep look at this vignette (DESeq2) :

https://bioconductor.org/packages/3.7/bioc/vignettes/DESeq2/inst/doc/DESeq2.html

Try to experiment all the command line of this doc in order to assimilate the process

You will find how to remove your 0 counts row, how to normalize your counts for exploratory analysis, and how to create a proper heatmap.

Also, to remove rows with NA you can try the following ( https://stackoverflow.com/questions/4862178/remove-rows-with-nas-missing-values-in-data-frame ) :

df[complete.cases(df), ]

Thank you so much for all the feedback Bastien. I appreciate it.

Log in to answer this question.