From 2c73e8ebf836769e9ea68c84b39156a76832333a Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Mon, 3 Mar 2025 10:00:41 -0500 Subject: [PATCH 01/11] Add files via upload --- R/target_cn.R | 21 +++++++++++++++++++++ R/target_methylation.R | 21 +++++++++++++++++++++ R/target_methylation_1.R | 17 +++++++++++++++++ R/tcga_proteome.R | 29 +++++++++++++++++++++++++++++ R/tcga_slides.R | 25 +++++++++++++++++++++++++ R/tcga_slides_1.R | 27 +++++++++++++++++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 R/target_cn.R create mode 100644 R/target_methylation.R create mode 100644 R/target_methylation_1.R create mode 100644 R/tcga_proteome.R create mode 100644 R/tcga_slides.R create mode 100644 R/tcga_slides_1.R diff --git a/R/target_cn.R b/R/target_cn.R new file mode 100644 index 0000000..547a681 --- /dev/null +++ b/R/target_cn.R @@ -0,0 +1,21 @@ +library(GenomicDataCommons) +library(dplyr) +library(tibble) +#Clear Cell Sarcoma of the Kidney. Disease Type. Complex Mixed and Stromal Neoplasms. Primary Site. Kidney. Program. TARGET + + +cn_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( analysis.workflow_type == 'ASCAT2') |> manifest() +n<-which(cn_manifest_CCSK$access=='open') + +#save dat to file +write.csv(cn_manifest_CCSK[n,],file='out.txt',quote=FALSE,row.names=FALSE) +##########----------####################### +#select files +for( i in seq(1,length(n))) +{ +# +id<-0; + id<-as.character(cn_manifest_CCSK[n[i],1]) +###### +gdcdata(id) +} diff --git a/R/target_methylation.R b/R/target_methylation.R new file mode 100644 index 0000000..1f54692 --- /dev/null +++ b/R/target_methylation.R @@ -0,0 +1,21 @@ +library(GenomicDataCommons) +library(dplyr) +library(tibble) +#Clear Cell Sarcoma of the Kidney. Disease Type. Complex Mixed and Stromal Neoplasms. Primary Site. Kidney. Program. TARGET + +#get familiar with aggregations +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TARGET-CCSK') |> facet(c("data_type","data_format","analysis.workflow_type","file_id","file_name")) |> aggregations() + + + +q_1 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TARGET-CCSK') |> facet(c("data_type","data_format","analysis.workflow_type")) |> aggregations() + +idat_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( data_type == 'Methylation Beta Value' ) |> GenomicDataCommons::filter( analysis.workflow_type == 'SeSAMe Methylation Beta Estimation') |> manifest() +n<-which(idat_manifest_CCSK$access=='open') + +#save data to file +write.csv(idat_manifest_CCSK[n,],file='manifest.txt',quote=FALSE,row.names=FALSE) + + +###### test single file +gdcdata(idat_manifest_CCSK[n[1],1])) diff --git a/R/target_methylation_1.R b/R/target_methylation_1.R new file mode 100644 index 0000000..2c091c4 --- /dev/null +++ b/R/target_methylation_1.R @@ -0,0 +1,17 @@ +library(GenomicDataCommons) +library(dplyr) +library(tibble) + + +idat_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( data_type == 'Methylation Beta Value' ) |> GenomicDataCommons::filter( analysis.workflow_type == 'SeSAMe Methylation Beta Estimation') |> manifest() +n<-which(idat_manifest_CCSK$access=='open') + +##########----------####################### +for( i in seq(1,length(n))) +{ +#use cast +id<-0; + id<-as.character(idat_manifest_CCSK[n[i],1]) +######only test with single file +gdcdata(id) +} diff --git a/R/tcga_proteome.R b/R/tcga_proteome.R new file mode 100644 index 0000000..d4dd688 --- /dev/null +++ b/R/tcga_proteome.R @@ -0,0 +1,29 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +p_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_type == 'Protein Expression Quantification' & data_format == 'tsv') |> manifest() +#locate open data +open_access<-which(p_2$access=="open") +#381 files +#download select files +#for(i in length(open_access)) +#for(i in seq(3,5)) +#for(i in seq(20,24)) + +for(i in seq(200,202)) +{ +uid<-0;uid<-as.character(p_2[open_access[i],1]) +gdcdata(uid) +} + +#sanity check , use the filter function + + +p_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_type == 'Protein Expression Quantification' & data_format == 'tsv') |> filter(access == 'open') |> manifest() + +for(i in seq(20,24)) +{ +uid<-0;uid<-as.character(p_3[i,1]) +gdcdata(uid) +} diff --git a/R/tcga_slides.R b/R/tcga_slides.R new file mode 100644 index 0000000..f260f3d --- /dev/null +++ b/R/tcga_slides.R @@ -0,0 +1,25 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +#specify project name +#q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-KIRC' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-BRCA' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() +#locate open data +open_access<-which(q_2$access=="open") + +#select files +#for(i in length(open_access)) +#for(i in seq(3,5)) +#for(i in seq(20,24)) +for(i in seq(200,202)) +{ +uid<-0;uid<-as.character(q_2[open_access[i],1]) +gdcdata(uid) +} + + +######alternatively, use filter +#both approaches should list same files +q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-BRCA' & data_type == 'Slide Image' & data_format == 'svs') |> filter(access == 'open') |> manifest() + diff --git a/R/tcga_slides_1.R b/R/tcga_slides_1.R new file mode 100644 index 0000000..057547b --- /dev/null +++ b/R/tcga_slides_1.R @@ -0,0 +1,27 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-COAD' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() +#locate open data +open_access<-which(q_2$access=="open") + +#for(i in length(open_access)) +#for(i in seq(3,5)) +#for(i in seq(20,24)) +for(i in seq(200,202)) +{ +uid<-0;uid<-as.character(q_2[open_access[i],1]) +gdcdata(uid) +} + + +#or sanity check + +q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-COAD' & data_type == 'Slide Image' & data_format == 'svs') |> filter(access == 'open') |> manifest() + +for(i in seq(2,4)) +{ +uid<-0;uid<-as.character(q_3[i,1]) +gdcdata(uid) +} From 7e08ba780bc2fd29e5788f7e4edae57236478add Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Mon, 3 Mar 2025 10:11:50 -0500 Subject: [PATCH 02/11] Add files via upload --- vignettes/overviewGenomicDataCommons.Rmd | 811 +++++++++++++++++++++++ vignettes/questions-and-answers.Rmd | 6 +- vignettes/somatic_mutations.Rmd | 10 +- 3 files changed, 819 insertions(+), 8 deletions(-) create mode 100644 vignettes/overviewGenomicDataCommons.Rmd diff --git a/vignettes/overviewGenomicDataCommons.Rmd b/vignettes/overviewGenomicDataCommons.Rmd new file mode 100644 index 0000000..4269cda --- /dev/null +++ b/vignettes/overviewGenomicDataCommons.Rmd @@ -0,0 +1,811 @@ +--- +title: "The GenomicDataCommons Package" +author: "Sean Davis & Martin Morgan" +date: "`r format(Sys.Date(), '%A, %B %d, %Y')`" +always_allow_html: yes +output: + BiocStyle::html_document: + df_print: paged + toc_float: true +abstract: > + The National Cancer Institute (NCI) has established + the [Genomic Data Commons](https://gdc.nci.nih.gov/) (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. + +vignette: > + %\VignetteIndexEntry{Introduction to Accessing the NCI Genomic Data Commons} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r init, results='hide', echo=FALSE, warning=FALSE, message=FALSE} +library(knitr) +opts_chunk$set(warning=FALSE, message=FALSE) +BiocStyle::markdown() +``` + + +# What is the GDC? + +From the [Genomic Data Commons (GDC) website](https://gdc.cancer.gov/about-gdc): + +> 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](https://gdc.cancer.gov/developers/gdc-data-model/gdc-data-model-components), +but it worth a quick overview and a graphical representation is included here. + +![The data model is encoded as a +so-called property graph. Nodes represent entities such as Projects, +Cases, Diagnoses, Files (various kinds), and Annotations. The +relationships between these entities are maintained as edges. Both +nodes and edges may have Properties that supply instance details. ](all_nodes_040318.png) + + The +GDC API exposes these nodes and edges in a somewhat simplified set +of +[RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer) endpoints. + +# Quickstart + +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](https://github.com/Bioconductor/GenomicDataCommons/issues) +or submit a `bug.report(package='GenomicDataCommons')` from within R (which +will redirect you to the new issue on GitHub). + +## Installation + +Installation can be achieved via Bioconductor's `BiocManager` package. + +```{r install_bioc, eval=FALSE} +if (!require("BiocManager")) + install.packages("BiocManager") +BiocManager::install('GenomicDataCommons') +``` + +```{r libraries, message=FALSE} +library(GenomicDataCommons) +``` + +## Check connectivity and status + +The `r Biocpkg("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. + +```{r statusQS} +GenomicDataCommons::status() +``` + +And to check the status in code: + +```{r statusCheck} +stopifnot(GenomicDataCommons::status()$status=="OK") +``` + + +## Find data +Please use a fresh R session to minimise package conflicts arising from identical function names. +For example the functions filter(), results() are available with R packages dplyr, GenomicDataCommons . Instead consider using the R package conflicted. +Example usage +conflicts_prefer(dplyr::filter()) +conflicts_prefer(GenomicDataCommons::filter) +conflicts_prefer(stats :: filter) + +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. + +```{r manifest} +ge_manifest <- files() |> + filter( cases.project.project_id == 'TCGA-OV') |> + filter( type == 'gene_expression' ) |> + filter( analysis.workflow_type == 'STAR - Counts') |> + manifest() +head(ge_manifest) +``` + +## Download data + +After the `r nrow(ge_manifest)` 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. + +```{r downloadQS, eval=FALSE} +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](#authentication). + +## Metadata queries + +### Clinical data + +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. + +- demographic +- diagnoses +- exposures +- main + +```{r gdc_clinical} +case_ids <- cases() |> results(size=10) |> ids() +clindat <- gdc_clinical(case_ids) +names(clindat) +``` + +```{r clinData} +head(clindat[["main"]]) +head(clindat[["diagnoses"]]) +``` + +### General metadata queries + +The `r Biocpkg("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 `r Biocpkg("GenomicDataCommons")` package +make much flexibility if fine-tuning is required. + +```{r metadataQS} +expands <- c("diagnoses","annotations", + "demographic","exposures") +clinResults <- cases() |> + GenomicDataCommons::select(NULL) |> + GenomicDataCommons::expand(expands) |> + results(size=50) +str(clinResults[[1]],list.len=6) +# or listviewer::jsonedit(clinResults) +``` + +# Basic design + +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: + +1. Simple query constructors based on GDC API endpoints. +2. A set of verbs that when applied, adjust filtering, field selection, and +faceting (fields for aggregation) and result in a new query object (an +endomorphism) +3. A set of verbs that take a query and return results from the GDC + +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 functionality[^1]. + + +- Creating a query + - `projects()` + - `cases()` + - `files()` + - `annotations()` +- Manipulating a query + - `filter()` + - `facet()` + - `select()` +- Introspection on the GDC API fields + - `mapping()` + - `available_fields()` + - `default_fields()` + - `grep_fields()` + - `available_values()` + - `available_expand()` +- Executing an API call to retrieve query results + - `results()` + - `count()` + - `response()` +- Raw data file downloads + - `gdcdata()` + - `transfer()` + - `gdc_client()` +- Summarizing and aggregating field values (faceting) + - `aggregations()` +- Authentication + - `gdc_token()` +- BAM file slicing + - `slicing()` + +[^1]: See individual function and methods documentation for specific details. + + +# Usage + +There are two main classes of operations when working with the NCI GDC. + +1. [Querying metadata and finding data files](#querying-metadata) (e.g., finding +all gene expression quantifications data files for all colon cancer patients). +2. [Transferring raw or processed data](#datafile-access-and-download) from the +GDC to another computer (e.g., downloading raw or processed data) + +Both classes of operation are reviewed in detail in the following sections. + +## Querying metadata + +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](#creating-a-query). One +will often then want to [`filter`](#filtering) the query to limit results prior +to [retrieving results](#retrieving-results). The GenomicDataCommons package has +[helper functions for listing fields](#fields-and-values) that are available for +filtering. + +In addition to fetching results, the GDC API allows +[faceting, or aggregating,](#facets-and-aggregation), useful for compiling +reports, generating dashboards, or building user interfaces to GDC data (see GDC +web query interface for a non-R-based example). + +### Creating a query + +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()` + +```{r projectquery} +pquery <- projects() +``` + +The `pquery` object is now an object of (S3) class, `GDCQuery` (and +`gdc_projects` and `list`). The object contains the following elements: + +- fields: This is a character vector of the fields that will be returned when we +[retrieve data](#retrieving-results). If no fields are specified to, for +example, the `projects()` function, the default fields from the GDC are used +(see `default_fields()`) +- filters: This will contain results after calling the +[`filter()` method](#filtering) and will be used to filter results on +[retrieval](#retrieving-results). +- facets: A character vector of field names that will be used for +[aggregating data](#facets-and-aggregation) in a call to `aggregations()`. +- token: A character(1) token from the GDC. See +[the authentication section](#authentication) for details, but note that, in +general, the token is not necessary for metadata query and retrieval, only for +actual data download. + +Looking at the actual object (get used to using `str()`!), note that the query +contains no results. + +```{r pquery} +str(pquery) +``` +### Retrieving results + +[[ GDC pagination documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#size-and-from) + +[[ GDC sorting documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#sort) + +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" + +```{r pquerycount} +pcount <- count(pquery) +# or +pcount <- pquery |> count() +pcount +``` + +The `results()` method will fetch actual results. + +```{r pqueryresults} +presults <- pquery |> results() +``` +These results are +returned from the GDC in [JSON](http://www.json.org/) format and +converted into a (potentially nested) list in R. The `str()` method is useful +for taking a quick glimpse of the data. + +```{r presultsstr} +str(presults) +``` + +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()` + +```{r presultsall} +length(ids(presults)) +presults <- pquery |> results_all() +length(ids(presults)) +# includes all records +length(ids(presults)) == count(pquery) +``` + +Extracting subsets of +results or manipulating the results into a more conventional R data +structure is not easily generalizable. However, +the +[purrr](https://github.com/hadley/purrr), +[rlist](https://renkun.me/rlist/), +and [data.tree](https://cran.r-project.org/web/packages/data.tree/vignettes/data.tree.html) packages +are all potentially of interest for manipulating complex, nested list +structures. For viewing the results in an interactive viewer, consider the +[listviewer](https://github.com/timelyportfolio/listviewer) package. + + +### Fields and Values + +[[ GDC `fields` documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#fields) + +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. + +```{r defaultfields} +default_fields('files') +# The number of fields available for files endpoint +length(available_fields('files')) +# The first few fields available for files endpoint +head(available_fields('files')) +``` + +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`. + +```{r selectexample} +# Default fields here +qcases <- cases() +qcases$fields +# 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) +``` + +Finding fields of interest is such a common operation that the +GenomicDataCommons includes the `grep_fields()` function. +See the appropriate help pages for details. + +### Facets and aggregation + +[[ GDC `facet` documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#facets) + +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). + +```{r aggexample} +# 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. + +### Filtering + +[[ GDC `filtering` documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#filters-specifying-the-query) + +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](https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html) + +> 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 "~". + +```{r allfilesunfiltered} +qfiles <- files() +qfiles |> count() # all files +``` +To limit the file type, we can refer back to the +[section on faceting](#facets-and-aggregation) 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. + +```{r onlyGeneExpression} +qfiles <- files() |> filter( type == 'gene_expression') +# here is what the filter looks like after translation +str(get_filter(qfiles)) +``` + +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. + +```{r filtAvailFields} +grep('pro',available_fields('files'),value=TRUE) |> + head() +``` + +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. + +```{r filtProgramID} +files() |> + facet('cases.project.project_id') |> + aggregations() |> + head() +``` + +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*. + +```{r filtfinal} +qfiles <- files() |> + filter( cases.project.project_id == 'TCGA-OV' & type == 'gene_expression') +str(get_filter(qfiles)) +qfiles |> count() +``` + +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. + +```{r filtChain} +qfiles2 <- files() |> + filter( cases.project.project_id == 'TCGA-OV') |> + filter( type == 'gene_expression') +qfiles2 |> count() +(qfiles |> count()) == (qfiles2 |> count()) #TRUE +``` + + + +Generating a manifest for bulk downloads is as +simple as asking for the manifest from the current query. + +```{r filtAndManifest} +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. + + +```{r filterForSTARCounts} +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) +``` + +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](bulk-downloads) for +details. + + +## Authentication + +[[ GDC authentication documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#facets) + +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.](https://gdc.cancer.gov/access-data/obtaining-access-controlled-data) + +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](https://docs.gdc.cancer.gov/Data_Portal/Users_Guide/Authentication/#gdc-authentication-tokens), +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): + +1. As a string stored in the environment variable, `GDC_TOKEN` +2. As a file, stored in the file named by the environment variable, + `GDC_TOKEN_FILE` +3. In a file in the user home directory, called `.gdc_token` + +As a concrete example: + +```{r authenNoRun, eval=FALSE} +token <- gdc_token() +transfer(...,token=token) +# or +transfer(...,token=get_token()) +``` + + +## Datafile access and download + +### Data downloads via the GDC API + +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. + +```{r singlefileDL} +fnames <- gdcdata(manifest_df$id[1:2],progress=FALSE) + +``` + +Note that for controlled-access data, a +GDC [authentication token](#authentication) is required. Using the +`BiocParallel` package may be useful for downloading in parallel, +particularly for large numbers of smallish files. + +### Bulk downloads + +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. + +```{r bulkDL, eval=FALSE} +# Requires gcd_client command-line utility to be isntalled +# separately. +fnames <- gdcdata(manifest_df$id[3:10], access_method = 'client') +``` + + +### BAM slicing + +# Use Cases + +## Cases + +### How many cases are there per project_id? + +```{r casesPerProject} +res <- cases() |> facet("project.project_id") |> aggregations() +head(res) +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)) +``` + +### How many cases are included in all TARGET projects? + +```{r casesInTCGA} +cases() |> filter(~ project.program.name=='TARGET') |> count() +``` + +### How many cases are included in all TCGA projects? + +```{r casesInTARGET} +cases() |> filter(~ project.program.name=='TCGA') |> count() +``` + +### What is the breakdown of sample types in TCGA-BRCA? + +```{r casesTCGABRCASampleTypes} +# 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 +``` + +### Fetch all samples in TCGA-BRCA that use "Solid Tissue" as a normal. + +```{r casesTCGABRCASolidNormal} +# 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) +res <- resp |> results() +str(res[1],list.len=6) +head(ids(resp)) +``` + +### Get all TCGA case ids that are female + +```{r casesFemaleTCGA} +cases() |> + GenomicDataCommons::filter(~ project.program.name == 'TCGA' & + "cases.demographic.gender" %in% "female") |> + GenomicDataCommons::results(size = 4) |> + ids() +``` + +### Get all TCGA-COAD case ids that are NOT female + +```{r notFemaleTCGACOAD} +cases() |> + GenomicDataCommons::filter(~ project.project_id == 'TCGA-COAD' & + "cases.demographic.gender" %exclude% "female") |> + GenomicDataCommons::results(size = 4) |> + ids() +``` + +### Get all TCGA cases that are missing gender + +```{r missingGenderTCGA} +cases() |> + GenomicDataCommons::filter(~ project.program.name == 'TCGA' & + missing("cases.demographic.gender")) |> + GenomicDataCommons::results(size = 4) |> + ids() +``` + +### Get all TCGA cases that are NOT missing gender + +```{r notMissingGenderTCGA} +cases() |> + GenomicDataCommons::filter(~ project.program.name == 'TCGA' & + !missing("cases.demographic.gender")) |> + GenomicDataCommons::results(size = 4) |> + ids() +``` + + +## Files + +### How many of each type of file are available? + +```{r filesVCFCount} +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)) +``` + +### Find gene-level RNA-seq quantification files for GBM + +```{r filesRNAseqGeneGBM} +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() +# 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() +``` + +## Slicing + +### Get all BAM file ids from TCGA-GBM + +**I need to figure out how to do slicing reproducibly in a testing environment +and for vignette building**. + +```{r filesRNAseqGeneGBMforBAM} +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() +``` + + +```{r slicing10, eval=FALSE} +bamfile <- slicing(file_ids[1],regions="chr12:6534405-6538375",token=gdc_token()) +library(GenomicAlignments) +aligns <- readGAlignments(bamfile) +``` + +# Troubleshooting + +## SSL connection errors + +* Symptom: Trying to connect to the API results in: +``` +Error in curl::curl_fetch_memory(url, handle = handle) : +SSL connect error +``` +* Possible solutions: The [issue +is that the GDC supports only recent security Transport Layer Security (TLS)](http://stackoverflow.com/a/42599546/459633), +so the only known fix is to upgrade the system `openssl` to version +1.0.1 or later. + * [[Mac OS]](https://github.com/Bioconductor/GenomicDataCommons/issues/35#issuecomment-284233510), + * [[Ubuntu]](http://askubuntu.com/a/434245) + * [[Centos/RHEL]](https://www.liquidweb.com/kb/update-and-patch-openssl-for-the-ccs-injection-vulnerability/). + After upgrading `openssl`, reinstall the R `curl` and `httr` packages. + + +# sessionInfo() + +```{r sessionInfo} +sessionInfo() +``` + +# Developer notes + +- The `S3` object-oriented programming paradigm is used. +- We have adopted a functional programming style with functions and methods that +often take an "object" as the first argument. This style lends itself to +pipeline-style programming. +- The GenomicDataCommons package uses the +[alternative request format (POST)](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#alternative-request-format) +to allow very large request bodies. + diff --git a/vignettes/questions-and-answers.Rmd b/vignettes/questions-and-answers.Rmd index 67fcf74..d8649d6 100644 --- a/vignettes/questions-and-answers.Rmd +++ b/vignettes/questions-and-answers.Rmd @@ -29,7 +29,7 @@ changes to lazy evaluation best practices. There is now no need to include the `~` in the filter expression. So: ```{r} -q = files() |> +q <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TCGA-COAD' & data_type == 'Aligned Reads' & @@ -51,7 +51,7 @@ manifest(q) Your question about race and ethnicity is a good one. ```{r} -all_fields = available_fields(files()) +all_fields <- available_fields(files()) ``` And we can grep for `race` or `ethnic` to get potential matching fields @@ -72,7 +72,7 @@ available_values('files',"cases.demographic.race") We can complete our filter expression now to limit to `white` race only. ```{r} -q_white_only = q |> +q_white_only <- q |> GenomicDataCommons::filter(cases.demographic.race=='white') count(q_white_only) manifest(q_white_only) diff --git a/vignettes/somatic_mutations.Rmd b/vignettes/somatic_mutations.Rmd index 4268c16..1c6c975 100644 --- a/vignettes/somatic_mutations.Rmd +++ b/vignettes/somatic_mutations.Rmd @@ -38,7 +38,7 @@ head(available_values('genes','symbol')) ```{r} -tp53 = genes() |> +tp53 <- genes() |> GenomicDataCommons::filter(symbol=='TP53') |> results(size=10000) |> as_tibble() @@ -67,7 +67,7 @@ ssms() |> ```{r warning=FALSE,message=FALSE} library(VariantAnnotation) -vars = ssms() |> +vars <- ssms() |> GenomicDataCommons::filter( consequence.transcript.gene.symbol %in% c('TP53')) |> GenomicDataCommons::results_all() |> @@ -75,7 +75,7 @@ vars = ssms() |> ``` ```{r} -vr = VRanges(seqnames = vars$chromosome, +vr <- VRanges(seqnames = vars$chromosome, ranges = IRanges(start=vars$start_position, width=1), ref = vars$reference_allele, alt = vars$tumor_allele) @@ -89,7 +89,7 @@ ssm_occurrences() |> ``` ```{r} -var_samples = ssm_occurrences() |> +var_samples <- ssm_occurrences() |> GenomicDataCommons::filter( ssm.consequence.transcript.gene.symbol %in% c('TP53')) |> GenomicDataCommons::expand(c('case', 'ssm', 'case.project')) |> @@ -119,7 +119,7 @@ fnames <- files() |> ```{r cache=TRUE} library(maftools) -melanoma = read.maf(maf = fnames) +melanoma <- read.maf(maf = fnames) ``` ```{r} From d44262888bd66273b78acb3ebbb6ab7c06a77a2b Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Mon, 3 Mar 2025 10:34:13 -0500 Subject: [PATCH 03/11] Add files via upload --- R/tcga_CEL.R | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 R/tcga_CEL.R diff --git a/R/tcga_CEL.R b/R/tcga_CEL.R new file mode 100644 index 0000000..5cceb52 --- /dev/null +++ b/R/tcga_CEL.R @@ -0,0 +1,28 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +# + +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-GBM' & data_category == 'Transcriptome Profiling' & data_format == 'CEL') |> manifest() +#OR use filter fn +q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-GBM' & data_category == 'Transcriptome Profiling' & data_format == 'CEL') |> GenomicDataCommons::filter(access=='OPEN') |> manifest() + +for(i in seq(10,12)) +{ +uid<-0; +uid<-as.character(q_3[i,1]) +gdcdata(uid) +} + + +# +n<-which(q_2["access"] == 'open') +for(j in seq(2,3)) +{ +Id<-0 +Id<-as.character(q_3[n[j],1]) +gdcdata(Id) +} + + From 18e31be38e73048f2500b4cf7c7e3c97b3a66a81 Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Mon, 3 Mar 2025 11:24:45 -0500 Subject: [PATCH 04/11] Add files via upload --- vignettes/target_cn.R | 21 +++++++++++++++++++++ vignettes/target_methylation.R | 21 +++++++++++++++++++++ vignettes/target_methylation_1.R | 17 +++++++++++++++++ vignettes/tcga_CEL.R | 28 ++++++++++++++++++++++++++++ vignettes/tcga_proteome.R | 29 +++++++++++++++++++++++++++++ vignettes/tcga_slides.R | 25 +++++++++++++++++++++++++ vignettes/tcga_slides_1.R | 27 +++++++++++++++++++++++++++ 7 files changed, 168 insertions(+) create mode 100644 vignettes/target_cn.R create mode 100644 vignettes/target_methylation.R create mode 100644 vignettes/target_methylation_1.R create mode 100644 vignettes/tcga_CEL.R create mode 100644 vignettes/tcga_proteome.R create mode 100644 vignettes/tcga_slides.R create mode 100644 vignettes/tcga_slides_1.R diff --git a/vignettes/target_cn.R b/vignettes/target_cn.R new file mode 100644 index 0000000..547a681 --- /dev/null +++ b/vignettes/target_cn.R @@ -0,0 +1,21 @@ +library(GenomicDataCommons) +library(dplyr) +library(tibble) +#Clear Cell Sarcoma of the Kidney. Disease Type. Complex Mixed and Stromal Neoplasms. Primary Site. Kidney. Program. TARGET + + +cn_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( analysis.workflow_type == 'ASCAT2') |> manifest() +n<-which(cn_manifest_CCSK$access=='open') + +#save dat to file +write.csv(cn_manifest_CCSK[n,],file='out.txt',quote=FALSE,row.names=FALSE) +##########----------####################### +#select files +for( i in seq(1,length(n))) +{ +# +id<-0; + id<-as.character(cn_manifest_CCSK[n[i],1]) +###### +gdcdata(id) +} diff --git a/vignettes/target_methylation.R b/vignettes/target_methylation.R new file mode 100644 index 0000000..1f54692 --- /dev/null +++ b/vignettes/target_methylation.R @@ -0,0 +1,21 @@ +library(GenomicDataCommons) +library(dplyr) +library(tibble) +#Clear Cell Sarcoma of the Kidney. Disease Type. Complex Mixed and Stromal Neoplasms. Primary Site. Kidney. Program. TARGET + +#get familiar with aggregations +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TARGET-CCSK') |> facet(c("data_type","data_format","analysis.workflow_type","file_id","file_name")) |> aggregations() + + + +q_1 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TARGET-CCSK') |> facet(c("data_type","data_format","analysis.workflow_type")) |> aggregations() + +idat_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( data_type == 'Methylation Beta Value' ) |> GenomicDataCommons::filter( analysis.workflow_type == 'SeSAMe Methylation Beta Estimation') |> manifest() +n<-which(idat_manifest_CCSK$access=='open') + +#save data to file +write.csv(idat_manifest_CCSK[n,],file='manifest.txt',quote=FALSE,row.names=FALSE) + + +###### test single file +gdcdata(idat_manifest_CCSK[n[1],1])) diff --git a/vignettes/target_methylation_1.R b/vignettes/target_methylation_1.R new file mode 100644 index 0000000..2c091c4 --- /dev/null +++ b/vignettes/target_methylation_1.R @@ -0,0 +1,17 @@ +library(GenomicDataCommons) +library(dplyr) +library(tibble) + + +idat_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( data_type == 'Methylation Beta Value' ) |> GenomicDataCommons::filter( analysis.workflow_type == 'SeSAMe Methylation Beta Estimation') |> manifest() +n<-which(idat_manifest_CCSK$access=='open') + +##########----------####################### +for( i in seq(1,length(n))) +{ +#use cast +id<-0; + id<-as.character(idat_manifest_CCSK[n[i],1]) +######only test with single file +gdcdata(id) +} diff --git a/vignettes/tcga_CEL.R b/vignettes/tcga_CEL.R new file mode 100644 index 0000000..5cceb52 --- /dev/null +++ b/vignettes/tcga_CEL.R @@ -0,0 +1,28 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +# + +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-GBM' & data_category == 'Transcriptome Profiling' & data_format == 'CEL') |> manifest() +#OR use filter fn +q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-GBM' & data_category == 'Transcriptome Profiling' & data_format == 'CEL') |> GenomicDataCommons::filter(access=='OPEN') |> manifest() + +for(i in seq(10,12)) +{ +uid<-0; +uid<-as.character(q_3[i,1]) +gdcdata(uid) +} + + +# +n<-which(q_2["access"] == 'open') +for(j in seq(2,3)) +{ +Id<-0 +Id<-as.character(q_3[n[j],1]) +gdcdata(Id) +} + + diff --git a/vignettes/tcga_proteome.R b/vignettes/tcga_proteome.R new file mode 100644 index 0000000..d4dd688 --- /dev/null +++ b/vignettes/tcga_proteome.R @@ -0,0 +1,29 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +p_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_type == 'Protein Expression Quantification' & data_format == 'tsv') |> manifest() +#locate open data +open_access<-which(p_2$access=="open") +#381 files +#download select files +#for(i in length(open_access)) +#for(i in seq(3,5)) +#for(i in seq(20,24)) + +for(i in seq(200,202)) +{ +uid<-0;uid<-as.character(p_2[open_access[i],1]) +gdcdata(uid) +} + +#sanity check , use the filter function + + +p_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_type == 'Protein Expression Quantification' & data_format == 'tsv') |> filter(access == 'open') |> manifest() + +for(i in seq(20,24)) +{ +uid<-0;uid<-as.character(p_3[i,1]) +gdcdata(uid) +} diff --git a/vignettes/tcga_slides.R b/vignettes/tcga_slides.R new file mode 100644 index 0000000..f260f3d --- /dev/null +++ b/vignettes/tcga_slides.R @@ -0,0 +1,25 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +#specify project name +#q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-KIRC' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-BRCA' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() +#locate open data +open_access<-which(q_2$access=="open") + +#select files +#for(i in length(open_access)) +#for(i in seq(3,5)) +#for(i in seq(20,24)) +for(i in seq(200,202)) +{ +uid<-0;uid<-as.character(q_2[open_access[i],1]) +gdcdata(uid) +} + + +######alternatively, use filter +#both approaches should list same files +q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-BRCA' & data_type == 'Slide Image' & data_format == 'svs') |> filter(access == 'open') |> manifest() + diff --git a/vignettes/tcga_slides_1.R b/vignettes/tcga_slides_1.R new file mode 100644 index 0000000..057547b --- /dev/null +++ b/vignettes/tcga_slides_1.R @@ -0,0 +1,27 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-COAD' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() +#locate open data +open_access<-which(q_2$access=="open") + +#for(i in length(open_access)) +#for(i in seq(3,5)) +#for(i in seq(20,24)) +for(i in seq(200,202)) +{ +uid<-0;uid<-as.character(q_2[open_access[i],1]) +gdcdata(uid) +} + + +#or sanity check + +q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-COAD' & data_type == 'Slide Image' & data_format == 'svs') |> filter(access == 'open') |> manifest() + +for(i in seq(2,4)) +{ +uid<-0;uid<-as.character(q_3[i,1]) +gdcdata(uid) +} From b5e4e2ea504387a85e7948eebcb4950dc113ee6b Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Wed, 5 Mar 2025 15:30:20 -0500 Subject: [PATCH 05/11] Add files via upload --- vignettes/mmrf_commpass_wgs.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 vignettes/mmrf_commpass_wgs.R diff --git a/vignettes/mmrf_commpass_wgs.R b/vignettes/mmrf_commpass_wgs.R new file mode 100644 index 0000000..8624de2 --- /dev/null +++ b/vignettes/mmrf_commpass_wgs.R @@ -0,0 +1,34 @@ + + +#building queries + +#get available info for project MMRF-COMMPASS +q_1 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> manifest() + +#save info to file for future use +write.csv(q_1,file="out.txt",quote=FALE,row.names=FALSE) + +#list only open access entries +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open")|> manifest() + +# restrict data to WGS + + +q_3=files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open") |> filter(experimental_strategy == "WGS") |> manifest() + + +#restrict data to WGS Copy Number Segment +q_4=files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open") |> filter(experimental_strategy == "WGS" & data_type == 'Copy Number Segment') |> manifest() + + +#get files less than size 32000 + +q_5=files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open") |> filter(experimental_strategy == "WGS" & data_type == 'Copy Number Segment' & file_size < 32000) |> manifest() + +#get the files +for(i in seq(1,dim(q_5)[1])) +{ +uid<-0; +uid<-as.character(q_6[i,"id"]) +gdcdata(uid) +} From 3833ec238dd7ffc48437253ed67715b1e473e7bc Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Wed, 5 Mar 2025 16:46:28 -0500 Subject: [PATCH 06/11] Add files via upload --- vignettes/mmrf_commpass_wxs.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 vignettes/mmrf_commpass_wxs.R diff --git a/vignettes/mmrf_commpass_wxs.R b/vignettes/mmrf_commpass_wxs.R new file mode 100644 index 0000000..b04e128 --- /dev/null +++ b/vignettes/mmrf_commpass_wxs.R @@ -0,0 +1,34 @@ + + +#building queries + +#get available info for project MMRF-COMMPASS +q_1 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> manifest() + +#save info to file for future use +write.csv(q_3,file="out.txt",quote=FALE,row.names=FALSE) + +#list only open access entries +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open")|> manifest() + +# restrict data to WXS + + +q_3=files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open") |> filter(experimental_strategy == "WXS") |> manifest() + + +#restrict data to WXS Masked Somatic Mutation +q_4=files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open") |> filter(experimental_strategy == "WXS" & data_type == 'Masked Somatic Mutation') |> manifest() + + +#list files by timestamp + +q_5=files() |> GenomicDataCommons::filter(cases.project.project_id == 'MMRF-COMMPASS') |> filter(access == "open") |> filter(experimental_strategy == "WXS" & data_type == 'Masked Somatic Mutation' & created_datetime < "2022-08-22T10:48:06.705961-05:00" ) |> manifest() + +#get the files +for(i in seq(1,dim(q_5)[1])) +{ +uid<-0; +uid<-as.character(q_5[i,"id"]) +gdcdata(uid) +} From c36419132cdee2325524a967cadcc6b244ab3f3d Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Thu, 6 Mar 2025 15:23:07 -0500 Subject: [PATCH 07/11] Add files via upload --- vignettes/tcgaTHCA_clinical.R | 14 ++++++++++++++ vignettes/tcgaTHCA_pathology.R | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 vignettes/tcgaTHCA_clinical.R create mode 100644 vignettes/tcgaTHCA_pathology.R diff --git a/vignettes/tcgaTHCA_clinical.R b/vignettes/tcgaTHCA_clinical.R new file mode 100644 index 0000000..6a34221 --- /dev/null +++ b/vignettes/tcgaTHCA_clinical.R @@ -0,0 +1,14 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +#get files for project TCGA-THCA +#build a manifest file +#use col names with function calls +p_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_category == 'Clinical' & data_type == 'Clinical Supplement' & data_format == 'BCR XML') |> filter(access == "open") |> manifest() +#get select data +for(i in seq(20,24)) +{ +uid<-0;uid<-as.character(p_2[i,1]) +gdcdata(uid) +} diff --git a/vignettes/tcgaTHCA_pathology.R b/vignettes/tcgaTHCA_pathology.R new file mode 100644 index 0000000..6288dd9 --- /dev/null +++ b/vignettes/tcgaTHCA_pathology.R @@ -0,0 +1,33 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + + +# get pathology reports +q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_category == 'Clinical' & data_type == 'Pathology Report') |> manifest() + +for(i in seq(20,24)) +{ +uid<-0;uid<-as.character(q_2[i,1]) +gdcdata(uid) +} + +#use updated datetime to filter data +q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_category == 'Clinical' & data_type == 'Pathology Report' & (updated_datetime == "2022-12-06T15:32:24.960627-06:00")) |> manifest() + +#or + +q_4 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_category == 'Clinical' & data_type == 'Pathology Report' & (updated_datetime > "2022-12-06T15:32:24.960627-06:00")) |> manifest() + +for(i in seq(20,24)) +{ +uid<-0;uid<-as.character(q_4[i,1]) +gdcdata(uid) +} + +#use file size to filter and updated datetime +#single hit +q_5 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_category == 'Clinical' & data_type == 'Pathology Report' & (updated_datetime == "2022-12-06T15:32:24.960627-06:00") & file_size < 2350000) |> manifest() +#get one file that fits above criteria +gdcdata(q_5[1,"id"]) + From 630ee3d2f65ac128f253e90655821d47ad79af42 Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Wed, 12 Mar 2025 17:30:37 -0400 Subject: [PATCH 08/11] Files deleted from incorrect dir --- R/target_cn.R | 21 --------------------- R/target_methylation.R | 21 --------------------- R/target_methylation_1.R | 17 ----------------- R/tcga_CEL.R | 28 ---------------------------- R/tcga_proteome.R | 29 ----------------------------- R/tcga_slides.R | 25 ------------------------- R/tcga_slides_1.R | 27 --------------------------- 7 files changed, 168 deletions(-) delete mode 100644 R/target_cn.R delete mode 100644 R/target_methylation.R delete mode 100644 R/target_methylation_1.R delete mode 100644 R/tcga_CEL.R delete mode 100644 R/tcga_proteome.R delete mode 100644 R/tcga_slides.R delete mode 100644 R/tcga_slides_1.R diff --git a/R/target_cn.R b/R/target_cn.R deleted file mode 100644 index 547a681..0000000 --- a/R/target_cn.R +++ /dev/null @@ -1,21 +0,0 @@ -library(GenomicDataCommons) -library(dplyr) -library(tibble) -#Clear Cell Sarcoma of the Kidney. Disease Type. Complex Mixed and Stromal Neoplasms. Primary Site. Kidney. Program. TARGET - - -cn_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( analysis.workflow_type == 'ASCAT2') |> manifest() -n<-which(cn_manifest_CCSK$access=='open') - -#save dat to file -write.csv(cn_manifest_CCSK[n,],file='out.txt',quote=FALSE,row.names=FALSE) -##########----------####################### -#select files -for( i in seq(1,length(n))) -{ -# -id<-0; - id<-as.character(cn_manifest_CCSK[n[i],1]) -###### -gdcdata(id) -} diff --git a/R/target_methylation.R b/R/target_methylation.R deleted file mode 100644 index 1f54692..0000000 --- a/R/target_methylation.R +++ /dev/null @@ -1,21 +0,0 @@ -library(GenomicDataCommons) -library(dplyr) -library(tibble) -#Clear Cell Sarcoma of the Kidney. Disease Type. Complex Mixed and Stromal Neoplasms. Primary Site. Kidney. Program. TARGET - -#get familiar with aggregations -q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TARGET-CCSK') |> facet(c("data_type","data_format","analysis.workflow_type","file_id","file_name")) |> aggregations() - - - -q_1 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TARGET-CCSK') |> facet(c("data_type","data_format","analysis.workflow_type")) |> aggregations() - -idat_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( data_type == 'Methylation Beta Value' ) |> GenomicDataCommons::filter( analysis.workflow_type == 'SeSAMe Methylation Beta Estimation') |> manifest() -n<-which(idat_manifest_CCSK$access=='open') - -#save data to file -write.csv(idat_manifest_CCSK[n,],file='manifest.txt',quote=FALSE,row.names=FALSE) - - -###### test single file -gdcdata(idat_manifest_CCSK[n[1],1])) diff --git a/R/target_methylation_1.R b/R/target_methylation_1.R deleted file mode 100644 index 2c091c4..0000000 --- a/R/target_methylation_1.R +++ /dev/null @@ -1,17 +0,0 @@ -library(GenomicDataCommons) -library(dplyr) -library(tibble) - - -idat_manifest_CCSK <- files() |> GenomicDataCommons::filter( cases.project.project_id == 'TARGET-CCSK') |> GenomicDataCommons::filter( data_type == 'Methylation Beta Value' ) |> GenomicDataCommons::filter( analysis.workflow_type == 'SeSAMe Methylation Beta Estimation') |> manifest() -n<-which(idat_manifest_CCSK$access=='open') - -##########----------####################### -for( i in seq(1,length(n))) -{ -#use cast -id<-0; - id<-as.character(idat_manifest_CCSK[n[i],1]) -######only test with single file -gdcdata(id) -} diff --git a/R/tcga_CEL.R b/R/tcga_CEL.R deleted file mode 100644 index 5cceb52..0000000 --- a/R/tcga_CEL.R +++ /dev/null @@ -1,28 +0,0 @@ -library(dplyr) -library(tibble) -library(GenomicDataCommons) - -# - -q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-GBM' & data_category == 'Transcriptome Profiling' & data_format == 'CEL') |> manifest() -#OR use filter fn -q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-GBM' & data_category == 'Transcriptome Profiling' & data_format == 'CEL') |> GenomicDataCommons::filter(access=='OPEN') |> manifest() - -for(i in seq(10,12)) -{ -uid<-0; -uid<-as.character(q_3[i,1]) -gdcdata(uid) -} - - -# -n<-which(q_2["access"] == 'open') -for(j in seq(2,3)) -{ -Id<-0 -Id<-as.character(q_3[n[j],1]) -gdcdata(Id) -} - - diff --git a/R/tcga_proteome.R b/R/tcga_proteome.R deleted file mode 100644 index d4dd688..0000000 --- a/R/tcga_proteome.R +++ /dev/null @@ -1,29 +0,0 @@ -library(dplyr) -library(tibble) -library(GenomicDataCommons) - -p_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_type == 'Protein Expression Quantification' & data_format == 'tsv') |> manifest() -#locate open data -open_access<-which(p_2$access=="open") -#381 files -#download select files -#for(i in length(open_access)) -#for(i in seq(3,5)) -#for(i in seq(20,24)) - -for(i in seq(200,202)) -{ -uid<-0;uid<-as.character(p_2[open_access[i],1]) -gdcdata(uid) -} - -#sanity check , use the filter function - - -p_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-THCA' & data_type == 'Protein Expression Quantification' & data_format == 'tsv') |> filter(access == 'open') |> manifest() - -for(i in seq(20,24)) -{ -uid<-0;uid<-as.character(p_3[i,1]) -gdcdata(uid) -} diff --git a/R/tcga_slides.R b/R/tcga_slides.R deleted file mode 100644 index f260f3d..0000000 --- a/R/tcga_slides.R +++ /dev/null @@ -1,25 +0,0 @@ -library(dplyr) -library(tibble) -library(GenomicDataCommons) - -#specify project name -#q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-KIRC' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() -q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-BRCA' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() -#locate open data -open_access<-which(q_2$access=="open") - -#select files -#for(i in length(open_access)) -#for(i in seq(3,5)) -#for(i in seq(20,24)) -for(i in seq(200,202)) -{ -uid<-0;uid<-as.character(q_2[open_access[i],1]) -gdcdata(uid) -} - - -######alternatively, use filter -#both approaches should list same files -q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-BRCA' & data_type == 'Slide Image' & data_format == 'svs') |> filter(access == 'open') |> manifest() - diff --git a/R/tcga_slides_1.R b/R/tcga_slides_1.R deleted file mode 100644 index 057547b..0000000 --- a/R/tcga_slides_1.R +++ /dev/null @@ -1,27 +0,0 @@ -library(dplyr) -library(tibble) -library(GenomicDataCommons) - -q_2 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-COAD' & data_type == 'Slide Image' & data_format == 'svs') |> manifest() -#locate open data -open_access<-which(q_2$access=="open") - -#for(i in length(open_access)) -#for(i in seq(3,5)) -#for(i in seq(20,24)) -for(i in seq(200,202)) -{ -uid<-0;uid<-as.character(q_2[open_access[i],1]) -gdcdata(uid) -} - - -#or sanity check - -q_3 = files() |> GenomicDataCommons::filter(cases.project.project_id == 'TCGA-COAD' & data_type == 'Slide Image' & data_format == 'svs') |> filter(access == 'open') |> manifest() - -for(i in seq(2,4)) -{ -uid<-0;uid<-as.character(q_3[i,1]) -gdcdata(uid) -} From 34b4fa814436ed19adc36812548d3142269cec3c Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Wed, 12 Mar 2025 17:43:18 -0400 Subject: [PATCH 09/11] update overview.Rmd --- vignettes/overview.Rmd | 72 +- vignettes/overviewGenomicDataCommons.Rmd | 811 ----------------------- 2 files changed, 39 insertions(+), 844 deletions(-) delete mode 100644 vignettes/overviewGenomicDataCommons.Rmd diff --git a/vignettes/overview.Rmd b/vignettes/overview.Rmd index 17a1114..4269cda 100644 --- a/vignettes/overview.Rmd +++ b/vignettes/overview.Rmd @@ -118,6 +118,12 @@ stopifnot(GenomicDataCommons::status()$status=="OK") ## Find data +Please use a fresh R session to minimise package conflicts arising from identical function names. +For example the functions filter(), results() are available with R packages dplyr, GenomicDataCommons . Instead consider using the R package conflicted. +Example usage +conflicts_prefer(dplyr::filter()) +conflicts_prefer(GenomicDataCommons::filter) +conflicts_prefer(stats :: filter) The following code builds a `manifest` that can be used to guide the download of raw data. Here, filtering finds gene expression files @@ -164,8 +170,8 @@ the `gdc_clinical()` function will return a list of four `tibble`s. - main ```{r gdc_clinical} -case_ids = cases() |> results(size=10) |> ids() -clindat = gdc_clinical(case_ids) +case_ids <- cases() |> results(size=10) |> ids() +clindat <- gdc_clinical(case_ids) names(clindat) ``` @@ -183,9 +189,9 @@ be all that is needed, but the API and `r Biocpkg("GenomicDataCommons")` package make much flexibility if fine-tuning is required. ```{r metadataQS} -expands = c("diagnoses","annotations", +expands <- c("diagnoses","annotations", "demographic","exposures") -clinResults = cases() |> +clinResults <- cases() |> GenomicDataCommons::select(NULL) |> GenomicDataCommons::expand(expands) |> results(size=50) @@ -287,7 +293,7 @@ functions that each create `GDCQuery` objects (actually, specific subclasses of - `annotations()` ```{r projectquery} -pquery = projects() +pquery <- projects() ``` The `pquery` object is now an object of (S3) class, `GDCQuery` (and @@ -326,16 +332,16 @@ 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" ```{r pquerycount} -pcount = count(pquery) +pcount <- count(pquery) # or -pcount = pquery |> count() +pcount <- pquery |> count() pcount ``` The `results()` method will fetch actual results. ```{r pqueryresults} -presults = pquery |> results() +presults <- pquery |> results() ``` These results are returned from the GDC in [JSON](http://www.json.org/) format and @@ -356,7 +362,7 @@ size is probably warranted before calling `results_all()` ```{r presultsall} length(ids(presults)) -presults = pquery |> results_all() +presults <- pquery |> results_all() length(ids(presults)) # includes all records length(ids(presults)) == count(pquery) @@ -401,11 +407,11 @@ the dplyr `select()` verb that limits from already-present fields. We ```{r selectexample} # Default fields here -qcases = cases() +qcases <- cases() qcases$fields # set up query to use ALL available fields # Note that checking of fields is done by select() -qcases = cases() |> GenomicDataCommons::select(available_fields('cases')) +qcases <- cases() |> GenomicDataCommons::select(available_fields('cases')) head(qcases$fields) ``` @@ -428,7 +434,7 @@ tibbles). ```{r aggexample} # total number of files of a specific type -res = files() |> facet(c('type','data_type')) |> aggregations() +res <- files() |> facet(c('type','data_type')) |> aggregations() res$type ``` @@ -454,7 +460,7 @@ For the user, these details will not be too important except to note that a filter expression must begin with a "~". ```{r allfilesunfiltered} -qfiles = files() +qfiles <- files() qfiles |> count() # all files ``` To limit the file type, we can refer back to the @@ -463,7 +469,7 @@ the file field "type". For example, to filter file results to only "gene_expression" files, we simply specify a filter. ```{r onlyGeneExpression} -qfiles = files() |> filter( type == 'gene_expression') +qfiles <- files() |> filter( type == 'gene_expression') # here is what the filter looks like after translation str(get_filter(qfiles)) ``` @@ -495,7 +501,7 @@ note that `TCGA-OV` is the correct project_id, not `TCGA-OVCA`. Note that filter and does not build on any previous filters*. ```{r filtfinal} -qfiles = files() |> +qfiles <- files() |> filter( cases.project.project_id == 'TCGA-OV' & type == 'gene_expression') str(get_filter(qfiles)) qfiles |> count() @@ -507,7 +513,7 @@ accomplish the same effect as multiple `&` conditionals. The `count()` below is equivalent to the `&` filtering done above. ```{r filtChain} -qfiles2 = files() |> +qfiles2 <- files() |> filter( cases.project.project_id == 'TCGA-OV') |> filter( type == 'gene_expression') qfiles2 |> count() @@ -520,7 +526,7 @@ Generating a manifest for bulk downloads is as simple as asking for the manifest from the current query. ```{r filtAndManifest} -manifest_df = qfiles |> manifest() +manifest_df <- qfiles |> manifest() head(manifest_df) ``` @@ -531,11 +537,11 @@ that the field "analysis.workflow_type" has the appropriate filter criteria. ```{r filterForSTARCounts} -qfiles = files() |> filter( ~ cases.project.project_id == 'TCGA-OV' & +qfiles <- files() |> filter( ~ cases.project.project_id == 'TCGA-OV' & type == 'gene_expression' & access == "open" & analysis.workflow_type == 'STAR - Counts') -manifest_df = qfiles |> manifest() +manifest_df <- qfiles |> manifest() nrow(manifest_df) ``` @@ -577,7 +583,7 @@ be stored in one of three ways (resolved in this order): As a concrete example: ```{r authenNoRun, eval=FALSE} -token = gdc_token() +token <- gdc_token() transfer(...,token=token) # or transfer(...,token=get_token()) @@ -594,7 +600,7 @@ ids. A simple way of producing such a vector is to produce a contain file ids. ```{r singlefileDL} -fnames = gdcdata(manifest_df$id[1:2],progress=FALSE) +fnames <- gdcdata(manifest_df$id[1:2],progress=FALSE) ``` @@ -614,7 +620,7 @@ in parallel. ```{r bulkDL, eval=FALSE} # Requires gcd_client command-line utility to be isntalled # separately. -fnames = gdcdata(manifest_df$id[3:10], access_method = 'client') +fnames <- gdcdata(manifest_df$id[3:10], access_method = 'client') ``` @@ -627,7 +633,7 @@ fnames = gdcdata(manifest_df$id[3:10], access_method = 'client') ### How many cases are there per project_id? ```{r casesPerProject} -res = cases() |> facet("project.project_id") |> aggregations() +res <- cases() |> facet("project.project_id") |> aggregations() head(res) library(ggplot2) ggplot(res$project.project_id,aes(x = key, y = doc_count)) + @@ -653,7 +659,7 @@ cases() |> filter(~ project.program.name=='TCGA') |> count() # 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' & +resp <- cases() |> filter(~ project.project_id=='TCGA-BRCA' & project.project_id=='TCGA-BRCA' ) |> facet('samples.sample_type') |> aggregations() resp$samples.sample_type @@ -665,12 +671,12 @@ 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' & +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) -res = resp |> results() +res <- resp |> results() str(res[1],list.len=6) head(ids(resp)) ``` @@ -721,7 +727,7 @@ cases() |> ### How many of each type of file are available? ```{r filesVCFCount} -res = files() |> facet('type') |> aggregations() +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)) @@ -730,13 +736,13 @@ ggplot(res$type,aes(x = key,y = doc_count)) + geom_bar(stat='identity') + ### Find gene-level RNA-seq quantification files for GBM ```{r filesRNAseqGeneGBM} -q = files() |> +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() # so need to add another filter -file_ids = q |> filter(~ cases.project.project_id=='TCGA-GBM' & +file_ids <- q |> filter(~ cases.project.project_id=='TCGA-GBM' & data_type=='Gene Expression Quantification' & analysis.workflow_type == 'STAR - Counts') |> GenomicDataCommons::select('file_id') |> @@ -752,20 +758,20 @@ file_ids = q |> filter(~ cases.project.project_id=='TCGA-GBM' & and for vignette building**. ```{r filesRNAseqGeneGBMforBAM} -q = files() |> +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() +file_ids <- q |> response_all() |> ids() ``` ```{r slicing10, eval=FALSE} -bamfile = slicing(file_ids[1],regions="chr12:6534405-6538375",token=gdc_token()) +bamfile <- slicing(file_ids[1],regions="chr12:6534405-6538375",token=gdc_token()) library(GenomicAlignments) -aligns = readGAlignments(bamfile) +aligns <- readGAlignments(bamfile) ``` # Troubleshooting diff --git a/vignettes/overviewGenomicDataCommons.Rmd b/vignettes/overviewGenomicDataCommons.Rmd deleted file mode 100644 index 4269cda..0000000 --- a/vignettes/overviewGenomicDataCommons.Rmd +++ /dev/null @@ -1,811 +0,0 @@ ---- -title: "The GenomicDataCommons Package" -author: "Sean Davis & Martin Morgan" -date: "`r format(Sys.Date(), '%A, %B %d, %Y')`" -always_allow_html: yes -output: - BiocStyle::html_document: - df_print: paged - toc_float: true -abstract: > - The National Cancer Institute (NCI) has established - the [Genomic Data Commons](https://gdc.nci.nih.gov/) (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. - -vignette: > - %\VignetteIndexEntry{Introduction to Accessing the NCI Genomic Data Commons} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r init, results='hide', echo=FALSE, warning=FALSE, message=FALSE} -library(knitr) -opts_chunk$set(warning=FALSE, message=FALSE) -BiocStyle::markdown() -``` - - -# What is the GDC? - -From the [Genomic Data Commons (GDC) website](https://gdc.cancer.gov/about-gdc): - -> 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](https://gdc.cancer.gov/developers/gdc-data-model/gdc-data-model-components), -but it worth a quick overview and a graphical representation is included here. - -![The data model is encoded as a -so-called property graph. Nodes represent entities such as Projects, -Cases, Diagnoses, Files (various kinds), and Annotations. The -relationships between these entities are maintained as edges. Both -nodes and edges may have Properties that supply instance details. ](all_nodes_040318.png) - - The -GDC API exposes these nodes and edges in a somewhat simplified set -of -[RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer) endpoints. - -# Quickstart - -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](https://github.com/Bioconductor/GenomicDataCommons/issues) -or submit a `bug.report(package='GenomicDataCommons')` from within R (which -will redirect you to the new issue on GitHub). - -## Installation - -Installation can be achieved via Bioconductor's `BiocManager` package. - -```{r install_bioc, eval=FALSE} -if (!require("BiocManager")) - install.packages("BiocManager") -BiocManager::install('GenomicDataCommons') -``` - -```{r libraries, message=FALSE} -library(GenomicDataCommons) -``` - -## Check connectivity and status - -The `r Biocpkg("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. - -```{r statusQS} -GenomicDataCommons::status() -``` - -And to check the status in code: - -```{r statusCheck} -stopifnot(GenomicDataCommons::status()$status=="OK") -``` - - -## Find data -Please use a fresh R session to minimise package conflicts arising from identical function names. -For example the functions filter(), results() are available with R packages dplyr, GenomicDataCommons . Instead consider using the R package conflicted. -Example usage -conflicts_prefer(dplyr::filter()) -conflicts_prefer(GenomicDataCommons::filter) -conflicts_prefer(stats :: filter) - -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. - -```{r manifest} -ge_manifest <- files() |> - filter( cases.project.project_id == 'TCGA-OV') |> - filter( type == 'gene_expression' ) |> - filter( analysis.workflow_type == 'STAR - Counts') |> - manifest() -head(ge_manifest) -``` - -## Download data - -After the `r nrow(ge_manifest)` 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. - -```{r downloadQS, eval=FALSE} -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](#authentication). - -## Metadata queries - -### Clinical data - -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. - -- demographic -- diagnoses -- exposures -- main - -```{r gdc_clinical} -case_ids <- cases() |> results(size=10) |> ids() -clindat <- gdc_clinical(case_ids) -names(clindat) -``` - -```{r clinData} -head(clindat[["main"]]) -head(clindat[["diagnoses"]]) -``` - -### General metadata queries - -The `r Biocpkg("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 `r Biocpkg("GenomicDataCommons")` package -make much flexibility if fine-tuning is required. - -```{r metadataQS} -expands <- c("diagnoses","annotations", - "demographic","exposures") -clinResults <- cases() |> - GenomicDataCommons::select(NULL) |> - GenomicDataCommons::expand(expands) |> - results(size=50) -str(clinResults[[1]],list.len=6) -# or listviewer::jsonedit(clinResults) -``` - -# Basic design - -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: - -1. Simple query constructors based on GDC API endpoints. -2. A set of verbs that when applied, adjust filtering, field selection, and -faceting (fields for aggregation) and result in a new query object (an -endomorphism) -3. A set of verbs that take a query and return results from the GDC - -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 functionality[^1]. - - -- Creating a query - - `projects()` - - `cases()` - - `files()` - - `annotations()` -- Manipulating a query - - `filter()` - - `facet()` - - `select()` -- Introspection on the GDC API fields - - `mapping()` - - `available_fields()` - - `default_fields()` - - `grep_fields()` - - `available_values()` - - `available_expand()` -- Executing an API call to retrieve query results - - `results()` - - `count()` - - `response()` -- Raw data file downloads - - `gdcdata()` - - `transfer()` - - `gdc_client()` -- Summarizing and aggregating field values (faceting) - - `aggregations()` -- Authentication - - `gdc_token()` -- BAM file slicing - - `slicing()` - -[^1]: See individual function and methods documentation for specific details. - - -# Usage - -There are two main classes of operations when working with the NCI GDC. - -1. [Querying metadata and finding data files](#querying-metadata) (e.g., finding -all gene expression quantifications data files for all colon cancer patients). -2. [Transferring raw or processed data](#datafile-access-and-download) from the -GDC to another computer (e.g., downloading raw or processed data) - -Both classes of operation are reviewed in detail in the following sections. - -## Querying metadata - -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](#creating-a-query). One -will often then want to [`filter`](#filtering) the query to limit results prior -to [retrieving results](#retrieving-results). The GenomicDataCommons package has -[helper functions for listing fields](#fields-and-values) that are available for -filtering. - -In addition to fetching results, the GDC API allows -[faceting, or aggregating,](#facets-and-aggregation), useful for compiling -reports, generating dashboards, or building user interfaces to GDC data (see GDC -web query interface for a non-R-based example). - -### Creating a query - -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()` - -```{r projectquery} -pquery <- projects() -``` - -The `pquery` object is now an object of (S3) class, `GDCQuery` (and -`gdc_projects` and `list`). The object contains the following elements: - -- fields: This is a character vector of the fields that will be returned when we -[retrieve data](#retrieving-results). If no fields are specified to, for -example, the `projects()` function, the default fields from the GDC are used -(see `default_fields()`) -- filters: This will contain results after calling the -[`filter()` method](#filtering) and will be used to filter results on -[retrieval](#retrieving-results). -- facets: A character vector of field names that will be used for -[aggregating data](#facets-and-aggregation) in a call to `aggregations()`. -- token: A character(1) token from the GDC. See -[the authentication section](#authentication) for details, but note that, in -general, the token is not necessary for metadata query and retrieval, only for -actual data download. - -Looking at the actual object (get used to using `str()`!), note that the query -contains no results. - -```{r pquery} -str(pquery) -``` -### Retrieving results - -[[ GDC pagination documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#size-and-from) - -[[ GDC sorting documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#sort) - -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" - -```{r pquerycount} -pcount <- count(pquery) -# or -pcount <- pquery |> count() -pcount -``` - -The `results()` method will fetch actual results. - -```{r pqueryresults} -presults <- pquery |> results() -``` -These results are -returned from the GDC in [JSON](http://www.json.org/) format and -converted into a (potentially nested) list in R. The `str()` method is useful -for taking a quick glimpse of the data. - -```{r presultsstr} -str(presults) -``` - -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()` - -```{r presultsall} -length(ids(presults)) -presults <- pquery |> results_all() -length(ids(presults)) -# includes all records -length(ids(presults)) == count(pquery) -``` - -Extracting subsets of -results or manipulating the results into a more conventional R data -structure is not easily generalizable. However, -the -[purrr](https://github.com/hadley/purrr), -[rlist](https://renkun.me/rlist/), -and [data.tree](https://cran.r-project.org/web/packages/data.tree/vignettes/data.tree.html) packages -are all potentially of interest for manipulating complex, nested list -structures. For viewing the results in an interactive viewer, consider the -[listviewer](https://github.com/timelyportfolio/listviewer) package. - - -### Fields and Values - -[[ GDC `fields` documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#fields) - -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. - -```{r defaultfields} -default_fields('files') -# The number of fields available for files endpoint -length(available_fields('files')) -# The first few fields available for files endpoint -head(available_fields('files')) -``` - -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`. - -```{r selectexample} -# Default fields here -qcases <- cases() -qcases$fields -# 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) -``` - -Finding fields of interest is such a common operation that the -GenomicDataCommons includes the `grep_fields()` function. -See the appropriate help pages for details. - -### Facets and aggregation - -[[ GDC `facet` documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#facets) - -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). - -```{r aggexample} -# 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. - -### Filtering - -[[ GDC `filtering` documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#filters-specifying-the-query) - -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](https://cran.r-project.org/web/packages/dplyr/vignettes/nse.html) - -> 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 "~". - -```{r allfilesunfiltered} -qfiles <- files() -qfiles |> count() # all files -``` -To limit the file type, we can refer back to the -[section on faceting](#facets-and-aggregation) 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. - -```{r onlyGeneExpression} -qfiles <- files() |> filter( type == 'gene_expression') -# here is what the filter looks like after translation -str(get_filter(qfiles)) -``` - -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. - -```{r filtAvailFields} -grep('pro',available_fields('files'),value=TRUE) |> - head() -``` - -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. - -```{r filtProgramID} -files() |> - facet('cases.project.project_id') |> - aggregations() |> - head() -``` - -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*. - -```{r filtfinal} -qfiles <- files() |> - filter( cases.project.project_id == 'TCGA-OV' & type == 'gene_expression') -str(get_filter(qfiles)) -qfiles |> count() -``` - -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. - -```{r filtChain} -qfiles2 <- files() |> - filter( cases.project.project_id == 'TCGA-OV') |> - filter( type == 'gene_expression') -qfiles2 |> count() -(qfiles |> count()) == (qfiles2 |> count()) #TRUE -``` - - - -Generating a manifest for bulk downloads is as -simple as asking for the manifest from the current query. - -```{r filtAndManifest} -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. - - -```{r filterForSTARCounts} -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) -``` - -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](bulk-downloads) for -details. - - -## Authentication - -[[ GDC authentication documentation ]](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#facets) - -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.](https://gdc.cancer.gov/access-data/obtaining-access-controlled-data) - -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](https://docs.gdc.cancer.gov/Data_Portal/Users_Guide/Authentication/#gdc-authentication-tokens), -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): - -1. As a string stored in the environment variable, `GDC_TOKEN` -2. As a file, stored in the file named by the environment variable, - `GDC_TOKEN_FILE` -3. In a file in the user home directory, called `.gdc_token` - -As a concrete example: - -```{r authenNoRun, eval=FALSE} -token <- gdc_token() -transfer(...,token=token) -# or -transfer(...,token=get_token()) -``` - - -## Datafile access and download - -### Data downloads via the GDC API - -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. - -```{r singlefileDL} -fnames <- gdcdata(manifest_df$id[1:2],progress=FALSE) - -``` - -Note that for controlled-access data, a -GDC [authentication token](#authentication) is required. Using the -`BiocParallel` package may be useful for downloading in parallel, -particularly for large numbers of smallish files. - -### Bulk downloads - -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. - -```{r bulkDL, eval=FALSE} -# Requires gcd_client command-line utility to be isntalled -# separately. -fnames <- gdcdata(manifest_df$id[3:10], access_method = 'client') -``` - - -### BAM slicing - -# Use Cases - -## Cases - -### How many cases are there per project_id? - -```{r casesPerProject} -res <- cases() |> facet("project.project_id") |> aggregations() -head(res) -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)) -``` - -### How many cases are included in all TARGET projects? - -```{r casesInTCGA} -cases() |> filter(~ project.program.name=='TARGET') |> count() -``` - -### How many cases are included in all TCGA projects? - -```{r casesInTARGET} -cases() |> filter(~ project.program.name=='TCGA') |> count() -``` - -### What is the breakdown of sample types in TCGA-BRCA? - -```{r casesTCGABRCASampleTypes} -# 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 -``` - -### Fetch all samples in TCGA-BRCA that use "Solid Tissue" as a normal. - -```{r casesTCGABRCASolidNormal} -# 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) -res <- resp |> results() -str(res[1],list.len=6) -head(ids(resp)) -``` - -### Get all TCGA case ids that are female - -```{r casesFemaleTCGA} -cases() |> - GenomicDataCommons::filter(~ project.program.name == 'TCGA' & - "cases.demographic.gender" %in% "female") |> - GenomicDataCommons::results(size = 4) |> - ids() -``` - -### Get all TCGA-COAD case ids that are NOT female - -```{r notFemaleTCGACOAD} -cases() |> - GenomicDataCommons::filter(~ project.project_id == 'TCGA-COAD' & - "cases.demographic.gender" %exclude% "female") |> - GenomicDataCommons::results(size = 4) |> - ids() -``` - -### Get all TCGA cases that are missing gender - -```{r missingGenderTCGA} -cases() |> - GenomicDataCommons::filter(~ project.program.name == 'TCGA' & - missing("cases.demographic.gender")) |> - GenomicDataCommons::results(size = 4) |> - ids() -``` - -### Get all TCGA cases that are NOT missing gender - -```{r notMissingGenderTCGA} -cases() |> - GenomicDataCommons::filter(~ project.program.name == 'TCGA' & - !missing("cases.demographic.gender")) |> - GenomicDataCommons::results(size = 4) |> - ids() -``` - - -## Files - -### How many of each type of file are available? - -```{r filesVCFCount} -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)) -``` - -### Find gene-level RNA-seq quantification files for GBM - -```{r filesRNAseqGeneGBM} -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() -# 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() -``` - -## Slicing - -### Get all BAM file ids from TCGA-GBM - -**I need to figure out how to do slicing reproducibly in a testing environment -and for vignette building**. - -```{r filesRNAseqGeneGBMforBAM} -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() -``` - - -```{r slicing10, eval=FALSE} -bamfile <- slicing(file_ids[1],regions="chr12:6534405-6538375",token=gdc_token()) -library(GenomicAlignments) -aligns <- readGAlignments(bamfile) -``` - -# Troubleshooting - -## SSL connection errors - -* Symptom: Trying to connect to the API results in: -``` -Error in curl::curl_fetch_memory(url, handle = handle) : -SSL connect error -``` -* Possible solutions: The [issue -is that the GDC supports only recent security Transport Layer Security (TLS)](http://stackoverflow.com/a/42599546/459633), -so the only known fix is to upgrade the system `openssl` to version -1.0.1 or later. - * [[Mac OS]](https://github.com/Bioconductor/GenomicDataCommons/issues/35#issuecomment-284233510), - * [[Ubuntu]](http://askubuntu.com/a/434245) - * [[Centos/RHEL]](https://www.liquidweb.com/kb/update-and-patch-openssl-for-the-ccs-injection-vulnerability/). - After upgrading `openssl`, reinstall the R `curl` and `httr` packages. - - -# sessionInfo() - -```{r sessionInfo} -sessionInfo() -``` - -# Developer notes - -- The `S3` object-oriented programming paradigm is used. -- We have adopted a functional programming style with functions and methods that -often take an "object" as the first argument. This style lends itself to -pipeline-style programming. -- The GenomicDataCommons package uses the -[alternative request format (POST)](https://docs.gdc.cancer.gov/API/Users_Guide/Search_and_Retrieval/#alternative-request-format) -to allow very large request bodies. - From e205d62f455aab4e8b736d3db791168a22c35eb3 Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Wed, 19 Mar 2025 14:39:16 -0400 Subject: [PATCH 10/11] Add files via upload --- vignettes/get_projects.R | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 vignettes/get_projects.R diff --git a/vignettes/get_projects.R b/vignettes/get_projects.R new file mode 100644 index 0000000..d2cf7f4 --- /dev/null +++ b/vignettes/get_projects.R @@ -0,0 +1,39 @@ +library(GenomicDataCommons) + + +#more than one possibility to get availble projects on the gdc portal +#perhaps useful for anyone searching for gdc data to combine with existing laboratory samples +gdc_proj<-projects() + +#get available keys to build queries +#available_fields(gdc_proj) +#facet(gdc_proj) + +####get available gdc projects +res_1<-(gdc_proj |> facet('project_id') |> aggregations() ) +#save to file +write.csv(res$project_id$key,file="project_id.txt",quote=FALSE,row.names=FALSE) + +#get gdc project names +res_2<-(gdc_proj |> facet('program.name') |> aggregations() ) +#Save to file +write.csv(res$program.name$key,file=='program.name.txt',quote=FALSE,row.names=FALSE) + +#addtional exp details +res_3<-(gdc_proj |> facet('name') |> aggregations() ) +#get list components +#names(res) +write.csv(res$name["key"],file=='project_name.txt',quote=FALSE,row.names=FALSE) + +#get biospecimen, tissue site +res_4<-(gdc_proj |> facet('primary_site') |> aggregations() ) + +write.csv(res$primary_site['key'],file=='primary_site.txt',quote=FALSE,row.names=FALSE) + +####use multiple fields +res_5<-(gdc_proj |> facet(gdc_proj$fields[c(4:5,7)]) |> aggregations() ) + +x<-list(N=res$name["key"],P=res$project_id["key"],T=res$primary_site["key"]) + +#save to file , not a 1-1 map +#cat(capture.output(print(x), file="test.txt")) From 2531b93f320c3ef2ca0c633116093e533a766f1e Mon Sep 17 00:00:00 2001 From: bd4everyone Date: Thu, 27 Mar 2025 11:47:01 -0400 Subject: [PATCH 11/11] Add files via upload --- vignettes/ssm_examples.R | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 vignettes/ssm_examples.R diff --git a/vignettes/ssm_examples.R b/vignettes/ssm_examples.R new file mode 100644 index 0000000..0d6f225 --- /dev/null +++ b/vignettes/ssm_examples.R @@ -0,0 +1,51 @@ +library(dplyr) +library(tibble) +library(GenomicDataCommons) + +#build queries to get simple somatic mutations +q_primsite_1 = ssm_occurrences() |> GenomicDataCommons::filter(case.primary_site== 'Esophagus') |> GenomicDataCommons::expand(c('ssm','case')) |> GenomicDataCommons::results_all() |> as_tibble() + +#add search criteria +q_primsite_2 = ssm_occurrences() |> GenomicDataCommons::filter(case.primary_site== 'Esophagus' & case.lost_to_followup == 'No' ) |> GenomicDataCommons::expand(c('ssm','case')) |> GenomicDataCommons::results_all() |> as_tibble() + +################ +q_consent = ssm_occurrences() |> GenomicDataCommons::filter(case.consent_type== 'Consent by Death') |> GenomicDataCommons::expand(c('ssm','case')) |> GenomicDataCommons::results_all() |> as_tibble() + +write.csv(q_consent,file="ssm_consentbyDeath.txt",row.names=FALSE,quote=FALSE) + +q_del = ssm_occurrences() |> GenomicDataCommons::filter(ssm.mutation_subtype == 'Small deletion') |> GenomicDataCommons::expand(c('ssm')) |> GenomicDataCommons::results_all() |> as_tibble() + +write.csv(q_del,file="ssm_subtypeDeletions.txt",row.names=FALSE,quote=FALSE) + +#get simple somatic mutations on chr one +q_chrone = ssm_occurrences() |> GenomicDataCommons::filter(ssm.chromosome == 'chr1') |> GenomicDataCommons::expand(c('ssm')) |> GenomicDataCommons::results_all() |> as_tibble() + +write.csv(q_chrone,file="simplesomaticmutschr1.txt",row.names=FALSE,quote=FALSE) + +######################------------------------------################################ +####get all simple somatic mutations on chr 17 +q_1 = ssm_occurrences() |> GenomicDataCommons::filter(ssm.chromosome == 'chr17') |> GenomicDataCommons::expand(c('ssm')) |> GenomicDataCommons::results_all() |> as_tibble() + +write.csv(q_1,file="simplesomaticmutschr17.txt",row.names=FALSE,quote=FALSE) + + +#pull mutations on chr17 for TP53 + +q_2 = ssm_occurrences() |> GenomicDataCommons::filter(ssm.consequence.transcript.gene.symbol == 'TP53' & ssm.chromosome == 'chr17') |> GenomicDataCommons::expand(c('case','ssm')) |> GenomicDataCommons::results_all() |> as_tibble() + +write.csv(q_2,file="TP53var_samples17.txt",row.names=FALSE,quote=FALSE) +#sanity check: TP53 gene located on chr17 , so same results +q_3 = ssm_occurrences() |> GenomicDataCommons::filter(ssm.consequence.transcript.gene.symbol == 'TP53') |> GenomicDataCommons::expand(c('case','ssm')) |> GenomicDataCommons::results_all() |> as_tibble() + +write.csv(q_3,file="TP53var_samples.txt",row.names=FALSE,quote=FALSE) + + +#pull mutations on chr17 for NF1 +q_4 = ssm_occurrences() |> GenomicDataCommons::filter(ssm.consequence.transcript.gene.symbol == 'NF1' & ssm.chromosome == 'chr17') |> GenomicDataCommons::expand(c('case','ssm')) |> GenomicDataCommons::results_all() |> as_tibble() + +write.csv(q_4,file="NF1var_samples17.txt",row.names=FALSE,quote=FALSE) + +#sanity check : NF1 gene located on chr17, so same results +q_5 = ssm_occurrences() |> GenomicDataCommons::filter(ssm.consequence.transcript.gene.symbol == 'NF1') |> GenomicDataCommons::expand(c('case','ssm')) |> GenomicDataCommons::results_all() |> as_tibble() +write.csv(q_5,file="NF1var_samples.txt",row.names=FALSE,quote=FALSE) +