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.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.18-bioc/R/lib/libRblas.so 
## LAPACK: /home/biocbuild/.cache/R/basilisk/1.14.0/pareg/1.6.0/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.6.0          
##  [4] tfprobability_0.15.1  tensorflow_2.14.0     enrichplot_1.22.0    
##  [7] ComplexHeatmap_2.18.0 lubridate_1.9.3       forcats_1.0.0        
## [10] stringr_1.5.0         dplyr_1.1.3           purrr_1.0.2          
## [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.4        
## [19] BiocStyle_2.30.0     
## 
## loaded via a namespace (and not attached):
##   [1] fs_1.6.3                      matrixStats_1.0.0            
##   [3] bitops_1.0-7                  devtools_2.4.5               
##   [5] HDO.db_0.99.1                 httr_1.4.7                   
##   [7] RColorBrewer_1.1-3            doParallel_1.0.17            
##   [9] profvis_0.3.8                 tools_4.3.1                  
##  [11] doRNG_1.8.6                   utf8_1.2.4                   
##  [13] R6_2.5.1                      lazyeval_0.2.2               
##  [15] GetoptLong_1.0.5              urlchecker_1.0.1             
##  [17] withr_2.5.1                   prettyunits_1.2.0            
##  [19] gridExtra_2.3                 cli_3.6.1                    
##  [21] Biobase_2.62.0                Cairo_1.6-1                  
##  [23] scatterpie_0.2.1              labeling_0.4.3               
##  [25] sass_0.4.7                    proxy_0.4-27                 
##  [27] yulab.utils_0.1.0             DOSE_3.28.0                  
##  [29] parallelly_1.36.0             sessioninfo_1.2.2            
##  [31] RSQLite_2.3.1                 generics_0.1.3               
##  [33] gridGraphics_0.5-1            shape_1.4.6                  
##  [35] GO.db_3.18.0                  Matrix_1.6-1.1               
##  [37] fansi_1.0.5                   S4Vectors_0.40.0             
##  [39] logger_0.2.2                  lifecycle_1.0.3              
##  [41] whisker_0.4.1                 yaml_2.3.7                   
##  [43] qvalue_2.34.0                 BiocFileCache_2.10.0         
##  [45] blob_1.2.4                    promises_1.2.1               
##  [47] crayon_1.5.2                  dir.expiry_1.10.0            
##  [49] miniUI_0.1.1.1                lattice_0.22-5               
##  [51] cowplot_1.1.1                 KEGGREST_1.42.0              
##  [53] magick_2.8.1                  zeallot_0.1.0                
##  [55] pillar_1.9.0                  knitr_1.44                   
##  [57] fgsea_1.28.0                  rjson_0.2.21                 
##  [59] future.apply_1.11.0           codetools_0.2-19             
##  [61] fastmatch_1.1-4               glue_1.6.2                   
##  [63] doFuture_1.0.0                ggfun_0.1.3                  
##  [65] data.table_1.14.8             remotes_2.4.2.1              
##  [67] vctrs_0.6.4                   png_0.1-8                    
##  [69] treeio_1.26.0                 gtable_0.3.4                 
##  [71] cachem_1.0.8                  xfun_0.40                    
##  [73] mime_0.12                     tidygraph_1.2.3              
##  [75] iterators_1.0.14              interactiveDisplayBase_1.40.0
##  [77] ellipsis_0.3.2                nlme_3.1-163                 
##  [79] ggtree_3.10.0                 usethis_2.2.2                
##  [81] bit64_4.0.5                   progress_1.2.2               
##  [83] filelock_1.0.2                GenomeInfoDb_1.38.0          
##  [85] bslib_0.5.1                   colorspace_2.1-0             
##  [87] BiocGenerics_0.48.0           DBI_1.1.3                    
##  [89] tidyselect_1.2.0              processx_3.8.2               
##  [91] bit_4.0.5                     compiler_4.3.1               
##  [93] curl_5.1.0                    basilisk.utils_1.14.0        
##  [95] bookdown_0.36                 shadowtext_0.1.2             
##  [97] scales_1.2.1                  keras_2.13.0                 
##  [99] callr_3.7.3                   tfruns_1.5.1                 
## [101] rappdirs_0.3.3                digest_0.6.33                
## [103] rmarkdown_2.25                basilisk_1.14.0              
## [105] XVector_0.42.0                htmltools_0.5.6.1            
## [107] pkgconfig_2.0.3               base64enc_0.1-3              
## [109] dbplyr_2.3.4                  fastmap_1.1.1                
## [111] rlang_1.1.1                   GlobalOptions_0.1.2          
## [113] htmlwidgets_1.6.2             shiny_1.7.5.1                
## [115] farver_2.1.1                  jquerylib_0.1.4              
## [117] jsonlite_1.8.7                BiocParallel_1.36.0          
## [119] GOSemSim_2.28.0               RCurl_1.98-1.12              
## [121] magrittr_2.0.3                GenomeInfoDbData_1.2.11      
## [123] ggplotify_0.1.2               patchwork_1.1.3              
## [125] munsell_0.5.0                 Rcpp_1.0.11                  
## [127] ggnewscale_0.4.9              ape_5.7-1                    
## [129] viridis_0.6.4                 reticulate_1.34.0            
## [131] stringi_1.7.12                zlibbioc_1.48.0              
## [133] MASS_7.3-60                   AnnotationHub_3.10.0         
## [135] plyr_1.8.9                    pkgbuild_1.4.2               
## [137] parallel_4.3.1                HPO.db_0.99.2                
## [139] listenv_0.9.0                 ggrepel_0.9.4                
## [141] Biostrings_2.70.0             graphlayouts_1.0.1           
## [143] splines_4.3.1                 hms_1.1.3                    
## [145] ps_1.7.5                      igraph_1.5.1                 
## [147] rngtools_1.5.2                reshape2_1.4.4               
## [149] stats4_4.3.1                  pkgload_1.3.3                
## [151] BiocVersion_3.18.0            evaluate_0.22                
## [153] BiocManager_1.30.22           nloptr_2.0.3                 
## [155] tzdb_0.4.0                    foreach_1.5.2                
## [157] tweenr_2.0.2                  httpuv_1.6.12                
## [159] polyclip_1.10-6               reshape_0.8.9                
## [161] future_1.33.0                 clue_0.3-65                  
## [163] ggforce_0.4.1                 xtable_1.8-4                 
## [165] tidytree_0.4.5                MPO.db_0.99.7                
## [167] later_1.3.1                   viridisLite_0.4.2            
## [169] aplot_0.2.2                   memoise_2.0.1                
## [171] AnnotationDbi_1.64.0          IRanges_2.36.0               
## [173] cluster_2.1.4                 timechange_0.2.0             
## [175] globals_0.16.2

References

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