TCGAanalyze: Analyze data from TCGA.

You can easily analyze data using following functions:

TCGAanalyze_Preprocessing: Preprocessing of Gene Expression data (IlluminaHiSeq_RNASeqV2)

You can easily search TCGA samples, download and prepare a matrix of gene expression.

The result is shown below:

Example of a matrix of gene expression (10 genes in rows and 2 samples in columns)
TCGA-BH-A1FC-11A-32R-A13Q-07 TCGA-BH-A0DK-11A-13R-A089-07
BCL2L15|440603 14 39.00
ITPRIP|85450 913 4055.00
LY6G5C|80741 62 102.00
AADACL3|126767 19 0.00
TOP1|7150 3448 10533.00
SERPINB3|6317 1 9.95
UBE2D3|7323 9869 18133.00
NCRNA00052|145978 0 4.00
NOL9|79707 445 722.00
C4orf22|255119 0 2.00

The result from TCGAanalyze_Preprocessing is shown below:

TCGAanalyze_DEA & TCGAanalyze_LevelTab: Differential expression analysis (DEA)

Perform DEA (Differential expression analysis) to identify differentially expressed genes (DEGs) using the TCGAanalyze_DEA function.

TCGAanalyze_DEA performs DEA using following functions from R :

  1. edgeR::DGEList converts the count matrix into an edgeR object.
  2. edgeR::estimateCommonDisp each gene gets assigned the same dispersion estimate.
  3. edgeR::exactTest performs pair-wise tests for differential expression between two groups.
  4. edgeR::topTags takes the output from exactTest(), adjusts the raw p-values using the False Discovery Rate (FDR) correction, and returns the top differentially expressed genes.

This function receives as arguments:

  • mat1 The matrix of the first group (in the example, group 1 is the normal samples),
  • mat2 The matrix of the second group (in the example, group 2 is tumor samples)
  • Cond1type Label for group 1
  • Cond1type Label for group 2

Next, we filter the output of dataDEGs by abs(LogFC) >=1, and uses the TCGAanalyze_LevelTab function to create a table with DEGs (differentially expressed genes), log Fold Change (FC), false discovery rate (FDR), the gene expression level for samples in Cond1type, and Cond2type, and Delta value (the difference of gene expression between the two conditions multiplied logFC).

The result is shown below:

Table of DEGs after DEA
mRNA logFC FDR Tumor Normal Delta
FN1 2.88 1.296151e-19 347787.48 41234.12 1001017.3
COL1A1 1.77 1.680844e-08 358010.32 89293.72 633086.3
C4orf7 5.20 2.826474e-50 87821.36 2132.76 456425.4
COL1A2 1.40 9.480478e-06 273385.44 91241.32 383242.9
GAPDH 1.32 3.290678e-05 179057.44 63663.00 236255.5
CLEC3A 6.79 7.971002e-74 27257.16 259.60 185158.6
IGFBP5 1.24 1.060717e-04 128186.88 53323.12 158674.6
CPB1 4.27 3.044021e-37 37001.76 2637.72 157968.8
CARTPT 6.72 1.023371e-72 21700.96 215.16 145872.8
DCD 7.26 1.047988e-80 19941.20 84.80 144806.3

Other examples are in the next sections.

TCGAanalyze_EAcomplete & TCGAvisualize_EAbarplot: Enrichment Analysis

Researchers, in order to better understand the underlying biological processes, often want to retrieve a functional profile of a set of genes that might have an important role. This can be done by performing an enrichment analysis.

We will perform an enrichment analysis on gene sets using the TCGAanalyze_EAcomplete function. Given a set of genes that are up-regulated under certain conditions, an enrichment analysis will identify classes of genes or proteins that are over-represented using annotations for that gene set.

To view the results you can use the TCGAvisualize_EAbarplot function as shown below.

The result is shown below:

The figure shows canonical pathways significantly overrepresented (enriched) by the DEGs (differentially expressed genes). The most statistically significant canonical pathways identified in DEGs list are listed according to their p value corrected FDR (-Log) (colored bars) and the ratio of list genes found in each pathway over the total number of genes in that pathway (Ratio, red line).

TCGAanalyze_survival: Survival Analysis

When analyzing survival, different problems come up than the ones discussed so far. One question is how do we deal with subjects dropping out of a study. For example, assuming that we test a new cancer drug. While some subjects die, others may believe that the new drug is not effective, and decide to drop out of the study before the study is finished. A similar problem would be faced when we investigate how long a machine lasts before it breaks down.

Using the clinical data, it is possible to create a survival plot with the function TCGAanalyze_survival as follows:

