PhanstielLab / plotgardener

https://phanstiellab.github.io/plotgardener/
Other
299 stars 28 forks source link

Using tibble for geneHighlights #106

Closed maxim-h closed 10 months ago

maxim-h commented 10 months ago

Hello. Thank you for this great library!

We've noticed that when using geneHighlights in the plotGenes function, when it's provided as a data.frame everything works correctly. However if geneHighlights is given as a tibble with the same columns (gene, color) it doesn't work as expected:

  1. If it contains only 1 row, then it still works fine.
  2. If it contains > 1 row, then nothing is highlighted and everything is left grey.

The documentation does specify that it needs to be a data.frame, but in practice many people tend to use tibbles and data.frames interchangeably.

So perhaps it would help to make geneHighlights compatible with tibbles or make a larger point in the documentation, that it won't work with a tibble.

sessionInfo R version 4.2.2 (2022-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Rocky Linux 8.8 (Green Obsidian) Matrix products: default BLAS/LAPACK: []/FlexiBLAS/3.2.1-GCC-12.2.0/lib64/libflexiblas.so.3.2 locale: [1] LC_CTYPE=en_US.UTF-8 [2] LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 [4] LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 [6] LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 [8] LC_NAME=C [9] LC_ADDRESS=C [10] LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 [12] LC_IDENTIFICATION=C attached base packages: [1] stats4 stats graphics grDevices datasets [6] utils methods base other attached packages: [1] glue_1.6.2 here_1.0.1 [3] GRaNIE_1.2.7 plotgardener_1.4.2 [5] GenomicRanges_1.50.2 GenomeInfoDb_1.34.9 [7] IRanges_2.32.0 S4Vectors_0.36.2 [9] BiocGenerics_0.44.0 lubridate_1.9.2 [11] forcats_1.0.0 stringr_1.5.0 [13] dplyr_1.1.0 purrr_1.0.1 [15] readr_2.1.4 tidyr_1.3.0 [17] tibble_3.2.0 ggplot2_3.4.1 [19] tidyverse_2.0.0 loaded via a namespace (and not attached): [1] bitops_1.0-7 [2] matrixStats_0.63.0 [3] bit64_4.0.5 [4] filelock_1.0.2 [5] RColorBrewer_1.1-3 [6] progress_1.2.2 [7] httr_1.4.5 [8] rprojroot_2.0.3 [9] tools_4.2.2 [10] backports_1.4.1 [11] utf8_1.2.3 [12] R6_2.5.1 [13] DBI_1.1.3 [14] colorspace_2.1-0 [15] withr_2.5.0 [16] tidyselect_1.2.0 [17] prettyunits_1.1.1 [18] bit_4.0.5 [19] curl_5.0.0 [20] compiler_4.2.2 [21] cli_3.6.0 [22] Biobase_2.58.0 [23] xml2_1.3.3 [24] DelayedArray_0.24.0 [25] stringfish_0.15.8 [26] rtracklayer_1.58.0 [27] scales_1.2.1 [28] checkmate_2.1.0 [29] rappdirs_0.3.3 [30] digest_0.6.31 [31] Rsamtools_2.14.0 [32] yulab.utils_0.0.6 [33] XVector_0.38.0 [34] pkgconfig_2.0.3 [35] MatrixGenerics_1.10.0 [36] dbplyr_2.3.1 [37] fastmap_1.1.1 [38] GlobalOptions_0.1.2 [39] rlang_1.1.0 [40] rstudioapi_0.14 [41] RSQLite_2.3.0 [42] RApiSerialize_0.1.2 [43] shape_1.4.6 [44] gridGraphics_0.5-1 [45] BiocIO_1.8.0 [46] generics_0.1.3 [47] BiocParallel_1.32.6 [48] RCurl_1.98-1.10 [49] magrittr_2.0.3 [50] ggplotify_0.1.0 [51] GenomeInfoDbData_1.2.9 [52] patchwork_1.1.2 [53] Matrix_1.6-1.1 [54] Rcpp_1.0.10 [55] munsell_0.5.0 [56] fansi_1.0.4 [57] lifecycle_1.0.3 [58] stringi_1.7.12 [59] yaml_2.3.7 [60] SummarizedExperiment_1.28.0 [61] zlibbioc_1.44.0 [62] org.Hs.eg.db_3.16.0 [63] BiocFileCache_2.6.1 [64] grid_4.2.2 [65] blob_1.2.4 [66] parallel_4.2.2 [67] crayon_1.5.2 [68] lattice_0.20-45 [69] Biostrings_2.66.0 [70] GenomicFeatures_1.50.4 [71] circlize_0.4.15 [72] hms_1.1.2 [73] KEGGREST_1.38.0 [74] pillar_1.8.1 [75] rjson_0.2.21 [76] codetools_0.2-19 [77] biomaRt_2.54.1 [78] strawr_0.0.91 [79] XML_3.99-0.13 [80] RcppParallel_5.1.7 [81] data.table_1.14.8 [82] renv_0.15.5 [83] BiocManager_1.30.22 [84] vctrs_0.6.0 [85] png_0.1-8 [86] tzdb_0.3.0 [87] gtable_0.3.1 [88] qs_0.25.5 [89] cachem_1.0.7 [90] restfulr_0.0.15 [91] TxDb.Hsapiens.UCSC.hg38.knownGene_3.16.0 [92] GenomicAlignments_1.34.1 [93] AnnotationDbi_1.60.2 [94] plyranges_1.18.0 [95] memoise_2.0.1 [96] timechange_0.2.0 [97] ellipsis_0.3.2
jpflores-13 commented 10 months ago

Thanks for catching this! We will look into fixing this, pronto!

jpflores-13 commented 10 months ago

Hello @maxim-h!

A reason why plotGenes() worked for data.frame and not for tibble is because subsetting is different between the two.

For example, If we were to construct a data.frame and tibble:

tib <- tibble(str = c("a","b","c","d"), int = c(1,2,3,4))

df <- data.frame(str = c("a","b","c","d"), int = c(1,2,3,4))

and tried to subset them the same way:

tib[,"str"]

df[,"str"]

We'd receive a tibble and a vector:

> tib[,"str"]
# A tibble: 4 × 1
  str  
  <chr>
1 a    
2 b    
3 c    
4 d    

> df[,"str"]
[1] "a" "b" "c" "d"

I've updated plotGenes() such that it can accommodate both! Thank you for bringing this to our attention and happy gardening! 😊

Cheers, JP