Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple changes to fix R CMD check #20

Merged
merged 7 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
.github

# README files
README.Rmd
README.html
README.md
README.Rmd

# Local directories

cache/
inst/
# knitr and R markdown default cache directories
/cache/
48 changes: 35 additions & 13 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
# Workflow copied from
https://github.com/r-lib/actions/blob/v2-branch/examples/test-coverage.yaml

on:
push:
branches:
- master
branches: [main, master]
pull_request:
branches:
- master
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: macOS-latest
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
r-version: 'release'
use-public-rspm: true

- name: Install dependencies
run: |
install.packages(c("remotes", "rcmdcheck"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
shell: Rscript {0}
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: covr::codecov()
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,4 @@ vignettes/*.pdf

# R Environment Variables
.Renviron

# Local directories

cache/
inst/
inst/doc
25 changes: 22 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
Package: webseq
Type: Package
Title: This package collects R functions for working with sequence databases like NCBI, ENA, MGnify
Title: Access data from biological sequence databases like NCBI, ENA, MGnify
Description: This package interacts with online biological sequence databases.
It provides functions to search for sequences, convert identifiers and
download sequences and associated metadata.
Version: 0.1
Date: 2022-01-05
Author: Tamas Stirling
Maintainer: Tamas Stirling <[email protected]>
Description: TBA
License: TBD
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
curl,
dplyr,
genbankr,
httr,
jsonlite,
plyr,
rentrez,
stringi,
stringr,
tibble,
XML
Suggests:
knitr,
rmarkdown,
testthat
RoxygenNote: 7.2.3
VignetteBuilder: knitr
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2023
COPYRIGHT HOLDER: Tamás Stirling
2 changes: 1 addition & 1 deletion R/flag_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ flag_files <- function(filenames) {
if (nrow(cr) == 1) {
df$keep[i] = TRUE
} else {
cr <- cr[order(cr$source, cr$version, decreasing = c(TRUE, TRUE)),]
cr <- cr[order(cr$source, cr$version, decreasing = TRUE),]
cr$keep[1] <- TRUE
cr$keep[2:nrow(cr)] <- FALSE
df$keep[cr$row] <- cr$keep
Expand Down
12 changes: 12 additions & 0 deletions R/mgnify_instance.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#' Search for a specific entry in MGnify
#'
#' This function can be used for searching MGnify using an identifier.
#' @param query character; the indentifier
#' @param from character; the api which contains this identifier. See
#' \code{mgnify_endpoints()} for a list of possible apis.
#' @return a list
#' @examples
#' \dontrun{
#' # look up an assembly
#' mgnify_instance("ERZ477576", from = "assemblies")
#' }
#' @export
mgnify_instance <- function(query, from) {
query <- utils::URLencode(query)
Expand Down
11 changes: 10 additions & 1 deletion R/mgnify_list.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#' Retrieve a list of instances from MGnify
#' @param sleep character;
#'
#' This function retrieves a list of identifiers to look up with other
#' functions.
#' @param query character; what to look for.
#' @param from character; API. See \code{"mgnify_endpoints()"}.
#' @param from_id character; more precise filtering for the API.
#' @param page numeric; the API's response is paginated this tells the API which
#' page to return. If \code{NULL}, the function will return all pages.
#' @param sleep character; number of seconds to sleep before requesting the next
#' page.
#' @param verbose logical; should verbose messages be printed to console?
#' @examples
#' \dontrun{
Expand Down
2 changes: 1 addition & 1 deletion R/ncbi_download_genome.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ncbi_download_genome <- function(accession,
}
if (verbose) message(x, ". ", appendLF = FALSE)
Sys.sleep(stats::runif(1,0.2,0.5))
assembly_uid <- try(ncbi_get_uid(x, db = "assembly"), silent = TRUE)
assembly_uid <- try(get_uid(x, db = "assembly"), silent = TRUE)
if (inherits(assembly_uid, "try-error")) {
if (verbose) message("Failed. Webservice temporarily down.")
return(NA)
Expand Down
4 changes: 2 additions & 2 deletions R/ncbi_meta_biosample.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#' @examples
#' \dontrun{
#' # Sample metadata from BioSample ID
#' biosample_uid <- ncbi_get_uid("SAMN02714232", db = "biosample")
#' biosample_uid <- get_uid("SAMN02714232", db = "biosample")
#' ncbi_meta(biosample_uid)
#'
#' # Sample metadata from assembly accession
#' assembly_uid <- ncbi_get_uid("GCF_000695855.3")
#' assembly_uid <- get_uid("GCF_000695855.3")
#' biosample_uid <- ncbi_link_uids(assembly_uid, from = "assembly", to = "biosample")
#' ncbi_meta_biosample(biosample_uid)
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/ncbi_meta_sra.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#function currently used to get run id from sra_uid
ncbi_meta_sra <- function(sra) {
init <- substr(sra, 1, 3)
sra_uid <- ncbi_get_uid(sra, db = "sra")
sra_uid <- get_uid(sra, db = "sra")
res <- rentrez::entrez_fetch(
db = "sra", id = sra_uid, rettype = "docsum", retmode = "json")
cont <- jsonlite::fromJSON(res)$result[[2]]$runs
Expand Down
26 changes: 26 additions & 0 deletions man/mgnify_instance.Rd

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

15 changes: 13 additions & 2 deletions man/mgnify_list.Rd

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

4 changes: 2 additions & 2 deletions man/ncbi_meta_biosample.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library('testthat')
library('webseq')
test_check("webseq")
24 changes: 16 additions & 8 deletions vignettes/ncbi.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ vignette: >
\usepackage[utf8]{inputenc}
---

```{r}
library(webseq)
```

## Download genome assemblies

Download genbank file for GCF_003007635.1.
Expand All @@ -18,13 +22,13 @@ https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/003/007/635/

Let's download GCF_003007635.1_ASM300763v1_genomic.gbff.gz!

```{r}
```{r, eval = FALSE}
ncbi_download_genome("GCF_003007635.1", type = "genomic.gbff")
```

If we try to download it again, the function will indicate that the file is already downloaded.

```{r}
```{r, eval = FALSE}
ncbi_download_genome("GCF_003007635.1", type = "genomic.gbff")
```

Expand All @@ -35,25 +39,29 @@ Let's download some metadata for this assembly!
First, get the Assembly UID of the assembly, which is the internal identifier of the assembly within the NCBI Assembly database.

```{r}
assembly_uid <- ncbi_get_uid("GCF_003007635.1", db = "assembly")
assembly_uid <- get_uid("GCF_003007635.1", db = "assembly")
assembly_uid
```

Next, collect some assembly metadata.

```{r}
assembly_meta <- ncbi_meta_assembly(assembly_uid$uid)
assembly_meta <- get_meta(assembly_uid$uid, db = "assembly")
assembly_meta
```

Using this metadata we can find the BioSample ID associated with the assembly. Let's use this ID to get the BioSample UID of the sample within the NCBI BioSample database.

```{r}
biosample_uid <- ncbi_get_uid(assembly_meta$biosample, db = "biosample")
biosample_uid <- get_uid(assembly_meta$biosample, db = "biosample")
biosample_uid
```

And then get the metadata itself

```{r}
biosample_meta <- ncbi_meta_biosample(biosample_uid$uid)
biosample_meta <- get_meta(biosample_uid$uid, db = "biosample")
biosample_meta
```

## Parse metadata files
Expand All @@ -69,7 +77,7 @@ upper right corner -> send to -> file -> format = xml -> create file

Download the file and then parse it.

```{r}
```{r, eval = FALSE}
ncbi_parse_assembly_xml("assembly_summary.xml")
```

Expand All @@ -82,6 +90,6 @@ upper right corner -> send to -> file -> format = full (text) -> create file

Download the file and then parse it.

```{r}
```{r, eval = FALSE}
ncbi_parse_biosample_txt("biosample_summary.txt")
```