Contents

1 Prelude

library(tidyverse)
library(ComplexHeatmap)
library(circlize)
library(GGally)

library(pareg)
data(pathway_similarities, package = "pareg")

set.seed(42)

2 Introduction

Pathway similarities describe how similar two pathways are (you’re welcome). For example, when interpreting pathways as gene sets, one could count how many genes are shared between two sets. Many more sophisticated methods, such as the Jaccard index, exist (Gu and Huebschmann 2021).

pareg provides various pre-computed similarity measures (jaccard, overlap_coefficient, semantic) for selected pathway databases (:KEGG, :BP) in matrix form.

mat <- pathway_similarities$`C2@CP:KEGG`$jaccard %>%
  as_dense_sim()
mat[1:3, 1:3]
##          hsa00970    hsa05340    hsa04621
## hsa00970        1 0.000000000 0.000000000
## hsa05340        0 1.000000000 0.008196721
## hsa04621        0 0.008196721 1.000000000
Heatmap(
  mat,
  name = "similarity",
  col = colorRamp2(c(0, 1), c("white", "black")),
  show_row_names = FALSE,
  show_column_names = FALSE
)

3 Comparison of similarity measures

On the Gene Ontology’s Biological Process subcategory, we can observe how much pathway similarity measures can differ from each other.

df_sim <- pathway_similarities$`C5@GO:BP` %>%
  map_dfr(function(mat) {
    if (is.null(mat)) {
      return(NULL)
    }

    mat %>%
      as_dense_sim() %>%
      as.data.frame %>%
      rownames_to_column() %>%
      pivot_longer(-rowname)
  }, .id = "measure") %>%
  filter(value > 0) %>%
  pivot_wider(names_from = measure, values_from = value) %>%
  select(-rowname, -name)

ggpairs(df_sim) +
  theme_minimal()
## Warning: Removed 514552 rows containing non-finite values (`stat_density()`).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 514552 rows containing missing values
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 586334 rows containing missing values
## Warning: Removed 514552 rows containing missing values (`geom_point()`).
## Warning: Removed 514552 rows containing non-finite values (`stat_density()`).
## Warning in ggally_statistic(data = data, mapping = mapping, na.rm = na.rm, :
## Removed 586334 rows containing missing values
## Warning: Removed 586334 rows containing missing values (`geom_point()`).
## Removed 586334 rows containing missing values (`geom_point()`).
## Warning: Removed 71782 rows containing non-finite values (`stat_density()`).

4 Session information

