This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to export count data as .csv file in Seurat

Hi,

I'm trying to export the log normalized count data from Seurat in to a .csv file and get the following error:

library (Seurat)
fib.data <- subset(onlyharmonfib, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mito <5)
fib.data_norm<- NormalizeData(fib.data)
fib_count <- GetAssayData(object = fib.data_norm, assay = "RNA", slot = "data")
write.csv(as.matrix(fib_count), file = "file_path", quote = FALSE)

Error in file(file, ifelse(append, "a", "w")) : cannot open the connection

Is there an easier method to get the data in a .csv file?

Thank you for your help!

seurat countdata r

instead of the argument in write.csv file = "file_path", you probably meant file = file_path without the quotes as an object with your path and filename stored, that's why write.csv doesn't know which file to write into; but rpolicastro is absolutely right, data.table will be so much faster for this purpose

1 answer

I would use the data.table library to write the file, otherwise it could take a while to write to disk.

library("data.table")

fwrite(as.data.table(fib_count, keep.rownames="feature"), "counts.csv")

Thank you so much!! Really appreciate your help

Log in to answer this question.