Shians / NanoMethViz

https://shians.github.io/NanoMethViz/
Apache License 2.0
24 stars 1 forks source link

Error in `plot_gene()` and `plot_region()` #46

Closed IdoBar closed 1 month ago

IdoBar commented 1 month ago

Hi, I'm very excited about this package, but I'm unable to generate methylation plots. I created an mbr object from BAM files generated by dorado (using sup,5mCG_5hmCG,6mA models). The data seems to be loaded correctly and I can see the methylation probabilities:

> query_methy(mbr, "ArME14_ctg_11",1062600,1069500)
# A tibble: 65,016 × 7
   sample    chr               pos strand statistic read_name               mod_prob
   <chr>     <fct>           <int> <fct>      <dbl> <chr>                      <dbl>
 1 FT13092-6 ArME14_ctg_11 1062638 +         -1.31  e7821594-1337-44fa-bfd…    0.212
 2 FT13092-6 ArME14_ctg_11 1062659 +         -0.819 e7821594-1337-44fa-bfd…    0.306
 3 FT13092-6 ArME14_ctg_11 1062661 +         -1.14  e7821594-1337-44fa-bfd…    0.243
 4 FT13092-6 ArME14_ctg_11 1062667 +         -1.34  e7821594-1337-44fa-bfd…    0.208
 5 FT13092-6 ArME14_ctg_11 1062677 +         -1.62  e7821594-1337-44fa-bfd…    0.165
 6 FT13092-6 ArME14_ctg_11 1062679 +         -1.65  e7821594-1337-44fa-bfd…    0.161
 7 FT13092-6 ArME14_ctg_11 1062685 +         -1.60  e7821594-1337-44fa-bfd…    0.169
 8 FT13092-6 ArME14_ctg_11 1062688 +         -1.62  e7821594-1337-44fa-bfd…    0.165
 9 FT13092-6 ArME14_ctg_11 1062701 +         -1.81  e7821594-1337-44fa-bfd…    0.141
10 FT13092-6 ArME14_ctg_11 1062709 +         -1.87  e7821594-1337-44fa-bfd…    0.133
# ℹ 65,006 more rows

But when trying to plot them, I'm getting the following error message:

> plot_region(mbr, "ArME14_ctg_11",1062600,1069500, 
+             heatmap = TRUE, spaghetti = TRUE)
[W::hts_idx_load2] The index file is older than the data file: data/basecalling/barcode12/barcode12_basecalled_reads_Q7.sorted.bam.bai
[W::hts_idx_load2] The index file is older than the data file: data/basecalling/barcode15/barcode15_basecalled_reads_Q7.sorted.bam.bai
[W::hts_idx_load2] The index file is older than the data file: data/basecalling/barcode12/barcode12_basecalled_reads_Q7.sorted.bam.bai
[W::hts_idx_load2] The index file is older than the data file: data/basecalling/barcode15/barcode15_basecalled_reads_Q7.sorted.bam.bai
Error in `combine_vars()`:
! Faceting variables must have at least one value

When trying to use the provided nmr example, I'm getting the following error:

> nmr <- load_example_nanomethresult()
> plot_gene(nmr, "Peg3")
Error in self$get_transformation() : attempt to apply non-function

This is my session info:

