satijalab / seurat

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

Inconsistent Clusters with same R script #8342

Open hjbp0610 opened 10 months ago

hjbp0610 commented 10 months ago

Hi, I'm analyzing CosMx spatial data (1000plex panel) with Seurat package version 5.0.1.

Below is the code I used to normalize and integrate two different dataset.

However, when I run the exact same code multiple times, the results are completely inconsistent. For example, DimPlots of UMAP, the number of Clusters, etc.

I've never experienced this with my single cell data or Visium before. I was using Seurat version 4, then. Recently, I have rerun the single cell/visium data with Seurat version 5, and I think I haven't experienced this issue, either.

I'm not sure if this is bug of Seurat version 5, or I did something wrong.

======================================================================= lean <- LoadNanostring('FlatFiles/Lean', fov = 'Lean') ob <- LoadNanostring('FlatFile/Ob', fov = 'Ob')

Add fov number to the metadata

library(tibble)

lean@meta.data <- rownames_to_column(lean@meta.data, var = 'rowname') lean@meta.data$fov <- lean@meta.data$rowname lean@meta.data <- column_torownames(lean@meta.data, var = 'rowname') lean@meta.data$fov <- gsub(".*","", lean@meta.data$fov)

lean@meta.data$orig.ident <- 'lean'

ob@meta.data <- rownames_to_column(ob@meta.data, var = 'rowname') ob@meta.data$fov <- ob@meta.data$rowname ob@meta.data <- column_torownames(ob@meta.data, var = 'rowname') ob@meta.data$fov <- gsub(".*","", ob@meta.data$fov)

ob@meta.data$orig.ident <- 'ob'

Quality Control: All the detailed metadata in the original metadata_file, such as nCount/nFeature_RNA or negprobes are all lost

filter out Cells with an average negative control count greater than 0.5 && less than 20 detected features

........

Merge

merged <- merge (lean, ob)

Normalization

merged <- SCTransform(merged, assay = "Nanostring", clip.range= c(-10, 10), verbose = FALSE)

PCA reduction

Perform PCA on the normalized data as needed before running Harmony batch correction, npcs=50 by default

Calculate PCs using variable features determined by SCTransform (3000 by default)

total.pcad<- RunPCA(merged, npcs = 50)

PERFORM INTEGRATION

harmonized.total <- RunHarmony(total.pcad, group.by.vars = "orig.ident", reduction = "pca", assay.use = "SCT", reduction.save = "harmony") harmonized.total[["Nanostring"]] <- JoinLayers(harmonized.total[["Nanostring"]]) harmonized.total <- RunUMAP(harmonized.total, reduction = "harmony", assay = "SCT", dims = 1:30) harmonized.total <- FindNeighbors(object = harmonized.total, reduction = "harmony") harmonized.total <- FindClusters(harmonized.total, resolution = 0.3)

sessionInfo() R version 4.3.1 (2023-06-16) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Ventura 13.6.3

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Asia/Seoul tzcode source: internal

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

other attached packages: [1] tibble_3.2.1 dplyr_1.1.4 patchwork_1.1.3 ggplot2_3.4.4 harmony_1.2.0 Rcpp_1.0.11 Seurat_5.0.1 SeuratObject_5.0.1 [9] sp_2.1-2

