Suppl. Ch. 5 - Visualizing the Results

Gabriel Odom

2021-10-26

1. Overview

This vignette is the fifth chapter in the “Pathway Significance Testing with pathwayPCA” workflow, providing a detailed perspective to the Inspect Results section of the Quickstart Guide. This vignette will discuss graphing the pathway-specific \(p\)-values, FDR values, and associated log-scores. Also, we will discuss how to plot the gene- or protein-specific loadings within a certain pathway and further how to plot the correlation between a gene or protein within a pathway and the principal component representing that pathway.

Before we move on, we will outline our steps. After reading this vignette, you should be able to

  1. Plot the log-score rank of the top pathways.
  2. Plot the feature loadings for a single pathway.
  3. Plot the correlations between a pathway principal component and the features within that pathway.

1.1 Packages

First, load the pathwayPCA package and the tidyverse package suite.

1.2 Example Results

First, we will replicate the data setup from the previous vignette chapters on importing data and creating data objects ( Chapter 2: Import and Tidy Data and Chapter 3: Creating -Omics Data Objects, respectively). See these chapters for detailed explination of the code below.

We will resume inspection of the analysis results from the chapter 4 vignette for the AESPCA method.




2. Plot Pathway Significance Levels

The first element of this results data object is a data frame of pathways and their significance levels (pVals_df).

getPathpVals(colonSurv_aespcOut)
#> # A tibble: 15 × 4
#>    terms                                            rawp  FDR_BH FWER_Bonferroni
#>    <chr>                                           <dbl>   <dbl>           <dbl>
#>  1 PID_EPHB_FWD_PATHWAY                          6.53e-6 9.80e-5       0.0000980
#>  2 REACTOME_PHOSPHOLIPID_METABOLISM              1.96e-4 1.47e-3       0.00295  
#>  3 REACTOME_INSULIN_RECEPTOR_SIGNALLING_CASCADE  4.90e-4 2.45e-3       0.00735  
#>  4 KEGG_ASTHMA                                   8.21e-4 3.08e-3       0.0123   
#>  5 KEGG_ERBB_SIGNALING_PATHWAY                   1.47e-3 4.42e-3       0.0221   
#>  6 PID_TNF_PATHWAY                               2.60e-3 6.51e-3       0.0390   
#>  7 REACTOME_SIGNALING_BY_INSULIN_RECEPTOR        4.42e-3 9.08e-3       0.0662   
#>  8 KEGG_PENTOSE_PHOSPHATE_PATHWAY                4.84e-3 9.08e-3       0.0726   
#>  9 ST_GA12_PATHWAY                               1.48e-2 2.46e-2       0.222    
#> 10 KEGG_RETINOL_METABOLISM                       2.55e-2 3.82e-2       0.382    
#> 11 KEGG_NON_SMALL_CELL_LUNG_CANCER               4.69e-2 6.39e-2       0.703    
#> 12 KEGG_ANTIGEN_PROCESSING_AND_PRESENTATION      7.37e-2 9.21e-2       1        
#> 13 BIOCARTA_RELA_PATHWAY                         7.09e-1 8.01e-1       1        
#> 14 BIOCARTA_TNFR1_PATHWAY                        7.76e-1 8.01e-1       1        
#> 15 BIOCARTA_SET_PATHWAY                          8.01e-1 8.01e-1       1

Given the \(p\)-values from these pathways, we will now graph their score (negative log of the \(p\)-value) and description for the top 15 most-significant pathways.

2.1 Trim Pathway Names

Because pathway names are quite long, we truncate names longer than 35 characters for better display in the graphs.

2.2 Tidy the Pathway Results

For the data frame containing the survival data pathway \(p\)-values, we will transform the data for better graphics. This code takes in the pathway \(p\)-values data frame from the AESPCA method output and gathers it into a “tidy” data frame (compatible with ggplot). We also add on a column for the negative natural logarithm of the pathway \(p\)-values (called score) and recode the label of the \(p\)-value adjustment method.

2.3 Plot Significant Survival Pathways for One Adjustment

Now we will plot the pathway \(p\)-values for the most significant pathways as a horizontal bar chart. For more information on how to modify ggplot graphs, or to learn how to create your own, please see Chang’s R Graphics Cookbook or Wickham’s ggplot2: Elegant Graphics for Data Analysis.

First, we select the rows of the \(p\)-values data frame which correspond to the adjustment method we are interested in. We will select the Benjamini and Hochberg FDR-adjustment method.

Now we plot the pathway significance level for the pathways based on this FDR-adjustment method.

2.4 Plot Significant Survival Pathways for All Adjustments

If we were interested in comparing adjustment methods, we can. This figure shows that a few of the simulated pathways are significant at the \(\alpha = 0.01\) for either the Benjamini and Hochberg or Bonferroni FWER approaches. The vertical black line is at \(-\log(p = 0.01)\). This figure is slightly different from the figures shown in the Graph Top Pathways subsection of the Quickstart Guide.




3. Inspecting the Driving Genes

Now that we have a few significant pathways, we can look at the loadings of each gene onto the first AES-PC from these pathways.