The arguments of TCGAanalyze_survival are:

  • clinical_patient TCGA Clinical patient with the information days_to_death
  • clusterCol Column with groups to plot. This is a mandatory field, the caption will be based in this column
  • legend Legend title of the figure
  • xlim xlim x axis limits e.g. xlim = c(0, 1000). Present narrower X axis, but not affect survival estimates.
  • main main title of the plot
  • ylab y-axis text of the plot
  • xlab x-axis text of the plot
  • filename The name of the pdf file
  • color Define the colors of the lines.
  • pvalue Show pvalue in the plot.
  • risk.table Show or not the risk table
  • conf.int Show confidence intervals for point estimates of survival curves.

The result is shown below:

TCGAanalyze_DMR: Differentially methylated regions Analysis

We will search for differentially methylated CpG sites using the TCGAanalyze_DMR function. In order to find these regions we use the beta-values (methylation values ranging from 0.0 to 1.0) to compare two groups.

First, it calculates the difference between the mean DNA methylation of each group for each probe.

Second, it test for differential expression between two groups using the wilcoxon test adjusting by the Benjamini-Hochberg method. The default arguments was set to require a minimum absolute beta-values difference of 0.2 and an adjusted p-value of < 0.01.

After these tests, we save a volcano plot (x-axis:diff mean methylation, y-axis: statistical significance) that will help the user identify the differentially methylated CpG sites, then the results are saved in a csv file (DMR_results.groupCol.group1.group2.csv) and finally the object is returned with the calculus in the rowRanges.

The arguments of TCGAanalyze_DMR are:

Argument Description
data SummarizedExperiment obtained from the TCGAPrepare
groupCol Columns with the groups inside the SummarizedExperiment object. (This will be obtained by the function colData(data))
group1 In case our object has more than 2 groups, you should set the name of the group
group2 In case our object has more than 2 groups, you should set the name of the group
calculate.pvalues.probes In order to get the probes faster the user can select to calculate the pvalues only for the probes with a difference in DNA methylation. The default is to calculate to all probes. Possible values: “all”, “differential”. Default “all”
plot.filename Filename. Default: volcano.pdf, volcano.svg, volcano.png. If set to FALSE, there will be no plot.
ylab y axis text
xlab x axis text
title main title. If not specified it will be "Volcano plot (group1 vs group2)
legend Legend title
color vector of colors to be used in graph
label vector of labels to be used in the figure. Example: c(“Not Significant”,“Hypermethylated in group1”, “Hypomethylated in group1”))
xlim x limits to cut image
ylim y limits to cut image
p.cut p values threshold. Default: 0.01
probe.names is probe.names
diffmean.cut diffmean threshold. Default: 0.2
paired Wilcoxon paired parameter. Default: FALSE
adj.method Adjusted method for the p-value calculation
overwrite Overwrite the pvalues and diffmean values if already in the object for both groups? Default: FALSE
cores Number of cores to be used in the non-parametric test Default = groupCol.group1.group2.rda
save Save object with results? Default: TRUE

The output will be a plot such as the figure below. The green dots are the probes that are hypomethylated in group 2 compared to group 1, while the red dots are the hypermethylated probes in group 2 compared to group 1

Also, the TCGAanalyze_DMR function will save the plot as pdf and return the same SummarizedExperiment that was given as input with the values of p-value, p-value adjusted, diffmean and the group it belongs in the graph (non significant, hypomethylated, hypermethylated) in the rowRanges. The columns will be (where group1 and group2 are the names of the groups):

  • diffmean.group1.group2 (mean.group2 - mean.group1)
  • diffmean.group2.group1 (mean.group1 - mean.group2)
  • p.value.group1.group2
  • p.value.adj.group1.group2
  • status.group1.group2 (Status of probes in group2 in relation to group1)
  • status.group2.group1 (Status of probes in group1 in relation to group2)

This values can be view/acessed using the rowRanges acessesor (rowRanges(data)).

Observation: Calling the same function again, with the same arguments will only plot the results, as it was already calculated. If you want to have them recalculated, please set overwrite to TRUE or remove the calculated columns.

TCGAvisualize: Visualize results from analysis functions with TCGA’s data.

You can easily visualize results from some following functions:

TCGAvisualize_Heatmap: Create heatmaps with cluster bars

In order to have a better view of clusters, we normally use heatmaps. TCGAvisualize_Heatmap will plot a heatmap and add to each sample bars representing different features. This function is a wrapper to the package ComplexHeatmap package,