loaded via a namespace (and not attached): [1] RColorBrewer_1.1-3 rstudioapi_0.15.0 jsonlite_1.8.8 magrittr_2.0.3 spatstat.utils_3.0-4
[6] farver_2.1.1 zlibbioc_1.48.0 vctrs_0.6.5 ROCR_1.0-11 DelayedMatrixStats_1.24.0
[11] spatstat.explore_3.2-5 RCurl_1.98-1.13 htmltools_0.5.7 S4Arrays_1.2.0 SparseArray_1.2.2
[16] sctransform_0.4.1 parallelly_1.36.0 KernSmooth_2.23-22 htmlwidgets_1.6.4 ica_1.0-3
[21] plyr_1.8.9 plotly_4.10.3 zoo_1.8-12 igraph_1.6.0 mime_0.12
[26] lifecycle_1.0.4 pkgconfig_2.0.3 Matrix_1.6-4 R6_2.5.1 fastmap_1.1.1
[31] GenomeInfoDbData_1.2.11 MatrixGenerics_1.14.0 fitdistrplus_1.1-11 future_1.33.0 shiny_1.8.0
[36] digest_0.6.33 colorspace_2.1-0 S4Vectors_0.40.2 DESeq2_1.42.0 tensor_1.5
[41] RSpectra_0.16-1 irlba_2.3.5.1 GenomicRanges_1.54.1 labeling_0.4.3 progressr_0.14.0
[46] fansi_1.0.6 spatstat.sparse_3.0-3 httr_1.4.7 polyclip_1.10-6 abind_1.4-5
[51] compiler_4.3.1 withr_2.5.2 BiocParallel_1.36.0 fastDummies_1.7.3 MASS_7.3-60
[56] DelayedArray_0.28.0 tools_4.3.1 lmtest_0.9-40 httpuv_1.6.13 future.apply_1.11.0
[61] goftest_1.2-3 glmGamPoi_1.14.0 glue_1.6.2 nlme_3.1-164 promises_1.2.1
[66] grid_4.3.1 Rtsne_0.17 cluster_2.1.6 reshape2_1.4.4 generics_0.1.3
[71] gtable_0.3.4 spatstat.data_3.0-3 tidyr_1.3.0 data.table_1.14.10 utf8_1.2.4
[76] XVector_0.42.0 BiocGenerics_0.48.1 spatstat.geom_3.2-7 RcppAnnoy_0.0.21 ggrepel_0.9.4
[81] RANN_2.6.1 pillar_1.9.0 stringr_1.5.1 limma_3.58.1 spam_2.10-0
[86] RcppHNSW_0.5.0 later_1.3.2 splines_4.3.1 lattice_0.22-5 survival_3.5-7
[91] deldir_2.0-2 tidyselect_1.2.0 locfit_1.5-9.8 miniUI_0.1.1.1 pbapply_1.7-2
[96] gridExtra_2.3 IRanges_2.36.0 SummarizedExperiment_1.32.0 scattermore_1.2 RhpcBLASctl_0.23-42
[101] stats4_4.3.1 Biobase_2.62.0 statmod_1.5.0 matrixStats_1.2.0 stringi_1.8.3
[106] lazyeval_0.2.2 codetools_0.2-19 cli_3.6.2 uwot_0.1.16 xtable_1.8-4
[111] reticulate_1.34.0 munsell_0.5.0 GenomeInfoDb_1.38.2 globals_0.16.2 spatstat.random_3.2-2
[116] png_0.1-8 parallel_4.3.1 ellipsis_0.3.2 presto_1.0.0 dotCall64_1.1-1
[121] sparseMatrixStats_1.14.0 bitops_1.0-7 listenv_0.9.0 viridisLite_0.4.2 scales_1.3.0
[126] ggridges_0.5.5 leiden_0.4.3.1 purrr_1.0.2 crayon_1.5.2 rlang_1.1.2
[131] cowplot_1.1.2

saketkc commented 10 months ago

Hi @hjbp0610, Can you share the objects and the entire code with me over email shcoudhary@nygenome.org for me to reproduce.

hjbp0610 commented 10 months ago

Hi,

I'm out of the office for 3 days. May I send you the data next week?

Many thanks, Hee Joo

2024년 1월 20일 (토) 오전 5:36, Saket Choudhary @.***>님이 작성:

Hi @hjbp0610 https://github.com/hjbp0610, Can you share the objects and the entire code with me over email @.*** for me to reproduce.

— Reply to this email directly, view it on GitHub https://github.com/satijalab/seurat/issues/8342#issuecomment-1901077081, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASBWDWAUBG7JTCUVT6AWYNDYPLKMRAVCNFSM6AAAAABCBH5Z42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBRGA3TOMBYGE . You are receiving this because you were mentioned.Message ID: @.***>

hjbp0610 commented 10 months ago

