satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.25k stars 904 forks source link

running issue for SpatiallyVariableFeatures and FindSpatiallyVariableFeatures #7034

Open ScarletAmarantine opened 1 year ago

ScarletAmarantine commented 1 year ago

Hi, I am analyzing the spatial transcriptome data following the vignette. However, when I ran the function "SpatiallyVariableFeatures" at the part of spatial variation detection and "FindSpatiallyVariableFeatures" at the part of deconvolution, I got an error shown:

Error in [.data.frame(slot(object = x, name = "meta.features"), , i, : undefined columns selected

Error in markcorr(Xj, f = f, r = r, correction = correction, method = method, : Cannot normalise the mark correlation; the denominator is zero

Could you help solve the problem? Many thanks in advance.

Here are the codes I used: library(ggplot2) library(Seurat) library(SeuratData) library(cowplot) library(dplyr) suppressWarnings(suppressMessages(future::plan("multiprocess", workers = 40))) brain1 <- LoadData("stxBrain", type = "anterior1") brain2 <- LoadData("stxBrain", type = "posterior1") brain <- merge(brain1, brain2) brain <- SCTransform(brain, assay = "Spatial", verbose = TRUE, method = "poisson") brain <- RunPCA(brain, assay = "SCT", verbose = F) brain <- FindNeighbors(brain, reduction="pca",dims = 1:30) brain <- FindClusters(brain, verbose =F) brain <- RunUMAP(brain, reduction="pca",dims = 1:30)

integration

st.list = list(anterior1 = brain1, posterior1 = brain2)

run SCT on both datasets

st.list = lapply(st.list, SCTransform, assay = "Spatial", method = "poisson")

need to set maxSize for PrepSCTIntegration to work

options(future.globals.maxSize = 2000 * 1024^2) # set allowed size to 2K MiB st.features = SelectIntegrationFeatures(st.list, nfeatures = 3000, verbose = FALSE) st.list <- PrepSCTIntegration(object.list = st.list, anchor.features = st.features, verbose = FALSE) int.anchors <- FindIntegrationAnchors(object.list = st.list, normalization.method = "SCT", verbose = FALSE, anchor.features = st.features) brain.integrated <- IntegrateData(anchorset = int.anchors, normalization.method = "SCT",verbose = FALSE) brain.integrated <- RunPCA(brain.integrated, verbose = FALSE) brain.integrated <- FindNeighbors(brain.integrated, dims = 1:30) brain.integrated <- FindClusters(brain.integrated, verbose = FALSE) brain.integrated <- RunUMAP(brain.integrated, dims = 1:30) brain.integrated <- FindSpatiallyVariableFeatures(brain.integrated, assay = 'SCT', features =VariableFeatures(brain.integrated)[1:1000], selection.method = 'markvariogram')

To note, FindSpatiallyVariableFeatures work well here

However, the error occurs below:

top.features <- head(SpatiallyVariableFeatures(brain.integrated, selection.method = "markvariogram"),6)

Error in [.data.frame(slot(object = x, name = "meta.features"), , I, : undefined columns selected traceback() 11: stop("undefined columns selected") 10: [.data.frame(slot(object = x, name = "meta.features"), , i, drop = FALSE, ...) 9: slot(object = x, name = "meta.features")[, i, drop = FALSE, ...] 8: [[.Assay(object, paste0(selection.method, ".spatially.variable")) 7: object[[paste0(selection.method, ".spatially.variable")]] 6: SVFInfo.Assay(object = object, selection.method = selection.method, status = TRUE) 5: SVFInfo(object = object, selection.method = selection.method, status = TRUE) 4: SpatiallyVariableFeatures.Assay(object = object[[assay]], selection.method = selection.method, decreasing = decreasing) 3: SpatiallyVariableFeatures(object = object[[assay]], selection.method = selection.method, decreasing = decreasing) 2: SpatiallyVariableFeatures.Seurat(brain.integrated, selection.method = "markvariogram") 1: SpatiallyVariableFeatures(brain.integrated, selection.method = "markvariogram")

Deconvolution part------

cortex <- subset(brain.integrated, idents = c(1, 2, 3, 5, 6, 7))

now remove additional cells, use SpatialDimPlots to visualize what to remove

SpatialDimPlot(cortex,cells.highlight = WhichCells(cortex, expression = image_imagerow > 400

| image_imagecol < 150))

cortex <- subset(cortex, anterior1_imagerow > 400 | anterior1_imagecol < 150, invert = TRUE) cortex <- subset(cortex, anterior1_imagerow > 275 & anterior1_imagecol > 370, invert = TRUE) cortex <- subset(cortex, anterior1_imagerow > 250 & anterior1_imagecol > 440, invert = TRUE) cortex <- SCTransform(cortex, assay = "Spatial", verbose = FALSE) %>% RunPCA(verbose = FALSE)

allen_reference <- readRDS("./R source code/allen_cortex.rds") Idents(allen_reference) <- allen_reference$subclass allen_reference <- subset(allen_reference, cells = WhichCells(allen_reference, downsample = 200)) allen_reference <- SCTransform(allen_reference, ncells = 3000, verbose = FALSE, method = "poisson") %>% RunPCA(verbose = FALSE) %>% RunUMAP(dims = 1:30)

anchors <- FindTransferAnchors(reference = allen_reference, query = cortex, normalization.method = "SCT") predictions.assay <- TransferData(anchorset = anchors, refdata = allen_reference$subclass, prediction.assay = TRUE, weight.reduction = cortex[["pca"]], dims = 1:30) cortex[["predictions"]] <- predictions.assay DefaultAssay(cortex) <- "predictions"

Here comes the error

cortex <- FindSpatiallyVariableFeatures(cortex, assay = "predictions", selection.method = "markvariogram", features = rownames(cortex), r.metric = 5, slot = "data")

Error in markcorr(Xj, f = f, r = r, correction = correction, method = method, : Cannot normalise the mark correlation; the denominator is zero

traceback() 18: stop(condition) 17: signalConditions(obj, exclude = getOption("future.relay.immediate", "immediateCondition"), resignal = resignal, ...) 16: signalConditionsASAP(obj, resignal = FALSE, pos = ii) 15: resolve.list(y, result = TRUE, stdout = stdout, signal = signal, force = TRUE) 14: resolve(y, result = TRUE, stdout = stdout, signal = signal, force = TRUE) 13: value.list(fs) 12: value(fs) 11: (function() { oopts <- options(future.rng.onMisuse.keepFuture = FALSE) on.exit(options(oopts)) value(fs) })() 10: withCallingHandlers({ values <- local({ oopts <- options(future.rng.onMisuse.keepFuture = FALSE) on.exit(options(oopts)) value(fs) }) }, RngFutureCondition = function(cond) { idx <- NULL uuid <- attr(cond, "uuid") if (!is.null(uuid)) { for (kk in seq_along(fs)) { if (identical(fs[[kk]]$uuid, uuid)) idx <- kk } } else { f <- attr(cond, "future") if (is.null(f)) return() if (!isFALSE(f$seed)) ... 9: future_xapply(FUN = FUN, nX = nX, chunk_args = X, args = list(...), get_chunk = [, expr = expr, envir = envir, future.envir = future.envir, future.globals = future.globals, future.packages = future.packages, future.scheduling = future.scheduling, future.chunk.size = future.chunk.size, future.stdout = future.stdout, future.conditions = future.conditions, future.seed = future.seed, future.label = future.label, fcn_name = fcn_name, args_name = args_name, debug = debug) 8: future_lapply(X = features, FUN = function(x) { pp[["marks"]] <- as.data.frame(x = t(x = data[x, ])) markvario(X = pp, normalise = TRUE, ...) }) 7: RunMarkVario(spatial.location = spatial.location, data = object) 6: FindSpatiallyVariableFeatures.default(object = data, spatial.location = spatial.location, selection.method = selection.method, r.metric = r.metric, x.cuts = x.cuts, y.cuts = y.cuts, verbose = verbose, ...) 5: FindSpatiallyVariableFeatures(object = data, spatial.location = spatial.location, selection.method = selection.method, r.metric = r.metric, x.cuts = x.cuts, y.cuts = y.cuts, verbose = verbose, ...) 4: FindSpatiallyVariableFeatures.Assay(object = object[[assay]], slot = slot, features = features, spatial.location = tc, selection.method = selection.method, r.metric = r.metric, x.cuts = x.cuts, y.cuts = y.cuts, nfeatures = nfeatures, verbose = verbose, ...) 3: FindSpatiallyVariableFeatures(object = object[[assay]], slot = slot, features = features, spatial.location = tc, selection.method = selection.method, r.metric = r.metric, x.cuts = x.cuts, y.cuts = y.cuts, nfeatures = nfeatures, verbose = verbose, ...) 2: FindSpatiallyVariableFeatures.Seurat(cortex, assay = "predictions", selection.method = "markvariogram", features = rownames(cortex), r.metric = 5, slot = "data") 1: FindSpatiallyVariableFeatures(cortex, assay = "predictions", selection.method = "markvariogram", features = rownames(cortex), r.metric = 5, slot = "data")

sessionInfo() R version 4.2.2 (2022-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.5 LTS

Matrix products: default BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so

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

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

other attached packages: [1] xbioc_0.1.19 AnnotationDbi_1.60.0 IRanges_2.32.0 S4Vectors_0.36.1 Biobase_2.58.0 BiocGenerics_0.44.0
[7] SCDC_0.0.0.9000 patchwork_1.1.2 dplyr_1.0.10 cowplot_1.1.1 stxBrain.SeuratData_0.1.1 pbmc3k.SeuratData_3.1.4
[13] SeuratData_0.2.1 SeuratObject_4.1.3 Seurat_4.3.0 ggplot2_3.4.0 Matrix_1.5-3

loaded via a namespace (and not attached): [1] backports_1.4.1 plyr_1.8.8 igraph_1.3.5 lazyeval_0.2.2 sp_1.5-1 splines_4.2.2 listenv_0.9.0
[8] scattermore_0.8 GenomeInfoDb_1.34.6 usethis_2.1.6 digest_0.6.31 htmltools_0.5.4 fansi_1.0.3 checkmate_2.1.0
[15] magrittr_2.0.3 memoise_2.0.1 tensor_1.5 cluster_2.1.4 ROCR_1.0-11 limma_3.54.0 remotes_2.4.2
[22] Biostrings_2.66.0 globals_0.16.2 matrixStats_0.63.0 spatstat.sparse_3.0-0 prettyunits_1.1.1 colorspace_2.0-3 blob_1.2.3
[29] rappdirs_0.3.3 ggrepel_0.9.2 RCurl_1.98-1.9 callr_3.7.3 crayon_1.5.2 jsonlite_1.8.4 progressr_0.13.0
[36] spatstat.data_3.0-0 ape_5.6-2 survival_3.5-0 zoo_1.8-11 glue_1.6.2 polyclip_1.10-4 registry_0.5-1
[43] gtable_0.3.1 zlibbioc_1.44.0 XVector_0.38.0 nnls_1.4 leiden_0.4.3 pkgbuild_1.4.0 RcppZiggurat_0.1.6
[50] future.apply_1.10.0 abind_1.4-5 scales_1.2.1 pheatmap_1.0.12 DBI_1.1.3 spatstat.random_3.0-1 miniUI_0.1.1.1
[57] Rcpp_1.0.9 viridisLite_0.4.1 xtable_1.8-4 reticulate_1.27 bit_4.0.5 Rfast2_0.1.4 profvis_0.3.7
[64] htmlwidgets_1.6.1 httr_1.4.4 RColorBrewer_1.1-3 ellipsis_0.3.2 ica_1.0-3 urlchecker_1.0.1 pkgconfig_2.0.3
[71] farver_2.1.1 uwot_0.1.14 deldir_1.0-6 utf8_1.2.2 tidyselect_1.2.0 labeling_0.4.2 rlang_1.0.6
[78] reshape2_1.4.4 later_1.3.0 munsell_0.5.0 tools_4.2.2 cachem_1.0.6 cli_3.6.0 RSQLite_2.2.20
[85] generics_0.1.3 devtools_2.4.5 ggridges_0.5.4 stringr_1.5.0 fastmap_1.1.0 goftest_1.2-3 fastmatrix_0.4-1245
[92] bit64_4.0.5 processx_3.8.0 fs_1.5.2 fitdistrplus_1.1-8 purrr_1.0.1 RANN_2.6.1 KEGGREST_1.38.0
[99] pbapply_1.7-0 future_1.30.0 nlme_3.1-161 mime_0.12 ggrastr_1.0.1 compiler_4.2.2 rstudioapi_0.14
[106] beeswarm_0.4.0 plotly_4.10.1 curl_5.0.0 png_0.1-8 spatstat.utils_3.0-1 tibble_3.1.8 stringi_1.7.12
[113] ps_1.7.2 lattice_0.20-45 vctrs_0.5.1 pillar_1.8.1 lifecycle_1.0.3 BiocManager_1.30.19 spatstat.geom_3.0-3
[120] lmtest_0.9-40 RcppAnnoy_0.0.20 bitops_1.0-7 data.table_1.14.7 irlba_2.3.5.1 httpuv_1.6.8 R6_2.5.1
[127] promises_1.2.0.1 KernSmooth_2.23-20 gridExtra_2.3 vipor_0.4.5 parallelly_1.34.0 sessioninfo_1.2.2 codetools_0.2-18
[134] MASS_7.3-58.1 assertthat_0.2.1 pkgload_1.3.2 pkgmaker_0.32.7 withr_2.5.0 sctransform_0.3.5 GenomeInfoDbData_1.2.9 [141] parallel_4.2.2 grid_4.2.2 tidyr_1.2.1 L1pack_0.41-2 Rfast_2.0.6 Rtsne_0.16 spatstat.explore_3.0-5 [148] shiny_1.7.4 ggbeeswarm_0.7.1

AustinHartman commented 1 year ago

Can you try running FindSpatiallyVariableFeatures with the selection.method = "moransi" and let me know if that is successful?

joachimsiaw commented 1 year ago

Hi, I have similar error: I run initially with selection.method="markvariogram" and i got the same error: Stop.features <- head(SpatiallyVariableFeatures(suerat.integrated, selection.method = "markvariogram"), 6) Error in [.data.frame(slot(object = x, name = "meta.features"), , i, : undefined columns selected

I then run with selection.method="moransi"

and trying to visiualize features and got same error again: head(SpatiallyVariableFeatures(suerat.integrated, selection.method = "moransi"), 6) Error in [.data.frame(slot(object = x, name = "meta.features"), , i, : undefined columns selected

stefanerb89 commented 1 year ago

Have the same error "Error in [.data.frame(slot(object = x, name = "meta.features"), , i, : undefined columns selected", any suggestions?

limin321 commented 1 year ago

I have similar issue when running SpatiallyVariableFeatures(wt, selection.method = "moransi") , Here is my error message:

Screen Shot 2023-06-03 at 12 04 27 PM

Any suggestion how to troubleshoot that?

AnjaK88 commented 1 year ago

Same issue here. I am running the FindSpatiallyVariableFeatures on a merged and integrated dataset. The command itself works well. However, when I try: top.features <- head(SpatiallyVariableFeatures(integrated.brain_new, selection.method = "moransi") I get the Error Message: Error in [.data.frame(slot(object = x, name = "meta.features"), , i, : undefined columns selected

The same script works perfectly fine on each dataset individually (not merged or integrated).

Any suggestions where the issue lies?

ebtesam-rashid commented 1 year ago

I have similar issue while trying to run : top.features <- head(SpatiallyVariableFeatures(brain, selection.method = "moransi"), 6) I got the follwing error message: Error in xtfrm.data.frame(x) : cannot xtfrm data frames I have tried also without the head function and got the same error. It looks like something related to the input stucture for SpatiallyVariableFeatures function.

Are there any suggestion to deal with it?

marencc commented 10 months ago

Hi! I am having the same problem... Is SpatiallyVariableFeatures() deprecated?

JamieLord25 commented 9 months ago

Same issue here. I am running the FindSpatiallyVariableFeatures on a merged and integrated dataset. The command itself works well. However, when I try: top.features <- head(SpatiallyVariableFeatures(integrated.brain_new, selection.method = "moransi") I get the Error Message: Error in [.data.frame(slot(object = x, name = "meta.features"), , i, : undefined columns selected

The same script works perfectly fine on each dataset individually (not merged or integrated).

Any suggestions where the issue lies?

I tried head(variableFeatures) instead of SpatiallyVariableFeatures and it seems to work. SpatiallyVariableFeatures is giving me that error as well.

YangXuuu commented 6 months ago

I don't know whethere markvariogram is still working fine, it seems take quite a long time for this method

harper-ping commented 2 months ago

yeah i have same problem.and 屏幕截图 2024-07-10 185851 how to solve it please