The arguments of this function are:

  • data The object with the heatmap data (expression, methylation)
  • col.metadata Metadata for the columns (patients). It should have the column bcr_patient_barcode or patient or ID with the patients barcodes.
  • row.metadata Metadata for the rows genes (expression) or probes (methylation)
  • col.colors A list of names colors
  • row.colors A list of named colors
  • show_column_names Show column names names? Default: FALSE
  • show_row_names Show row names? Default: FALSE
  • cluster_rows Cluster rows ? Default: FALSE
  • cluster_columns Cluster columns ? Default: FALSE
  • sortCol Name of the column to be used to sort the columns
  • title Title of the plot
  • type Select the colors of the heatmap values. Possible values are “expression” (default), “methylation”
  • scale Use z-score to make the heamat? If we want to show differences between genes, it is good to make Z-score by samples (force each sample to have zero mean and standard deviation=1). If we want to show differences between samples, it is good to make Z-score by genes (force each gene to have zero mean and standard deviation=1). Possibilities: “row”, “col. Default”none"

For more information please take a look on case study #2.

The result is shown below:

TCGAvisualize_Volcano: Create volcano plot

Creates a volcano plot for DNA methylation or expression

The arguments of this function are:

Argument Description
x x-axis data
y y-axis data
filename Filename. Default: volcano.pdf, volcano.svg, volcano.png
ylab y axis text
xlab x axis text
title main title. If not specified it will be "Volcano plot (group1 vs group2)
legend Legend title
label vector of labels to be used in the figure. Example: c(“Not Significant”,“Hypermethylated in group1”, “Hypomethylated in group1”))#’
xlim x limits to cut image
ylim y limits to cut image
color vector of colors to be used in graph
names Names to be plotted if significant. Should be the same size of x and y
names.fill Names should be filled in a color box? Default: TRUE
show.names What names will be showd? Possibilities: “both”, “significant”, “highlighted”
x.cut x-axis threshold. Default: 0.0 If you give only one number (e.g. 0.2) the cut-offs will be -0.2 and 0.2. Or you can give different cut-offs as a vector (e.g. c(-0.3,0.4))
y.cut p-values threshold.
height Figure height
width Figure width
highlight List of genes/probes to be highlighted. It should be in the names argument.
highlight.color Color of the points highlighted
names.size Size of the names text
dpi Figure dpi

For more information please take a look on case study #3.

TCGAvisualize_PCA: Principal Component Analysis plot for differentially expressed genes

In order to better understand our genes, we can perform a PCA to reduce the number of dimensions of our gene set. The function TCGAvisualize_PCA will plot the PCA for different groups.

The arguments of this function are:

  • dataFilt The expression matrix after normalization and quantile filter
  • dataDEGsFiltLevel The TCGAanalyze_LevelTab output
  • ntopgenes number of DEGs genes to plot in PCA
  • ** group1 a string containing the barcode list of the samples in control group
  • ** group2 a string containing the barcode list of the samples in disease group

The result is shown below:

TCGAvisualize_starburst: Integration of gene expression and DNA methylation data

The starburst plot is proposed to combine information from two volcano plots, and is applied for a study of DNA methylation and gene expression. It first introduced in 2010 (Noushmehr et al. 2010). In order to reproduce this plot, we will use the TCGAvisualize_starburst function.

The function creates Starburst plot for comparison of DNA methylation and gene expression. The log10 (FDR-corrected P value) for DNA methylation is plotted in the x axis, and for gene expression in the y axis, for each gene. The black dashed line shows the FDR-adjusted P value of 0.01.

The arguments of this function are:

Argument Description
exp Object obtained by DEArnaSEQ function
group1 The name of the group 1 Obs: Column p.value.adj.group1.group2 should exist
group2 The name of the group 2. Obs: Column p.value.adj.group1.group2 should exist
exp.p.cut expression p value cut-off
met.p.cut methylation p value cut-off
diffmean.cut If set, the probes with diffmean higher than methylation cut-off will be highlighted in the plot. And the data frame return will be subseted.
logFC.cut If set, the probes with expression fold change higher than methylation cut-off will be highlighted in the plot. And the data frame return will be subseted.
met.platform DNA methylation platform (“27K”,“450K” or “EPIC”)
genome Genome of reference (“hg38” or “hg19”) used to identify nearest probes TSS
names Add the names of the significant genes? Default: FALSE
names.fill Names should be filled in a color box? Default: TRUE
filename The filename of the file (it can be pdf, svg, png, etc)
return.plot If true only plot object will be returned (pdf will not be created)
ylab y axis text
xlab x axis text
title main title
legend legend title
color vector of colors to be used in graph
label vector of labels to be used in graph
xlim x limits to cut image
ylim y limits to cut image
height Figure height
width Figure width
dpi Figure dpi

As a result, the function will a plot the figure below and return a matrix with the Gene_symbol and it status in relation to expression (up regulated/down regulated) and to methylation (Hyper/Hypo methylated). The case study 3, shows the complete pipeline for creating this figure.

Session Information


## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-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] grid      stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] jpeg_0.1-9                  png_0.1-7                  
##  [3] DT_0.25                     dplyr_1.0.10               
##  [5] SummarizedExperiment_1.27.3 Biobase_2.57.1             
##  [7] GenomicRanges_1.49.1        GenomeInfoDb_1.33.7        
##  [9] IRanges_2.31.2              S4Vectors_0.35.4           
## [11] BiocGenerics_0.43.4         MatrixGenerics_1.9.1       
## [13] matrixStats_0.62.0          TCGAbiolinks_2.25.3        
## [15] testthat_3.1.4             
## 
## loaded via a namespace (and not attached):
##   [1] colorspace_2.0-3            ellipsis_0.3.2             
##   [3] rprojroot_2.0.3             XVector_0.37.1             
##   [5] fs_1.5.2                    rstudioapi_0.14            
##   [7] remotes_2.4.2               bit64_4.0.5                
##   [9] AnnotationDbi_1.59.1        fansi_1.0.3                
##  [11] xml2_1.3.3                  R.methodsS3_1.8.2          
##  [13] cachem_1.0.6                knitr_1.40                 
##  [15] pkgload_1.3.0               jsonlite_1.8.0             
##  [17] dbplyr_2.2.1                R.oo_1.25.0                
##  [19] shiny_1.7.2                 readr_2.1.2                
##  [21] compiler_4.2.1              httr_1.4.4                 
##  [23] assertthat_0.2.1            Matrix_1.5-1               
##  [25] fastmap_1.1.0               cli_3.4.0                  
##  [27] later_1.3.0                 htmltools_0.5.3            
##  [29] prettyunits_1.1.1           tools_4.2.1                
##  [31] gtable_0.3.1                glue_1.6.2                 
##  [33] GenomeInfoDbData_1.2.8      rappdirs_0.3.3             
##  [35] Rcpp_1.0.9                  jquerylib_0.1.4            
##  [37] vctrs_0.4.1                 Biostrings_2.65.6          
##  [39] xfun_0.33                   stringr_1.4.1              
##  [41] brio_1.1.3                  ps_1.7.1                   
##  [43] rvest_1.0.3                 mime_0.12                  
##  [45] miniUI_0.1.1.1              lifecycle_1.0.2            
##  [47] devtools_2.4.4              XML_3.99-0.10              
##  [49] zlibbioc_1.43.0             scales_1.2.1               
##  [51] hms_1.1.2                   promises_1.2.0.1           
##  [53] yaml_2.3.5                  curl_4.3.2                 
##  [55] memoise_2.0.1               ggplot2_3.3.6              
##  [57] downloader_0.4              sass_0.4.2                 
##  [59] biomaRt_2.53.2              stringi_1.7.8              
##  [61] RSQLite_2.2.17              highr_0.9                  
##  [63] desc_1.4.2                  filelock_1.0.2             
##  [65] pkgbuild_1.3.1              rlang_1.0.5                
##  [67] pkgconfig_2.0.3             bitops_1.0-7               
##  [69] evaluate_0.16               TCGAbiolinksGUI.data_1.17.0
##  [71] lattice_0.20-45             purrr_0.3.4                
##  [73] htmlwidgets_1.5.4           bit_4.0.4                  
##  [75] processx_3.7.0              tidyselect_1.1.2           
##  [77] plyr_1.8.7                  magrittr_2.0.3             
##  [79] R6_2.5.1                    generics_0.1.3             
##  [81] profvis_0.3.7               DelayedArray_0.23.2        
##  [83] DBI_1.1.3                   pillar_1.8.1               
##  [85] withr_2.5.0                 KEGGREST_1.37.3            
##  [87] RCurl_1.98-1.8              tibble_3.1.8               
##  [89] crayon_1.5.1                utf8_1.2.2                 
##  [91] BiocFileCache_2.5.0         tzdb_0.3.0                 
##  [93] rmarkdown_2.16              urlchecker_1.0.1           
##  [95] progress_1.2.2              usethis_2.1.6              
##  [97] data.table_1.14.2           blob_1.2.3                 
##  [99] callr_3.7.2                 digest_0.6.29              
## [101] xtable_1.8-4                tidyr_1.2.1                
## [103] httpuv_1.6.6                R.utils_2.12.0             
## [105] munsell_0.5.0               bslib_0.4.0                
## [107] sessioninfo_1.2.2

Noushmehr, Houtan, Daniel J Weisenberger, Kristin Diefes, Heidi S Phillips, Kanan Pujara, Benjamin P Berman, Fei Pan, et al. 2010. “Identification of a Cpg Island Methylator Phenotype That Defines a Distinct Subgroup of Glioma.” Cancer Cell 17 (5): 510–22.