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

Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). #197

Closed LJK1991 closed 3 years ago

LJK1991 commented 3 years ago

Hello,

I'm playing around to get more familiar with MAGIC and PHATE but when i run this code i get an error.

`library(dplyr) library(Seurat) library(patchwork) library(phateR) library(ggplot2) library(readr) library(viridis) library(Rmagic)

wd_EB <- setwd("/home/lucas/Documents/Work/data_practice/GSE130146_RAW/EB/")

loading the dataset -- somtimes gets weird errors, dont know why

EB.data <- Read10X(data.dir = wd_EB)

initialize the Seurat object with the raw(non-normalized data).

EB <- CreateSeuratObject(counts = EB.data, project = "EB", min.cells = 3) EB[["percent.mt"]] <- PercentageFeatureSet(EB, pattern = "^mt-") EB <- subset(EB, subset = nFeature_RNA >= 2000 & percent.mt <= 5) EB_assay <- GetAssayData(EB, slot = "count")

EB_assay <- library.size.normalize(EB_assay) EB_assay <- sqrt(EB_assay)

may be fixed through transposing matrix

tEB_assay <- t(EB_assay)

running magic (can it be done on the whole library, it can)

tEB_magic <- magic(tEB_assay, t = "auto")`

The error is

Calculating MAGIC... Running MAGIC on 1731 cells and 16789 genes. Calculating graph and diffusion operator... Calculating PCA... Calculated PCA in 0.01 seconds. Calculated graph and diffusion operator in 0.01 seconds. Calculated MAGIC in 0.02 seconds. Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: Input contains NaN, infinity or a value too large for dtype('float64').

Detailed traceback: File "/home/lucas/.local/lib/python3.7/site-packages/magic/magic.py", line 651, in fit_transform self.fit(X, graph=graph) File "/home/lucas/.local/lib/python3.7/site-packages/magic/magic.py", line 446, in fit random_state=self.random_state, File "/home/lucas/.local/lib/python3.7/site-packages/graphtools/api.py", line 288, in Graph return Graph(params) File "/home/lucas/.local/lib/python3.7/site-packages/graphtools/graphs.py", line 132, in init super().init(data, n_pca=n_pca, kwargs) File "/home/lucas/.local/lib/python3.7/site-packages/graphtools/base.py", line 1019, in init super().init(data, **kwargs) File "/home/lucas/.local/lib/python3.7/site-packages/graphtools/base.py", line 134, in init self.data_nu = self._reduce_data() File "/home/lucas/.local/lib/python3.7/site-packages/graphtools/base.py", line 254, i

I have also tried uninstalling the packages with pip and then installing with pip install --user magic-impute as described in this issue #https://github.com/KrishnaswamyLab/MAGIC/issues/144

when i run it across a few genes instead of the whole matrix it gives an additional error line of

In addition: Warning message: In magic.default(EB_assay, genes = c("Kdr", "Runx1", "Pdgfra")) : Genes Kdr not found., Genes Runx1 not found., Genes Pdgfra not found.

Thank you in advance

scottgigante commented 3 years ago

I believe your problem has to do with Seurat working with transposed data. You should get the data out of Seurat with

EB_assay <- t(GetAssayData(EB, slot = "count"))

before normalizing and sqrt.

To check this is right, you should confirm that the genes are on the columns.

"Kdr" %in% colnames(EB_assay)
LJK1991 commented 3 years ago

that fixed it indeed. thanks!