RausellLab/CelliD

NA in dgCMatrix

Closed this issue · 2 comments

Hi

I'm trying to use Cell-ID with data from SeqGeq. The problem is that I can only export csv files from SeqGeq. I have tried to transform a csv into a dgCMatrix but I get some NAs. I have tried to figure out what I'm doing wrong but I need some help.

This is what I do:

data = read.csv("controlsHDG.csv") #columns = cells
data = t(data) #columns = genes
write.csv(a, "controlsHDG2.csv")

Then I cut row and column names to keep just the counts.

control = Matrix("controlsHDG2.csv", byrow = TRUE, nrow = 2502, ncol = 147 , sparse = TRUE)

Then I enter row and column names

control@Dimnames[[1]] = colcontrol
control@Dimnames[[2]] = rowcontrol

#my data:
str(control)
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
..@ i : int [1:367794] 0 1 2 3 4 5 6 7 8 9 ...
..@ p : int [1:148] 0 2502 5004 7506 10008 12510 15012 17514 20016 22518 ...
..@ Dim : int [1:2] 2502 147
..@ Dimnames:List of 2
.. ..$ : chr [1:147] "ADGRE1" "ANXA5" "ARL4C" "BCL2A1" ...
.. ..$ : chr [1:2502] "1_233112" "1_171522" "1_23853" "1_119501" ...
..@ x : num [1:367794] NA NA NA NA NA NA NA NA NA NA ...
..@ factors : list()

your data:
str(SegerMatrix)
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
..@ i : int [1:13671588] 1 4 5 15 24 28 29 30 33 37 ...
..@ p : int [1:2169] 0 3027 6409 10887 16635 20364 25845 30334 35568 41066 ...
..@ Dim : int [1:2] 25454 2168
..@ Dimnames:List of 2
.. ..$ : chr [1:25454] "SGIP1" "AZIN2" "CLIC4" "AGBL4" ...
.. ..$ : chr [1:2168] "HP1502401_H13" "HP1502401_J14" "HP1502401_B14" "HP1502401_A14" ...
..@ x : num [1:13671588] 3 1 13 3 3 1 3 4 2 15 ...
..@ factors : list()

What am I missing?

Regards
Juan

Hi,

Sorry for the late reply.

Have you tried first constructing a regular matrix?
you can then use the as.sparse() function to convert it in dgC Matrix.

I would do something along the line of

data = read.csv("controlsHDG.csv") #first column is genes and then thes rest is cells
matrix = as.matrix(data[,-1])
rownames(matrix) = data[[1]]
sparse_matrix <- as.sparse(matrix)

Best regards

Akira Cortal

Hi Akira

Thank you for your answer, it was very useful.

Regards
Juan