Change format of counts of single cell RNA-seq data from csv to mtx format from synapse.org
I have downloaded a count matrix of a single-cell dataset in csv format (let's call it a.csv) from synaps.org, with the following structure:
i j x
34 1 1
35 1 1
43 1 1
74 1 1
How can I generate the corresponding count matrix in R in mtx format? I have two meta data file associated with a.csv. Here I provide the first two lines of those files (with modifications)
b.csv:
cell_name specimenID broad_class subtype
1 cellname1 specimenID1 Exc Exc.Exc.L3
2 cellname2 specimenID2 Exc Exc.Exc.L3
c.csv:
X x
1 gene1
2 gene2
• 2,847 views
•
link
1 answer
I was finally able to solve the issue. Here is the code I used:
library(data.table)
synapser::synLogin()
counts <- fread(synapser::synGet('syn23554292')$path ) # this reads the a.csv file
i=as.vector(counts$i)
j=as.vector(counts$j)
x=as.vector(counts$x)
library(Matrix)
A <- sparseMatrix(i, j, x)
Meta.cells <- read.csv(synapser::synGet('syn23554294')$path, header=T, stringsAsFactors = F) # this reads the b.csv file
Meta.genes <- read.csv(synapser::synGet('syn23554293')$path, header=T, stringsAsFactors = F ) # this reads the c.csv file
rownames(A)=Meta.genes$x
colnames(A)=Meta.cells$cell_name
• 0 views
•
link
Log in to answer this question.
Please put effort into formatting your post better. See this post for tips: How to Use Biostars Part-3: Formatting Text and Using GitHub Gists
I've fixed your post this time.
Thank you Ram
Isn't that already mtx format? Try to read that first csv with `Matrix::readMM` into R and see what happens. The other two files are then the row- and coldata to annotate that matrix. You probably want to make a more suitable format to work downstream, e.g. SingleCellExperiment or Seurat. Does that make sense?Thanks for your reply ATpoint .
No, unfortunately, it is not in mtx format. readMM gives the following error:
file is not a MatrixMarket file