Skip to content

CoveragePlot not properly handling GRanges object for features #1970

@daniel-spies

Description

@daniel-spies

Hi There,

thanks for the great tool, I was trying to plot a gene with multiple genomic locations supplying a GRanges object but get an error that Granges does not support [[, as.list, lapply at the moment

the cause is that whilst the GRanges object has a length > 1 it can only be accessed by single brackets and not like a list or vector, thus an additional check is required when dealing with GRanges objects or to transform those into a list.

so I guess this can be circumvented by supplying a GRangesList or by calling GRangesToString but would need an update of the function documentation

# gene has two isoforms on two chromosomes, create separate plots as otherwise a single chromsome is plotted with max span of coordinates

# get gene coordinates in GRanges format
gene_idx <- which(so_neural@assays$ATAC@annotation$gene_name == 'SLC5A7' & so_neural@assays$ATAC@annotation$type == 'cds')
plot_regions <- GRanges(so_neural@assays$ATAC@annotation[c(gene_idx[1],gene_idx[length(gene_idx)]),])

CoveragePlot(so_neural,
             assay = 'ATAC',
             expression.assay = 'SCT',
             region = plot_regions,
             feature = 'SLC5A7',
             group.by = 'predicted.id.neural',
             extend.upstream = 1000,
             extend.downstream = 1000,
             peaks = TRUE
)
Error in getListElement(x, i, ...) :
GRanges objects don't support [[, as.list(), lapply(), or unlist() at the moment
> sessionInfo()
R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Debian GNU/Linux 12 (bookworm)

Matrix products: default
BLAS:   /nfs/scistore07/clustersw/debian/bookworm/R/4.5.2/lib/R/lib/libRblas.so 
LAPACK: /nfs/scistore07/clustersw/debian/bookworm/R/4.5.2/lib/R/lib/libRlapack.so;  LAPACK version 3.12.1

Random number generation:
 RNG:     L'Ecuyer-CMRG 
 Normal:  Inversion 
 Sample:  Rejection 
 
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: Europe/Vienna
tzcode source: system (glibc)

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

other attached packages:
 [1] GenomeInfoDb_1.46.0                 future_1.67.0                       BSgenome.Mmusculus.UCSC.mm10_1.4.3 
 [4] BSgenome.Drerio.UCSC.danRer11_1.4.2 BSgenome_1.78.0                     rtracklayer_1.70.0                 
 [7] BiocIO_1.20.0                       Biostrings_2.78.0                   XVector_0.50.0                     
[10] GenomicRanges_1.62.0                Seqinfo_1.0.0                       IRanges_2.44.0                     
[13] S4Vectors_0.48.0                    motifmatchr_1.32.0                  TFBSTools_1.48.0                   
[16] JASPAR2024_0.99.7                   chromVAR_1.32.0                     AnnotationHub_4.0.0                
[19] BiocFileCache_3.0.0                 dbplyr_2.5.1                        BiocGenerics_0.56.0                
[22] generics_0.1.4                      ggplot2_4.0.0                       Signac_1.16.0                      
[25] dplyr_1.1.4                         CyteTypeR_0.1.5                     Seurat_5.3.1                       
[28] SeuratObject_5.2.0                  sp_2.2-0                           

loaded via a namespace (and not attached):
  [1] matrixStats_1.5.0           spatstat.sparse_3.1-0       bitops_1.0-9               
  [4] DirichletMultinomial_1.52.0 httr_1.4.7                  RColorBrewer_1.1-3         
  [7] tools_4.5.2                 sctransform_0.4.2           utf8_1.2.6                 
 [10] R6_2.6.1                    DT_0.34.0                   lazyeval_0.2.2             
 [13] uwot_0.2.3                  withr_3.0.2                 gridExtra_2.3              
 [16] clustermq_0.9.9             progressr_0.18.0            textshaping_1.0.4          
 [19] cli_3.6.5                   Biobase_2.70.0              spatstat.explore_3.5-3     
 [22] fastDummies_1.7.5           labeling_0.4.3              sass_0.4.10                
 [25] S7_0.2.0                    spatstat.data_3.1-9         ggridges_0.5.7             
 [28] pbapply_1.7-4               Rsamtools_2.26.0            systemfonts_1.3.1          
 [31] dichromat_2.0-0.1           parallelly_1.45.1           rstudioapi_0.17.1          
 [34] RSQLite_2.4.3               gtools_3.9.5                ica_1.0-3                  
 [37] spatstat.random_3.4-2       Matrix_1.7-4                logger_0.4.1               
 [40] abind_1.4-8                 lifecycle_1.0.4             yaml_2.3.10                
 [43] SummarizedExperiment_1.40.0 SparseArray_1.10.1          Rtsne_0.17                 
 [46] glmGamPoi_1.22.0            grid_4.5.2                  blob_1.2.4                 
 [49] promises_1.5.0              crayon_1.5.3                pwalign_1.6.0              
 [52] miniUI_0.1.2                lattice_0.22-7              beachmat_2.26.0            
 [55] cowplot_1.2.0               cigarillo_1.0.0             KEGGREST_1.50.0            
 [58] pillar_1.11.1               knitr_1.50                  rjson_0.2.23               
 [61] future.apply_1.20.0         codetools_0.2-20            fastmatch_1.1-6            
 [64] glue_1.8.0                  spatstat.univar_3.1-4       data.table_1.17.8          
 [67] vctrs_0.6.5                 png_0.1-8                   spam_2.11-1                
 [70] gtable_0.3.6                cachem_1.1.0                xfun_0.54                  
 [73] S4Arrays_1.10.0             mime_0.13                   survival_3.8-3             
 [76] RcppRoll_0.3.1              fitdistrplus_1.2-4          ROCR_1.0-11                
 [79] nlme_3.1-168                bit64_4.6.0-1               filelock_1.0.3             
 [82] RcppAnnoy_0.0.22            bslib_0.9.0                 irlba_2.3.5.1              
 [85] KernSmooth_2.23-26          otel_0.2.0                  seqLogo_1.76.0             
 [88] DBI_1.2.3                   tidyselect_1.2.1            bit_4.6.0                  
 [91] compiler_4.5.2              curl_7.0.0                  httr2_1.2.1                
 [94] DelayedArray_0.36.0         plotly_4.11.0               scales_1.4.0               
 [97] caTools_1.18.3              lmtest_0.9-40               rappdirs_0.3.3             
[100] stringr_1.6.0               digest_0.6.37               goftest_1.2-3              
[103] presto_1.0.0                spatstat.utils_3.2-0        rmarkdown_2.30             
[106] htmltools_0.5.8.1           pkgconfig_2.0.3             sparseMatrixStats_1.22.0   
[109] MatrixGenerics_1.22.0       fastmap_1.2.0               rlang_1.1.6                
[112] htmlwidgets_1.6.4           UCSC.utils_1.6.0            shiny_1.11.1               
[115] DelayedMatrixStats_1.32.0   farver_2.1.2                jquerylib_0.1.4            
[118] zoo_1.8-14                  jsonlite_2.0.0              BiocParallel_1.44.0        
[121] RCurl_1.98-1.17             magrittr_2.0.4              dotCall64_1.2              
[124] patchwork_1.3.2             Rcpp_1.1.0                  reticulate_1.44.0          
[127] stringi_1.8.7               MASS_7.3-65                 plyr_1.8.9                 
[130] parallel_4.5.2              listenv_0.10.0              ggrepel_0.9.6              
[133] deldir_2.0-4                splines_4.5.2               tensor_1.5.1               
[136] igraph_2.2.1                spatstat.geom_3.6-0         RcppHNSW_0.6.0             
[139] reshape2_1.4.4              pkgload_1.4.1               TFMPvalue_0.0.9            
[142] BiocVersion_3.22.0          XML_3.99-0.19               evaluate_1.0.5             
[145] BiocManager_1.30.27         tweenr_2.0.3                httpuv_1.6.16              
[148] RANN_2.6.2                  tidyr_1.3.1                 purrr_1.2.0                
[151] polyclip_1.10-7             scattermore_1.2             ggforce_0.5.0              
[154] xtable_1.8-4                restfulr_0.0.16             RSpectra_0.16-2            
[157] later_1.4.4                 ragg_1.5.0                  viridisLite_0.4.2          
[160] tibble_3.3.0                memoise_2.0.1               AnnotationDbi_1.72.0       
[163] GenomicAlignments_1.46.0    cluster_2.1.8.1             globals_0.18.0   

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions