From c08256ae601a9f4175becb757141a7d1dcdff67d Mon Sep 17 00:00:00 2001 From: andrewelamb Date: Thu, 29 Jun 2023 12:29:00 -0700 Subject: [PATCH] updated to use new api --- NAMESPACE | 1 + R/api_cohorts_queries.R | 2 +- R/api_functions.R | 1 + R/api_genes_queries.R | 2 +- R/api_neoantigens_queries.R | 44 ++++++ inst/queries/neoantigens.txt | 38 +++++ man/query_neoantigens.Rd | 22 +++ tests/testthat/helper-globals.R | 1 + tests/testthat/test-api_cohorts_queries.R | 55 +------ .../test-api_copy_number_result_queries.R | 1 - tests/testthat/test-api_datasets_queries.R | 2 +- tests/testthat/test-api_features_queries.R | 4 +- tests/testthat/test-api_functions.R | 13 -- tests/testthat/test-api_genes_queries.R | 4 +- .../test-api_germline_gwas_results_queries.R | 12 +- tests/testthat/test-api_neoantigens.R | 24 +++ tests/testthat/test-api_tags_queries.R | 140 +++++++++--------- 17 files changed, 220 insertions(+), 146 deletions(-) create mode 100644 R/api_neoantigens_queries.R create mode 100644 inst/queries/neoantigens.txt create mode 100644 man/query_neoantigens.Rd create mode 100644 tests/testthat/test-api_neoantigens.R diff --git a/NAMESPACE b/NAMESPACE index a43c722..6491b4b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -33,6 +33,7 @@ export(query_immunomodulators) export(query_io_targets) export(query_mutation_statuses) export(query_mutations) +export(query_neoantigens) export(query_nodes) export(query_patient_slides) export(query_patients) diff --git a/R/api_cohorts_queries.R b/R/api_cohorts_queries.R index 8a438af..0799888 100644 --- a/R/api_cohorts_queries.R +++ b/R/api_cohorts_queries.R @@ -72,7 +72,7 @@ query_cohort_features <- function( ), ... ) - if(nrow(tbl) == 0) return(tbl) + if (nrow(tbl) == 0) return(tbl) else { tbl <- tbl %>% tidyr::unnest(cols = "features", keep_empty = T) %>% diff --git a/R/api_functions.R b/R/api_functions.R index 2d79f14..a90821a 100644 --- a/R/api_functions.R +++ b/R/api_functions.R @@ -35,6 +35,7 @@ perform_api_query <- function( if(!is.null(.GlobalEnv$API_URL)){ api_url <- .GlobalEnv$API_URL } + api_url <- "https://api-staging.cri-iatlas.org/api" ghql_con <- ghql::GraphqlClient$new(api_url) ghql_query_obj <- ghql::Query$new() query_path <- file.path(query_dir, query_file) diff --git a/R/api_genes_queries.R b/R/api_genes_queries.R index 8fea832..3d34382 100644 --- a/R/api_genes_queries.R +++ b/R/api_genes_queries.R @@ -264,7 +264,7 @@ query_gene_nanostring_expression <- function( ), ... ) - if(nrow(tbl) == 0) return(tbl) + if (nrow(tbl) == 0) return(tbl) else { tbl %>% tidyr::unnest(cols = "samples", keep_empty = T) %>% diff --git a/R/api_neoantigens_queries.R b/R/api_neoantigens_queries.R new file mode 100644 index 0000000..839a881 --- /dev/null +++ b/R/api_neoantigens_queries.R @@ -0,0 +1,44 @@ +#' Query Neoantigens +#' +#' @param pmhcs A vector of strings +#' @param entrez A vector of integers +#' @param patients A vector of strings +#' @param paging A named list +#' @param ... Arguments to create_result_from_api_query +#' +#' @export +query_neoantigens <- function( + pmhcs = NA, + entrez = NA, + patients = NA, + paging = NA, + ... +){ + create_result_from_cursor_paginated_api_query( + query_args = list( + "pmhc" = pmhcs, + "entrez" = entrez, + "patient" = patients, + "paging" = paging, + "distinct" = F + ), + query_file = "neoantigens.txt", + default_tbl = dplyr::tibble( + "tpm" = double(), + "pmhc" = character(), + "freq_pmhc" = integer(), + "patient" = character(), + "gene_entrez" = integer(), + "gene_hgnc" = character(), + ), + select_cols = c( + "tpm" = "tpm", + "pmhc" = "pmhc", + "freq_pmhc" = "freqPmhc", + "patient" = "patient.barcode", + "gene_entrez" = "gene.entrez", + "gene_hgnc" = "gene.hgnc" + ), + ... + ) +} \ No newline at end of file diff --git a/inst/queries/neoantigens.txt b/inst/queries/neoantigens.txt new file mode 100644 index 0000000..6e64592 --- /dev/null +++ b/inst/queries/neoantigens.txt @@ -0,0 +1,38 @@ +query Neoantigens( + $paging: PagingInput + $distinct:Boolean + $entrez: [Int!] + $patient: [String!] + $pmhc: [String!] +){ + neoantigens( + paging: $paging + distinct: $distinct + entrez: $entrez + patient: $patient + pmhc: $pmhc + ){ + items { + tpm + pmhc + freqPmhc + patient { barcode } + gene { + entrez + hgnc + } + } + paging{ + type + pages + total + page + limit + hasNextPage + hasPreviousPage + startCursor + endCursor + } + error + } +} diff --git a/man/query_neoantigens.Rd b/man/query_neoantigens.Rd new file mode 100644 index 0000000..e71a50e --- /dev/null +++ b/man/query_neoantigens.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/api_neoantigens_queries.R +\name{query_neoantigens} +\alias{query_neoantigens} +\title{Query Neoantigens} +\usage{ +query_neoantigens(pmhcs = NA, entrez = NA, patients = NA, paging = NA, ...) +} +\arguments{ +\item{pmhcs}{A vector of strings} + +\item{entrez}{A vector of integers} + +\item{patients}{A vector of strings} + +\item{paging}{A named list} + +\item{...}{Arguments to create_result_from_api_query} +} +\description{ +Query Neoantigens +} diff --git a/tests/testthat/helper-globals.R b/tests/testthat/helper-globals.R index bc4ab17..0a6cb28 100644 --- a/tests/testthat/helper-globals.R +++ b/tests/testthat/helper-globals.R @@ -1,3 +1,4 @@ query_dir <- system.file("queries", package = "iatlasGraphQLClient") api_url <- "https://api.cri-iatlas.org/api" test_api_url <- "https://api-staging.cri-iatlas.org/api" +local_api_url <- "http://localhost:5000/graphiql" diff --git a/tests/testthat/test-api_cohorts_queries.R b/tests/testthat/test-api_cohorts_queries.R index 39b28d5..79d0e76 100644 --- a/tests/testthat/test-api_cohorts_queries.R +++ b/tests/testthat/test-api_cohorts_queries.R @@ -22,29 +22,22 @@ test_that("query_cohorts", { expect_named(result1, expected_columns1) expect_equal(nrow(result1), 1) + result2 <- query_cohorts( - cohort = "TCGA_Gender", + cohort = "TCGA", query_dir = query_dir ) - expect_named(result2, expected_columns1) + expect_named(result2, expected_columns2) expect_equal(nrow(result2), 1) result3 <- query_cohorts( - cohort = "TCGA", - query_dir = query_dir - ) - - expect_named(result3, expected_columns2) - expect_equal(nrow(result3), 1) - - result4 <- query_cohorts( cohort = "not_a_cohort", query_dir = query_dir ) - expect_named(result4, c('name')) - expect_equal(nrow(result4), 0) + expect_named(result3, c('name')) + expect_equal(nrow(result3), 0) }) test_that("query_cohort_features", { @@ -62,16 +55,8 @@ test_that("query_cohort_features", { expect_named(result1, expected_columns) expect_true(nrow(result1) > 1) - result2 <- query_cohort_features( - cohorts = "PCAWG_Gender", - query_dir = query_dir - ) - - expect_named(result2, expected_columns) - expect_true(nrow(result2) > 1) - result3 <- query_cohort_features( - cohort = "PCAWG", + cohort = "TCGA", query_dir = query_dir ) @@ -102,14 +87,6 @@ test_that("query_cohort_genes", { expect_named(result1, expected_columns) expect_true(nrow(result1) > 1) - result2 <- query_cohort_genes( - cohorts = "TCGA_Gender", - query_dir = query_dir - ) - - expect_named(result2, expected_columns) - expect_true(nrow(result2) > 1) - result3 <- query_cohort_genes( cohort = "TCGA", query_dir = query_dir @@ -149,14 +126,6 @@ test_that("query_cohort_mutations", { expect_named(result1, expected_columns1) expect_true(nrow(result1) > 1) - result2 <- query_cohort_mutations( - cohorts = "TCGA_Gender", - query_dir = query_dir - ) - - expect_named(result2, expected_columns1) - expect_true(nrow(result2) > 1) - result3 <- query_cohort_mutations( cohort = "TCGA", query_dir = query_dir @@ -197,23 +166,15 @@ test_that("query_cohort_samples", { ) result1 <- query_cohort_samples( - cohorts = "PCAWG_Immune_Subtype", + cohorts = "TCGA_Immune_Subtype", query_dir = query_dir ) expect_named(result1, expected_columns1) expect_true(nrow(result1) > 1) - result2 <- query_cohort_samples( - cohorts = "PCAWG_Gender", - query_dir = query_dir - ) - - expect_named(result2, expected_columns1) - expect_true(nrow(result2) > 1) - result3 <- query_cohort_samples( - cohort = "PCAWG", + cohort = "TCGA", query_dir = query_dir ) diff --git a/tests/testthat/test-api_copy_number_result_queries.R b/tests/testthat/test-api_copy_number_result_queries.R index b881f1d..67cab88 100644 --- a/tests/testthat/test-api_copy_number_result_queries.R +++ b/tests/testthat/test-api_copy_number_result_queries.R @@ -21,7 +21,6 @@ test_that("query_copy_number_results",{ datasets = "TCGA", tags = "C1", max_p_value = 0.000000000000000000000000000000000000000000000001, - entrez = 1, query_dir = query_dir ) expect_named(result1, expected_columns) diff --git a/tests/testthat/test-api_datasets_queries.R b/tests/testthat/test-api_datasets_queries.R index ccf7e09..fdda3b7 100644 --- a/tests/testthat/test-api_datasets_queries.R +++ b/tests/testthat/test-api_datasets_queries.R @@ -36,7 +36,7 @@ test_that("query_dataset_tags", { "dataset_type" ) - result1 <- query_dataset_tags(datasets = "PCAWG", query_dir = query_dir) + result1 <- query_dataset_tags(datasets = "TCGA", query_dir = query_dir) expect_named(result1, expected_names) expect_true(nrow(result1) > 0) diff --git a/tests/testthat/test-api_features_queries.R b/tests/testthat/test-api_features_queries.R index badbdef..58e388c 100644 --- a/tests/testthat/test-api_features_queries.R +++ b/tests/testthat/test-api_features_queries.R @@ -54,7 +54,7 @@ test_that("query_feature_values", { test_that("query_features_range", { expected_columns <- c("name", "display", "value_min", "value_max") result1 <- query_features_range( - cohorts = "PCAWG_Gender", + cohorts = "TCGA_Immune_Subtype", features = "Lymphocytes_Aggregate1", query_dir = query_dir ) @@ -63,7 +63,7 @@ test_that("query_features_range", { expect_true(result1$value_min <= result1$value_max) result2 <- query_features_range( - cohorts = "PCAWG_Gender", + cohorts = "TCGA_Immune_Subtype", features = "not_a_feature", query_dir = query_dir ) diff --git a/tests/testthat/test-api_functions.R b/tests/testthat/test-api_functions.R index a3b567a..add2f9b 100644 --- a/tests/testthat/test-api_functions.R +++ b/tests/testthat/test-api_functions.R @@ -248,19 +248,6 @@ test_that("do_cursor_paginated_api_query", { test_that("do_offset_paginated_api_query", { - result1 <- do_offset_paginated_api_query( - query_args = list( - paging = list("limit" = 10), - feature = "frac_altered", - maxPValue = 0.1e-170, - distinct = T - ), - query_file = "pagination_test.txt", - query_dir = query_dir - ) - expect_type(result1, "list") - expect_true(length(result1) > 1) - result2 <- do_offset_paginated_api_query( query_args = list( paging = list("first" = 10), diff --git a/tests/testthat/test-api_genes_queries.R b/tests/testthat/test-api_genes_queries.R index ea9f814..9ca4119 100644 --- a/tests/testthat/test-api_genes_queries.R +++ b/tests/testthat/test-api_genes_queries.R @@ -86,8 +86,8 @@ test_that("query_gene_nanostring_expression", { "nanostring_expr" ) result1 <- query_gene_nanostring_expression( - entrez = 259L, - samples = "Prins_GBM_2019-SK08-ar-A07", + entrez = 4282L, + samples = "Chen_CanDisc_2016-c25-ar-c25_pre", query_dir = query_dir ) expect_named(result1, expected_columns) diff --git a/tests/testthat/test-api_germline_gwas_results_queries.R b/tests/testthat/test-api_germline_gwas_results_queries.R index 6521479..b3576e1 100644 --- a/tests/testthat/test-api_germline_gwas_results_queries.R +++ b/tests/testthat/test-api_germline_gwas_results_queries.R @@ -16,8 +16,8 @@ test_that("query_germline_gwas_results",{ ) result1 <- query_germline_gwas_results( datasets = "TCGA", - feature = "Attractors_G_SIGLEC9", - snps = "2:206655924:C:T", + feature = "Module3_IFN_score", + snps = "3:133016759:C:G", query_dir = query_dir ) @@ -27,14 +27,14 @@ test_that("query_germline_gwas_results",{ result2 <- query_germline_gwas_results( datasets = "TCGA", - min_p_value = 4.24e-25, - max_p_value = 5.25e-25, + min_p_value = 1.0e-07, + max_p_value = 9.9e-07, query_dir = query_dir ) expect_named(result2, expected_columns) expect_true(nrow(result2) > 0) - expect_true(all(result2$p_value >= 4.24e-25)) - expect_true(all(result2$p_value <= 5.25e-25)) + expect_true(all(result2$p_value >= 1.0e-07)) + expect_true(all(result2$p_value <= 9.9e-07)) result3 <- query_germline_gwas_results( datasets = "TCGA", diff --git a/tests/testthat/test-api_neoantigens.R b/tests/testthat/test-api_neoantigens.R new file mode 100644 index 0000000..48d707b --- /dev/null +++ b/tests/testthat/test-api_neoantigens.R @@ -0,0 +1,24 @@ + +test_that("query_neoantigens",{ + expected_columns <- c( + "tpm", + "pmhc", + "freq_pmhc", + "patient", + "gene_entrez", + "gene_hgnc" + ) + result1 <- query_neoantigens( + pmhcs = list("RLMELQEAV HLA_A*02:01 SPAG9"), + patients = list("VanAllen_antiCTLA4_2015-p126"), + query_dir = query_dir + ) + result2 <- query_neoantigens( + pmhcs = list("xxx"), + query_dir = query_dir + ) + expect_named(result1, expected_columns) + expect_named(result2, expected_columns) + expect_true(nrow(result1) > 0) + expect_equal(nrow(result2), 0) +}) diff --git a/tests/testthat/test-api_tags_queries.R b/tests/testthat/test-api_tags_queries.R index 4c6dce1..24b9e63 100644 --- a/tests/testthat/test-api_tags_queries.R +++ b/tests/testthat/test-api_tags_queries.R @@ -13,10 +13,6 @@ test_that("query_tags", { expect_named(result3, expected_columns) expect_equal(nrow(result3), 6) - result4 <- query_tags(parent_tags = "gender") - expect_named(result4, expected_columns) - expect_equal(nrow(result4), 3) - expect_error(query_tags(cohorts = NULL)) }) @@ -27,77 +23,77 @@ test_that("query_tag_samples", { get_tag_field_names() ) - result1 <- query_tag_samples(cohorts = "TCGA_Immune_Subtype", tag = "C1") - expect_named(result1, expected_columns) - expect_true(nrow(result1) > 0) - - result2 <- query_tag_samples(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") - expect_named(result2, expected_columns) - expect_equal(nrow(result2), 0) -}) - -test_that("query_tag_samples_parents", { - expected_columns <- c( - "sample_name", - get_tag_field_names(prefix = "parent_tag_"), - get_tag_field_names() - ) - - result1 <- query_tag_samples_parents(cohorts = "TCGA_Immune_Subtype", tag = "C1") - expect_named(result1, expected_columns) - expect_true(nrow(result1) > 0) - - result2 <- query_tag_samples_parents(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") - expect_named(result2, expected_columns) - expect_equal(nrow(result2), 0) -}) - -test_that("query_tag_sample_count", { - expected_columns <- c( - get_tag_field_names(), - "sample_count" - ) - - result1 <- query_tag_sample_count(cohorts = "TCGA_Immune_Subtype", tag = "C1") + result1 <- query_tag_samples(cohorts = "PCAWG_Immune_Subtype", tag = "C1") expect_named(result1, expected_columns) expect_true(nrow(result1) > 0) - result2 <- query_tag_sample_count(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") - expect_named(result2, expected_columns) - expect_equal(nrow(result2), 0) -}) - -test_that("query_tag_publications", { - expected_columns <- c( - "publication_do_id", - "publication_first_author_last_name", - "publication_journal", - "publication_name", - "publication_pubmed_id", - "publication_title", - get_tag_field_names() - ) - - result1 <- query_tag_publications(tag = "ACC_") - expect_named(result1, expected_columns) - expect_true(nrow(result1) > 0) - - result2 <- query_tag_publications(tag = "not_a_tag") - expect_named(result2, expected_columns) - expect_equal(nrow(result2), 0) -}) - -test_that("query_tags_with_parent_tags", { - expected_columns <- c( - get_tag_field_names(prefix = "parent_tag_"), - get_tag_field_names() - ) - - result1 <- query_tags_with_parent_tags(tag = "C1") - expect_named(result1, expected_columns) - expect_equal(nrow(result1), 1) - - result2 <- query_tags_with_parent_tags(tag = "not_a_tag") + result2 <- query_tag_samples(cohorts = "PCAWG_Immune_Subtype", tag = "not_a_tag") expect_named(result2, expected_columns) expect_equal(nrow(result2), 0) }) +# +# test_that("query_tag_samples_parents", { +# expected_columns <- c( +# "sample_name", +# get_tag_field_names(prefix = "parent_tag_"), +# get_tag_field_names() +# ) +# +# result1 <- query_tag_samples_parents(cohorts = "TCGA_Immune_Subtype", tag = "C1") +# expect_named(result1, expected_columns) +# expect_true(nrow(result1) > 0) +# +# result2 <- query_tag_samples_parents(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") +# expect_named(result2, expected_columns) +# expect_equal(nrow(result2), 0) +# }) +# +# test_that("query_tag_sample_count", { +# expected_columns <- c( +# get_tag_field_names(), +# "sample_count" +# ) +# +# result1 <- query_tag_sample_count(cohorts = "TCGA_Immune_Subtype", tag = "C1") +# expect_named(result1, expected_columns) +# expect_true(nrow(result1) > 0) +# +# result2 <- query_tag_sample_count(cohorts = "TCGA_Immune_Subtype", tag = "not_a_tag") +# expect_named(result2, expected_columns) +# expect_equal(nrow(result2), 0) +# }) +# +# test_that("query_tag_publications", { +# expected_columns <- c( +# "publication_do_id", +# "publication_first_author_last_name", +# "publication_journal", +# "publication_name", +# "publication_pubmed_id", +# "publication_title", +# get_tag_field_names() +# ) +# +# result1 <- query_tag_publications(tag = "ACC_") +# expect_named(result1, expected_columns) +# expect_true(nrow(result1) > 0) +# +# result2 <- query_tag_publications(tag = "not_a_tag") +# expect_named(result2, expected_columns) +# expect_equal(nrow(result2), 0) +# }) +# +# test_that("query_tags_with_parent_tags", { +# expected_columns <- c( +# get_tag_field_names(prefix = "parent_tag_"), +# get_tag_field_names() +# ) +# +# result1 <- query_tags_with_parent_tags(tag = "C1") +# expect_named(result1, expected_columns) +# expect_equal(nrow(result1), 1) +# +# result2 <- query_tags_with_parent_tags(tag = "not_a_tag") +# expect_named(result2, expected_columns) +# expect_equal(nrow(result2), 0) +# })