pVals_df %>% 
  filter(FDR_BH < 0.01) %>% 
  select(terms)
#> # A tibble: 8 × 1
#>   terms                               
#>   <chr>                               
#> 1 PID_EPHB_FWD_PATHWAY                
#> 2 REACTOME_PHOSPHOLIPID_METABOLISM    
#> 3 REACTOME_INSULIN_RECEPTOR_SIGNALL...
#> 4 KEGG_ASTHMA                         
#> 5 KEGG_ERBB_SIGNALING_PATHWAY         
#> 6 PID_TNF_PATHWAY                     
#> 7 REACTOME_SIGNALING_BY_INSULIN_REC...
#> 8 KEGG_PENTOSE_PHOSPHATE_PATHWAY

3.1 Extract Pathway Decomposition

We will chose the top two significant pathways for closer inspection, and we want to ascertain which genes load onto the pathway PCs. Notice that the pathway loadings are named by the internal pathway key, so we need to use the getPathPCL() to match this key to its pathway and extract the pathway PCs and loadings (PC & L) list from the colonSurv_aespcOut object. Here are the loading vectors and pathway details from PID_EPHB_FWD_PATHWAY:

This tells us that pathway491 represents the EPHB forward signaling pathway.

We can also extract the PCs and loadings vectors for KEGG_ASTHMA (the Asthma pathway), which we will compare later.

3.2 Gene Loadings

3.2.1 Wrangle Pathway Loadings

Given the loading vectors from the EPHB forward signaling pathway, we need to wrangle them into a data frame that the ggplot() function can use. For this, we’ve written a function that you can modify as you need. This function takes in the pathway PC & L list returned by the getPathPCLs() function and returns a data frame with all the components necessary for a plot of the gene loadings. For more aesthetically-pleasing plots, we set the default for one PC or loading vector per figure.

We can use this function to “tidy up” the loadings from the EPHB forward signaling pathway:

3.2.2 Plot the Gene Loadings

We also wrote a function to create a ggplot graph object which uses this tidy data frame.

This is the resulting loading bar plot for the EPHB forward signaling pathway (because all of the loadings are between -1 and 1, we set the significant figures to 2):

For comparison, this is the bar plot for the asthma pathway (pathway177 in our -Omics data container):

3.3 Gene Correlations with PCs

3.3.1 Calculate Pathway Correlations

Additionally, we can calculate the correlation between gene expression in the assay corresponding to the EPHB forward signaling pathway and the PC vectors extracted from this pathway. Thus, we need to extract the recorded gene levels corresponding to the non-zero loadings for the PCs, calculate the Spearman correlations between these values and their extracted PCs, then wrangle these correlations into a data frame that the ggplot() function can use. We have written an additional function that you can modify as you need. This function takes in the Omics data container (that you created in Chapter 3) and the PC & L list returned by getPathPCLs(). This function returns a data frame with all the components necessary for a plot of the assay-PC correlations.

We can use this function to “tidy up” the loadings from the EPHB forward signaling pathway:

3.3.2 Plot the Assay-PC Correlation

This is the resulting correlation bar plot for the EPHB forward signaling pathway:

And this is the same figure for the asthma pathway.

4. Plot patient-specific pathway activities

estimate pathway activities for each patient, both for protein expressions and copy number expressions separately

This is the circle plot for the IL-1 signaling pathway:

# Load data (already ordered by copyNumber PC1 score)
circlePlotData <- readRDS("circlePlotData.RDS")

# Set color scales
library(grDevices)
bluescale <- colorRampPalette(c("blue", "white"))(45)
redscale  <- colorRampPalette(c("white", "red"))(38)
Totalpalette <- c(bluescale,redscale)

# Apply colours
copyCol <-  Totalpalette[circlePlotData$copyNumOrder]
proteoCol <- Totalpalette[circlePlotData$proteinOrder]

Blue stands for negative PC1 score, Red stands for positive PC1 score. The inner loop measures copy number variation, while the outer loop measures protein expression.

library(circlize)
#> ========================================
#> circlize version 0.4.13
#> CRAN page: https://cran.r-project.org/package=circlize
#> Github page: https://github.com/jokergoo/circlize
#> Documentation: https://jokergoo.github.io/circlize_book/book/
#> 
#> If you use it in published research, please cite:
#> Gu, Z. circlize implements and enhances circular visualization
#>   in R. Bioinformatics 2014.
#> 
#> This message can be suppressed by:
#>   suppressPackageStartupMessages(library(circlize))
#> ========================================

# Set parameters
nPathway <- 83
factors  <- 1:nPathway

# Plot Setup
circos.clear()
circos.par(
  "gap.degree" = 0,
  "cell.padding" = c(0, 0, 0, 0),
  start.degree = 360/40,
  track.margin = c(0, 0),
  "clock.wise" = FALSE
)
circos.initialize(factors = factors, xlim = c(0, 3))

# ProteoOmics
circos.trackPlotRegion(
  ylim = c(0, 3),
  factors = factors,
  bg.col = proteoCol,
  track.height = 0.3
)

