Using RTCGA package to download mRNA data that are included in RTCGA.mRNA package

Date of datasets release: 2015-11-01

Witold Chodor


RTCGA package

The Cancer Genome Atlas (TCGA) Data Portal provides a platform for researchers to search, download, and analyze data sets generated by TCGA. It contains clinical information, genomic characterization data, and high level sequence analysis of the tumor genomes. The key is to understand genomics to improve cancer care.

RTCGA package offers download and integration of the variety and volume of TCGA data using patient barcode key, what enables easier data possession. This may have a benefcial infuence on development of science and improvement of patients’ treatment. RTCGA is an open-source R package, available to download from Bioconductor

if (!requireNamespace("BiocManager", quietly=TRUE))

or use below code to download the development version which is like to be more bug-free than the release version on Bioconductor:

if (!require(devtools)) {

Furthermore, RTCGA package transforms TCGA data into form which is convenient to use in R statistical package. Those data transformations can be a part of statistical analysis pipeline which can be more reproducible with RTCGA.

Use cases and examples are shown in RTCGA packages vignettes:


How to download mRNA data to gain the same datasets as in RTCGA.mRNA package?

There are many available date times of TCGA data releases. To see them all just type:


Version 1.0 of RTCGA.mRNA package contains mRNA datasets which were released 2015-11-01. They were downloaded in the following way (which is mainly copied from

Available cohorts

All cohort names can be checked using:

(cohorts <- infoTCGA() %>% 
   rownames() %>% 
   sub("-counts", "", x=.))

For all cohorts the following code downloads the mRNA data.

Downloading tarred files

# dir.create( "data2" )
releaseDate <- "2015-11-01"
sapply( cohorts, function(element){
downloadTCGA( cancerTypes = element, 
              dataSet = "Merge_transcriptome__agilentg4502a_07_3__unc_edu__Level_3__unc_lowess_normalization_gene_level__data.Level_3",
              destDir = "data2", 
              date = releaseDate )},
error = function(cond){
   cat("Error: Maybe there weren't mutations data for ", element, " cancer.\n")

Reading downloaded mRNA dataset

Shortening paths and directories

list.files( "data2") %>% 
   file.path( "data2", .) %>%
   file.rename( to = substr(.,start=1,stop=50))

Removing NA files from data2

There were not mRNA data for these cohorts.

list.files( "data2") %>%
   file.path( "data2", .) %>%
      if (x == "data2/NA")

Paths to mRNA data

Below is the code that removes unneeded “MANIFEST.txt” file from each mRNA cohort folder.

list.files( "data2") %>% 
   file.path( "data2", .) %>%
      file.path(x, list.files(x)) %>%
         grep(pattern = "MANIFEST.txt", x = ., value=TRUE) %>%

Below is the code that automatically gives the path to files for all available mRNA cohorts types downloaded to data2 folder.

list.files("data2") %>%
   file.path("data2", .) %>%
      file.path(y, list.files(y)) %>%
      assign( value = .,
              x = paste0(list.files(y) %>%
                            gsub(x = .,
                                 pattern = "\\..*",
                                 replacement = "") %>%
                            gsub(x=., pattern="-", replacement = "_"),
              envir = .GlobalEnv)

Reading mRNA data using readTCGA

Because of the fact that mRNA data are transposed in downloaded files, there has been prepared special function readTCGA to read and transpose data automatically. Code is below

ls() %>%
   grep("mRNA\\.path", x = ., value = TRUE) %>% 
         readTCGA(get(element, envir = .GlobalEnv),
               dataType = "mRNA") %>%
         assign(value = .,
                x = sub("\\.path", "", x = element),
                envir = .GlobalEnv )
      }, error = function(cond){

Saving mRNA data to RTCGA.mRNA package

grep( "mRNA", ls(), value = TRUE) %>%
   grep("path", x=., value = TRUE, invert = TRUE) %>%
   cat( sep="," ) #can one to id better? as from use_data documentation:
   # ...    Unquoted names of existing objects to save
                      overwrite = TRUE,