R: 读取S4类

1.s4中属性相关

https://github.com/cole-trapnell-lab/monocle-release/issues/262

data <- as(as.matrix(seurat_object@assays$RNA@data), 'sparseMatrix')

上面这句有些许帮助,将对象属性数据转换为一个稀疏矩阵。

https://www.biostars.org/p/312933/ 将稀疏矩阵写入mtx文件,这个教程简直so good!

复制代码
library(Matrix)

# generate single-cell RNA seq data
gbm <- replicate(10, rpois(10, 1))
rownames(gbm) <- paste0("gene_", 1:nrow(gbm))
colnames(gbm) <- paste0("cell_",1:ncol(gbm))

# save sparse matrix
sparse.gbm <- Matrix(gbm , sparse = T )
head(sparse.gbm)
writeMM(obj = sparse.gbm, file="matrix.mtx")

# save genes and cells names
write(x = rownames(gbm), file = "genes.tsv")
write(x = colnames(gbm), file = "barcodes.tsv")
复制代码

 R中的稀疏矩阵格式为:dgCMatrix。

 

posted @ 2020-12-10 22:08  lypbendlf  阅读(437)  评论(0编辑  收藏  举报