# Copy Number
circos.trackPlotRegion(
  ylim = c(0, 3),
  factors = factors,
  bg.col = copyCol,
  track.height = 0.3
)

# Add labels
suppressMessages(
  circos.trackText(
    x = rep(-3, nPathway),
    y = rep(-3.8, nPathway),
    labels = "PID_IL1",
    factors = factors,
    col = "#2d2d2d",
    font = 2,
    adj = par("adj"),
    cex = 1.5,
    facing = "downward",
    niceFacing = TRUE
  )
)



5. Review

We have has covered in this vignette:

  1. Plotting the log-score rank of the top pathways.
  2. Plotting the feature loadings for a single pathway.
  3. Plotting the correlations between a pathway principal component and the features within that pathway.

We are exploring options to connect this package to other pathway-testing software. We are further considering other summary functions and/or graphics to help display the output of our *_pVals() functions. If you have any questions, comments, complaints, or suggestions, please submit an issue ticket and give us some feedback. Also you can visit our development page.

Here is the R session information for this vignette:

sessionInfo()
#> R version 4.1.1 (2021-08-10)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
#> 
#> 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       
#> 
#> attached base packages:
#> [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
#> [8] methods   base     
#> 
#> other attached packages:
#>  [1] circlize_0.4.13             SummarizedExperiment_1.24.0
#>  [3] Biobase_2.54.0              GenomicRanges_1.46.0       
#>  [5] GenomeInfoDb_1.30.0         IRanges_2.28.0             
#>  [7] S4Vectors_0.32.0            BiocGenerics_0.40.0        
#>  [9] MatrixGenerics_1.6.0        matrixStats_0.61.0         
#> [11] survminer_0.4.9             ggpubr_0.4.0               
#> [13] survival_3.2-13             pathwayPCA_1.10.0          
#> [15] forcats_0.5.1               stringr_1.4.0              
#> [17] dplyr_1.0.7                 purrr_0.3.4                
#> [19] readr_2.0.2                 tidyr_1.1.4                
#> [21] tibble_3.1.5                ggplot2_3.3.5              
#> [23] tidyverse_1.3.1            
#> 
#> loaded via a namespace (and not attached):
#>  [1] colorspace_2.0-2       ggsignif_0.6.3         ellipsis_0.3.2        
#>  [4] rio_0.5.27             XVector_0.34.0         GlobalOptions_0.1.2   
#>  [7] fs_1.5.0               rstudioapi_0.13        farver_2.1.0          
#> [10] bit64_4.0.5            fansi_0.5.0            lubridate_1.8.0       
#> [13] xml2_1.3.2             splines_4.1.1          knitr_1.36            
#> [16] jsonlite_1.7.2         broom_0.7.9            km.ci_0.5-2           
#> [19] dbplyr_2.1.1           compiler_4.1.1         httr_1.4.2            
#> [22] backports_1.2.1        assertthat_0.2.1       Matrix_1.3-4          
#> [25] fastmap_1.1.0          cli_3.0.1              lars_1.2              
#> [28] htmltools_0.5.2        tools_4.1.1            gtable_0.3.0          
#> [31] glue_1.4.2             GenomeInfoDbData_1.2.7 Rcpp_1.0.7            
#> [34] carData_3.0-4          cellranger_1.1.0       jquerylib_0.1.4       
#> [37] vctrs_0.3.8            nlme_3.1-153           xfun_0.27             
#> [40] openxlsx_4.2.4         rvest_1.0.2            lifecycle_1.0.1       
#> [43] rstatix_0.7.0          zlibbioc_1.40.0        zoo_1.8-9             
#> [46] scales_1.1.1           vroom_1.5.5            hms_1.1.1             
#> [49] yaml_2.2.1             curl_4.3.2             gridExtra_2.3         
#> [52] KMsurv_0.1-5           sass_0.4.0             stringi_1.7.5         
#> [55] highr_0.9              zip_2.2.0              shape_1.4.6           
#> [58] rlang_0.4.12           pkgconfig_2.0.3        bitops_1.0-7          
#> [61] evaluate_0.14          lattice_0.20-45        labeling_0.4.2        
#> [64] bit_4.0.4              tidyselect_1.1.1       magrittr_2.0.1        
#> [67] R6_2.5.1               generics_0.1.1         DelayedArray_0.20.0   
#> [70] DBI_1.1.1              pillar_1.6.4           haven_2.4.3           
#> [73] foreign_0.8-81         withr_2.4.2            mgcv_1.8-38           
#> [76] abind_1.4-5            RCurl_1.98-1.5         modelr_0.1.8          
#> [79] crayon_1.4.1           car_3.0-11             survMisc_0.5.5        
#> [82] utf8_1.2.2             tzdb_0.1.2             rmarkdown_2.11        
#> [85] grid_4.1.1             readxl_1.3.1           data.table_1.14.2     
#> [88] reprex_2.0.1           digest_0.6.28          xtable_1.8-4          
#> [91] munsell_0.5.0          bslib_0.3.1