sessionInfo()
## R version 4.3.1 (2023-06-16)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.2 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.17-bioc/R/lib/libRblas.so 
## LAPACK: /home/biocbuild/.cache/R/basilisk/1.12.1/pareg/1.4.1/pareg/lib/libmkl_rt.so.1;  LAPACK version 3.9.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] GGally_2.1.2          circlize_0.4.15       pareg_1.4.1          
##  [4] tfprobability_0.15.1  tensorflow_2.11.0     enrichplot_1.20.0    
##  [7] ComplexHeatmap_2.16.0 lubridate_1.9.2       forcats_1.0.0        
## [10] stringr_1.5.0         dplyr_1.1.2           purrr_1.0.1          
## [13] readr_2.1.4           tidyr_1.3.0           tibble_3.2.1         
## [16] tidyverse_2.0.0       ggraph_2.1.0          ggplot2_3.4.2        
## [19] BiocStyle_2.28.0     
## 
## loaded via a namespace (and not attached):
##   [1] splines_4.3.1           later_1.3.1             bitops_1.0-7           
##   [4] ggplotify_0.1.1         filelock_1.0.2          polyclip_1.10-4        
##   [7] basilisk.utils_1.12.1   lifecycle_1.0.3         rprojroot_2.0.3        
##  [10] doParallel_1.0.17       globals_0.16.2          processx_3.8.2         
##  [13] lattice_0.21-8          MASS_7.3-60             magrittr_2.0.3         
##  [16] sass_0.4.6              rmarkdown_2.23          jquerylib_0.1.4        
##  [19] yaml_2.3.7              remotes_2.4.2           httpuv_1.6.11          
##  [22] doRNG_1.8.6             sessioninfo_1.2.2       pkgbuild_1.4.2         
##  [25] reticulate_1.30         cowplot_1.1.1           DBI_1.1.3              
##  [28] RColorBrewer_1.1-3      keras_2.11.1            pkgload_1.3.2.1        
##  [31] zlibbioc_1.46.0         BiocGenerics_0.46.0     RCurl_1.98-1.12        
##  [34] yulab.utils_0.0.6       tweenr_2.0.2            GenomeInfoDbData_1.2.10
##  [37] IRanges_2.34.1          S4Vectors_0.38.1        ggrepel_0.9.3          
##  [40] listenv_0.9.0           tidytree_0.4.2          parallelly_1.36.0      
##  [43] codetools_0.2-19        DOSE_3.26.1             ggforce_0.4.1          
##  [46] tidyselect_1.2.0        shape_1.4.6             aplot_0.1.10           
##  [49] farver_2.1.1            viridis_0.6.3           doFuture_1.0.0         
##  [52] matrixStats_1.0.0       stats4_4.3.1            base64enc_0.1-3        
##  [55] jsonlite_1.8.7          GetoptLong_1.0.5        ellipsis_0.3.2         
##  [58] tidygraph_1.2.3         iterators_1.0.14        foreach_1.5.2          
##  [61] ggnewscale_0.4.9        progress_1.2.2          tools_4.3.1            
##  [64] treeio_1.24.1           Rcpp_1.0.11             glue_1.6.2             
##  [67] gridExtra_2.3           tfruns_1.5.1            here_1.0.1             
##  [70] xfun_0.39               usethis_2.2.2           qvalue_2.32.0          
##  [73] GenomeInfoDb_1.36.1     withr_2.5.0             BiocManager_1.30.21    
##  [76] fastmap_1.1.1           basilisk_1.12.1         fansi_1.0.4            
##  [79] callr_3.7.3             digest_0.6.33           timechange_0.2.0       
##  [82] R6_2.5.1                mime_0.12               gridGraphics_0.5-1     
##  [85] colorspace_2.1-0        Cairo_1.6-0             GO.db_3.17.0           
##  [88] RSQLite_2.3.1           utf8_1.2.3              generics_0.1.3         
##  [91] data.table_1.14.8       prettyunits_1.1.1       graphlayouts_1.0.0     
##  [94] httr_1.4.6              htmlwidgets_1.6.2       scatterpie_0.2.1       
##  [97] whisker_0.4.1           pkgconfig_2.0.3         gtable_0.3.3           
## [100] blob_1.2.4              XVector_0.40.0          shadowtext_0.1.2       
## [103] htmltools_0.5.5         profvis_0.3.8           bookdown_0.34          
## [106] fgsea_1.26.0            clue_0.3-64             scales_1.2.1           
## [109] Biobase_2.60.0          png_0.1-8               ggfun_0.1.1            
## [112] knitr_1.43              tzdb_0.4.0              reshape2_1.4.4         
## [115] rjson_0.2.21            nloptr_2.0.3            nlme_3.1-162           
## [118] proxy_0.4-27            cachem_1.0.8            GlobalOptions_0.1.2    
## [121] parallel_4.3.1          miniUI_0.1.1.1          HDO.db_0.99.1          
## [124] AnnotationDbi_1.62.2    reshape_0.8.9           logger_0.2.2           
## [127] pillar_1.9.0            vctrs_0.6.3             urlchecker_1.0.1       
## [130] promises_1.2.0.1        xtable_1.8-4            cluster_2.1.4          
## [133] evaluate_0.21           magick_2.7.4            zeallot_0.1.0          
## [136] cli_3.6.1               compiler_4.3.1          rngtools_1.5.2         
## [139] rlang_1.1.1             crayon_1.5.2            future.apply_1.11.0    
## [142] labeling_0.4.2          ps_1.7.5                plyr_1.8.8             
## [145] fs_1.6.2                stringi_1.7.12          viridisLite_0.4.2      
## [148] BiocParallel_1.34.2     munsell_0.5.0           Biostrings_2.68.1      
## [151] lazyeval_0.2.2          devtools_2.4.5          GOSemSim_2.26.1        
## [154] Matrix_1.6-0            dir.expiry_1.8.0        hms_1.1.3              
## [157] patchwork_1.1.2         future_1.33.0           bit64_4.0.5            
## [160] KEGGREST_1.40.0         shiny_1.7.4.1           highr_0.10             
## [163] igraph_1.5.0            memoise_2.0.1           bslib_0.5.0            
## [166] ggtree_3.8.0            fastmatch_1.1-3         bit_4.0.5              
## [169] ape_5.7-1

References

Gu, Zuguang, and Daniel Huebschmann. 2021. “SimplifyEnrichment: An R/Bioconductor Package for Clustering and Visualizing Functional Enrichment Results.” bioRxiv.