# how to generate an scRNA counts file

I have barcodes.tsv, genes.tsv and matrix.mtx file from my RNA seq data and I want to generate a scRNA counts files using R. When I tried using the readMM function, it gave me the following error:

Error: cannot allocate vector of size 185.1 Gb.


This happens even when I run it as a job. How can I generate a combined csv file using R?

Thank you.

• Hi and welcome to the site! It is very hard to help without a concrete example to work on. Could you show us a few lines of a couple of your input files and then the output you require from those example lines? That way we can understand what you need better and we can also make sure any solutions we come up with actually work for your data. Aug 21 '19 at 16:47
• Please edit your question to add extra information. Comments are hard to read, easy to miss and can be deleted without warning. Aug 21 '19 at 16:52
• Also posted on biostars: biostars.org/p/395275 Aug 21 '19 at 18:10
• Most likely you tried other things with these files and you are not reading a sparse matrix anymore. a good place to start is usually the documentation associated with the software. For cell ranger v3.0 you can find this here. support.10xgenomics.com/single-cell-gene-expression/software/…. If you scroll down you will see a section on how to generate a csv file. Restart with the zipped output of the filtered_feature_bc matrix. If you still get error update your post with code + error Aug 21 '19 at 23:15

I use the DropletUtils package from Bioconductor. Getting counts begins like this:

library(DropletUtils)
filePath <- "path_to_data/raw_feature_bc_matrix/"
singleCellExperiment <- read10xCounts(filePath, col.names = TRUE)


You probably need to load the matrices part by part in order to avoid loading a large size vector. One way is to use features like nlines or skip of the scan() function. Also, this is suggested code by 10xgenomics:

library(Matrix)
matrix_dir = "/opt/sample345/outs/filtered_feature_bc_matrix/"
barcode.path <- paste0(matrix_dir, "barcodes.tsv.gz")
features.path <- paste0(matrix_dir, "features.tsv.gz")
matrix.path <- paste0(matrix_dir, "matrix.mtx.gz")
colnames(mat) = barcode.names$$V1 rownames(mat) = feature.names$$V1