> session_info()
─ Session info ───────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.1 (2022-06-23 ucrt)
 os       Windows 10 x64 (build 22631)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United Kingdom.utf8
 ctype    English_United Kingdom.utf8
 tz       Australia/Brisbane
 date     2024-09-21
 rstudio  2024.04.2+764 Chocolate Cosmos (desktop)
 pandoc   3.1.11 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────────
 ! package                            * version   date (UTC) lib source
   AnnotationDbi                        1.60.2    2023-03-10 [1] Bioconductor
   assertthat                           0.2.1     2019-03-21 [1] CRAN (R 4.2.0)
   beachmat                             2.14.2    2023-04-07 [1] Bioconductor
   beeswarm                             0.4.0     2021-06-01 [1] CRAN (R 4.2.0)
   Biobase                              2.56.0    2022-04-26 [1] Bioconductor
   BiocFileCache                        2.4.0     2022-04-26 [1] Bioconductor
   BiocGenerics                         0.42.0    2022-04-26 [1] Bioconductor
   BiocIO                               1.6.0     2022-04-26 [1] Bioconductor
   BiocManager                          1.30.18   2022-05-18 [1] CRAN (R 4.2.1)
   BiocParallel                         1.30.3    2022-06-07 [1] Bioconductor
   BiocSingular                         1.14.0    2022-11-01 [1] Bioconductor
   biomaRt                              2.52.0    2022-04-26 [1] Bioconductor
   Biostrings                           2.64.0    2022-04-26 [1] Bioconductor
   bit                                  4.0.4     2020-08-04 [1] CRAN (R 4.2.0)
   bit64                                4.0.5     2020-08-30 [1] CRAN (R 4.2.0)
   bitops                               1.0-7     2021-04-24 [1] CRAN (R 4.2.0)
   blob                                 1.2.3     2022-04-10 [1] CRAN (R 4.2.0)
   BSgenome                             1.64.0    2022-04-26 [1] Bioconductor
   bsseq                                1.34.0    2022-11-01 [1] Bioconductor
   cachem                               1.0.6     2021-08-19 [1] CRAN (R 4.2.0)
   callr                                3.7.6     2024-03-25 [1] CRAN (R 4.2.3)
   cellranger                           1.1.0     2016-07-27 [1] CRAN (R 4.2.0)
   class                                7.3-20    2022-01-16 [2] CRAN (R 4.2.1)
   cli                                  3.6.3     2024-06-21 [1] CRAN (R 4.2.1)
   codetools                            0.2-18    2020-11-04 [2] CRAN (R 4.2.1)
   colorspace                           2.1-1     2024-07-26 [1] CRAN (R 4.2.1)
   cpp11                                0.4.3     2022-10-12 [1] CRAN (R 4.2.2)
   crayon                               1.5.2     2022-09-29 [1] CRAN (R 4.2.2)
   curl                                 4.3.2     2021-06-23 [1] CRAN (R 4.2.0)
   data.table                           1.15.4    2024-03-30 [1] CRAN (R 4.2.3)
   DBI                                  1.1.3     2022-06-18 [1] CRAN (R 4.2.0)
   dbplyr                               2.3.2     2023-03-21 [1] CRAN (R 4.2.3)
   dbscan                               1.1-12    2023-11-28 [1] CRAN (R 4.2.3)
   DelayedArray                         0.22.0    2022-04-26 [1] Bioconductor
   DelayedMatrixStats                   1.20.0    2022-11-01 [1] Bioconductor
   devtools                           * 2.4.5     2022-10-11 [1] CRAN (R 4.2.3)
   digest                               0.6.35    2024-03-11 [1] CRAN (R 4.2.3)
   dplyr                              * 1.1.2     2023-04-20 [1] CRAN (R 4.2.3)
   e1071                                1.7-11    2022-06-07 [1] CRAN (R 4.2.1)
   ellipsis                             0.3.2     2021-04-29 [1] CRAN (R 4.2.0)
   evaluate                             0.23      2023-11-01 [1] CRAN (R 4.2.3)
   fansi                                1.0.6     2023-12-08 [1] CRAN (R 4.2.3)
   farver                               2.1.2     2024-05-13 [1] CRAN (R 4.2.1)
   fastmap                              1.1.1     2023-02-24 [1] CRAN (R 4.2.3)
   filelock                             1.0.2     2018-10-05 [1] CRAN (R 4.2.1)
   forcats                            * 1.0.0     2023-01-29 [1] CRAN (R 4.2.3)
   fs                                   1.5.2     2021-12-08 [1] CRAN (R 4.2.0)
   generics                             0.1.3     2022-07-05 [1] CRAN (R 4.2.1)
   GenomeInfoDb                         1.32.2    2022-05-15 [1] Bioconductor
   GenomeInfoDbData                     1.2.8     2022-07-05 [1] Bioconductor
   GenomicAlignments                    1.32.0    2022-04-26 [1] Bioconductor
   GenomicFeatures                      1.48.3    2022-05-31 [1] Bioconductor
   GenomicRanges                        1.48.0    2022-04-26 [1] Bioconductor
   ggbeeswarm                           0.6.0     2017-08-07 [1] CRAN (R 4.2.1)
   ggplot2                            * 3.4.4     2024-09-20 [1] Github (tidyverse/ggplot2@e593b99)
   ggrastr                              1.0.2     2023-06-01 [1] CRAN (R 4.2.3)
   glue                                 1.7.0     2024-01-09 [1] CRAN (R 4.2.3)
   GO.db                                3.16.0    2024-04-24 [1] Bioconductor
   graph                                1.76.0    2022-11-01 [1] Bioconductor
   gtable                               0.3.5     2024-04-22 [1] CRAN (R 4.2.3)
   gtools                               3.9.4     2022-11-27 [1] CRAN (R 4.2.2)
   HDF5Array                            1.26.0    2022-11-01 [1] Bioconductor
   hms                                  1.1.2     2022-08-19 [1] CRAN (R 4.2.2)
   htmltools                            0.5.8.1   2024-04-04 [1] CRAN (R 4.2.3)
   htmlwidgets                          1.6.1     2023-01-07 [1] CRAN (R 4.2.2)
   httpuv                               1.6.5     2022-01-05 [1] CRAN (R 4.2.0)
   httr                                 1.4.6     2023-05-08 [1] CRAN (R 4.2.3)
   IRanges                              2.30.0    2022-04-26 [1] Bioconductor
   irlba                                2.3.5.1   2022-10-03 [1] CRAN (R 4.2.3)
   janitor                            * 2.2.0     2023-02-02 [1] CRAN (R 4.2.3)
   KEGGREST                             1.36.2    2022-06-09 [1] Bioconductor
   knitr                                1.46      2024-04-06 [1] CRAN (R 4.2.3)
   labeling                             0.4.3     2023-08-29 [1] CRAN (R 4.2.3)
   later                                1.3.0     2021-08-18 [1] CRAN (R 4.2.0)
   lattice                              0.22-6    2024-03-20 [1] CRAN (R 4.2.3)
   lifecycle                            1.0.4     2023-11-07 [1] CRAN (R 4.2.3)
   limma                                3.54.1    2023-01-26 [1] Bioconductor
   locfit                               1.5-9.7   2023-01-02 [1] CRAN (R 4.2.2)
   lubridate                          * 1.9.3     2023-09-27 [1] CRAN (R 4.2.3)
   magrittr                             2.0.3     2022-03-30 [1] CRAN (R 4.2.0)
   Matrix                               1.6-5     2024-01-11 [1] CRAN (R 4.2.3)
   MatrixGenerics                       1.8.1     2022-06-30 [1] Bioconductor
   matrixStats                          0.62.0    2022-04-19 [1] CRAN (R 4.2.1)
   memoise                              2.0.1     2021-11-26 [1] CRAN (R 4.2.0)
   mime                                 0.12      2021-09-28 [1] CRAN (R 4.2.0)
   miniUI                               0.1.1.1   2018-05-18 [1] CRAN (R 4.2.1)
   munsell                              0.5.1     2024-04-01 [1] CRAN (R 4.2.3)
   Mus.musculus                         1.3.1     2024-09-20 [1] Bioconductor
   NanoMethViz                        * 3.1.6     2024-09-20 [1] Github (Shians/NanoMethViz@5a411a6)
   openxlsx                           * 4.2.5.2   2023-02-06 [1] CRAN (R 4.2.3)
   org.Mm.eg.db                         3.16.0    2024-09-20 [1] Bioconductor
   OrganismDbi                          1.40.0    2022-11-01 [1] Bioconductor
   pacman                             * 0.5.1     2019-03-11 [1] CRAN (R 4.2.0)
   pak                                  0.4.0     2023-01-15 [1] CRAN (R 4.2.2)
   patchwork                            1.1.2     2022-08-19 [1] CRAN (R 4.2.2)
   permute                              0.9-7     2022-01-27 [1] CRAN (R 4.2.0)
   pillar                               1.9.0     2023-03-22 [1] CRAN (R 4.2.3)
   pkgbuild                             1.3.1     2021-12-20 [1] CRAN (R 4.2.0)
   pkgconfig                            2.0.3     2019-09-22 [1] CRAN (R 4.2.0)
   pkgload                              1.3.4     2024-01-16 [1] CRAN (R 4.2.3)
   png                                  0.1-7     2013-12-03 [1] CRAN (R 4.2.0)
   prettyunits                          1.1.1     2020-01-24 [1] CRAN (R 4.2.0)
   processx                             3.8.4     2024-03-16 [1] CRAN (R 4.2.3)
   profvis                              0.3.8     2023-05-02 [1] CRAN (R 4.2.3)
   progress                             1.2.2     2019-05-16 [1] CRAN (R 4.2.0)
   promises                             1.2.0.1   2021-02-11 [1] CRAN (R 4.2.0)
   proxy                                0.4-27    2022-06-09 [1] CRAN (R 4.2.1)
   ps                                   1.7.6     2024-01-18 [1] CRAN (R 4.2.3)
   purrr                              * 1.0.1     2023-01-10 [1] CRAN (R 4.2.3)
   R.methodsS3                          1.8.2     2022-06-13 [1] CRAN (R 4.2.0)
   R.oo                                 1.25.0    2022-06-12 [1] CRAN (R 4.2.0)
   R.utils                              2.12.2    2022-11-11 [1] CRAN (R 4.2.2)
   R6                                   2.5.1     2021-08-19 [1] CRAN (R 4.2.0)
   rappdirs                             0.3.3     2021-01-31 [1] CRAN (R 4.2.0)
   RBGL                                 1.74.0    2022-11-01 [1] Bioconductor
   RColorBrewer                         1.1-3     2022-04-03 [1] CRAN (R 4.2.0)
   Rcpp                                 1.0.12    2024-01-09 [1] CRAN (R 4.2.3)
   RCurl                                1.98-1.7  2022-06-09 [1] CRAN (R 4.2.0)
   readr                              * 2.1.4     2023-02-10 [1] CRAN (R 4.2.3)
   readxl                             * 1.4.3     2023-07-06 [1] CRAN (R 4.2.3)
   remotes                              2.5.0     2024-03-17 [1] CRAN (R 4.2.3)
   restfulr                             0.0.15    2022-06-16 [1] CRAN (R 4.2.1)
   rhdf5                                2.42.1    2023-04-07 [1] Bioconductor
 D rhdf5filters                         1.10.1    2023-03-24 [1] Bioconductor
   Rhdf5lib                             1.20.0    2022-11-01 [1] Bioconductor
   rjson                                0.2.21    2022-01-09 [1] CRAN (R 4.2.0)
   rlang                                1.1.4     2024-06-04 [1] CRAN (R 4.2.1)
   rmarkdown                            2.20      2023-01-19 [1] CRAN (R 4.2.2)
   Rsamtools                            2.12.0    2022-04-26 [1] Bioconductor
   RSQLite                              2.2.14    2022-05-07 [1] CRAN (R 4.2.1)
   rstudioapi                           0.14      2022-08-22 [1] CRAN (R 4.2.3)
   rsvd                                 1.0.5     2021-04-16 [1] CRAN (R 4.2.3)
   rtracklayer                          1.56.1    2022-06-23 [1] Bioconductor
   S4Vectors                            0.34.0    2022-04-26 [1] Bioconductor
   ScaledMatrix                         1.6.0     2022-11-01 [1] Bioconductor
   scales                               1.3.0     2023-11-28 [1] CRAN (R 4.2.3)
   sessioninfo                          1.2.2     2021-12-06 [1] CRAN (R 4.2.0)
   shiny                                1.8.1.1   2024-04-02 [1] CRAN (R 4.2.3)
   snakecase                            0.11.0    2019-05-25 [1] CRAN (R 4.2.1)
   sparseMatrixStats                    1.10.0    2022-11-01 [1] Bioconductor
   stringi                              1.7.6     2021-11-29 [1] CRAN (R 4.2.0)
   stringr                            * 1.5.0     2022-12-02 [1] CRAN (R 4.2.2)
   SummarizedExperiment                 1.26.1    2022-04-29 [1] Bioconductor
   tibble                             * 3.2.1     2023-03-20 [1] CRAN (R 4.2.3)
   tidyr                              * 1.3.0     2023-01-24 [1] CRAN (R 4.2.3)
   tidyselect                           1.2.0     2022-10-10 [1] CRAN (R 4.2.2)
   tidyverse                          * 2.0.0     2023-02-22 [1] CRAN (R 4.2.3)
   timechange                           0.2.0     2023-01-11 [1] CRAN (R 4.2.3)
   TxDb.Mmusculus.UCSC.mm10.knownGene   3.10.0    2024-09-20 [1] Bioconductor
   tzdb                                 0.3.0     2022-03-28 [1] CRAN (R 4.2.0)
   urlchecker                           1.0.1     2021-11-30 [1] CRAN (R 4.2.3)
   usethis                            * 2.2.3     2024-02-19 [1] CRAN (R 4.2.3)
   utf8                                 1.2.4     2023-10-22 [1] CRAN (R 4.2.3)
   vctrs                                0.6.5     2023-12-01 [1] CRAN (R 4.2.3)
   vipor                                0.4.5     2017-03-22 [1] CRAN (R 4.2.1)
   withr                                3.0.1     2024-07-31 [1] CRAN (R 4.2.1)
   xfun                                 0.43      2024-03-25 [1] CRAN (R 4.2.3)
   XML                                  3.99-0.10 2022-06-09 [1] CRAN (R 4.2.0)
   xml2                                 1.3.3     2021-11-30 [1] CRAN (R 4.2.0)
   xtable                               1.8-4     2019-04-21 [1] CRAN (R 4.2.0)
   XVector                              0.36.0    2022-04-26 [1] Bioconductor
   yaml                                 2.3.6     2022-10-18 [1] CRAN (R 4.2.2)
   zip                                  2.2.0     2021-05-31 [1] CRAN (R 4.2.0)
   zlibbioc                             1.42.0    2022-04-26 [1] Bioconductor

 [1] C:/Users/idoid/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.1/library

 D ── DLL MD5 mismatch, broken installation.

