Open SavKilPat opened 2 months ago
Hello SavKilPat, thanks for using SPATA2. Can you show me the complete function call you are using for spatialTrajectoryScreening()
with all argument inputs?
Hi Jan, thanks for your quick reply!
sts_out <-
SPATA2::spatialTrajectoryScreening(object = FAM3WT1,
id = id,
variables = input_genes)
Where id = a trajectory I made using createSpatialTrajectories and input_genes = sparkx genes with a pvalue of 0.05 or lower
I suspect that getCaptureArea
may be involved in this issue, as when I use it independently on the same SPATA2 object, it creates the same error.
Thank you!
It does. I am currently, fixing it. The fixxed version will be released either today or by tomorrow.
Wonderful! I look forward to the updates.
Thank you!
Hi, sorry for the delay. Could you install SPATA2 with install_github("kueckelj/SPATA2")
and run the code again? Use my_object <- updateSpataObject(my_object)
to update your SPATA2 object.
Thanks very much for the updated package!
spatialTrajectoryScreening now runs with one of my samples, but with others there is a new error regarding the zero_infl_vars
and coords_df
variables (see below).
Do you have suggestions on how to proceed/allow for NA values in the coords_df?
Error in `dplyr::select()`:
! Selections can't have missing values.
Backtrace:
1. SPATA2::spatialTrajectoryScreening(...)
2. SPATA2::spatial_gradient_screening(...)
4. dplyr:::select.data.frame(coords_df, -dplyr::all_of(zero_infl_vars))
When I run getCoordsDfST(object)
the dataframe does have some NA values in the projection_length and dist column.
16:42:46 Spatial trajectory: 'DV1'
A tibble: 478 × 12
barcodes sample x y x_orig y_orig projection_length dist dist_unit
1 WT-WT2_AACC… WT-WT2 104. 282. 3074. 8362. 13.0 0.137 mm 2 WT-WT2_AACC… WT-WT2 268. 520. 7954. 15420. NA NA mm 3 WT-WT2_AACG… WT-WT2 471. 64.2 13948. 1903. NA NA mm 4 WT-WT2_AACG… WT-WT2 529. 94.0 15680. 2785. NA NA mm 5 WT-WT2_AACT… WT-WT2 129. 306. 3814. 9054. 42.7 0.450 mm 6 WT-WT2_AACT… WT-WT2 170. 369. 5041. 10940. 116. 1.22 mm 7 WT-WT2_AACT… WT-WT2 243. 481. 7187. 14241. NA NA mm 8 WT-WT2_AACT… WT-WT2 525. 102. 15554. 3036. NA NA mm 9 WT-WT2_AACT… WT-WT2 124. 314. 3688. 9305. 49.5 0.522 mm 10 WT-WT2_AACT… WT-WT2 306. 263. 9078. 7788. NA NA mm 468 more rows 3 more variables: rel_loc , bins_dist , bins_order
I can not reproduce the error you mention. Does that occur in multiple SPATA2 objects or in all of them? And how did you create the objects where these errors occur? With updateSpataObject()
or with initiateSpataObjectVisium()
?
There are usually spots that feature NAs for distance with getCoordsDfST()
. If you use plotSurface(coords_df_st, color_by = "dist")
you should see a square that aligns with the course of the denoted trajectory. Spots that do not fall into this rectangle obtain NAs during trajectory analysis and are removed. This should not be any part of the error in which you run. (Ref. Supplementary Figure 7 e-h in Kueckelhaus et al. 2024).
Hi Jan,
The error occurs in 3/4 of my SPATA2 objects, all of which are from the same merged Seurat object that I have then subsetted each sample and transformed individually to SPATA2 objects using the asSPATA2
function.
The following yields the image below, which is quite different than the Supp Fig 7e-h plots in your paper
coords_df_st <- getCoordsDfST(
FAM3WT1,
id = idST(FAM3WT1),
width = getTrajectoryLength(FAM3WT1, id = id),
dist_unit = getDefaultUnit(FAM3WT1),
resolution = recSgsRes(FAM3WT1),
outside = TRUE,
variables = NULL,
format = "wide",
incl_edge = TRUE,
drop_na = TRUE,
verbose = TRUE)
plotSurface(coords_df_st, color_by = "dist")
Of note, the FAM3WT1@spatial@trajectories[["DV1"]]@coords
slot is empty in all of my SPATA2 objects, I'm wondering if that may be relevant to the issue I'm having?
If this is too tangential to my original post, I'm happy to make a new one. Additionally, I can provide the SPATA2 or Seurat objects if that's helpful.
Thank you so much!!
No, we can continue in this issue. Indeed, it would be helpful to have your SPATA2 objects and, if possible, the script with which you created them so I can reconstruct the way you got there and identify the problem. How do you want to provide them?
Hi Jan, Fantastic! The files aren't very large (15KB Script and 0.15GB Dataset). Would email suit you? I can upload to a OneDrive or Google Drive, whichever you prefer. Thanks very much for your help so far!
GoogleDrive is fine. Just sent the link to jankueckelhaus@gmx.de and I'll have a look. Dont forget about the script with which you processed and created them! It does not need to work in terms of file directories but I need the functions and processing steps to identify what has noot been transferred properly from Seurat to SPATA2.
Wonderful, thank you! I've shared a folder with the original Seurat processed dataset, the SPATA2 objects that work and do not work, as well as the scripts to process the both the Serurat and SPATA2 objects.
Thanks so much!!
Can you reinstall SPATA2 with install_github("kueckelj/SPATA2")
and see if the error persists? Make sure to restart the Rsession prior to installation.
Fantastic, that did the trick! Thank you so much, I really appreciate your help.
Hi MILO Lab,
Thanks so much for a wonderful tool. I'm hoping to use the Spatial Trajectory screen on a Visium V2 dataset (pre-processed with Seurat and converted to a SPATA2 object using the asSPATA2 function) using your most recent vignette, but am having trouble with the spatial trajectory screen function (see below). Any help in navigating this issue would be much appreciated! I'm also happy to attach the SPATA2 object, if that's helpful.
Thank you!
Savannah
Script below:
Load in seurat processed V2 dataset
spatial_harmony <- readRDS("C:/Users/19055/Documents/Visium HD/Analysis/All samples/rds folder/spatial_harmony_BANKSY kgeom 30 lambda 02_PCA only Aug 12_annotated1.rds")
Subset individual samples for SPATA2 conversion
Idents(spatial_harmony) <- "sample.id" FAM3WT1 <- subset(spatial_harmony, idents = "WT-WT1") FAM3WT1 <- SPATA2::asSPATA2(FAM3WT1, sample_name = "WT-WT1", platform = "VisiumSmall", assay_name = "Spatial", assay_modality = "gene", verbose = TRUE) #No directory was specified to store the image. Unloading won't be possible. Set with
setImageDir()
.setImageDir(FAM3WT1, "slice1", "D:/Transcriptomic raw data/Spatial transcriptomics/Visium V2/VISIUM V2 Raw Data/2023 deeper sequencing/20231013_LH00244_0018_A22CGVJLT3_Singh_Savannah_Visium/Singh_Savannah__Fam_3_WT-WT_D-V_A1/outs/spatial")
Check if the input object has an image in the respective slot or if the slot is empty
containsImage(FAM3WT1, img_name = activeImage(FAM3WT1), error = FALSE) #TRUE
Image processing
FAM3WT1 <- identifyPixelContent(FAM3WT1)
FAM3WT1 <- identifyTissueOutline(FAM3WT1, method = "obs", eps = "125um", minPts = 3)
plotSurface(FAM3WT1, color_by = "tissue_section", pt_clrp = "tab20")
Trajectory analysis
FAM3WT1 <- createSpatialTrajectories(FAM3WT1)
getTrajectoryWidth(FAM3WT1, id = "DV") #[1] 3.173595, attr(,"unit"), [1] "px"
FAM3WT1 <- SPATA2::runSPARKX(FAM3WT1, assay_name = "gene") #Prompts "Warning in FUN(newX[, i], ...) : There are p-values that are exactly 1!"
spark_df <- getSparkxGeneDf(object = FAM3WT1, threshold_pval = 0.05)
input_genes <- spark_df[["genes"]]
id <- "DV"
sts_out <- SPATA2::spatialTrajectoryScreening(object = FAM3WT1, id = id, #ID of the spatial trajectory variables = input_genes)
Creates the following error below:
21:05:50 Estimating R2 between total variation and noise ratio. 21:05:50 Iterating over 2640 simulations for equally distributed noise. Progress: [==========================================================================] 100% eta: 0s Progress: [==========================================================================] 100% eta: 0s 21:06:01 Estimated R2: 0.64102 21:06:01 Starting spatial trajectory screening. Error in
purrr::set_names()
: ! The size ofnm
(2) must be compatible with the size ofx
(0). Backtrace:SPATA2 Sample info
For extra context, FAM3WT1@spatial@coordinates reads "A tibble: 187 × 4", FAM3WT1@assays[["gene"]]@active_mtr = [1] "counts", and both FAM3WT1@assays[["gene"]]@analysis[["sparkx"]][["stats"]] and FAM3WT1@assays[["gene"]]@meta_var seem to check out.
My SPATA2 Object looks like this: SPATA2 object of size: 187 x 18087 (spots x molecules) Platform: VisiumSmall Sample name: WT-WT1 Molecular assays (1):
Session info:
R version 4.4.0 (2024-04-24 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 11 x64 (build 22631)
Matrix products: default
attached base packages: [1] stats4 stats graphics grDevices utils datasets [7] methods base
other attached packages: [1] pryr_0.1.6 shiny_1.9.1
[3] SPATA2_3.0.1 SPATAData_1.0.0
[5] confuns_1.0.3 viridis_0.6.5
[7] viridisLite_0.4.2 Banksy_1.0.0
[9] arrow_17.0.0.1 hdf5r_1.3.11
[11] ggpubr_0.6.0 enrichR_3.2
[13] gprofiler2_0.2.3 glmGamPoi_1.16.0
[15] harmony_1.2.0 DESeq2_1.44.0
[17] MAST_1.30.0 SingleCellExperiment_1.26.0 [19] SummarizedExperiment_1.34.0 Biobase_2.64.0
[21] GenomicRanges_1.56.1 GenomeInfoDb_1.40.1
[23] IRanges_2.38.1 S4Vectors_0.42.1
[25] BiocGenerics_0.50.0 MatrixGenerics_1.16.0
[27] matrixStats_1.3.0 cowplot_1.1.3
[29] Rfast2_0.1.5.2 RcppParallel_5.1.9
[31] Rcpp_1.0.13 vembedr_0.1.5
[33] htmltools_0.5.8.1 RColorBrewer_1.1-3
[35] patchwork_1.2.0 SeuratWrappers_0.3.5
[37] SeuratData_0.2.2.9001 Seurat_5.1.0
[39] SeuratObject_5.0.2 sp_2.1-4
[41] lubridate_1.9.3 forcats_1.0.0
[43] stringr_1.5.1 dplyr_1.1.4
[45] purrr_1.0.2 readr_2.1.5
[47] tidyr_1.3.1 tibble_3.2.1
[49] ggplot2_3.5.1 tidyverse_2.0.0
loaded via a namespace (and not attached): [1] SpatialExperiment_1.14.0 R.methodsS3_1.8.2
[3] progress_1.2.3 tiff_0.1-12
[5] urlchecker_1.0.1 goftest_1.2-3
[7] Biostrings_2.72.1 vctrs_0.6.5
[9] spatstat.random_3.3-1 digest_0.6.36
[11] png_0.1-8 ggrepel_0.9.5
[13] deldir_2.0-4 parallelly_1.38.0
[15] Rnanoflann_0.0.3 magick_2.8.4
[17] MASS_7.3-60.2 reshape2_1.4.4
[19] foreach_1.5.2 httpuv_1.6.15
[21] qvalue_2.36.0 withr_3.0.1
[23] ggfun_0.1.5 xfun_0.47
[25] ellipsis_0.3.2 survival_3.5-8
[27] memoise_2.0.1 profvis_0.3.8
[29] systemfonts_1.1.0 ragg_1.3.2
[31] tidytree_0.4.6 zoo_1.8-12
[33] V8_5.0.0 pbapply_1.7-2
[35] R.oo_1.26.0 prettyunits_1.2.0
[37] KEGGREST_1.44.1 promises_1.3.0
[39] SPARK_1.1.1 httr_1.4.7
[41] rstatix_0.7.2 globals_0.16.3
[43] fitdistrplus_1.2-1 rstudioapi_0.16.0
[45] UCSC.utils_1.0.0 units_0.8-5
[47] miniUI_0.1.1.1 generics_0.1.3
[49] DOSE_3.30.4 shinyhelper_0.3.2
[51] concaveman_1.1.0 curl_5.2.1
[53] zlibbioc_1.50.0 ggraph_2.2.1
[55] polyclip_1.10-7 RcppZiggurat_0.1.6
[57] GenomeInfoDbData_1.2.12 SparseArray_1.4.8
[59] fftwtools_0.9-11 pracma_2.4.4
[61] doParallel_1.0.17 xtable_1.8-4
[63] evaluate_0.24.0 S4Arrays_1.4.1
[65] Rfast_2.1.0 hms_1.1.3
[67] irlba_2.3.5.1 colorspace_2.1-1
[69] ROCR_1.0-11 reticulate_1.38.0
[71] spatstat.data_3.1-2 shinyWidgets_0.8.6
[73] magrittr_2.0.3 lmtest_0.9-40
[75] ggtree_3.12.0 later_1.3.2
[77] lattice_0.22-6 spatstat.geom_3.3-2
[79] future.apply_1.11.2 shadowtext_0.1.4
[81] scattermore_1.2 RcppAnnoy_0.0.22
[83] pillar_1.9.0 nlme_3.1-164
[85] iterators_1.0.14 EBImage_4.46.0
[87] compiler_4.4.0 RSpectra_0.16-2
[89] stringi_1.8.4 tensor_1.5
[91] devtools_2.4.5 plyr_1.8.9
[93] crayon_1.5.3 abind_1.4-5
[95] gridGraphics_0.5-1 locfit_1.5-9.10
[97] graphlayouts_1.1.1 bit_4.0.5
[99] fastmatch_1.1-4 textshaping_0.4.0
[101] codetools_0.2-20 bslib_0.8.0
[103] plotly_4.10.4 mime_0.12
[105] splines_4.4.0 fastDummies_1.7.4
[107] knitr_1.48 blob_1.2.4
[109] utf8_1.2.4 WriteXLS_6.7.0
[111] fs_1.6.4 listenv_0.9.1
[113] pkgbuild_1.4.4 openxlsx_4.2.6.1
[115] ggplotify_0.1.2 ggsignif_0.6.4
[117] RcppHungarian_0.3 Matrix_1.7-0
[119] tzdb_0.4.0 tweenr_2.0.3
[121] pkgconfig_2.0.3 tools_4.4.0
[123] cachem_1.1.0 aricode_1.0.3
[125] RhpcBLASctl_0.23-42 RSQLite_2.3.7
[127] DBI_1.2.3 fastmap_1.2.0
[129] rmarkdown_2.28 scales_1.3.0
[131] grid_4.4.0 usethis_3.0.0
[133] ica_1.0-3 shinydashboard_0.7.2
[135] sass_0.4.9 broom_1.0.6
[137] BiocManager_1.30.24 dotCall64_1.1-1
[139] carData_3.0-5 fontawesome_0.5.2
[141] RANN_2.6.1 farver_2.1.2
[143] scatterpie_0.2.3 tidygraph_1.3.1
[145] yaml_2.3.10 cli_3.6.3
[147] leiden_0.4.3.1 lifecycle_1.0.4
[149] dbscan_1.2-0 uwot_0.2.2
[151] sessioninfo_1.2.2 backports_1.5.0
[153] shinybusy_0.3.3 BiocParallel_1.38.0
[155] timechange_0.3.0 gtable_0.3.5
[157] rjson_0.2.22 ggridges_0.5.6
[159] progressr_0.14.0 ape_5.8
[161] parallel_4.4.0 jsonlite_1.8.8
[163] RcppHNSW_0.6.0 bitops_1.0-8
[165] bit64_4.0.5 assertthat_0.2.1
[167] Rtsne_0.17 yulab.utils_0.1.6
[169] spatstat.utils_3.1-0 matlab_1.0.4.1
[171] zip_2.3.1 jquerylib_0.1.4
[173] GOSemSim_2.30.2 spatstat.univar_3.0-0
[175] R.utils_2.12.3 lazyeval_0.2.2
[177] enrichplot_1.24.2 GO.db_3.19.1
[179] sctransform_0.4.1 rappdirs_0.3.3
[181] glue_1.7.0 spam_2.10-0
[183] httr2_1.0.3 lobstr_1.1.2
[185] XVector_0.44.0 RCurl_1.98-1.16
[187] treeio_1.28.0 mclust_6.1.1
[189] jpeg_0.1-10 gridExtra_2.3
[191] sccore_1.0.5 igraph_2.0.3
[193] R6_2.5.1 CompQuadForm_1.4.3
[195] labeling_0.4.3 cluster_2.1.6
[197] pkgload_1.4.0 stringdist_0.9.12
[199] aplot_0.2.3 DelayedArray_0.30.1
[201] tidyselect_1.2.1 ggforce_0.4.2
[203] car_3.1-2 AnnotationDbi_1.66.0
[205] future_1.34.0 leidenAlg_1.1.3
[207] rsvd_1.0.5 munsell_0.5.1
[209] KernSmooth_2.23-22 data.table_1.15.4
[211] htmlwidgets_1.6.4 fgsea_1.30.0
[213] rlang_1.1.4 spatstat.sparse_3.1-0
[215] spatstat.explore_3.3-2 remotes_2.5.0
[217] fansi_1.0.6