Skip to content

Commit 475a77c

Browse files
authored
Merge pull request #102 from stitam/ena
Fix ena_query()
2 parents ab2beb6 + 5fd79b9 commit 475a77c

File tree

5 files changed

+72
-19
lines changed

5 files changed

+72
-19
lines changed

.github/workflows/test-coverage.yaml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ on:
55
push:
66
branches: [main, master]
77
pull_request:
8-
branches: [main, master]
98

10-
name: test-coverage
9+
name: test-coverage.yaml
10+
11+
permissions: read-all
1112

1213
jobs:
1314
test-coverage:
@@ -16,36 +17,47 @@ jobs:
1617
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1718

1819
steps:
19-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2021

2122
- uses: r-lib/actions/setup-r@v2
2223
with:
2324
use-public-rspm: true
2425

2526
- uses: r-lib/actions/setup-r-dependencies@v2
2627
with:
27-
extra-packages: any::covr
28+
extra-packages: any::covr, any::xml2
2829
needs: coverage
2930

3031
- name: Test coverage
3132
run: |
32-
covr::codecov(
33+
cov <- covr::package_coverage(
3334
quiet = FALSE,
3435
clean = FALSE,
35-
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
36+
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
3637
)
38+
print(cov)
39+
covr::to_cobertura(cov)
3740
shell: Rscript {0}
3841

42+
- uses: codecov/codecov-action@v5
43+
with:
44+
# Fail if error if not on PR, or if on PR and token is given
45+
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
46+
files: ./cobertura.xml
47+
plugins: noop
48+
disable_search: true
49+
token: ${{ secrets.CODECOV_TOKEN }}
50+
3951
- name: Show testthat output
4052
if: always()
4153
run: |
4254
## --------------------------------------------------------------------
43-
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
55+
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
4456
shell: bash
4557

4658
- name: Upload test results
4759
if: failure()
48-
uses: actions/upload-artifact@v3
60+
uses: actions/upload-artifact@v4
4961
with:
5062
name: coverage-test-failures
5163
path: ${{ runner.temp }}/package

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Version: 0.1
88
Date: 2022-01-05
99
Author: Tamas Stirling
1010
Maintainer: Tamas Stirling <stirling.tamas@gmail.com>
11+
URL: https://github.com/stitam/webseq
12+
BugReports: https://github.com/stitam/webseq/issues
1113
License: MIT + file LICENSE
1214
Encoding: UTF-8
1315
LazyData: true

R/ena_query.R

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#'\code{"batch"}: one file for each batch, \code{"all"}: one file altogether.
1212
#'@param gzip logical; Download the result as a gzip file.
1313
#'@param set logical; ???
14+
#'@param include_links logical; ???
1415
#'@param range character; ???
1516
#'@param complement logical; ???
1617
#'@param batch_size integer; Number of accessions to query in a single request.
@@ -34,6 +35,7 @@ ena_query <- function(
3435
destfile_by = "all",
3536
gzip = FALSE,
3637
set = FALSE,
38+
include_links = FALSE,
3739
range = NULL,
3840
complement = FALSE,
3941
batch_size = 0,
@@ -45,6 +47,7 @@ ena_query <- function(
4547
stopifnot(length(download) == 1 && is.logical(download))
4648
stopifnot(length(gzip) == 1 && is.logical(gzip))
4749
stopifnot(length(set) == 1 && is.logical(set))
50+
stopifnot(length(include_links) == 1 && is.logical(include_links))
4851
#stopifnot(length(range) == 1 && is.character(range))
4952
stopifnot(length(complement) == 1 && is.logical(complement))
5053
stopifnot(length(verbose) == 1 && is.logical(verbose))
@@ -77,16 +80,7 @@ ena_query <- function(
7780
} else {
7881
destfile <- paste0(x, ".", mode, ifelse(gzip == "true", ".gz", ""))
7982
}
80-
url <- paste0(
81-
"https://www.ebi.ac.uk/ena/browser/api/", mode, "?",
82-
"accessions=", x,
83-
"&expanded=", expanded,
84-
"&annotationOnly=", annotation_only,
85-
"&download=", download,
86-
"&gzip=", gzip,
87-
"&set=", set,
88-
"&complement=", complement
89-
)
83+
url <- paste0("https://www.ebi.ac.uk/ena/browser/api/", mode)
9084
if (download == "true") {
9185
# TODO: finalise dev code
9286
# variations based on number of accessions, batch_size, download_by, gzip
@@ -100,7 +94,28 @@ ena_query <- function(
10094
mode = mode
10195
)
10296
} else {
103-
res <- try_url("POST", url)
97+
headers <- c(Accept = "text/plain", `Content-Type` = "application/json")
98+
body <- list(
99+
"accessions" = list(x),
100+
"expanded" = expanded,
101+
"annotationOnly" = annotation_only,
102+
"lineLimit" = 0,
103+
"download" = download,
104+
"gzip" = gzip,
105+
"set" = set,
106+
"includeLinks" = include_links,
107+
"range" = range,
108+
"complement" = complement
109+
)
110+
res <- try(httr::RETRY(
111+
"POST",
112+
url,
113+
httr::user_agent(package_url()),
114+
httr::add_headers(.headers = headers),
115+
body = body,
116+
encode = "json",
117+
terminate_on = 404,
118+
quiet = TRUE), silent = TRUE)
104119
seqs <- ena_parse(res, mode = mode)
105120
return(seqs)
106121
}

R/utils.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
#' Get package URL
2+
#'
3+
#' Look up the DESCRIPTION file of the package that called this function and
4+
#' return the package URL (the first element of the URL field).
5+
#'
6+
#' @return Either a URL
7+
#' @noRd
8+
package_url <- function() {
9+
# Get package name
10+
ns <- parent.frame()
11+
pkg <- utils::packageName(ns)
12+
if (is.null(pkg)) stop("Could not extract package name.")
13+
# Extract URL from DESCRIPTION file
14+
desc <- utils::packageDescription(pkg)
15+
if (!"URL" %in% names(desc)) stop("Could not extract URL, missing field.")
16+
urls <- unlist(strsplit(desc[["URL"]], "[[:space:],]+"))
17+
urls <- urls[nzchar(urls)]
18+
if (length(urls) == 0) stop("Could not extract URL, empty field.")
19+
return(urls[1])
20+
}
21+
122
#' Retry a function call
223
#'
324
#' @param expr expression; Expression to evaluate.

man/ena_query.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)