https://github.com/cnr-ibba/r-smarter-api
R code to query SMARTER-backend
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.8%) to scientific vocabulary
Keywords
api
smarter
Last synced: 10 months ago
·
JSON representation
Repository
R code to query SMARTER-backend
Basic Info
- Host: GitHub
- Owner: cnr-ibba
- License: gpl-3.0
- Language: R
- Default Branch: master
- Homepage: https://cnr-ibba.github.io/r-smarter-api/
- Size: 3.19 MB
Statistics
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 4
- Releases: 1
Topics
api
smarter
Created over 4 years ago
· Last pushed 10 months ago
Metadata Files
Readme
License
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# smarterapi
[](https://github.com/cnr-ibba/r-smarter-api/actions/workflows/R-CMD-check.yaml)
[](https://github.com/cnr-ibba/r-smarter-api/actions/workflows/lint.yaml)
[](https://github.com/cnr-ibba/r-smarter-api/actions/workflows/pkgdown.yaml)
The goal of `smarterapi` is to collect data from
[SMARTER REST API](https://webserver.ibba.cnr.it/smarter-api/docs/) and provide them to
the user as a dataframe. Get more information with the
[online vignette](https://cnr-ibba.github.io/r-smarter-api/articles/smarterapi.html).
## Installation
The `smarterapi` package is only available from [GitHub](https://github.com/)
and can be installed as a *source package* or in alternative using
[devtools](https://CRAN.R-project.org/package=devtools)
package, for example:
```r
# install devtools if needed
# install.packages("devtools")
devtools::install_github("cnr-ibba/r-smarter-api")
```
After the installation, you can load the package in your R session:
```{r eval = FALSE, import}
# import this library to deal with the SMARTER API
library(smarterapi)
```
## SMARTER credentials
After the public release of SMARTER data, there's no need to provide credentials
to access the data. If you used to have credentials to access the data, you need
to install the latest version of `smarterapi` package.
## Querying the SMARTER backend
`smarterapi` provides a set of functions used to fetch data from *SMARTER-backend*
endpoints described in [api documentation](https://webserver.ibba.cnr.it/smarter-api/docs/)
and returning them into a `data.frame` object. For example, the `get_smarter_datasets`
lets to query the [Datasets endpoint](https://webserver.ibba.cnr.it/smarter-api/docs/#/Datasets/get_datasets),
while `get_smarter_samples` is able to query and parse the
[Sample endpoints](https://webserver.ibba.cnr.it/smarter-api/docs/#/Samples)
response. Each `smarterapi` function is documented in `R` and you can get help on
each function like any other R functions.
There are two types of parameters that are required to fetch data through
the *SMARTER-backend*: the `species` parameter, which can be `Goat` or `Sheep` respectively
for goat and sheep [Samples](https://webserver.ibba.cnr.it/smarter-api/docs/#/Samples)
or [Variants](https://webserver.ibba.cnr.it/smarter-api/docs/#/Variants) endpoints,
and the `query` parameter which can be provided to any *get_smarter_* function.
The `species` parameter is *mandatory* in order to query an endpoint specific for
*Goat* or *Sheep*, while the `query` parameter is optional and need to be specified
as a `list()` object in order to limit your query to some data in particular.
For example, if you need all the foreground genotypes datasets, you can collect
data like this:
```{r eval = FALSE, dataset}
datasets <- get_smarter_datasets(
query = list(type = "genotypes", type = "foreground"))
```
while if you require only background goat samples, you can do like this:
```{r eval = FALSE, samples}
goat_samples <- get_smarter_samples(
species = "Goat", query = list(type = "background"))
```
The full option list available to each endpoint is available on the SMARTER-backend
[swagger documentation](https://webserver.ibba.cnr.it/smarter-api/docs/): the option
name to use is the same name described in *parameters*, and description and parameter
types can give you hints on how to exploit endpoint properly. For instance, parameters
described as *array of objects* can be specified multiple times:
```r
> goat_breeds <- get_smarter_breeds(query = list(species="Goat", search="land"))
> goat_breeds[c("name","code")]
name code
1 Rangeland RAN
2 Landrace LNR
3 Landin LND
4 Icelandic goat ICL
> goat_samples <- get_smarter_samples(
species = "Goat",
query = list(
breed_code="RAN",
breed_code="LNR",
breed_code="LND",
breed_code="ICL"
)
)
```
## Examples
This is a basic example which shows you how to collect data from SMARTER REST API
for the *Italian* goats belonging to the *Adaptmap* dataset:
```{r eval = FALSE, adaptmap}
# collect the dataset by providing part of the name with the search option:
# since we are forcing to collect only background genotypes, only one dataset
# will be returned
datasets <- get_smarter_datasets(
query = list(
species = "Goat",
search = "adaptmap",
type = "genotypes",
type = "background"
)
)
# get the dataset id
adatpmap_id <- datasets["_id.$oid"][1]
# collect all the italian goats from the adaptmap dataset. Using the dataset id
# to filter out all the samples belonging to this dataset and the country option
# to filter out only the italian samples for this dataset
adaptmap_goats <- get_smarter_samples(
species = "Goat",
query = list(
dataset = adatpmap_id,
country = "Italy"
)
)
```
We have other examples in the [vignettes](https://cnr-ibba.github.io/r-smarter-api/articles/),
for example how to collect data from the [Variants](https://cnr-ibba.github.io/r-smarter-api/articles/variants.html)
endpoints or how to work with [geographic coordinates](https://cnr-ibba.github.io/r-smarter-api/articles/geojson.html).
Owner
- Name: CNR-IBBA
- Login: cnr-ibba
- Kind: organization
- Location: Milan
- Website: https://www.ibba.cnr.it/
- Repositories: 25
- Profile: https://github.com/cnr-ibba
Bioinformatic Group @ CNR-IBBA
GitHub Events
Total
- Push event: 1
- Pull request event: 1
- Create event: 1
Last Year
- Push event: 1
- Pull request event: 1
- Create event: 1
Dependencies
DESCRIPTION
cran
- dplyr * imports
- httr * imports
- jsonlite * imports
- logger * imports
- lubridate * imports
- sf * imports
- tidyr * imports
- urltools * imports
- elevatr * suggests
- geodata * suggests
- ggplot2 * suggests
- ggspatial * suggests
- knitr * suggests
- leaflet * suggests
- lintr * suggests
- pander * suggests
- progress * suggests
- rcmdcheck * suggests
- rmarkdown * suggests
- rnaturalearth * suggests
- rnaturalearthdata * suggests
- roxygen2 * suggests
- styler * suggests
- terra * suggests
- testthat >= 3.0.0 suggests
- usethis * suggests
- utils * suggests
.github/workflows/R-CMD-check.yaml
actions
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-renv v2 composite
.github/workflows/lint.yaml
actions
- actions/checkout v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-renv v2 composite
.github/workflows/pkgdown.yaml
actions
- JamesIves/github-pages-deploy-action v4.3.3 composite
- actions/checkout v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-renv v2 composite