Prelude

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

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

set.seed(42)

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
)

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).

Session information

## R version 4.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur ... 10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] pareg_0.99.5          tfprobability_0.15.0  tensorflow_2.9.0     
##  [4] GGally_2.1.2          circlize_0.4.15       ComplexHeatmap_2.12.0
##  [7] forcats_0.5.1         stringr_1.4.0         dplyr_1.0.9          
## [10] purrr_0.3.4           readr_2.1.2           tidyr_1.2.0          
## [13] tibble_3.1.7          ggplot2_3.3.6         tidyverse_1.3.1      
## [16] BiocStyle_2.24.0     
## 
## loaded via a namespace (and not attached):
##   [1] utf8_1.2.2             reticulate_1.25-9000   tidyselect_1.1.2      
##   [4] RSQLite_2.2.14         AnnotationDbi_1.58.0   BiocParallel_1.30.3   
##   [7] devtools_2.4.3         munsell_0.5.0          codetools_0.2-18      
##  [10] ragg_1.2.2             future_1.26.1          withr_2.5.0           
##  [13] keras_2.9.0            colorspace_2.0-3       GOSemSim_2.22.0       
##  [16] Biobase_2.56.0         highr_0.9              logger_0.2.2          
##  [19] knitr_1.39             rstudioapi_0.13        stats4_4.2.1          
##  [22] DOSE_3.22.0            listenv_0.8.0          labeling_0.4.2        
##  [25] GenomeInfoDbData_1.2.8 polyclip_1.10-0        bit64_4.0.5           
##  [28] farver_2.1.0           rprojroot_2.0.3        parallelly_1.32.0     
##  [31] vctrs_0.4.1            generics_0.1.3         xfun_0.31             
##  [34] R6_2.5.1               doParallel_1.0.17      GenomeInfoDb_1.32.2   
##  [37] clue_0.3-61            graphlayouts_0.8.0     bitops_1.0-7          
##  [40] cachem_1.0.6           reshape_0.8.9          fgsea_1.22.0          
##  [43] assertthat_0.2.1       scales_1.2.0           ggraph_2.0.5          
##  [46] gtable_0.3.0           globals_0.15.1         processx_3.6.1        
##  [49] tidygraph_1.2.1        rlang_1.0.3            zeallot_0.1.0         
##  [52] systemfonts_1.0.4      GlobalOptions_0.1.2    splines_4.2.1         
##  [55] broom_1.0.0            BiocManager_1.30.18    yaml_2.3.5            
##  [58] reshape2_1.4.4         modelr_0.1.8           backports_1.4.1       
##  [61] qvalue_2.28.0          tools_4.2.1            usethis_2.1.6         
##  [64] bookdown_0.27          ellipsis_0.3.2         jquerylib_0.1.4       
##  [67] RColorBrewer_1.1-3     proxy_0.4-27           BiocGenerics_0.42.0   
##  [70] sessioninfo_1.2.2      Rcpp_1.0.8.3           plyr_1.8.7            
##  [73] base64enc_0.1-3        progress_1.2.2         zlibbioc_1.42.0       
##  [76] RCurl_1.98-1.7         ps_1.7.1               prettyunits_1.1.1     
##  [79] GetoptLong_1.0.5       viridis_0.6.2          S4Vectors_0.34.0      
##  [82] haven_2.5.0            ggrepel_0.9.1          cluster_2.1.3         
##  [85] fs_1.5.2               magrittr_2.0.3         data.table_1.14.2     
##  [88] DO.db_2.9              reprex_2.0.1           whisker_0.4           
##  [91] matrixStats_0.62.0     pkgload_1.3.0          hms_1.1.1             
##  [94] evaluate_0.15          readxl_1.4.0           IRanges_2.30.0        
##  [97] gridExtra_2.3          shape_1.4.6            tfruns_1.5.0          
## [100] compiler_4.2.1         crayon_1.5.1           htmltools_0.5.2       
## [103] tzdb_0.3.0             lubridate_1.8.0        DBI_1.1.3             
## [106] tweenr_1.0.2           dbplyr_2.2.1           MASS_7.3-57           
## [109] Matrix_1.4-1           cli_3.3.0              parallel_4.2.1        
## [112] igraph_1.3.2           pkgconfig_2.0.3        pkgdown_2.0.5         
## [115] xml2_1.3.3             foreach_1.5.2          bslib_0.3.1           
## [118] rngtools_1.5.2         XVector_0.36.0         doFuture_0.12.2       
## [121] rvest_1.0.2            doRNG_1.8.2            callr_3.7.0           
## [124] digest_0.6.29          Biostrings_2.64.0      rmarkdown_2.14        
## [127] cellranger_1.1.0       fastmatch_1.1-3        rjson_0.2.21          
## [130] nloptr_2.0.3           lifecycle_1.0.1        jsonlite_1.8.0        
## [133] desc_1.4.1             viridisLite_0.4.0      fansi_1.0.3           
## [136] pillar_1.7.0           lattice_0.20-45        KEGGREST_1.36.2       
## [139] fastmap_1.1.0          httr_1.4.3             pkgbuild_1.3.1        
## [142] GO.db_3.15.0           glue_1.6.2             remotes_2.4.2         
## [145] png_0.1-7              iterators_1.0.14       bit_4.0.4             
## [148] ggforce_0.3.3          stringi_1.7.6          sass_0.4.1            
## [151] blob_1.2.3             textshaping_0.3.6      memoise_2.0.1

References

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