The National Cancer Institute (NCI) has established the Genomic Data Commons (GDC). The GDC provides the cancer research community with an open and unified repository for sharing and accessing data across numerous cancer studies and projects via a high-performance data transfer and query infrastructure. The GenomicDataCommons Bioconductor package provides basic infrastructure for querying, accessing, and mining genomic datasets available from the GDC. We expect that the Bioconductor developer and the larger bioinformatics communities will build on the GenomicDataCommons package to add higher-level functionality and expose cancer genomics data to the plethora of state-of-the-art bioinformatics methods available in Bioconductor.
From the Genomic Data Commons (GDC) website:
The National Cancer Institute’s (NCI’s) Genomic Data Commons (GDC) is a data sharing platform that promotes precision medicine in oncology. It is not just a database or a tool; it is an expandable knowledge network supporting the import and standardization of genomic and clinical data from cancer research programs. The GDC contains NCI-generated data from some of the largest and most comprehensive cancer genomic datasets, including The Cancer Genome Atlas (TCGA) and Therapeutically Applicable Research to Generate Effective Therapies (TARGET). For the first time, these datasets have been harmonized using a common set of bioinformatics pipelines, so that the data can be directly compared. As a growing knowledge system for cancer, the GDC also enables researchers to submit data, and harmonizes these data for import into the GDC. As more researchers add clinical and genomic data to the GDC, it will become an even more powerful tool for making discoveries about the molecular basis of cancer that may lead to better care for patients.
The data model for the GDC is complex, but it worth a quick overview and a graphical representation is included here.
The GDC API exposes these nodes and edges in a somewhat simplified set of RESTful endpoints.
This quickstart section is just meant to show basic functionality. More details of functionality are included further on in this vignette and in function-specific help.
This software is available at Bioconductor.org and can be downloaded via
BiocManager::install
.
To report bugs or problems, either
submit a new issue
or submit a bug.report(package='GenomicDataCommons')
from within R (which
will redirect you to the new issue on GitHub).
Installation can be achieved via Bioconductor’s BiocManager
package.
if (!require("BiocManager"))
install.packages("BiocManager")
BiocManager::install('GenomicDataCommons')
library(GenomicDataCommons)
The GenomicDataCommons package relies on having network
connectivity. In addition, the NCI GDC API must also be operational
and not under maintenance. Checking status
can be used to check this
connectivity and functionality.
GenomicDataCommons::status()
## $commit
## [1] "4dd3680528a19ed33cfc83c7d049426c97bb903b"
##
## $data_release
## [1] "Data Release 37.0 - March 29, 2023"
##
## $status
## [1] "OK"
##
## $tag
## [1] "3.0.0"
##
## $version
## [1] 1
And to check the status in code:
stopifnot(GenomicDataCommons::status()$status=="OK")
The following code builds a manifest
that can be used to guide the
download of raw data. Here, filtering finds gene expression files
quantified as raw counts using STAR
from ovarian cancer patients.
ge_manifest <- files() %>%
filter( cases.project.project_id == 'TCGA-OV') %>%
filter( type == 'gene_expression' ) %>%
filter( analysis.workflow_type == 'STAR - Counts') %>%
manifest()
head(ge_manifest)
After the 858 gene expression files
specified in the query above. Using multiple processes to do the download very
significantly speeds up the transfer in many cases. On a standard 1Gb
connection, the following completes in about 30 seconds. The first time the
data are downloaded, R will ask to create a cache directory (see ?gdc_cache
for details of setting and interacting with the cache). Resulting
downloaded files will be stored in the cache directory. Future access to
the same files will be directly from the cache, alleviating multiple downloads.
fnames <- lapply(ge_manifest$id[1:20], gdcdata)
If the download had included controlled-access data, the download above would
have needed to include a token
. Details are available in
the authentication section below.
Accessing clinical data is a very common task. Given a set of case_ids
,
the gdc_clinical()
function will return a list of four tibble
s.
case_ids = cases() %>% results(size=10) %>% ids()
clindat = gdc_clinical(case_ids)
names(clindat)
## [1] "demographic" "diagnoses" "exposures" "main"
head(clindat[["main"]])
head(clindat[["diagnoses"]])
The GenomicDataCommons package can access the significant
clinical, demographic, biospecimen, and annotation information
contained in the NCI GDC. The gdc_clinical()
function will often
be all that is needed, but the API and GenomicDataCommons package
make much flexibility if fine-tuning is required.
expands = c("diagnoses","annotations",
"demographic","exposures")
clinResults = cases() %>%
GenomicDataCommons::select(NULL) %>%
GenomicDataCommons::expand(expands) %>%
results(size=50)
str(clinResults[[1]],list.len=6)
## chr [1:50] "0286c31b-a704-4d7d-99e3-0bc4e8975b8b" ...
# or listviewer::jsonedit(clinResults)
This package design is meant to have some similarities to the “hadleyverse” approach of dplyr. Roughly, the functionality for finding and accessing files and metadata can be divided into:
In addition, there are exhiliary functions for asking the GDC API for information about available and default fields, slicing BAM files, and downloading actual data files. Here is an overview of functionality1 See individual function and methods documentation for specific details..
projects()
cases()
files()
annotations()
filter()
facet()
select()
mapping()
available_fields()
default_fields()
grep_fields()
available_values()
available_expand()
results()
count()
response()
gdcdata()
transfer()
gdc_client()
aggregations()
gdc_token()
slicing()
There are two main classes of operations when working with the NCI GDC.
Both classes of operation are reviewed in detail in the following sections.
Vast amounts of metadata about cases (patients, basically), files, projects, and
so-called annotations are available via the NCI GDC API. Typically, one will
want to query metadata to either focus in on a set of files for download or
transfer or to perform so-called aggregations (pivot-tables, facets, similar
to the R table()
functionality).
Querying metadata starts with creating a “blank” query. One
will often then want to filter
the query to limit results prior
to retrieving results. The GenomicDataCommons package has
helper functions for listing fields that are available for
filtering.
In addition to fetching results, the GDC API allows faceting, or aggregating,, useful for compiling reports, generating dashboards, or building user interfaces to GDC data (see GDC web query interface for a non-R-based example).
A query of the GDC starts its life in R. Queries follow the four metadata
endpoints available at the GDC. In particular, there are four convenience
functions that each create GDCQuery
objects (actually, specific subclasses of
GDCQuery
):
projects()
cases()
files()
annotations()
pquery = projects()
The pquery
object is now an object of (S3) class, GDCQuery
(and
gdc_projects
and list
). The object contains the following elements:
projects()
function, the default fields from the GDC are used
(see default_fields()
)filter()
method and will be used to filter results on
retrieval.aggregations()
.Looking at the actual object (get used to using str()
!), note that the query
contains no results.
str(pquery)
## List of 5
## $ fields : chr [1:10] "dbgap_accession_number" "disease_type" "intended_release_date" "name" ...
## $ filters: NULL
## $ facets : NULL
## $ legacy : logi FALSE
## $ expand : NULL
## - attr(*, "class")= chr [1:3] "gdc_projects" "GDCQuery" "list"
[ GDC pagination documentation ]
With a query object available, the next step is to retrieve results from the
GDC. The GenomicDataCommons package. The most basic type of results we can get
is a simple count()
of records available that satisfy the filter criteria.
Note that we have not set any filters, so a count()
here will represent all
the project records publicly available at the GDC in the “default” archive"
pcount = count(pquery)
# or
pcount = pquery %>% count()
pcount
## [1] 78
The results()
method will fetch actual results.
presults = pquery %>% results()
These results are
returned from the GDC in JSON format and
converted into a (potentially nested) list in R. The str()
method is useful
for taking a quick glimpse of the data.
str(presults)
## List of 9
## $ id : chr [1:10] "HCMI-CMDC" "TCGA-BRCA" "APOLLO-LUAD" "CPTAC-3" ...
## $ primary_site :List of 10
## ..$ HCMI-CMDC : chr [1:18] "Small intestine" "Esophagus" "Gallbladder" "Rectosigmoid junction" ...
## ..$ TCGA-BRCA : chr "Breast"
## ..$ APOLLO-LUAD : chr "Bronchus and lung"
## ..$ CPTAC-3 : chr [1:6] "Uterus, NOS" "Kidney" "Brain" "Other and ill-defined sites" ...
## ..$ MATCH-Y : chr [1:10] "Retroperitoneum and peritoneum" "Renal pelvis" "Breast" "Bronchus and lung" ...
## ..$ TCGA-THCA : chr "Thyroid gland"
## ..$ TCGA-UCEC : chr [1:2] "Uterus, NOS" "Corpus uteri"
## ..$ GENIE-MSK : chr [1:49] "Other and unspecified parts of biliary tract" "Thymus" "Gallbladder" "Bladder" ...
## ..$ FM-AD : chr [1:42] "Bronchus and lung" "Esophagus" "Cervix uteri" "Other and unspecified female genital organs" ...
## ..$ VAREPOP-APOLLO: chr "Bronchus and lung"
## $ dbgap_accession_number: chr [1:10] NA NA "phs003011" "phs001287" ...
## $ project_id : chr [1:10] "HCMI-CMDC" "TCGA-BRCA" "APOLLO-LUAD" "CPTAC-3" ...
## $ disease_type :List of 10
## ..$ HCMI-CMDC : chr [1:13] "Complex Mixed and Stromal Neoplasms" "Adenomas and Adenocarcinomas" "Nevi and Melanomas" "Gliomas" ...
## ..$ TCGA-BRCA : chr [1:9] "Basal Cell Neoplasms" "Complex Epithelial Neoplasms" "Fibroepithelial Neoplasms" "Epithelial Neoplasms, NOS" ...
## ..$ APOLLO-LUAD : chr "Adenomas and Adenocarcinomas"
## ..$ CPTAC-3 : chr [1:5] "Ductal and Lobular Neoplasms" "Adenomas and Adenocarcinomas" "Gliomas" "Not Applicable" ...
## ..$ MATCH-Y : chr [1:9] "Transitional Cell Papillomas and Carcinomas" "Ductal and Lobular Neoplasms" "Myomatous Neoplasms" "Squamous Cell Neoplasms" ...
## ..$ TCGA-THCA : chr [1:2] "Epithelial Neoplasms, NOS" "Adenomas and Adenocarcinomas"
## ..$ TCGA-UCEC : chr [1:4] "Adenomas and Adenocarcinomas" "Epithelial Neoplasms, NOS" "Not Reported" "Cystic, Mucinous and Serous Neoplasms"
## ..$ GENIE-MSK : chr [1:49] "Mesothelial Neoplasms" "Adenomas and Adenocarcinomas" "Blood Vessel Tumors" "Fibromatous Neoplasms" ...
## ..$ FM-AD : chr [1:23] "Gliomas" "Acinar Cell Neoplasms" "Specialized Gonadal Neoplasms" "Miscellaneous Tumors" ...
## ..$ VAREPOP-APOLLO: chr [1:2] "Squamous Cell Neoplasms" "Epithelial Neoplasms, NOS"
## $ name : chr [1:10] "NCI Cancer Model Development for the Human Cancer Model Initiative" "Breast Invasive Carcinoma" "APOLLO1: Proteogenomic characterization of lung adenocarcinoma" "CPTAC-Brain, Head and Neck, Kidney, Lung, Pancreas, Uterus" ...
## $ releasable : logi [1:10] TRUE TRUE FALSE TRUE FALSE TRUE ...
## $ state : chr [1:10] "open" "open" "open" "open" ...
## $ released : logi [1:10] TRUE TRUE TRUE TRUE TRUE TRUE ...
## - attr(*, "row.names")= int [1:10] 1 2 3 4 5 6 7 8 9 10
## - attr(*, "class")= chr [1:3] "GDCprojectsResults" "GDCResults" "list"
A default of only 10 records are returned. We can use the size
and from
arguments to results()
to either page through results or to change the number
of results. Finally, there is a convenience method, results_all()
that will
simply fetch all the available results given a query. Note that results_all()
may take a long time and return HUGE result sets if not used carefully. Use of a
combination of count()
and results()
to get a sense of the expected data
size is probably warranted before calling results_all()
length(ids(presults))
## [1] 10
presults = pquery %>% results_all()
length(ids(presults))
## [1] 78
# includes all records
length(ids(presults)) == count(pquery)
## [1] TRUE
Extracting subsets of results or manipulating the results into a more conventional R data structure is not easily generalizable. However, the purrr, rlist, and data.tree packages are all potentially of interest for manipulating complex, nested list structures. For viewing the results in an interactive viewer, consider the listviewer package.
Central to querying and retrieving data from the GDC is the ability to specify
which fields to return, filtering by fields and values, and faceting or
aggregating. The GenomicDataCommons package includes two simple functions,
available_fields()
and default_fields()
. Each can operate on a character(1)
endpoint name (“cases”, “files”, “annotations”, or “projects”) or a GDCQuery
object.
default_fields('files')
## [1] "access" "acl"
## [3] "average_base_quality" "average_insert_size"
## [5] "average_read_length" "channel"
## [7] "chip_id" "chip_position"
## [9] "contamination" "contamination_error"
## [11] "created_datetime" "data_category"
## [13] "data_format" "data_type"
## [15] "error_type" "experimental_strategy"
## [17] "file_autocomplete" "file_id"
## [19] "file_name" "file_size"
## [21] "imaging_date" "magnification"
## [23] "md5sum" "mean_coverage"
## [25] "msi_score" "msi_status"
## [27] "pairs_on_diff_chr" "plate_name"
## [29] "plate_well" "platform"
## [31] "proc_internal" "proportion_base_mismatch"
## [33] "proportion_coverage_10X" "proportion_coverage_10x"
## [35] "proportion_coverage_30X" "proportion_coverage_30x"
## [37] "proportion_reads_duplicated" "proportion_reads_mapped"
## [39] "proportion_targets_no_coverage" "read_pair_number"
## [41] "revision" "stain_type"
## [43] "state" "state_comment"
## [45] "submitter_id" "tags"
## [47] "total_reads" "tumor_ploidy"
## [49] "tumor_purity" "type"
## [51] "updated_datetime"
# The number of fields available for files endpoint
length(available_fields('files'))
## [1] 1017
# The first few fields available for files endpoint
head(available_fields('files'))
## [1] "access" "acl"
## [3] "analysis.analysis_id" "analysis.analysis_type"
## [5] "analysis.created_datetime" "analysis.input_files.access"
The fields to be returned by a query can be specified following a similar
paradigm to that of the dplyr package. The select()
function is a verb that
resets the fields slot of a GDCQuery
; note that this is not quite analogous to
the dplyr select()
verb that limits from already-present fields. We
completely replace the fields when using select()
on a GDCQuery
.
# Default fields here
qcases = cases()
qcases$fields
## [1] "aliquot_ids" "analyte_ids"
## [3] "case_autocomplete" "case_id"
## [5] "consent_type" "created_datetime"
## [7] "days_to_consent" "days_to_lost_to_followup"
## [9] "diagnosis_ids" "disease_type"
## [11] "index_date" "lost_to_followup"
## [13] "portion_ids" "primary_site"
## [15] "sample_ids" "slide_ids"
## [17] "state" "submitter_aliquot_ids"
## [19] "submitter_analyte_ids" "submitter_diagnosis_ids"
## [21] "submitter_id" "submitter_portion_ids"
## [23] "submitter_sample_ids" "submitter_slide_ids"
## [25] "updated_datetime"
# set up query to use ALL available fields
# Note that checking of fields is done by select()
qcases = cases() %>% GenomicDataCommons::select(available_fields('cases'))
head(qcases$fields)
## [1] "case_id" "aliquot_ids"
## [3] "analyte_ids" "annotations.annotation_id"
## [5] "annotations.case_id" "annotations.case_submitter_id"
Finding fields of interest is such a common operation that the
GenomicDataCommons includes the grep_fields()
function.
See the appropriate help pages for details.
The GDC API offers a feature known as aggregation or faceting. By
specifying one or more fields (of appropriate type), the GDC can
return to us a count of the number of records matching each potential
value. This is similar to the R table
method. Multiple fields can be
returned at once, but the GDC API does not have a cross-tabulation
feature; all aggregations are only on one field at a time. Results of
aggregation()
calls come back as a list of data.frames (actually,
tibbles).
# total number of files of a specific type
res = files() %>% facet(c('type','data_type')) %>% aggregations()
res$type
Using aggregations()
is an also easy way to learn the contents of individual
fields and forms the basis for faceted search pages.
[ GDC filtering
documentation ]
The GenomicDataCommons package uses a form of non-standard evaluation to specify R-like queries that are then translated into an R list. That R list is, upon calling a method that fetches results from the GDC API, translated into the appropriate JSON string. The R expression uses the formula interface as suggested by Hadley Wickham in his vignette on non-standard evaluation
It’s best to use a formula because a formula captures both the expression to evaluate and the environment where the evaluation occurs. This is important if the expression is a mixture of variables in a data frame and objects in the local environment [for example].
For the user, these details will not be too important except to note that a filter expression must begin with a “~”.
qfiles = files()
qfiles %>% count() # all files
## [1] 931947
To limit the file type, we can refer back to the section on faceting to see the possible values for the file field “type”. For example, to filter file results to only “gene_expression” files, we simply specify a filter.
qfiles = files() %>% filter( type == 'gene_expression')
# here is what the filter looks like after translation
str(get_filter(qfiles))
## List of 2
## $ op : 'scalar' chr "="
## $ content:List of 2
## ..$ field: chr "type"
## ..$ value: chr "gene_expression"
What if we want to create a filter based on the project (‘TCGA-OVCA’, for example)? Well, we have a couple of possible ways to discover available fields. The first is based on base R functionality and some intuition.
grep('pro',available_fields('files'),value=TRUE) %>%
head()
## [1] "analysis.input_files.proc_internal"
## [2] "analysis.input_files.proportion_base_mismatch"
## [3] "analysis.input_files.proportion_coverage_10X"
## [4] "analysis.input_files.proportion_coverage_10x"
## [5] "analysis.input_files.proportion_coverage_30X"
## [6] "analysis.input_files.proportion_coverage_30x"
Interestingly, the project information is “nested” inside the case. We don’t need to know that detail other than to know that we now have a few potential guesses for where our information might be in the files records. We need to know where because we need to construct the appropriate filter.
files() %>%
facet('cases.project.project_id') %>%
aggregations() %>%
head()
## $cases.project.project_id
## doc_count key
## 1 54096 FM-AD
## 2 55451 TCGA-BRCA
## 3 64127 CPTAC-3
## 4 38305 TARGET-AML
## 5 29733 TCGA-LUAD
## 6 25870 TCGA-UCEC
## 7 26901 TCGA-HNSC
## 8 36470 GENIE-MSK
## 9 26698 TCGA-THCA
## 10 27463 TCGA-KIRC
## 11 25567 TCGA-OV
## 12 26689 TCGA-LUSC
## 13 25996 TCGA-LGG
## 14 25425 TCGA-PRAD
## 15 23571 TCGA-COAD
## 16 21096 TCGA-GBM
## 17 22846 TCGA-SKCM
## 18 22632 TCGA-STAD
## 19 28464 GENIE-DFCI
## 20 20712 TCGA-BLCA
## 21 27014 MMRF-COMMPASS
## 22 19037 TCGA-LIHC
## 23 17583 TARGET-ALL-P2
## 24 14982 TCGA-CESC
## 25 15011 TCGA-KIRP
## 26 12997 TCGA-SARC
## 27 14968 BEATAML1.0-COHORT
## 28 14859 HCMI-CMDC
## 29 9432 TCGA-ESCA
## 30 9125 TCGA-PAAD
## 31 8782 TCGA-PCPG
## 32 11553 REBC-THYR
## 33 8137 TCGA-READ
## 34 7499 TCGA-TGCT
## 35 8156 TCGA-LAML
## 36 9244 CPTAC-2
## 37 5705 TARGET-NBL
## 38 6000 TCGA-THYM
## 39 5304 CGCI-HTMCP-CC
## 40 3979 TCGA-KICH
## 41 4332 TCGA-ACC
## 42 4101 TCGA-MESO
## 43 5454 CMI-MBC
## 44 5286 NCICCR-DLBCL
## 45 3885 TCGA-UVM
## 46 2532 TARGET-WT
## 47 2972 TARGET-OS
## 48 3625 TARGET-ALL-P3
## 49 3857 GENIE-MDA
## 50 2829 TCGA-UCS
## 51 3833 GENIE-VICC
## 52 3320 GENIE-JHU
## 53 2305 TCGA-DLBC
## 54 2280 TCGA-CHOL
## 55 2632 GENIE-UHN
## 56 2139 CGCI-BLGSP
## 57 1826 EXCEPTIONAL_RESPONDERS-ER
## 58 1747 CDDP_EAGLE-1
## 59 1571 MP2PRT-WT
## 60 1455 APOLLO-LUAD
## 61 1036 TARGET-RT
## 62 1305 CMI-MPC
## 63 1093 WCDT-MCRPC
## 64 896 CGCI-HTMCP-LC
## 65 1038 GENIE-GRCC
## 66 878 OHSU-CNL
## 67 875 MATCH-Z1D
## 68 806 CMI-ASC
## 69 832 MATCH-Q
## 70 801 GENIE-NKI
## 71 775 MATCH-Y
## 72 758 ORGANOID-PANCREATIC
## 73 553 CTSP-DLBCL1
## 74 339 TRIO-CRU
## 75 222 BEATAML1.0-CRENOLANIB
## 76 163 TARGET-CCSK
## 77 96 TARGET-ALL-P1
## 78 21 VAREPOP-APOLLO
We note that cases.project.project_id
looks like it is a good fit. We also
note that TCGA-OV
is the correct project_id, not TCGA-OVCA
. Note that
unlike with dplyr and friends, the filter()
method here replaces the
filter and does not build on any previous filters.
qfiles = files() %>%
filter( cases.project.project_id == 'TCGA-OV' & type == 'gene_expression')
str(get_filter(qfiles))
## List of 2
## $ op : 'scalar' chr "and"
## $ content:List of 2
## ..$ :List of 2
## .. ..$ op : 'scalar' chr "="
## .. ..$ content:List of 2
## .. .. ..$ field: chr "cases.project.project_id"
## .. .. ..$ value: chr "TCGA-OV"
## ..$ :List of 2
## .. ..$ op : 'scalar' chr "="
## .. ..$ content:List of 2
## .. .. ..$ field: chr "type"
## .. .. ..$ value: chr "gene_expression"
qfiles %>% count()
## [1] 858
Asking for a count()
of results given these new filter criteria gives r qfiles %>% count()
results. Filters can be chained (or nested) to
accomplish the same effect as multiple &
conditionals. The count()
below is equivalent to the &
filtering done above.
qfiles2 = files() %>%
filter( cases.project.project_id == 'TCGA-OV') %>%
filter( type == 'gene_expression')
qfiles2 %>% count()
## [1] 858
(qfiles %>% count()) == (qfiles2 %>% count()) #TRUE
## [1] TRUE
Generating a manifest for bulk downloads is as simple as asking for the manifest from the current query.
manifest_df = qfiles %>% manifest()
head(manifest_df)
Note that we might still not be quite there. Looking at filenames, there are
suspiciously named files that might include “FPKM”, “FPKM-UQ”, or “counts”.
Another round of grep
and available_fields
, looking for “type” turned up
that the field “analysis.workflow_type” has the appropriate filter criteria.
qfiles = files() %>% filter( ~ cases.project.project_id == 'TCGA-OV' &
type == 'gene_expression' &
access == "open" &
analysis.workflow_type == 'STAR - Counts')
manifest_df = qfiles %>% manifest()
nrow(manifest_df)
## [1] 429
The GDC Data Transfer Tool can be used (from R, transfer()
or from the
command-line) to orchestrate high-performance, restartable transfers of all the
files in the manifest. See the bulk downloads section for
details.
[ GDC authentication documentation ]
The GDC offers both “controlled-access” and “open” data. As of this writing, only data stored as files is “controlled-access”; that is, metadata accessible via the GDC is all “open” data and some files are “open” and some are “controlled-access”. Controlled-access data are only available after going through the process of obtaining access.
After controlled-access to one or more datasets has been granted, logging into the GDC web portal will allow you to access a GDC authentication token, which can be downloaded and then used to access available controlled-access data via the GenomicDataCommons package.
The GenomicDataCommons uses authentication tokens only for downloading
data (see transfer
and gdcdata
documentation). The package
includes a helper function, gdc_token
, that looks for the token to
be stored in one of three ways (resolved in this order):
GDC_TOKEN
GDC_TOKEN_FILE
.gdc_token
As a concrete example:
token = gdc_token()
transfer(...,token=token)
# or
transfer(...,token=get_token())
The gdcdata
function takes a character vector of one or more file
ids. A simple way of producing such a vector is to produce a
manifest
data frame and then pass in the first column, which will
contain file ids.
fnames = gdcdata(manifest_df$id[1:2],progress=FALSE)
Note that for controlled-access data, a
GDC authentication token is required. Using the
BiocParallel
package may be useful for downloading in parallel,
particularly for large numbers of smallish files.
The bulk download functionality is only efficient (as of v1.2.0 of the GDC Data Transfer Tool) for relatively large files, so use this approach only when transferring BAM files or larger VCF files, for example. Otherwise, consider using the approach shown above, perhaps in parallel.
# Requires gcd_client command-line utility to be isntalled
# separately.
fnames = gdcdata(manifest_df$id[3:10], access_method = 'client')
res = cases() %>% facet("project.project_id") %>% aggregations()
head(res)
## $project.project_id
## doc_count key
## 1 18004 FM-AD
## 2 16824 GENIE-MSK
## 3 14232 GENIE-DFCI
## 4 3857 GENIE-MDA
## 5 3320 GENIE-JHU
## 6 2632 GENIE-UHN
## 7 2492 TARGET-AML
## 8 2052 GENIE-VICC
## 9 1587 TARGET-ALL-P2
## 10 1185 CPTAC-3
## 11 1132 TARGET-NBL
## 12 1098 TCGA-BRCA
## 13 1038 GENIE-GRCC
## 14 995 MMRF-COMMPASS
## 15 826 BEATAML1.0-COHORT
## 16 801 GENIE-NKI
## 17 652 TARGET-WT
## 18 617 TCGA-GBM
## 19 608 TCGA-OV
## 20 585 TCGA-LUAD
## 21 560 TCGA-UCEC
## 22 537 TCGA-KIRC
## 23 528 TCGA-HNSC
## 24 516 TCGA-LGG
## 25 507 TCGA-THCA
## 26 504 TCGA-LUSC
## 27 500 TCGA-PRAD
## 28 489 NCICCR-DLBCL
## 29 470 TCGA-SKCM
## 30 461 TCGA-COAD
## 31 443 TCGA-STAD
## 32 440 REBC-THYR
## 33 412 TCGA-BLCA
## 34 383 TARGET-OS
## 35 377 TCGA-LIHC
## 36 342 CPTAC-2
## 37 339 TRIO-CRU
## 38 307 TCGA-CESC
## 39 291 TCGA-KIRP
## 40 261 TCGA-SARC
## 41 228 HCMI-CMDC
## 42 212 CGCI-HTMCP-CC
## 43 200 CMI-MBC
## 44 200 TCGA-LAML
## 45 191 TARGET-ALL-P3
## 46 185 TCGA-ESCA
## 47 185 TCGA-PAAD
## 48 179 TCGA-PCPG
## 49 176 OHSU-CNL
## 50 172 TCGA-READ
## 51 150 TCGA-TGCT
## 52 124 TCGA-THYM
## 53 120 CGCI-BLGSP
## 54 113 TCGA-KICH
## 55 101 WCDT-MCRPC
## 56 92 TCGA-ACC
## 57 87 APOLLO-LUAD
## 58 87 TCGA-MESO
## 59 84 EXCEPTIONAL_RESPONDERS-ER
## 60 80 TCGA-UVM
## 61 70 ORGANOID-PANCREATIC
## 62 69 TARGET-RT
## 63 63 CMI-MPC
## 64 58 TCGA-DLBC
## 65 57 TCGA-UCS
## 66 56 BEATAML1.0-CRENOLANIB
## 67 52 MP2PRT-WT
## 68 51 TCGA-CHOL
## 69 50 CDDP_EAGLE-1
## 70 45 CTSP-DLBCL1
## 71 39 CGCI-HTMCP-LC
## 72 36 CMI-ASC
## 73 36 MATCH-Z1D
## 74 35 MATCH-Q
## 75 31 MATCH-Y
## 76 24 TARGET-ALL-P1
## 77 13 TARGET-CCSK
## 78 7 VAREPOP-APOLLO
library(ggplot2)
ggplot(res$project.project_id,aes(x = key, y = doc_count)) +
geom_bar(stat='identity') +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
cases() %>% filter(~ project.program.name=='TARGET') %>% count()
## [1] 6543
cases() %>% filter(~ project.program.name=='TCGA') %>% count()
## [1] 11315
# The need to do the "&" here is a requirement of the
# current version of the GDC API. I have filed a feature
# request to remove this requirement.
resp = cases() %>% filter(~ project.project_id=='TCGA-BRCA' &
project.project_id=='TCGA-BRCA' ) %>%
facet('samples.sample_type') %>% aggregations()
resp$samples.sample_type
# The need to do the "&" here is a requirement of the
# current version of the GDC API. I have filed a feature
# request to remove this requirement.
resp = cases() %>% filter(~ project.project_id=='TCGA-BRCA' &
samples.sample_type=='Solid Tissue Normal') %>%
GenomicDataCommons::select(c(default_fields(cases()),'samples.sample_type')) %>%
response_all()
count(resp)
## [1] 162
res = resp %>% results()
str(res[1],list.len=6)
## List of 1
## $ id: chr [1:162] "2680da86-c977-4611-b75f-df015283c023" "74f31744-0aed-4633-beec-4e203315f0b7" "ecab16bc-28d5-4c3a-8735-3c785bd047c4" "2a84997d-ccee-4f46-bea2-752534f26416" ...
head(ids(resp))
## [1] "2680da86-c977-4611-b75f-df015283c023"
## [2] "74f31744-0aed-4633-beec-4e203315f0b7"
## [3] "ecab16bc-28d5-4c3a-8735-3c785bd047c4"
## [4] "2a84997d-ccee-4f46-bea2-752534f26416"
## [5] "2b22db1d-54a1-4b9e-a86e-a174cf51d95c"
## [6] "ef4cbd38-bc79-4d60-a715-647edd2ebe9e"
cases() %>%
GenomicDataCommons::filter(~ project.program.name == 'TCGA' &
"cases.demographic.gender" %in% "female") %>%
GenomicDataCommons::results(size = 4) %>%
ids()
## [1] "24e39609-9645-43e5-960b-db5446eaea65"
## [2] "e9a12df9-024e-4cbc-b6bf-e4e87485fa90"
## [3] "e9f4f373-37a5-48ad-a1a0-b0d47820111a"
## [4] "739cb132-51e9-41be-8064-311a13da0d74"
cases() %>%
GenomicDataCommons::filter(~ project.project_id == 'TCGA-COAD' &
"cases.demographic.gender" %exclude% "female") %>%
GenomicDataCommons::results(size = 4) %>%
ids()
## [1] "01ad5016-f691-4bca-82a0-910429d8d25b"
## [2] "022f39e9-57ee-4b2b-8b3a-8929e3d69a37"
## [3] "03efbc94-a43d-4db0-9377-e397348430a6"
## [4] "04d7a52f-a89b-4114-a608-a6254b4d604f"
cases() %>%
GenomicDataCommons::filter(~ project.program.name == 'TCGA' &
missing("cases.demographic.gender")) %>%
GenomicDataCommons::results(size = 4) %>%
ids()
## [1] "f1d74175-f501-4a35-863b-fbaa385a8662"
## [2] "f8360744-6bc8-4f53-b1fc-a133789455a8"
## [3] "09621bd6-3eed-4af4-8416-cdacffce68d9"
## [4] "0b0a54ac-bb74-40a4-b647-d067fb9de1ff"
cases() %>%
GenomicDataCommons::filter(~ project.program.name == 'TCGA' &
!missing("cases.demographic.gender")) %>%
GenomicDataCommons::results(size = 4) %>%
ids()
## [1] "24e39609-9645-43e5-960b-db5446eaea65"
## [2] "e9a12df9-024e-4cbc-b6bf-e4e87485fa90"
## [3] "e9f4f373-37a5-48ad-a1a0-b0d47820111a"
## [4] "739cb132-51e9-41be-8064-311a13da0d74"
res = files() %>% facet('type') %>% aggregations()
res$type
ggplot(res$type,aes(x = key,y = doc_count)) + geom_bar(stat='identity') +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
q = files() %>%
GenomicDataCommons::select(available_fields('files')) %>%
filter(~ cases.project.project_id=='TCGA-GBM' &
data_type=='Gene Expression Quantification')
q %>% facet('analysis.workflow_type') %>% aggregations()
## list()
# so need to add another filter
file_ids = q %>% filter(~ cases.project.project_id=='TCGA-GBM' &
data_type=='Gene Expression Quantification' &
analysis.workflow_type == 'STAR - Counts') %>%
GenomicDataCommons::select('file_id') %>%
response_all() %>%
ids()
I need to figure out how to do slicing reproducibly in a testing environment and for vignette building.
q = files() %>%
GenomicDataCommons::select(available_fields('files')) %>%
filter(~ cases.project.project_id == 'TCGA-GBM' &
data_type == 'Aligned Reads' &
experimental_strategy == 'RNA-Seq' &
data_format == 'BAM')
file_ids = q %>% response_all() %>% ids()
bamfile = slicing(file_ids[1],regions="chr12:6534405-6538375",token=gdc_token())
library(GenomicAlignments)
aligns = readGAlignments(bamfile)
Error in curl::curl_fetch_memory(url, handle = handle) :
SSL connect error
openssl
to version
1.0.1 or later.
openssl
, reinstall the R curl
and httr
packages.sessionInfo()
## R version 4.2.3 (2023-03-15)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.6 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] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggplot2_3.4.2 GenomicDataCommons_1.22.3
## [3] magrittr_2.0.3 knitr_1.42
## [5] BiocStyle_2.26.0
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.0 xfun_0.38 bslib_0.4.2
## [4] colorspace_2.1-0 vctrs_0.6.1 generics_0.1.3
## [7] htmltools_0.5.5 stats4_4.2.3 yaml_2.3.7
## [10] utf8_1.2.3 rlang_1.1.0 jquerylib_0.1.4
## [13] pillar_1.9.0 glue_1.6.2 withr_2.5.0
## [16] rappdirs_0.3.3 BiocGenerics_0.44.0 GenomeInfoDbData_1.2.9
## [19] lifecycle_1.0.3 zlibbioc_1.44.0 munsell_0.5.0
## [22] gtable_0.3.3 evaluate_0.20 labeling_0.4.2
## [25] tzdb_0.3.0 IRanges_2.32.0 fastmap_1.1.1
## [28] GenomeInfoDb_1.34.9 curl_5.0.0 fansi_1.0.4
## [31] highr_0.10 Rcpp_1.0.10 readr_2.1.4
## [34] scales_1.2.1 BiocManager_1.30.20 cachem_1.0.7
## [37] S4Vectors_0.36.2 magick_2.7.4 jsonlite_1.8.4
## [40] XVector_0.38.0 farver_2.1.1 hms_1.1.3
## [43] digest_0.6.31 bookdown_0.33 dplyr_1.1.1
## [46] GenomicRanges_1.50.2 grid_4.2.3 cli_3.6.1
## [49] tools_4.2.3 bitops_1.0-7 sass_0.4.5
## [52] RCurl_1.98-1.12 tibble_3.2.1 crayon_1.5.2
## [55] pkgconfig_2.0.3 xml2_1.3.3 rmarkdown_2.21
## [58] httr_1.4.5 R6_2.5.1 compiler_4.2.3
S3
object-oriented programming paradigm is used.