Contents

suppressPackageStartupMessages({
  library(tidyverse)
  library(survival)
  library(dplyr)
  library(survminer)
  library(Biobase)
  library(ggsci)
  library(ggbeeswarm)
  library(TOP)
  library(curatedOvarianData)
})

theme_set(theme_bw())

1 Installation

# Install the package from Bioconductor
if (!requireNamespace("BiocManager", quietly = TRUE)) {
  install.packages("BiocManager")
}
BiocManager::install("TOP")

2 Overview

The TOP R package provides a transfer learning approach for building predictive models across multiple omics datasets. With the increasing availability of omics data, there is a growing need for methods that can effectively integrate and analyze data from multiple sources. However, merging datasets can be challenging due to batch effects and other sources of variation.

TOP uses transfer learning strategies to build predictive models that can be applied across multiple datasets without the need for extensive batch correction methods. Specifically, TOP employs a lasso regression model to identify important features and construct a transferable predictive model. By leveraging information from multiple datasets, TOP can improve predictive accuracy and identify common biomarkers across different omics datasets.

The package provides several functions for building and evaluating transfer learning models, including options for visualizing results. Additionally, the package includes sample datasets and detailed documentation to help users get started with the package and understand the underlying methods.

Overall, TOP offers a flexible and powerful approach for integrating and analyzing omics data from multiple sources, making it a valuable tool for researchers in a variety of fields.

3 Loading example data

The example data used in this vignette is the curatedOvarianData. Described in the paper from Benjamin Frederick Ganzfried et al (2013)

data("GSE12418_eset", package = "curatedOvarianData")
data("GSE30009_eset", package = "curatedOvarianData")

4 Building a survival model.

The transferable omics prediction framework is also able to build survival models. In this section, we will demonstrate how to use TOP to build a survival model using example ovarian cancer datasets. First we utilise nine datasets that were preparred by Ganzfield et al. 

data("GSE32062.GPL6480_eset")
japan_a <- GSE32062.GPL6480_eset

data("GSE9891_eset")
tothill <- GSE9891_eset

data("GSE32063_eset")
japan_b <- GSE32063_eset

data("TCGA.RNASeqV2_eset")
selection <- TCGA.RNASeqV2_eset$tumorstage %in% c(3, 4) & TCGA.RNASeqV2_eset$site_of_tumor_first_recurrence == "metastasis"
selection[is.na(selection)] <- FALSE
tcgarnaseq <- TCGA.RNASeqV2_eset[, selection]

data("E.MTAB.386_eset")
bentink <- E.MTAB.386_eset

data("GSE13876_eset")
crijns <- GSE13876_eset
crijns <- crijns[, crijns$grade %in% c(3, 4)]

data("GSE18520_eset")
mok <- GSE18520_eset

data("GSE17260_eset")
yoshihara2010 <- GSE17260_eset

data("GSE26712_eset")
bonome <- GSE26712_eset

list_ovarian_eset <- lst(
  japan_a, tothill, japan_b,
  tcgarnaseq, bonome, mok, yoshihara2010,
  bentink, crijns
)

list_ovarian_eset %>%
  sapply(dim)
#>          japan_a tothill japan_b tcgarnaseq bonome   mok yoshihara2010 bentink
#> Features   20106   19816   20106      20502  13104 19816         20106   10357
#> Samples      260     285      40         51    195    63           110     129
#>          crijns
#> Features  20577
#> Samples      85

5 Common genes between datasets

In order to apply the TOP framework, it is important that the input matrices have identical feature names, such as gene names, across all datasets. In this example, we will identify the common genes present in all the datasets, as these will be the features used for transfer learning.

raw_gene_list <- purrr::map(list_ovarian_eset, rownames)
common_genes <- Reduce(f = intersect, x = raw_gene_list)
length(common_genes)
#> [1] 7517

6 Survival samples

Next, we will prepare the survival data from each of the ovarian cancer datasets. The survival data includes the survival time and the event status (i.e., whether the event of interest, such as death, has occurred)

ov_pdata <- purrr::map(list_ovarian_eset, pData)
list_pdata <- list_ovarian_eset %>%
  purrr::map(pData) %>%
  purrr::map(tibble::rownames_to_column, var = "sample_id")

