stuart-lab / signac

R toolkit for the analysis of single-cell chromatin data
https://stuartlab.org/signac/
Other
330 stars 88 forks source link

Cannot add ATAC assay to Seurat Object? Following "Joint RNA and ATAC analysis: 10x multiomic" Vignette #1785

Closed sohkhar closed 1 month ago

sohkhar commented 1 month ago

Hi all, I'm relatively new to bioinformatics / single-cell analysis but I was wondering if I could get some help fixing this error I've been having with doing joint 10X Genomics Multiome RNA-seq and matched ATAC-seq data analysis in R with Seurat and Signac.

I keep running into this issue where I cannot add an assay object to my Seurat object as I did previously. I came to find this recently updated vignette "Joint RNA and ATAC analysis: 10x multiomic" which includes the following code:

# load the RNA and ATAC data
counts <- [Read10X_h5](https://satijalab.org/seurat/reference/Read10X_h5.html)("pbmc_granulocyte_sorted_10k_filtered_feature_bc_matrix.h5")
fragpath <- "pbmc_granulocyte_sorted_10k_atac_fragments.tsv.gz"
# get gene annotations for hg38
annotation <- [GetGRangesFromEnsDb](https://stuartlab.org/signac/reference/getgrangesfromensdb)(ensdb = EnsDb.Hsapiens.v86)
[seqlevels](https://stuartlab.org/signac/reference/seqinfo-methods)(annotation) <- [paste0](https://rdrr.io/r/base/paste.html)('chr', [seqlevels](https://stuartlab.org/signac/reference/seqinfo-methods)(annotation))

# create a Seurat object containing the RNA adata
pbmc <- [CreateSeuratObject](https://mojaveazure.github.io/seurat-object/reference/CreateSeuratObject.html)(
  counts = counts$`Gene Expression`,
  assay = "RNA"
)

# create ATAC assay and add it to the object
pbmc[["ATAC"]] <- [CreateChromatinAssay](https://stuartlab.org/signac/reference/createchromatinassay)(
  counts = counts$Peaks,
  sep = [c](https://rdrr.io/r/base/c.html)(":", "-"),
  fragments = fragpath,
  annotation = annotation
)

And this seems to work in the vignette but when I run my code below, I get the error that is provided. Just wondering what this means and if there is a fix? Or do I have to roll back my Seurat/Signac versions because this worked previously?

My code:

adata = Read10X_h5("aggregated_outs/filtered_feature_bc_matrix.h5")
#Extracting RNA-seq and ATAC-seq data
rnaCounts = adata$`Gene Expression`
peakCounts = adata$Peaks

annotation = GetGRangesFromEnsDb(ensdb = EnsDb.Mmusculus.v79)
seqlevels(annotation) = paste0('chr', seqlevels(annotation))

actGC <- CreateSeuratObject(counts = rnaCounts, assay = "RNA" , min.cells = 3, min.features = 200)

> frag.file = "aggregated_outs/atac_fragments.tsv.gz"
> actGC[["ATAC"]] = CreateChromatinAssay(
+     counts = peakCounts,
+     sep = c(":", "-"),
+     fragments = frag.file,
+     annotation = annotation
+ )
Computing hash
Checking for 46002 cell barcodes
Error in `[[<-`:
! Cannot add new cells with [[<-
Run `rlang::last_trace()` to see where the error occurred.

I did also check thread https://github.com/stuart-lab/signac/discussions/1692 - https://github.com/stuart-lab/signac/discussions/1692#discussion-6564054 However I am unsure what they mean by "One of the objects I merged did not have matching cell id". Is this a similar situation to mine?

Apologies if this is a duplicate, I couldn't find any other articles relating to the same assay / issue that I'm having.

Would appreciate any help! Please let me know if I can provide more information.

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.6.1

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.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.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: Australia/Melbourne
tzcode source: internal

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

other attached packages:
 [1] ggplot2_3.5.1              EnsDb.Mmusculus.v79_2.99.0 ensembldb_2.28.1           AnnotationFilter_1.28.0    GenomicFeatures_1.56.0     AnnotationDbi_1.66.0      
 [7] Biobase_2.64.0             GenomicRanges_1.56.1       GenomeInfoDb_1.40.1        IRanges_2.38.1             S4Vectors_0.42.1           BiocGenerics_0.50.0       
[13] dplyr_1.1.4                Signac_1.14.0              Seurat_5.1.0               SeuratObject_5.0.2         sp_2.1-4                  

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.22            splines_4.4.1               later_1.3.2                 BiocIO_1.14.0               bitops_1.0-8                tibble_3.2.1               
  [7] polyclip_1.10-7             rpart_4.1.23                XML_3.99-0.17               fastDummies_1.7.4           lifecycle_1.0.4             hdf5r_1.3.11               
 [13] globals_0.16.3              lattice_0.22-6              MASS_7.3-60.2               backports_1.5.0             magrittr_2.0.3              Hmisc_5.1-3                
 [19] plotly_4.10.4               rmarkdown_2.28              yaml_2.3.10                 httpuv_1.6.15               sctransform_0.4.1           spam_2.10-0                
 [25] spatstat.sparse_3.1-0       reticulate_1.39.0           cowplot_1.1.3               pbapply_1.7-2               DBI_1.2.3                   RColorBrewer_1.1-3         
 [31] pkgload_1.4.0               abind_1.4-8                 zlibbioc_1.50.0             Rtsne_0.17                  purrr_1.0.2                 biovizBase_1.52.0          
 [37] RCurl_1.98-1.16             nnet_7.3-19                 VariantAnnotation_1.50.0    GenomeInfoDbData_1.2.12     ggrepel_0.9.6               irlba_2.3.5.1              
 [43] listenv_0.9.1               spatstat.utils_3.1-0        goftest_1.2-3               RSpectra_0.16-2             spatstat.random_3.3-2       fitdistrplus_1.2-1         
 [49] parallelly_1.38.0           leiden_0.4.3.1              codetools_0.2-20            DelayedArray_0.30.1         RcppRoll_0.3.1              tidyselect_1.2.1           
 [55] UCSC.utils_1.0.0            farver_2.1.2                base64enc_0.1-3             matrixStats_1.4.1           spatstat.explore_3.3-2      GenomicAlignments_1.40.0   
 [61] jsonlite_1.8.9              Formula_1.2-5               progressr_0.14.0            ggridges_0.5.6              survival_3.6-4              tools_4.4.1                
 [67] ica_1.0-3                   Rcpp_1.0.13                 glue_1.7.0                  gridExtra_2.3               SparseArray_1.4.8           xfun_0.47                  
 [73] MatrixGenerics_1.16.0       withr_3.0.1                 fastmap_1.2.0               fansi_1.0.6                 digest_0.6.37               R6_2.5.1                   
 [79] mime_0.12                   colorspace_2.1-1            scattermore_1.2             tensor_1.5                  dichromat_2.0-0.1           spatstat.data_3.1-2        
 [85] RSQLite_2.3.7               utf8_1.2.4                  tidyr_1.3.1                 generics_0.1.3              data.table_1.16.0           rtracklayer_1.64.0         
 [91] httr_1.4.7                  htmlwidgets_1.6.4           S4Arrays_1.4.1              uwot_0.2.2                  pkgconfig_2.0.3             gtable_0.3.5               
 [97] blob_1.2.4                  lmtest_0.9-40               XVector_0.44.0              htmltools_0.5.8.1           dotCall64_1.1-1             ProtGenerics_1.36.0        
[103] scales_1.3.0                png_0.1-8                   spatstat.univar_3.0-1       knitr_1.48                  rstudioapi_0.16.0           reshape2_1.4.4             
[109] rjson_0.2.23                checkmate_2.3.2             nlme_3.1-164                curl_5.2.3                  zoo_1.8-12                  cachem_1.1.0               
[115] stringr_1.5.1               KernSmooth_2.23-24          parallel_4.4.1              miniUI_0.1.1.1              foreign_0.8-86              restfulr_0.0.15            
[121] pillar_1.9.0                grid_4.4.1                  vctrs_0.6.5                 RANN_2.6.2                  promises_1.3.0              xtable_1.8-4               
[127] cluster_2.1.6               htmlTable_2.4.3             evaluate_1.0.0              cli_3.6.3                   compiler_4.4.1              Rsamtools_2.20.0           
[133] rlang_1.1.4                 crayon_1.5.3                future.apply_1.11.2         plyr_1.8.9                  stringi_1.8.4               viridisLite_0.4.2          
[139] deldir_2.0-4                BiocParallel_1.38.0         munsell_0.5.1               Biostrings_2.72.1           lazyeval_0.2.2              spatstat.geom_3.3-3        
[145] Matrix_1.7-0                BSgenome_1.72.0             RcppHNSW_0.6.0              patchwork_1.3.0             bit64_4.5.2                 future_1.34.0              
[151] KEGGREST_1.44.1             shiny_1.9.1                 SummarizedExperiment_1.34.0 ROCR_1.0-11                 igraph_2.0.3                memoise_2.0.1              
[157] fastmatch_1.1-4             bit_4.5.0