Skip to content

Commit

Permalink
complete dynamic association endpoints; also rename calculate_eqtls()…
Browse files Browse the repository at this point in the history
… to calculate_splicing_quantitative_trait_loci()
  • Loading branch information
rmgpanw committed May 28, 2024
1 parent 340bf80 commit 71b8efa
Show file tree
Hide file tree
Showing 20 changed files with 423 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
^README\.Rmd$
^codecov\.yml$
^.vscode$
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ docs
.vscode
inst/doc
.Renviron
/doc/
/Meta/
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Generated by roxygen2: do not edit by hand

export(available_tissueSiteDetailIds)
export(calculate_eqtls)
export(calculate_expression_quantitative_trait_loci)
export(calculate_ieqtls)
export(calculate_isqtls)
export(calculate_splicing_quantitative_trait_loci)
export(get_annotation)
export(get_clustered_median_exon_expression)
export(get_clustered_median_gene_expression)
Expand Down
44 changes: 0 additions & 44 deletions R/calculate_eqtls.R

This file was deleted.

91 changes: 91 additions & 0 deletions R/calculate_expression_quantitative_trait_loci.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#' Calculate Expression Quantitative Trait Loci
#'
#' @description Calculate your own eQTLs
#'
#' - This service calculates the gene-variant association for any given pair of gene and variant, which may or may not be significant.
#' - This requires as input a GENCODE ID, GTEx variant ID, and tissue site detail ID.
#'
#' By default, the calculation is based on the latest GTEx release.
#'
#' [GTEx Portal API documentation](https://gtexportal.org/api/v2/redoc#tag/Dynamic-Association-Endpoints/operation/calculate_expression_quantitative_trait_loci_api_v2_association_dyneqtl_get).
#'
#' @details Notes on output:
#'
#' * Beta and standard error are recorded in columns `nes` and `error` respectively (see [GTEx FAQs](https://gtexportal.org/home/faq#nes_beta))
#' * `variantId` contains (in order) chromosome, position, reference allele, alternative allele and human genome build separated by underscores. The reference and alternative alleles for "chr1_13550_G_A_b38" for example are "G" and "A" respectively.
#' * See examples for how to calculate minor and alternative allele frequencies.
#'
#' Notes on input:
#'
#' * Argument `variantId` also accepts RSIDs.
#'
#' @inheritParams gtexr_arguments
#'
#' @return A tibble.
#' @export
#' @family Dynamic Association Endpoints
#'
#' @examples
#' \dontrun{
#' # perform request - returns a tibble with a single row
#' calculate_expression_quantitative_trait_loci(tissueSiteDetailId = "Whole_Blood",
#' gencodeId = "ENSG00000203782.5",
#' variantId = "rs79641866")
#'
#' # unnest list columns with tidyr::unnest()
#' calculate_expression_quantitative_trait_loci(tissueSiteDetailId = "Whole_Blood",
#' gencodeId = "ENSG00000203782.5",
#' variantId = "rs79641866") |>
#' tidyr::unnest(c("data", "genotypes"))
#'
#' # to calculate minor and alternative allele frequencies
#' calculate_expression_quantitative_trait_loci(
#' tissueSiteDetailId = "Liver",
#' gencodeId = "ENSG00000237973.1",
#' variantId = "rs12119111"
#' ) |>
#' dplyr::bind_rows(.id = "rsid") |>
#'
#' tidyr::separate(
#' col = "variantId",
#' into = c(
#' "chromosome",
#' "position",
#' "reference_allele",
#' "alternative_allele",
#' "genome_build"
#' ),
#' sep = "_"
#' ) |>
#'
#' # ...then ascertain alternative_allele frequency
#' dplyr::mutate(
#' alt_allele_count = (2 * homoAltCount) + hetCount,
#' total_allele_count = 2 * (homoAltCount + hetCount + homoRefCount),
#' alternative_allele_frequency = alt_allele_count / total_allele_count
#' ) |>
#'
#' dplyr::select(
#' rsid,
#' beta = nes,
#' se = error,
#' pValue,
#' minor_allele_frequency = maf,
#' alternative_allele_frequency,
#' chromosome:genome_build,
#' tissueSiteDetailId
#' )
#' }
calculate_expression_quantitative_trait_loci <- function(tissueSiteDetailId,
gencodeId,
variantId,
datasetId = "gtex_v8") {
result <- gtex_query("association/dyneqtl",
return_raw = TRUE)
result$data <- list(tibble::tibble(data = as.numeric(result$data)))
result$genotypes <- list(tibble::tibble(genotypes = as.integer(result$genotypes)))

result <- tibble::as_tibble(result)

return(result)
}
13 changes: 8 additions & 5 deletions R/calculate_ieqtls.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#' Calculate Ieqtls
#'
#'Calculate your own Cell Specific eQTLs.
#' @description Calculate your own Cell Specific eQTLs.
#'
#'- This service calculates the gene-variant association for any given pair of gene and variant, which may or may not be significant.
#'- This requires as input a GENCODE ID, GTEx variant ID, and tissue site detail ID.
#'By default, the calculation is based on the latest GTEx release.
#' - This service calculates the gene-variant association for any given pair of gene and variant, which may or may not be significant.
#' - This requires as input a GENCODE ID, GTEx variant ID, and tissue site detail ID.
#'
#' By default, the calculation is based on the latest GTEx release.
#'
#' [GTEx Portal API documentation](https://gtexportal.org/api/v2/redoc#tag/Dynamic-Association-Endpoints/operation/calculate_ieqtls_api_v2_association_dynieqtl_get).
#'
#' @inheritParams gtexr_arguments
#'
Expand All @@ -19,7 +22,7 @@
#' tissueSiteDetailId = "Adipose_Subcutaneous",
#' gencodeId = "ENSG00000203782.5",
#' variantId = "chr1_1099341_T_C_b38")
#'}
#' }
calculate_ieqtls <-
function(cellType,
tissueSiteDetailId,
Expand Down
41 changes: 41 additions & 0 deletions R/calculate_isqtls.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Calculate Isqtls
#'
#' @description Calculate your own Cell Specific sQTLs.
#'
#' - This service calculates the gene-variant association for any given pair of gene and variant, which may or may not be significant.
#' - This requires as input a GENCODE ID, GTEx variant ID, and tissue site detail ID.
#'
#' By default, the calculation is based on the latest GTEx release.
#'
#' [GTEx Portal API documentation](https://gtexportal.org/api/v2/redoc#tag/Dynamic-Association-Endpoints/operation/calculate_ieqtls_api_v2_association_dynieqtl_get).
#'
#' @inheritParams gtexr_arguments
#'
#' @return A tibble.
#' @export
#' @family Dynamic Association Endpoints
#'
#' @examples
#' \dontrun{
#' # perform request
#' calculate_isqtls(cellType = "Neutrophils",
#' tissueSiteDetailId = "Whole_Blood",
#' phenotypeId = "chr1:15947:16607:clu_40980:ENSG00000227232.5",
#' variantId = "chr1_1099341_T_C_b38")
#' }
calculate_isqtls <-
function(cellType,
tissueSiteDetailId,
phenotypeId,
variantId,
datasetId = "gtex_v8") {
gtex_query(endpoint = "association/dynisqtl", return_raw = TRUE) |>
purrr::imap(\(x, idx) ifelse(is.list(x),
tibble::tibble(
data = purrr::map_depth(x,
purrr::pluck_depth(x) - 2,
unlist)
),
x)) |>
tibble::as_tibble()
}
31 changes: 31 additions & 0 deletions R/calculate_splicing_quantitative_trait_loci.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Calculate Splicing Quantitative Trait Loci
#'
#' @description
#' [GTEx Portal API documentation](https://gtexportal.org/api/v2/redoc#tag/Dynamic-Association-Endpoints/operation/calculate_splicing_quantitative_trait_loci_api_v2_association_dynsqtl_get).
#'
#' @inheritParams gtexr_arguments
#'
#' @return A tibble.
#' @export
#' @family Dynamic Association Endpoints
#'
#' @examples
#' \dontrun{
#' # perform request - returns a tibble with a single row
#' calculate_splicing_quantitative_trait_loci(
#' tissueSiteDetailId = "Whole_Blood",
#' phenotypeId = "chr1:15947:16607:clu_40980:ENSG00000227232.5",
#' variantId = "chr1_14677_G_A_b38")
#' }
calculate_splicing_quantitative_trait_loci <- function(tissueSiteDetailId,
phenotypeId,
variantId,
datasetId = "gtex_v8") {
result <- gtex_query("association/dynsqtl", return_raw = TRUE)
result$data <- list(tibble::tibble(data = as.numeric(result$data)))
result$genotypes <- list(tibble::tibble(genotypes = as.integer(result$genotypes)))

result <- tibble::as_tibble(result)

return(result)
}
4 changes: 4 additions & 0 deletions R/gtexr_arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#' "pancreatitis", "pigment", "pneumonia", "post_menopausal", "prostatitis",
#' "saponification", "scarring", "sclerotic", "solar_elastosis",
#' "spermatogenesis", "steatosis", "sweat_glands", "tma".
#' @param phenotypeId String. See
#' [GTEx portal FAQs](https://www.gtexportal.org/home/faq#splicingPhenotypeId)
#' for further details.
#' @param pos Integer, vector.
#' @param project_id String. Options: "gtex", "adult-gtex", "egtex".
#' @param rin Integer vector.
Expand Down Expand Up @@ -123,6 +126,7 @@ gtexr_arguments <- function() {
"organizationName", "character", TRUE, FALSE, "selectInput", c("GTEx Consortium", "Kid's First"),
"page", "integer", TRUE, FALSE, "numericInput", c(0, 1000000),
"pathCategory", "character", FALSE, FALSE, "selectInput", c("adenoma", "amylacea", "atelectasis", "atherosclerosis", "atherosis", "atrophy", "calcification", "cirrhosis", "clean_specimens", "congestion", "corpora_albicantia", "cyst", "desquamation", "diabetic", "dysplasia", "edema", "emphysema", "esophagitis", "fibrosis", "gastritis", "glomerulosclerosis", "goiter", "gynecomastoid", "hashimoto", "heart_failure_cells", "hemorrhage", "hepatitis", "hyalinization", "hypereosinophilia", "hyperplasia", "hypertrophy", "hypoxic", "infarction", "inflammation", "ischemic_changes", "macrophages", "mastopathy", "metaplasia", "monckeberg", "necrosis", "nephritis", "nephrosclerosis", "no_abnormalities", "nodularity", "pancreatitis", "pigment", "pneumonia", "post_menopausal", "prostatitis", "saponification", "scarring", "sclerotic", "solar_elastosis", "spermatogenesis", "steatosis", "sweat_glands", "tma"),
"phenotypeId", "character", TRUE, FALSE, "textInput", NA,
"pos", "integer", FALSE, FALSE, "numericInput", c(0, 248945542),
"project_id", "character", TRUE, FALSE, "selectInput", c("gtex", "adult-gtex", "egtex"),
"rin", "integer", FALSE, FALSE, "numericInput", c(-1e8L, 1e8L),
Expand Down
2 changes: 1 addition & 1 deletion R/validate_args.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ validate_args <- function(arguments,
call) {
metadata <- gtexr_arguments()

# TODO move checks for missing args here, and also any "" values e.g. calculate_eqtls(tissueSiteDetailId = "Whole_Blood",
# TODO move checks for missing args here, and also any "" values e.g. calculate_expression_quantitative_trait_loci(tissueSiteDetailId = "Whole_Blood",
# gencodeId = "",
# variantId = "rs79641866")

Expand Down
2 changes: 1 addition & 1 deletion inst/app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ endpointUI <- function(id, gtexr_fn, gtexr_arguments_metadata, gtexr_functions_m
gtexr_fn_args <- get_gtexr_fn_args(gtexr_fn)
gtexr_fn_metadata <- gtexr_functions_metadata[gtexr_functions_metadata$fn_name == gtexr_fn, ]

# if (gtexr_fn == "calculate_eqtls") {
# if (gtexr_fn == "calculate_expression_quantitative_trait_loci") {
# browser()
# }

Expand Down
61 changes: 0 additions & 61 deletions man/calculate_eqtls.Rd

This file was deleted.

Loading

0 comments on commit 71b8efa

Please sign in to comment.