ov_surv_raw <- purrr::map(
  .x = list_pdata,
  .f = ~ data.frame(
    sample_id = .x$sample_id,
    time = .x$days_to_death %>% as.integer(),
    dead = ifelse(.x$vital_status == "deceased", 1, 0)
  ) %>%
    na.omit() %>%
    dplyr::filter(
      time > 0,
      !is.nan(time),
      !is.nan(dead)
    )
)
ov_surv_raw %>% sapply(nrow)
#>       japan_a       tothill       japan_b    tcgarnaseq        bonome 
#>           260           276            40            51           185 
#>           mok yoshihara2010       bentink        crijns 
#>            53           110           129            85
ov_surv_y <- ov_surv_raw %>%
  purrr::map(~ .x %>%
    dplyr::select(-sample_id)) %>%
  purrr::map(~ Surv(time = .x$time, event = .x$dead))

7 Preparing data for modelling.

In this section, we will prepare the gene expression data and survival data for visualization. We will subset the gene expression data to include only the common genes and samples with survival information. Then, we will create a combined survival data table, with a data_source column to identify the origin of each sample. Finally we plot the distribution of survival times across datasets.

ov_surv_exprs <- purrr::map2(
  .x = list_ovarian_eset,
  .y = ov_surv_raw,
  .f = ~ exprs(.x[common_genes, .y$sample_id])
)

ov_surv_tbl <- ov_surv_raw %>%
  bind_rows(.id = "data_source")
ov_surv_tbl %>%
  ggplot(aes(
    x = time,
    y = ..density..,
    fill = data_source
  )) +
  geom_density(alpha = 0.25) +
  scale_fill_d3()
#> Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
#> ℹ Please use `after_stat(density)` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.

# Building a TOP survival model. In this section, we will build the survival model using the TOP framework. To do this, we will first organize the survival data and gene expression data into appropriate data structures. Then, we will apply the TOP_survival function to build the model, specifying the number of features to be selected by the lasso regression.

surv_list <- ov_surv_tbl %>%
  split(ov_surv_tbl$data_source)
surv_list <- lapply(surv_list, function(x) x[, 3:4])

surv_counts <- ov_surv_exprs %>% lapply(t)
surv_list <- surv_list[names(surv_counts)]
surv_model <- TOP_survival(
  x_list = surv_counts, y_list = surv_list, nFeatures = 10
)

8 Visualising performance.

Once we have built the survival model using the TOP framework, it is important to evaluate its performance. In this section, we will visualize the performance of the model by calculating the concordance index (C-index) for each dataset. The C-index measures the agreement between the predicted and observed survival times, with values ranging from 0 to 1,

conf_results <- unlist(lapply(seq_along(surv_counts), function(x) {
  Surv_TOP_CI(
    surv_model,
    newx = surv_counts[[x]], newy = surv_list[[x]]
  )$concordance
}))

conf_results %>%
  tibble::enframe() %>%
  mutate(Metric = "C-index") %>%
  ggplot(aes(y = value, x = Metric)) +
  geom_boxplot(width = 0.5) +
  ylab("C-index") +
  geom_jitter(alpha = 0.7, width = 0.1) +
  theme(axis.text.x = element_blank()) +
  xlab("Survival Model")

9 sessionInfo