CosMx_Seurat.zip https://drive.google.com/file/d/1OUVv873YRirfba1LSppS6rT3JP0jyiIe/view?usp=drive_web Hi,

I've attached the script file and the original flatfiles of the dataset.

Thank you very much for your nice package and help.

Best wishes, Hee Joo

On Sat, Jan 20, 2024 at 7:25 AM Hee Joo Kim김희주 @.***> wrote:

Hi,

I'm out of the office for 3 days. May I send you the data next week?

Many thanks, Hee Joo

2024년 1월 20일 (토) 오전 5:36, Saket Choudhary @.***>님이 작성:

Hi @hjbp0610 https://github.com/hjbp0610, Can you share the objects and the entire code with me over email @.*** for me to reproduce.

— Reply to this email directly, view it on GitHub https://github.com/satijalab/seurat/issues/8342#issuecomment-1901077081, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASBWDWAUBG7JTCUVT6AWYNDYPLKMRAVCNFSM6AAAAABCBH5Z42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBRGA3TOMBYGE . You are receiving this because you were mentioned.Message ID: @.***>

hjbp0610 commented 10 months ago

Hi,

I wanted to emphasize that the dataset I sent you is our own, and not any open public data. So, please be discrete with it and do not share the dataset with other people. If no update or solution is available, please completely discard the dataset.

Thanks,

Hee Joo

On Mon, Jan 22, 2024 at 7:51 AM Hee Joo Kim김희주 @.***> wrote:

CosMx_Seurat.zip https://drive.google.com/file/d/1OUVv873YRirfba1LSppS6rT3JP0jyiIe/view?usp=drive_web Hi,

I've attached the script file and the original flatfiles of the dataset.

Thank you very much for your nice package and help.

Best wishes, Hee Joo

On Sat, Jan 20, 2024 at 7:25 AM Hee Joo Kim김희주 @.***> wrote:

Hi,

I'm out of the office for 3 days. May I send you the data next week?

Many thanks, Hee Joo

2024년 1월 20일 (토) 오전 5:36, Saket Choudhary @.***>님이 작성:

Hi @hjbp0610 https://github.com/hjbp0610, Can you share the objects and the entire code with me over email @.*** for me to reproduce.

— Reply to this email directly, view it on GitHub https://github.com/satijalab/seurat/issues/8342#issuecomment-1901077081, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASBWDWAUBG7JTCUVT6AWYNDYPLKMRAVCNFSM6AAAAABCBH5Z42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBRGA3TOMBYGE . You are receiving this because you were mentioned.Message ID: @.***>

jmgs7 commented 9 months ago

Hello.

I have recently encountered the same problem. Re-running my analysis script changed the results. I also tried to re-run it in a different computer, and results were not consistent either.

leonfodoulian commented 7 months ago

Hi @hjbp0610 and @jmgs7,

Do you get a warning message saying Quick-TRANSfer stage steps exceeded maximum when you run RunHarmony? Check issue #25 on their GitHub page. One thing you could do is to increase max.iter.harmony and max.iter.cluster (e.g. to 100).

Hope this helps!

Best, Leon

Gesmira commented 5 months ago

Hi @hjbp0610, Thank you for reaching out! We’re always grateful when folks take the time to post issues and help make Seurat better 🙂

Unfortunately, with the details provided, we cannot reproduce your issue. To help us better understand and resolve this issue, please ensure that you provide the following information when reporting a bug:

  1. Reproducing Code Example:

    • Provide a minimal reproducible example that demonstrates the issue using one of the datasets available through SeuratData. Paste the code in a code block.
    • The code example should make use of pbmc_small or one of the datasets available through SeuratData.
  2. System Information:

    • Run sessionInfo() and paste the result in a code block.

Once you’ve gathered these details we will be more than happy to help you resolve the problem.

jmgs7 commented 5 months ago

Hi @Gesmira,

FYI, I have disussed this already with @saketkc in this issue: #8501

We even exchanged additional information through emails.

Unfortunately, we couldn't solve the problem. I suggest to reach him for more info about the issue since maybe he could go further into the technical details behind the code.

Thank you very much, best regards.