Skip to content

Commit

Permalink
udpate Reference Genome Endpoints functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgpanw committed Jun 24, 2024
1 parent 7b60371 commit 06ece1e
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 52 deletions.
5 changes: 5 additions & 0 deletions R/get_exons.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#' Get Exons
#'
#' @description
#' This service returns exons from all known transcripts of the given gene.
#'
#' - A versioned GENCODE ID is required to ensure that all exons are from a single gene.
#' - A dataset ID or both GENCODE version and genome build must be provided.
#' - Although annotated exons are not dataset dependent, specifying a dataset here is equivalent to specifying the GENCODE version and genome build used by that dataset.
#'
#' [GTEx Portal API documentation](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_exons_api_v2_reference_exon_get)
#'
#' @inheritParams gtexr_arguments
#'
#' @return A tibble.
#' @export
#' @family Reference Genome Endpoints
#'
#' @examples
#' \dontrun{
#' get_exons(gencodeId = "ENSG00000203782.5")
#' }
get_exons <- function(gencodeId,
gencodeVersion = NULL,
genomeBuild = NULL,
Expand Down
8 changes: 6 additions & 2 deletions R/get_gene_search.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#' Get Gene Search
#'
#' [Find genes that are partial or complete match of a
#' gene_id](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_gene_search_api_v2_reference_geneSearch_get)
#' @description Find genes that are partial or complete match of a gene_id
#'
#' - gene_id could be a gene symbol, a gencode ID, or an Ensemble ID
#' - Gencode Version and Genome Build must be specified
#'
#' [GTEx Portal API
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_gene_search_api_v2_reference_geneSearch_get)
#'
#' @inheritParams gtexr_arguments
#'
#' @return A tibble.
#' @export
#' @family Reference Genome Endpoints
#'
#' @examples
#' \dontrun{
#' get_gene_search("CRP")
#' }
get_gene_search <- function(geneId,
gencodeVersion = "v26",
genomeBuild = "GRCh38/hg38",
Expand Down
9 changes: 6 additions & 3 deletions R/get_genes.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#' Get Genes
#'
#' This service returns information about reference genes. A genome build and
#' GENCODE version must be provided.
#' @description This service returns information about reference genes. A genome
#' build and GENCODE version must be provided.
#'
#' - Genes are searchable by gene symbol, GENCODE ID and versioned GENCODE ID.
#' - Versioned GENCODE ID is recommended to ensure unique ID matching.
#' - By default, this service queries the genome build and GENCODE version used by the latest GTEx release.
#'
#' [GTEx API Portal docs](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_genes_api_v2_reference_gene_get)
#' [GTEx API Portal
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_genes_api_v2_reference_gene_get)
#'
#' @inheritParams gtexr_arguments
#'
Expand All @@ -16,7 +17,9 @@
#' @family Reference Genome Endpoints
#'
#' @examples
#' \dontrun{
#' get_genes(c("CRP", "IL6R"))
#' }
get_genes <- function(geneIds,
gencodeVersion = "v26",
genomeBuild = "GRCh38/hg38",
Expand Down
23 changes: 13 additions & 10 deletions R/get_genomic_features.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' Get Genomic Features
#'
#' @description [GTEx API Portal
#' docs](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_genomic_features_api_v2_reference_features__featureId__get)
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_genomic_features_api_v2_reference_features__featureId__get)
#'
#' @details This endpoint takes a path parameter "featureId".
#'
#' @inheritParams gtexr_arguments
#'
#' @return A tibble
#' @return A tibble.
#' @export
#' @family Reference Genome Endpoints
#'
Expand All @@ -25,20 +25,17 @@
#' # GTEx variant ID
#' get_genomic_features("chr11_66561023_G_GTTA_b38")
#' }
get_genomic_features <- function(.featureId,
datasetId = "gtex_v8") {

get_genomic_features <- function(.featureId, datasetId = "gtex_v8") {
# validate `.featureId`
validate_featureId(.featureId)

# perform query
gtex_query(endpoint = paste0("reference/features/", .featureId),
return_raw = TRUE) |>
return_raw = TRUE) |>
process_get_genomic_features_resp_json(.featureId = .featureId)
}