Any help would be appreciated!

Thanks, Ido

IdoBar commented 1 month ago

Just a quick update, when I specify heatmap=FALSE, it generates a plot, but it is empty with no traces.

plot_gene(mbr, "EKO05_006932", heatmap = FALSE, spaghetti = TRUE)

image

Shians commented 1 month ago

Hmm that's not an error I've seen before, when you get an error, are you able to get any information from traceback(). The only unusual thing I can see is using a very cutting edge version of ggplot2, but that really shouldn't cause this problem.

IdoBar commented 1 month ago

It seems that there are issues with patchwork and recent versions of ggplot2, I actually reverted back to v3.4.4 (based on this discussion) and updated pathcwork, which solved some problem with patchwork, but the plotting functions in NanoMethViz still don't work. This is my last_trace() output:

Error in `combine_vars()`:
! Faceting variables must have at least one value
---
Backtrace:
     ▆
  1. ├─base (local) `<fn>`(x)
  2. └─patchwork:::print.patchwork(x)
  3.   └─patchwork:::build_patchwork(plot, plot$layout$guides %||% "auto")
  4.     └─base::lapply(x$plots, plot_table, guides = guides)
  5.       ├─patchwork (local) FUN(X[[i]], ...)
  6.       └─patchwork:::plot_table.ggplot(X[[i]], ...)
  7.         └─ggplot2::ggplotGrob(x)
  8.           ├─ggplot2::ggplot_gtable(ggplot_build(x))
  9.           │ └─ggplot2:::attach_plot_env(data$plot$plot_env)
 10.           │   └─base::options(ggplot2_plot_env = env)
 11.           ├─ggplot2::ggplot_build(x)
 12.           └─ggplot2:::ggplot_build.ggplot(x)
 13.             └─layout$setup(data, plot$data, plot$plot_env)
 14.               └─ggplot2 (local) setup(..., self = self)
 15.                 └─self$facet$compute_layout(data, self$facet_params)
 16.                   └─ggplot2 (local) compute_layout(..., self = self)
 17.                     └─ggplot2::combine_vars(data, params$plot_env, vars, drop = params$drop)
IdoBar commented 1 month ago

Can you recommend versions of patchwork and ggplot2 that you are using so I could try?

IdoBar commented 1 month ago

I have an update - after updating both ggplot2 and patchwork and changing the sample names to not include dashes (following this thread on Bioconductor) I can get the plot if I turn off the heatmap.

plot_gene(mbr, "EKO05_006932", heatmap = FALSE, spaghetti = FALSE)

image

nmr <- load_example_nanomethresult()
plot_gene(nmr, "Peg3", heatmap = FALSE)

image

With heatmap=TRUE I still get the error:

> plot_gene(nmr, "Peg3")
Error in self$get_transformation() : attempt to apply non-function
Shians commented 1 month ago

I am currently working with ggplot2_3.5.1 and patchwork_1.3.0.

IdoBar commented 1 month ago

I am currently working with ggplot2_3.5.1 and patchwork_1.3.0.

Thanks, it's working with these versions.