stuart-lab / signac

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

TSSPlot function unable to access Position enrichment matrix from the object #1500

Closed vijender-singh closed 1 year ago

vijender-singh commented 1 year ago

Problem I am following the tutorial/vignette on "Analyzing PBMC scATAC-seq" with the provided dataset (https://stuartlab.org/signac/articles/pbmc_vignette) and trying to plot the TSS enrichment plot. When I execute the function I get an error Error in TSSPlot(pbmc, group.by = "high.tss") : Position enrichment matrix not present in assay I can see that position Enrichment matrix exists and can access with pbmc@assays$peaks@positionEnrichment.

The code I am following is below

library(Signac)
library(Seurat)
library(EnsDb.Hsapiens.v75)
library(ggplot2)
library(patchwork)

#load the counts
counts <- Read10X_h5(filename = "./atac_v1_pbmc_10k_filtered_peak_bc_matrix.h5")
metadata <- read.csv(
  file = "./atac_v1_pbmc_10k_singlecell.csv",
  header = TRUE,
  row.names = 1
)

# Create chromatin assay
chrom_assay <- CreateChromatinAssay(
  counts = counts,
  sep = c(":", "-"),
  fragments = './atac_v1_pbmc_10k_fragments.tsv.gz',
  min.cells = 10,
  min.features = 200
)

# create Seurat object
pbmc <- CreateSeuratObject(
  counts = chrom_assay,
  assay = "peaks",
  meta.data = metadata
)

pbmc

pbmc[["peaks"]]

# genomic ranges associated with each feature in the object.
granges(pbmc)

annotations <- GetGRangesFromEnsDb(ensdb = EnsDb.Hsapiens.v75)

seqlevels(annotations) <- paste0('chr', seqlevels(annotations))
genome(annotations) <- "hg19"

# add the gene information to the object
Annotation(pbmc) <- annotations

# compute nucleosome signal score per cell
pbmc <- NucleosomeSignal(object = pbmc)

# compute TSS enrichment score per cell
pbmc <- TSSEnrichment(object = pbmc, fast = FALSE)

# add blacklist ratio and fraction of reads in peaks
pbmc$pct_reads_in_peaks <- pbmc$peak_region_fragments / pbmc$passed_filters * 100
pbmc$blacklist_ratio <- pbmc$blacklist_region_fragments / pbmc$peak_region_fragments

#DensityScatter(pbmc, x = 'nCount_peaks', y = 'TSS.enrichment', log_x = TRUE, quantiles = TRUE)

pbmc$high.tss <- ifelse(pbmc$TSS.enrichment > 3, 'High', 'Low')
TSSPlot(pbmc, group.by = 'high.tss') + NoLegend()

My Session Info

Session info
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3 
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3;  LAPACK version 3.9.0

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       

time zone: America/New_York
tzcode source: system (glibc)

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

other attached packages:
 [1] patchwork_1.1.3         ggplot2_3.4.3           Seurat_4.9.9.9045       SeuratObject_4.9.9.9084 sp_2.0-0               
 [6] Signac_1.10.0           GenomicRanges_1.52.0    GenomeInfoDb_1.36.3     IRanges_2.34.1          S4Vectors_0.38.2       
[11] BiocGenerics_0.46.0    

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3      rstudioapi_0.15.0       jsonlite_1.8.7          magrittr_2.0.3          spatstat.utils_3.0-3   
  [6] farver_2.1.1            zlibbioc_1.46.0         vctrs_0.6.3             ROCR_1.0-11             spatstat.explore_3.2-3 
 [11] Rsamtools_2.16.0        RCurl_1.98-1.12         RcppRoll_0.3.0          htmltools_0.5.6         sctransform_0.4.0      
 [16] parallelly_1.36.0       KernSmooth_2.23-20      htmlwidgets_1.6.2       ica_1.0-3               plyr_1.8.8             
 [21] plotly_4.10.2           zoo_1.8-12              igraph_1.5.1            mime_0.12               lifecycle_1.0.3        
 [26] pkgconfig_2.0.3         Matrix_1.6-1.1          R6_2.5.1                fastmap_1.1.1           GenomeInfoDbData_1.2.10
 [31] fitdistrplus_1.1-11     future_1.33.0           shiny_1.7.5             digest_0.6.33           colorspace_2.1-0       
 [36] tensor_1.5              RSpectra_0.16-1         irlba_2.3.5.1           labeling_0.4.3          progressr_0.14.0       
 [41] fansi_1.0.4             spatstat.sparse_3.0-2   httr_1.4.7              polyclip_1.10-4         abind_1.4-5            
 [46] compiler_4.3.0          bit64_4.0.5             withr_2.5.1             BiocParallel_1.34.2     fastDummies_1.7.3      
 [51] MASS_7.3-58.3           tools_4.3.0             lmtest_0.9-40           httpuv_1.6.11           future.apply_1.11.0    
 [56] goftest_1.2-3           glue_1.6.2              nlme_3.1-162            promises_1.2.1          grid_4.3.0             
 [61] Rtsne_0.16              cluster_2.1.4           reshape2_1.4.4          generics_0.1.3          hdf5r_1.3.8            
 [66] gtable_0.3.4            spatstat.data_3.0-1     tidyr_1.3.0             data.table_1.14.8       utf8_1.2.3             
 [71] XVector_0.40.0          spatstat.geom_3.2-5     RcppAnnoy_0.0.21        ggrepel_0.9.3           RANN_2.6.1             
 [76] pillar_1.9.0            stringr_1.5.0           spam_2.9-1              RcppHNSW_0.5.0          later_1.3.1            
 [81] splines_4.3.0           dplyr_1.1.3             lattice_0.20-45         bit_4.0.5               survival_3.5-5         
 [86] deldir_1.0-9            tidyselect_1.2.0        Biostrings_2.68.1       miniUI_0.1.1.1          pbapply_1.7-2          
 [91] gridExtra_2.3           scattermore_1.2         matrixStats_1.0.0       stringi_1.7.12          lazyeval_0.2.2         
 [96] codetools_0.2-19        tibble_3.2.1            cli_3.6.1               uwot_0.1.16             xtable_1.8-4           
[101] reticulate_1.32.0       munsell_0.5.0           Rcpp_1.0.11             globals_0.16.2          spatstat.random_3.1-6  
[106] png_0.1-8               parallel_4.3.0          ellipsis_0.3.2          dotCall64_1.0-2         bitops_1.0-7           
[111] listenv_0.9.0           viridisLite_0.4.2       scales_1.2.1            ggridges_0.5.4          leiden_0.4.3           
[116] purrr_1.0.2             crayon_1.5.2            rlang_1.1.1             cowplot_1.1.1           fastmatch_1.1-4    
vijender-singh commented 1 year ago

Not to copy the whole object structure with str(pbmc), I am pasting below the slot part that I think corresponds to Position enrichment matrix.


.. .. .. ..@ positionEnrichment:List of 1
  .. .. .. .. ..$ TSS:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. .. .. .. ..@ i       : int [1:14399626] 0 2 3 5 7 9 10 11 16 18 ...
  .. .. .. .. .. .. ..@ p       : int [1:2002] 0 3805 7655 11920 16142 20467 24717 29285 33425 37572 ...
  .. .. .. .. .. .. ..@ Dim     : int [1:2] 8730 2001
  .. .. .. .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. .. .. .. ..$ : chr [1:8730] "AAACGAAAGAGCGAAA-1" "AAACGAAAGAGTTTGA-1" "AAACGAAAGCGAGCTA-1" "AAACGAAAGGCTTCGC-1" ...
  .. .. .. .. .. .. .. ..$ : chr [1:2001] "-999" "-998" "-997" "-996" ...
  .. .. .. .. .. .. ..@ x       : num [1:14399626] 0.971 0.412 1.031 0.481 0.631 ...
  .. .. .. .. .. .. ..@ factors : list()```
timoast commented 1 year ago

What is TSSPlot_c? Can you try using the function defined in Signac?

vijender-singh commented 1 year ago

Sorry about that, I tried TSSPlot and when it did not work I pulled the function and tried modifying it (TSSPlot_c). The error is consistent and reproducible with Signac::TSSPlot.

timoast commented 1 year ago

I see you have Seurat v5 installed, if you're using v5 you will need to install Signac from the seurat5 branch:

remotes::install_github("stuart-lab/signac", "seurat5")
vijender-singh commented 1 year ago

Thankyou, I will try it and will get back. Thanks again for your time.

vijender-singh commented 1 year ago

Thank you, that worked. I reinstalled Signac from the seurat5 branch with remotes::install_github("stuart-lab/signac@seurat5")