sessionInfo()
#> R Under development (unstable) (2023-10-22 r85388)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 22.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.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] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] curatedOvarianData_1.39.1 TOP_1.3.0                
#>  [3] ggbeeswarm_0.7.2          ggsci_3.0.0              
#>  [5] Biobase_2.63.0            BiocGenerics_0.49.0      
#>  [7] survminer_0.4.9           ggpubr_0.6.0             
#>  [9] survival_3.5-7            lubridate_1.9.3          
#> [11] forcats_1.0.0             stringr_1.5.0            
#> [13] dplyr_1.1.3               purrr_1.0.2              
#> [15] readr_2.1.4               tidyr_1.3.0              
#> [17] tibble_3.2.1              ggplot2_3.4.4            
#> [19] tidyverse_2.0.0           BiocStyle_2.31.0         
#> 
#> loaded via a namespace (and not attached):
#>   [1] splines_4.4.0               bitops_1.0-7               
#>   [3] latex2exp_0.9.6             polyclip_1.10-6            
#>   [5] hardhat_1.3.0               pROC_1.18.4                
#>   [7] rpart_4.1.21                lifecycle_1.0.3            
#>   [9] rstatix_0.7.2               doParallel_1.0.17          
#>  [11] globals_0.16.2              lattice_0.22-5             
#>  [13] MASS_7.3-60.1               MultiAssayExperiment_1.29.0
#>  [15] backports_1.4.1             magrittr_2.0.3             
#>  [17] plotly_4.10.3               limma_3.59.0               
#>  [19] Hmisc_5.1-1                 sass_0.4.7                 
#>  [21] rmarkdown_2.25              jquerylib_0.1.4            
#>  [23] yaml_2.3.7                  ClassifyR_3.7.0            
#>  [25] abind_1.4-5                 zlibbioc_1.49.0            
#>  [27] GenomicRanges_1.55.0        ggraph_2.1.0               
#>  [29] RCurl_1.98-1.12             nnet_7.3-19                
#>  [31] tweenr_2.0.2                ipred_0.9-14               
#>  [33] lava_1.7.2.1                GenomeInfoDbData_1.2.11    
#>  [35] IRanges_2.37.0              KMsurv_0.1-5               
#>  [37] S4Vectors_0.41.0            ggrepel_0.9.4              
#>  [39] listenv_0.9.0               parallelly_1.36.0          
#>  [41] codetools_0.2-19            DelayedArray_0.29.0        
#>  [43] ggforce_0.4.1               tidyselect_1.2.0           
#>  [45] shape_1.4.6                 farver_2.1.1               
#>  [47] viridis_0.6.4               matrixStats_1.0.0          
#>  [49] stats4_4.4.0                base64enc_0.1-3            
#>  [51] jsonlite_1.8.7              caret_6.0-94               
#>  [53] tidygraph_1.2.3             Formula_1.2-5              
#>  [55] iterators_1.0.14            foreach_1.5.2              
#>  [57] tools_4.4.0                 ggnewscale_0.4.9           
#>  [59] Rcpp_1.0.11                 glue_1.6.2                 
#>  [61] prodlim_2023.08.28          gridExtra_2.3              
#>  [63] SparseArray_1.3.0           xfun_0.40                  
#>  [65] MatrixGenerics_1.15.0       ggthemes_4.2.4             
#>  [67] GenomeInfoDb_1.39.0         withr_2.5.1                
#>  [69] BiocManager_1.30.22         fastmap_1.1.1              
#>  [71] fansi_1.0.5                 digest_0.6.33              
#>  [73] timechange_0.2.0            R6_2.5.1                   
#>  [75] colorspace_2.1-0            utf8_1.2.4                 
#>  [77] generics_0.1.3              directPA_1.5               
#>  [79] calibrate_1.7.7             data.table_1.14.8          
#>  [81] recipes_1.0.8               class_7.3-22               
#>  [83] httr_1.4.7                  graphlayouts_1.0.1         
#>  [85] htmlwidgets_1.6.2           S4Arrays_1.3.0             
#>  [87] ModelMetrics_1.2.2.2        pkgconfig_2.0.3            
#>  [89] gtable_0.3.4                timeDate_4022.108          
#>  [91] XVector_0.43.0              survMisc_0.5.6             
#>  [93] htmltools_0.5.6.1           carData_3.0-5              
#>  [95] bookdown_0.36               scales_1.2.1               
#>  [97] gower_1.0.1                 knitr_1.44                 
#>  [99] km.ci_0.5-6                 rstudioapi_0.15.0          
#> [101] tzdb_0.4.0                  reshape2_1.4.4             
#> [103] checkmate_2.3.0             nlme_3.1-163               
#> [105] cachem_1.0.8                zoo_1.8-12                 
#> [107] parallel_4.4.0              vipor_0.4.5                
#> [109] foreign_0.8-85              pillar_1.9.0               
#> [111] grid_4.4.0                  vctrs_0.6.4                
#> [113] car_3.1-2                   xtable_1.8-4               
#> [115] cluster_2.1.4               beeswarm_0.4.0             
#> [117] htmlTable_2.4.1             evaluate_0.22              
#> [119] magick_2.8.1                cli_3.6.1                  
#> [121] compiler_4.4.0              rlang_1.1.1                
#> [123] crayon_1.5.2                future.apply_1.11.0        
#> [125] ggsignif_0.6.4              labeling_0.4.3             
#> [127] plyr_1.8.9                  stringi_1.7.12             
#> [129] viridisLite_0.4.2           BiocParallel_1.37.0        
#> [131] assertthat_0.2.1            munsell_0.5.0              
#> [133] lazyeval_0.2.2              glmnet_4.1-8               
#> [135] Matrix_1.6-1.1              hms_1.1.3                  
#> [137] future_1.33.0               statmod_1.5.0              
#> [139] SummarizedExperiment_1.33.0 igraph_1.5.1               
#> [141] broom_1.0.5                 bslib_0.5.1