Change format of counts of single cell RNA-seq data from csv to mtx format from synapse.org
1
0
Entering edit mode
2.9 years ago

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
single RNA-seq cell • 1.5k views
ADD COMMENT
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Thank you Ram

ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

Thanks for your reply ATpoint .

No, unfortunately, it is not in mtx format. readMM gives the following error:

file is not a MatrixMarket file

ADD REPLY
2
Entering edit mode
2.9 years ago

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
ADD COMMENT

Login before adding your answer.

Traffic: 2845 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6