How to export count data as .csv file in Seurat
1
1
Entering edit mode
3 months ago
rb56 ▴ 30

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?

Seurat countdata R • 510 views
0
Entering edit mode

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

2
Entering edit mode
3 months ago

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")

0
Entering edit mode

Thank you so much!! Really appreciate your help