Hello Seurat devs,
I ran into an unexpected problem when trying to use FeaturePlot to visualize pseudotime values (which I store in the @meta.data slot of my Seurat object) on a reduced dimension embedding. Some cells might contain NA values if they are not part of a particular trajectory. This is in general not a problem as FeaturePlot will just color those cells in a dark grey color. However, when the first cell/row of @meta.data contains an NA value, then FeaturePlot throws the following error:
Error in if (all(data.plot[, feature] == data.plot[, feature][1])) { : missing value where TRUE/FALSE needed
This is rather unexpected and seems to be a problem that could occur with any variable where the first cell has a missing value.
Is there an easy fix for this or would you consider implementing a more permanent bug fix for this behavior?
I created a reproducible example below using pbmc_small and some random pseudotime values. I tried to simply reorder the meta.data data.frame so that the NA values would appear last, but this did not solve the problem.
Thanks a lot for your help!
library(Seurat)
pbmc_small
# create random pseudotime variable
set.seed(42)
pseudotime <- sample(1:dim(pbmc_small)[2])
# introduce random NAs
na_idx <- which(pseudotime %in% sample(pseudotime, 15))
pseudotime[na_idx] <- NA
# add pseudotime to seurat
names(pseudotime) <- rownames([email protected])
pbmc_small$pseudotime <- pseudotime
# FeaturePlot with pseudotime (works)
FeaturePlot(pbmc_small, features = "pseudotime", reduction = "tsne")
# when first cell has pseudotime == NA
pbmc_small$pseudotime2 <- pbmc_small$pseudotime
pbmc_small$pseudotime2[1] <- NA
# does not work
FeaturePlot(pbmc_small, features = "pseudotime2", reduction = "tsne")
# reorder meta.data so that first cell is not NA anymore
[email protected] <- [email protected][order([email protected]$pseudotime2),]
# still doesn't work
FeaturePlot(pbmc_small, features = "pseudotime2", reduction = "tsne")
Thanks for the bug report. We will fix it in the next version.
Right now, you could do is to reorder the cell input rather than the meta.data table.
new.cell.order <- rownames([email protected])[order([email protected]$pseudotime2)]
FeaturePlot(pbmc_small, features = "pseudotime2", reduction = "tsne", cells = new.cell.order )
This should be fixed in the development version of Seurat. To install the development version of Seurat, please see the instructions here.
Hi,
I am using seurat V3 to analyze v2 chemistry data. I have the same problem. Could someone advise me what to do next? Thank you.
head(x = Top[[]])
orig.ident nCount_RNA nFeature_RNA percent.mt
AAACCTGAGAAACCAT-1 Top 0 0 NaN
AAACCTGAGAAACCGC-1 Top 0 0 NaN
AAACCTGAGAAACCTA-1 Top 2 2 0.000000
VlnPlot(Top, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
Error in if (all(data[, feature] == data[, feature][1])) { :
missing value where TRUE/FALSE needed
Most helpful comment
Thanks for the bug report. We will fix it in the next version.
Right now, you could do is to reorder the cell input rather than the meta.data table.