Noble-Lab / Polarbear

Polarbear translates between different single-cell data modalities
Apache License 2.0
7 stars 2 forks source link

How do process a scanpy cell-by-gene matrix? #4

Open gmurtaza404 opened 6 months ago

gmurtaza404 commented 6 months ago

Can you share any scripts that you have to convert an arbitrary scRNA-seq cell-by-gene matrix into the format your model inputs?

Thanks

RanZhang08 commented 6 months ago

Here's an example script (please refer to https://gist.github.com/xie186/332eff13dcac50f101f91494402b4bd1#file-csv2mex-r for more details).

library(Matrix)

# generate single-cell RNA seq data
count <- read.csv(input_matrix, header=T, row.names = 1)
gbm <- t(count)

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

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