process_get_genomic_features_resp_json <- function(resp_json, .featureId) {

if (rlang::is_empty(resp_json$features)) {
result <- tibble::tibble(assembly = resp_json$assembly)
} else {
Expand All @@ -51,9 +48,15 @@ process_get_genomic_features_resp_json <- function(resp_json, .featureId) {

validate_featureId <- function(.featureId) {
if (!rlang::is_string(.featureId)) {
cli::cli_abort(c("!" = "Invalid `.featureId` input",
"x" = cli::format_inline("You supplied: {class(.featureId)} of length {length(.featureId)}"),
"i" = "`.featureId` must be a single string"))
cli::cli_abort(
c(
"!" = "Invalid `.featureId` input",
"x" = cli::format_inline(
"You supplied: {class(.featureId)} of length {length(.featureId)}"
),
"i" = "`.featureId` must be a single string"
)
)
}

if (grepl("[^a-zA-Z0-9_.]", .featureId)) {
Expand Down
17 changes: 12 additions & 5 deletions R/get_gwas_catalog_by_location.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#' Get Gwas Catalog By Location
#' Find the GWAS Catalog on a certain chromosome between start and end locations.
#'
#' @description Find the GWAS Catalog on a certain chromosome between start and
#' end locations.
#'
#' [GTEx API Portal
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_gwas_catalog_by_location_api_v2_reference_gwasCatalogByLocation_get)
#'
#' @inheritParams gtexr_arguments
#'
Expand All @@ -8,11 +13,13 @@
#' @family Reference Genome Endpoints
#'
#' @examples
#' \dontrun{
#' get_gwas_catalog_by_location(start = 1, end = 10000000, chromosome = "chr1")
#' }
get_gwas_catalog_by_location <- function(start,
end,
chromosome,
page = 0,
itemsPerPage = 250) {
end,
chromosome,
page = 0,
itemsPerPage = 250) {
gtex_query(endpoint = "reference/gwasCatalogByLocation")
}
17 changes: 12 additions & 5 deletions R/get_neighbor_gene.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#' Get Neighbor Gene
#' Find all neighboring genes on a certain chromosome around a position with a certain window size.
#'
#' @description Find all neighboring genes on a certain chromosome around a
#' position with a certain window size.
#'
#' [GTEx API Portal
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_neighbor_gene_api_v2_reference_neighborGene_get)
#'
#' @inheritParams gtexr_arguments
#'
Expand All @@ -8,11 +13,13 @@
#' @family Reference Genome Endpoints
#'
#' @examples
#' \dontrun{
#' get_neighbor_gene(pos = 1000000, chromosome = "chr1", bp_window = 10000)
#' }
get_neighbor_gene <- function(pos,
chromosome,
bp_window,
page = 0,
itemsPerPage = 250) {
chromosome,
bp_window,
page = 0,
itemsPerPage = 250) {
gtex_query(endpoint = "reference/neighborGene")
}
15 changes: 10 additions & 5 deletions R/get_transcripts.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
#' Get Transcripts
#'
#' Find all transcripts of a reference gene.
#' @description Find all transcripts of a reference gene.
#'
#' - This service returns information about transcripts of the given versioned GENCODE ID.
#' - A genome build and GENCODE version must be provided.
#' - By default, this service queries the genome build and GENCODE version used by the latest GTEx release.
#'
#' [GTEx API Portal
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Reference-Genome-Endpoints/operation/get_transcripts_api_v2_reference_transcript_get)
#'
#' @inheritParams gtexr_arguments
#'
#' @return A tibble.
#' @export
#' @family Reference Genome Endpoints
#'
#' @examples
#' \dontrun{
#' get_transcripts(gencodeId = "ENSG00000203782.5")
#' }
get_transcripts <- function(gencodeId,
gencodeVersion = "v26",
genomeBuild = "GRCh38/hg38",
page = 0,
itemsPerPage = 250) {
gencodeVersion = "v26",
genomeBuild = "GRCh38/hg38",
page = 0,
itemsPerPage = 250) {
gtex_query(endpoint = "reference/transcript")
}
6 changes: 4 additions & 2 deletions man/get_exons.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/get_gene_search.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/get_genes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/get_genomic_features.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions man/get_gwas_catalog_by_location.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions man/get_neighbor_gene.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/get_transcripts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 06ece1e

Please sign in to comment.