Entering edit mode
7 months ago
jkim
▴
190
Hello,
I would like to know how to create a csv file from a raw gene count sparse matrix from a seurat object.
library(Seurat)
library(tidyverse)
library(Matrix)
abc <- Read10X_h5(filename = "../input/abc_raw_feature_bc_matrix.h5")
se_obj <- CreateSeuratObject(abc, project="ABC")
count_matx <- se_obj@assays$RNA@counts
writeMM(count_matx, "../output/abc.csv")
The abc.csv
file doesn't look what I wanted. I'd like to have a matrix that each row represents gene_id and each column represents cell_barcode. I'm just not sure how to create such a matrix csv file.
head abc.csv
%%MatrixMarket matrix coordinate integer general
36601 1830874 41217502
7589 1 1
36562 2 1
8286 3 1
17209 4 1
18177 4 1
count_matx |> head ()
6 x 1830874 sparse Matrix of class "dgCMatrix"
[[ suppressing 70 column names ‘AAACCCAAGAAACCCA-1’, ‘AAACCCAAGAAACCCG-1’, ‘AAACCCAAGAAACTCA-1’ ... ]]
MIR1302-2HG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FAM138A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
OR4F5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AL627309.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AL627309.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
AL627309.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MIR1302-2HG ......
FAM138A ......
OR4F5 ......
AL627309.1 ......
AL627309.3 ......
AL627309.2 ......
Have you tried a simple
write.table
with thecount_matx
object?Thanks for the input. I did. The process froze in the middle of generating a csv.file.
That's a sign that you should not be writing a CSV file of this magnitude. Why are you trying to get a CSV anyway?
I understand that, but unfortunately that's what I am asked to do.
Take this information to the person that asked you to do this and if they insist, figure out how to lease a high RAM machine (HPC/Cloud) and use data.table::fwrite.
In fact, you could try
fwrite
on your current machine instead ofwrite.csv()
and see if that works.Thanks! In fact, I found a function works for me. It is just unfortunate that the researcher doesn't seem to understand the dimension of the matrix...
https://rdrr.io/github/AllenInstitute/scrattch.io/man/write_dgCMatrix_csv.html