Skip to content

Commit

Permalink
fixing r cmd check
Browse files Browse the repository at this point in the history
  • Loading branch information
explodecomputer committed Mar 12, 2024
1 parent 5738726 commit a4fb057
Show file tree
Hide file tree
Showing 57 changed files with 2,763 additions and 5,193 deletions.
14 changes: 11 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
Package: ieugwasr
Title: R Interface to the OpenGWAS Database API
Version: 0.1.6
Authors@R:
Version: 0.1.7
Authors@R: c(
person("Gibran", "Hemani", , "g.hemani@bristol.ac.uk", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0920-1055"))
comment = c(ORCID = "0000-0003-0920-1055")),
person("Ben", "Elsworth", , "Ben.Elsworth@bristol.ac.uk", role = "aut",
comment = c(ORCID = "0000-0001-7328-4233")),
person("Tom", "Palmer", , "tom.palmer@bristol.ac.uk", role = "aut",
comment = c(ORCID = "0000-0003-4655-4511")),
person("Rita", "Rasteiro", , "rita.rasteiro@bristol.ac.uk", role = "aut",
comment = c(ORCID = "0000-0002-4217-3060"))
)
Description: R interface to the OpenGWAS database API. Includes a wrapper
to make generic calls to the API, plus convenience functions for
specific queries.
Expand All @@ -30,3 +37,4 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
4 changes: 2 additions & 2 deletions R/afl2.r
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ afl2_list <- function(variantlist=c("reduced", "hapmap3")[1])
afl2_rsid <- function(rsid, reference="1000g")
{
out <- api_query("variants/afl2", list(rsid=rsid)) %>% get_query_content()
if(class(out) == "response")
if(inherits(out, "response"))
{
return(out)
} else if(is.data.frame(out)) {
Expand All @@ -60,7 +60,7 @@ afl2_rsid <- function(rsid, reference="1000g")
afl2_chrpos <- function(chrpos, reference="1000g")
{
out <- api_query("variants/afl2", list(chrpos=chrpos)) %>% get_query_content()
if(class(out) == "response")
if(inherits(out, "response"))
{
return(out)
} else if(is.data.frame(out)) {
Expand Down
7 changes: 5 additions & 2 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#'
#' @param where Which API to use. Choice between `"public"`, `"private"`, `"dev1"`, `"dev2"`.
#' Default = `"public"`.
#' @param silent Silent? Default = FALSE
#'
#' @export
#' @return NULL
select_api <- function(where="public")
select_api <- function(where="public", silent=FALSE)
{
url <- switch(where,
public = "http://gwas-api.mrcieu.ac.uk/",
Expand All @@ -20,7 +21,9 @@ select_api <- function(where="public")
}

options(ieugwasr_api=url)
message("API: ", where, ": ", url)
if(!silent) {
message("API: ", where, ": ", url)
}
}


Expand Down
21 changes: 6 additions & 15 deletions R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ api_query <- function(path, query=NULL, access_token=check_access_token(),
silent=TRUE
)
}
if('try-error' %in% class(r))
if(inherits(r, 'try-error'))
{
if(grepl("Timeout", as.character(attributes(r)$condition)))
{
stop("The query to MR-Base exceeded ", timeout, " seconds and timed out. Please simplify the query")
}
}
if(! 'try-error' %in% class(r))
if(! inherits(r, 'try-error'))
{
if(r$status_code >= 500 & r$status_code < 600)
{
Expand All @@ -94,7 +94,7 @@ api_query <- function(path, query=NULL, access_token=check_access_token(),
message("Failed to retrieve results from server. See error status message in the returned object and contact the developers if the problem persists.")
return(r)
}
if('try-error' %in% class(r))
if(inherits(r, 'try-error'))
{
if(grepl("Could not resolve host", as.character(attributes(r)$condition)))
{
Expand Down Expand Up @@ -145,11 +145,6 @@ api_status <- function()
return(o)
}

print.ApiStatus <- function(x)
{
lapply(names(x), function(y) cat(format(paste0(y, ":"), width=30, justify="right"), x[[y]], "\n"))
}


#' Get list of studies with available GWAS summary statistics through API
#'
Expand Down Expand Up @@ -180,10 +175,6 @@ gwasinfo <- function(id=NULL, access_token = check_access_token())
return(out)
}

print.GwasInfo <- function(x)
{
dplyr::glimpse(x)
}

#' Extract batch name from study ID
#'
Expand Down Expand Up @@ -246,7 +237,7 @@ associations <- function(variants, id, proxies=1, r2=0.8, align_alleles=1, palin
maf_threshold=maf_threshold
), access_token=access_token) %>% get_query_content()

if(class(out) == "response")
if(inherits(out, "response"))
{
return(out)
} else if(is.data.frame(out)) {
Expand Down Expand Up @@ -316,7 +307,7 @@ phewas <- function(variants, pval = 0.00001, batch=c(), access_token=check_acces
pval=pval,
index_list=batch
), access_token=access_token) %>% get_query_content()
if(class(out) != "response")
if(!inherits(out, "response"))
{
out <- out %>% dplyr::as_tibble() %>% fix_n()
if(nrow(out) > 0)
Expand Down Expand Up @@ -377,7 +368,7 @@ tophits <- function(id, pval=5e-8, clump = 1, r2 = 0.001, kb = 10000, pop="EUR",
kb=kb,
pop=pop
), access_token=access_token) %>% get_query_content()
if(class(out) == "response")
if(inherits(out, "response"))
{
return(out)
} else if(is.data.frame(out)) {
Expand Down
6 changes: 3 additions & 3 deletions R/variants.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ variants_gene <- function(gene, radius=0)
{
message("Looking up ", gene[i])
o <- api_query(paste0('variants/gene/', gene[i], "?radius=", format(radius, scientific=FALSE))) %>% get_query_content()
if(class(o) != "response")
if(! inherits(o, "response"))
{
l[[gene[i]]] <- o %>% dplyr::bind_rows() %>% format_variants()
}
Expand All @@ -35,7 +35,7 @@ variants_gene <- function(gene, radius=0)
variants_rsid <- function(rsid)
{
o <- api_query("variants/rsid", list(rsid = rsid)) %>% get_query_content()
if(! class(o) %in% "response")
if(! inherits(o, "response"))
{
if(!is.data.frame(o) & is.list(o))
{
Expand All @@ -62,7 +62,7 @@ variants_chrpos <- function(chrpos, radius=0)
{
o <- api_query("variants/chrpos", list(chrpos = chrpos, radius=radius)) %>% get_query_content()

if(! class(o) %in% "response")
if(! inherits(o, "response"))
{
o %>% dplyr::bind_rows() %>% format_variants() %>% return()
} else {
Expand Down
121 changes: 38 additions & 83 deletions docs/404.html

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

Loading

0 comments on commit a4fb057

Please sign in to comment.