KrishnaswamyLab / MAGIC

MAGIC (Markov Affinity-based Graph Imputation of Cells), is a method for imputing missing values restoring structure of large biological datasets.
GNU General Public License v2.0
341 stars 97 forks source link

R package 'Error in t.default(W) : argument is not a matrix' #60

Closed wen-zhou-caltech closed 6 years ago

wen-zhou-caltech commented 6 years ago

Hi Magic developer. I kept running into the problem when it says "Symmetrize distances", and keeps popping up an error saying 't.default(W) : argument is not a matrix'. Any help would greatly appreciated!

Regards, Wen

dpcook commented 6 years ago

Yes, I ran into this issue as well. I'm not 100% sure why, but I think it's related to the transpose function not liking the sparseMatrix class of W. I got around it by manually running through the run_magic() code, but just made sure that I converted W to a normal matrix prior to line 63.

Note that I also ran into an error at line 82, where I believe it should be:

W_t <- W^t

R didn't like the %^% operator in the original source code.

pkathail commented 6 years ago

Thanks for pointing out these bugs, will implement the changes that @dpcook has suggested. And please let me know if you find any more bugs in the R implementation!

pkathail commented 6 years ago

Pushed a change that I think should fix this, please let me know if you're still having problems with it.

djchin25 commented 6 years ago

From https://github.com/pkathail/magic/blob/525e36f6b59cffd26c3c0de2904242ff5db3a690/R/run_magic.R line 63 has:
W <- as.matrix(W) This yields an error after 'Computing kernel' Error: $ operator is invalid for atomic vectors

So i commented out line 63 but had to change line 78 to: W <- W / rowSums(as.matrix(W))

The code runs further but an error still occurs after 'Diffusing' Error in W^t : non-numeric argument to binary operator

I thought this line might actually be W_t <- W^t(W) but while this modified code completes, when i plot some genes from the ~2600 cell 10X PBMC dataset, the imputed values are roughly uniform in expression. The original cells that had localized expression are a bit lighter prior to running magic. I don't think my modification to run_magic is correct, but W^t definitely still does not resolve the problem.

Here is a tSNE graphic: left is FCGR3A before run_magic, right is after magic fcgr3a

jennapappalardo commented 6 years ago

I'm getting the error during Compute Kernel as well ($ operator is invalid for atomic vectors). I've tried modifying the object class/how it's extracted but it hasn't worked.

nganvu commented 6 years ago

I cleaned up the R code and everything should work now. Let me know there are any issues.