EBS Example

QBMS

This R package assists breeders in linking data systems with their analytic pipelines, a crucial step in digitizing breeding processes. It supports querying and retrieving phenotypic and genotypic data from systems like EBS, BMS, BreedBase, and GIGWA (using BrAPI calls). Extra helper functions support environmental data sources, including TerraClimate and FAO HWSDv2 soil database.

EBS

The Enterprise Breeding System (EBS) is an open-source breeding informatics software being developed for crop breeding programs serving resource-poor farmers in Africa, Asia and Latin America.

EBS connects, merges and builds upon existing breeding software and data solutions to offer a single powerful tool, so that breeders can focus on using data to create better varieties, faster.

Development is led by the CGIAR Excellence in Breeding Platform and the CGIAR Breeding Resources Initiative, which support CGIAR and national agricultural research system programs to adopt the breeding workflows and data management practices required to adopt EBS.

EBS has been chosen as the preferred data management system of CGIAR (source).

BrAPI

The Breeding API (BrAPI) project is an effort to enable interoperability among plant breeding databases. BrAPI is a standardized RESTful web service API specification for communicating plant breeding data. This community driven standard is free to be used by anyone interested in plant breeding data management.

OAuth 2.0

OAuth 2.0 is the industry-standard protocol for authorization. OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices. This specification and its extensions are being developed within the IETF OAuth Working Group.

Package maintainers might want to build this app in as a fallback, possibly taking some measures to obfuscate the client ID and secret and limit its use to your package.

Note that three-legged OAuth always requires the involvement of a user, so the word “secret” here can be somewhat confusing. It is not a secret in the same sense as a password or token. But you probably still want to store it in an opaque way, so that someone else cannot easily “borrow” it and present an OAuth consent screen that impersonates your package.

The Client ID is a public identifier of your application, it is not a secret anyway and any end user can see what it is when the app redirects them to sign in (e.g., if they use browser tools to view the HTTP request).

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties. https://jwt.io/ allows you to decode, verify and generate JWT.

Example

Connect and authenticate to EBS

Before querying data from EBS, configure QBMS with the required BrAPI endpoint URL (e.g., https://cbbrapi-wheat.ebs.cimmyt.org) and authenticate the user.

QBMS supports two authentication approaches. Most users can sign in through the EBS BrAPI login page using their organization credentials, copy the returned access token, and pass it to QBMS with set_token(). Developers with an OAuth 2.0 client ID and client secret can instead authenticate using login_oauth2().

For the token-based approach, open the BrAPI login page for the corresponding EBS instance (e.g., https://cbbrapi-wheat.ebs.cimmyt.org/brapi/v2/auth/login). After successful authentication, a JSON response is returned. Copy only the value of the "token" field; do not copy the "refreshToken" or any surrounding JSON text.

For security, avoid hard-coding access tokens in shared scripts. The readline() approach below allows the token to be entered interactively in the R console.

# load the QBMS library
library(QBMS)

# config the EBS connection
set_qbms_config(url = 'https://cbbrapi-wheat.ebs.cimmyt.org', engine = 'ebs', brapi_ver = 'v2')

# ---------------------------------------------------------------------------
# Authentication option 1: provide an EBS access token manually
# ---------------------------------------------------------------------------

# Obtain the token from the authentication endpoint of your EBS instance.
# After signing in, copy ONLY the value of the "token" field from the returned
# JSON response, then run the command below and paste the token when prompted.
set_token(readline('token:'))

# ---------------------------------------------------------------------------
# Authentication option 2: use the EBS OAuth 2.0 workflow
# ---------------------------------------------------------------------------

login_oauth2(authorize_url = 'https://auth.ebsproject.org/oauth2/authorize', 
             access_url    = 'https://auth.ebsproject.org/oauth2/token', 
             client_id     = '<your client id>', 
             client_secret = '<your client secret>')

Query data

After the EBS connection has been configured and authentication has been completed using either option above, the usual QBMS workflow can be used to select a breeding program, trial, and study and then retrieve the required data.

# list all breeding programs
list_programs()

# select a breeding program by name
set_program('Irrigated South-East Asia')

# list all trials in the selected program
list_trials()

# select a specific trial by name
set_trial('CORB-5272 -test1')

# list all studies (occurancies) in the selected trial
list_studies()

# select a specific study (occurance) by name
set_study('CORB-5272 -test1-001')

# retrieve study (occurance) metadata/information
info <- get_study_info()

# retrieve study (occurance) data
data <- get_study_data()

# retrieve study (occurance) germplasm list
germplasm <- get_germplasm_list()

# retrieve traits ontology for the selected trial
ontology <- get_trial_obs_ontology()

# retrieve multi-environment (occurencies) data of the selected trial
MET <- get_trial_data()