Hi,

I have a read counts file from single cell seq from RSEM, I want to store that in a matrix.mtx format required for Seurat pipeline, how can I do that?

    > head(all.counts)
                  HSC1_1 HSC1_2 HSC1_3 HSC1_4 HSC1_5 HSC1_6 HSC1_7
    0610005C13Rik      0      0      0      0      0      0      0
    0610007P14Rik     25      0    304      0    154    550    117
    0610008F07Rik      0      0      0      0      0      0      0
    0610009B14Rik      0      0      0      0      0      0      0
    0610009B22Rik      0      0      0      8     83    521    236
    0610009D07Rik    241      0     66     60    356    173    385

to 


    %%MatrixMarket matrix coordinate real general
    %
    32738 2700 2286884
    32709 1 4
    32707 1 1
    32706 1 10
    32704 1 1
    32703 1 5
    32702 1 6
    32700 1 10
    32699 1 25
    32698 1 3
    32697 1 8
    32527 1 1


Hi!
Use the Matrix library to create and write a sparse matrix:

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

Result: 

    $ head matrix.mtx 
    %%MatrixMarket matrix coordinate integer general
    10 10 65
    1 1 3
    2 1 1
    3 1 3
    6 1 1
    7 1 1
    8 1 1
    10 1 3
    1 2 2

Jean-Baptiste