From e7d319010b987efeef710fbcb9df653ee22f8a0e Mon Sep 17 00:00:00 2001 From: Karl Broman Date: Tue, 25 Oct 2022 15:27:34 -0500 Subject: [PATCH 1/2] query_gn(): look for error in title of output --- R/query_gn.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/R/query_gn.R b/R/query_gn.R index 7a0a453..1ea0a9a 100644 --- a/R/query_gn.R +++ b/R/query_gn.R @@ -11,6 +11,11 @@ query_gn <- result <- httr::GET(url) httr::stop_for_status(result) + + if(error_in_title(result, encoding)) { + stop(attr(error_in_title(result, encoding), "error_text")) + } + result <- httr::content(result, encoding=encoding, as=output) result[vapply(result, is.null, TRUE)] <- NA # added to avoid having as.data.frame(result) crash @@ -18,6 +23,24 @@ query_gn <- check_gn_error(result) } +# if the result is a web page with Error: in the title +error_in_title <- + function(result, encoding="UTF-8") +{ + result_text <- httr::content(result, encoding=encoding, as="text") + error <- regexpr("Error:.*", result_text) + if(error < 0) return(FALSE) + else { + error_text <- substr(result_text, error+13, error+attr(error, "match.length")-23) + error_text <- gsub(""", '"', error_text) + error_text <- gsub("'", "'", error_text) + result <- TRUE + attr(result, "error_text") <- error_text + return(result) + } +} + + # check whether the result is an error check_gn_error <- function(result) From b94ce671764958b8425e9452c87541adf8cc6c8b Mon Sep 17 00:00:00 2001 From: Karl Broman Date: Tue, 25 Oct 2022 15:28:11 -0500 Subject: [PATCH 2/2] Get run_rqtl and run_gemma working again --- DESCRIPTION | 4 ++-- NEWS.md | 21 +++++++++++++++++++++ R/run_stuff.R | 8 ++++---- man/run_gemma.Rd | 2 +- man/run_rqtl.Rd | 4 ++-- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fa31d9f..410ee9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GNapi -Version: 0.3-6 -Date: 2022-09-26 +Version: 0.3-7 +Date: 2022-10-25 Title: Connection to the GeneNetwork API Description: Tools for connecting to the GeneNetwork API. Author: Karl W Broman [aut, cre] () diff --git a/NEWS.md b/NEWS.md index fa2bdfe..1f6ce9d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,24 @@ +## GNapi 0.3-7 (2022-10-25) + +### Bug fixes + +- `run_gemma()` and `run_rqtl()` are working again. + +- Trapped additional errors by looking for `Error:` in title of + output. (in new internal function `error_in_title()`) + + +## GNapi 0.3-6 (2022-09-26) + +### Bug fixes + +- `get_geno()` is working again + +- `info_pheno()` can no longer get a list of traits within a group + +- `list_groups()` no longer takes an individual group name + + ## GNapi 0.3-4 (2021-11-17) ### Bug fixes diff --git a/R/run_stuff.R b/R/run_stuff.R index 49b1088..f4940d2 100644 --- a/R/run_stuff.R +++ b/R/run_stuff.R @@ -14,7 +14,7 @@ #' @export #' #' @examples -#' \dontrun{out <- run_gemma("BXDPublish", "10015")} +#' out <- run_gemma("HC_M2_0606_P", "1418701_at") run_gemma <- function(dataset, trait, use_loco=FALSE, maf=0.01, url=gnapi_url()) { @@ -30,7 +30,7 @@ run_gemma <- "&maf=", maf), url=url, output="parsed") - list2df(result) + list2df(result[[1]]) # not sure why we need the [[1]] } @@ -43,7 +43,7 @@ run_gemma <- #' @param method Indicates whether to use the EM algorithm, imputation, Haley-Knott regression, the extended Haley-Knott method, or marker regression. #' @param model The phenotype model: the usual normal model, a model for binary traits, a two-part model, or non-parametric analysis #' @param n_perm Number of permutations -#' @param control_marker Name of marker to use as control +#' @param control_marker Name of marker to use as a covariate #' @param interval_mapping Whether to use interval mapping #' @param url The URL for the GeneNetwork API #' @@ -53,7 +53,7 @@ run_gemma <- #' @export #' #' @examples -#' \dontrun{out <- run_rqtl("BXDPublish", "10015")} +#' out <- run_rqtl("HC_M2_0606_P", "1418701_at") run_rqtl <- function(dataset, trait, method=c("hk", "ehk", "em", "imp", "mr", "mr-imp", "mr-argmax"), model=c("normal", "binary", "2part", "np"), diff --git a/man/run_gemma.Rd b/man/run_gemma.Rd index 2f1c7e3..58db7d4 100644 --- a/man/run_gemma.Rd +++ b/man/run_gemma.Rd @@ -24,5 +24,5 @@ A data frame Perform a genome scan using gemma } \examples{ -\dontrun{out <- run_gemma("BXDPublish", "10015")} +out <- run_gemma("HC_M2_0606_P", "1418701_at") } diff --git a/man/run_rqtl.Rd b/man/run_rqtl.Rd index 8a1c271..0832bd9 100644 --- a/man/run_rqtl.Rd +++ b/man/run_rqtl.Rd @@ -26,7 +26,7 @@ run_rqtl( \item{n_perm}{Number of permutations} -\item{control_marker}{Name of marker to use as control} +\item{control_marker}{Name of marker to use as a covariate} \item{interval_mapping}{Whether to use interval mapping} @@ -39,5 +39,5 @@ A data frame Perform a genome scan using R/qtl } \examples{ -\dontrun{out <- run_rqtl("BXDPublish", "10015")} +out <- run_rqtl("HC_M2_0606_P", "1418701_at") }