Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Featureplot not plotting if one of the variables is missing from the seurat object #64

Closed
Prathyusha-konda opened this issue Oct 17, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Prathyusha-konda
Copy link

Feature plot quits plotting if one of the variables is missing instead of plotting existing variables.

Error in FetchData.Seurat(object = seurat_object, vars = features[i], :
None of the requested variables were found: CD279

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.7 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /opt/R/4.2.1/lib/R/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] readr_2.1.3 scCustomize_0.7.0 RColorBrewer_1.1-3 glmGamPoi_1.9.2 pheatmap_1.0.12 cowplot_1.1.1
[7] patchwork_1.1.2 sp_1.5-0 SeuratObject_4.1.2 Seurat_4.2.0 dplyr_1.0.10

@samuel-marsh
Copy link
Owner

samuel-marsh commented Oct 17, 2022

Hi,

Could you please post the full code that you are running which causes the error? Also, if you update scCustomize to the develop branch does that resolve the issue?

devtools::install_github(repo = "samuel-marsh/scCustomize", ref = "develop")

When I run the following code (using dev branch) it seems to work ok.

library(tidyverse)
library(scCustomize)
library(Seurat)

pbmc <- pbmc3k.SeuratData::pbmc3k.final
pbmc <- UpdateSeuratObject(pbmc)

FeaturePlot_scCustom(seurat_object = pbmc, c("FOS", "fdskjf", "CD3E"))

Warning message:
In FetchData.Seurat(object = object, vars = c(dims, "ident", features),  :
  The following requested variables were not found: fdskjf

image

Best,
Sam

@Prathyusha-konda
Copy link
Author

Prathyusha-konda commented Oct 17, 2022

Hi Sam @samuel-marsh , thanks for the quick response. So it looks like featureplot doesn't plot when you include 'split.by' option and have a missing variable in the list. Without split.by, it works fine even with missing variable. This error also applies to Iterate_FeaturePlot_scCustom

Example code to reproduce using seurat's ifnb data

install dataset

InstallData("ifnb")

load dataset

LoadData("ifnb")

split the dataset into a list of two seurat objects (stim and CTRL)

ifnb.list <- SplitObject(ifnb, split.by = "stim")

ctrl <- ifnb.list[["CTRL"]]
stim <- ifnb.list[["STIM"]]

normalize and run dimensionality reduction on control dataset

ctrl <- SCTransform(ctrl, vst.flavor = "v2", verbose = FALSE) %>%
RunPCA(npcs = 30, verbose = FALSE)

stim <- SCTransform(stim, vst.flavor = "v2", verbose = FALSE) %>%
RunPCA(npcs = 30, verbose = FALSE)

ifnb.list <- list(ctrl = ctrl, stim = stim)
features <- SelectIntegrationFeatures(object.list = ifnb.list, nfeatures = 3000)
ifnb.list <- PrepSCTIntegration(object.list = ifnb.list, anchor.features = features)

immune.anchors <- FindIntegrationAnchors(object.list = ifnb.list, normalization.method = "SCT",
anchor.features = features)
immune.combined.sct <- IntegrateData(anchorset = immune.anchors, normalization.method = "SCT")

immune.combined.sct <- RunPCA(immune.combined.sct, verbose = FALSE)
immune.combined.sct <- RunUMAP(immune.combined.sct, reduction = "pca", dims = 1:30, verbose = FALSE)
immune.combined.sct <- FindNeighbors(immune.combined.sct, reduction = "pca", dims = 1:30)
immune.combined.sct <- FindClusters(immune.combined.sct, resolution = 0.3)

immune.combined.sct$celltype.stim <- paste(immune.combined.sct$seurat_annotations, immune.combined.sct$stim,
sep = "_")
Idents(immune.combined.sct) <- "celltype.stim"

pdf("featureplot_test.pdf")
FeaturePlot_scCustom(immune.combined.sct, features = c("CD3D", "GNLY", "FLT1"),split.by="stim")
dev.off()

Found the following features in more than one assay, excluding the default. We will not include these in the final data frame: FLT1Error in FetchData.Seurat(object = seurat_object, vars = features[i], :
None of the requested variables were found: FLT1

@samuel-marsh
Copy link
Owner

Gotcha, thanks! Now I understand why that's happening. I will work on patch for release this week.

In mean time you can run:

gene_plot <- c(...)

found_features <- Gene_Present(data = obj, gene_list =  genes_plot)[[1]]

That will return a vector of genes found within the object.

I will try and get patch out in next day or two (with release of scCustomize v1.0.0).

Thanks!
Sam

@samuel-marsh samuel-marsh self-assigned this Oct 18, 2022
@samuel-marsh samuel-marsh added the bug Something isn't working label Oct 18, 2022
@samuel-marsh
Copy link
Owner

Ok fix is live in the develop branch v(0.7.0.9951).

If setting split.by the function will check for features against the assay features and meta data columns and return a warning of which features were not found and return plot with found features.

If you have any issues once updated please let me know and I'll reopen the issue.

Best,
Sam

@Prathyusha-konda
Copy link
Author

Ok fix is live in the develop branch v(0.7.0.9951).

If setting split.by the function will check for features against the assay features and meta data columns and return a warning of which features were not found and return plot with found features.

If you have any issues once updated please let me know and I'll reopen the issue.

Best, Sam

That's awesome! Thank you, Sam! Looking forward to the new release 👍 💯

@samuel-marsh
Copy link
Owner

glad to help!!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants