Learn R Programming

QBMS

Overview

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.

Author and Maintainer: Khaled Al-Shamaa <k.el-shamaa (at) cgiar (dot) org>

Contributor: Mariano Omar CRIMI <m.crimi (at) cgiar (dot) org>

Contributor: Zakaria Kehel <z.kehel (at) cgiar (dot) org>

Contributor: Johan Aparicio <j.aparicio (at) cgiar (dot) org>

Copyright Holder: International Center for Agricultural Research in the Dry Areas (ICARDA)

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.

Supported Data Sources

  • BMS: vignette("bms_example").
  • EBS: vignette("ebs_example").
  • Breedbase: vignette("breedbase_example").
  • GIGWA: vignette("gigwa_example").

Extra sub-systems supported:

Installation

install.packages("QBMS")

Development version

To get a bug fix or to use a feature from the development version, you can install the development version of QBMS from GitHub.

if (!require("remotes")) install.packages("remotes")
remotes::install_github("icarda-git/QBMS")

Getting Started

Once you successfully install the QBMS R package, you can load it as a library and set up your remote server configuration (e.g., EBS, BMS, BreedBase, or GIGWA) by simply copying and pasting the login page URL from your web browser.

# load the QBMS library
library(QBMS)

# config your BMS connection (by providing your BMS login page URL)
set_qbms_config("https://bms.icarda.org/ibpworkbench/controller/auth/login")

To start querying and retrieving data from your remote server, you have to login using the same credentials for that server’s GUI/web interface. Please note that you can call the login function(s) with no parameters (interactive mode), where you will get a popup window to insert your username and password (highly advised as one of the best security practices). Although, for automatic analysis pipeline(s) or server services, you can still provide the required username and password as login function parameters (i.e., batch mode).

# login using your account (interactive mode)
login_bms()

# or pass your username and password as parameters (batch mode)
login_bms("username", "password")

You should be careful when sharing your batch mode code to avoid leaking your credential in public or not authorized spaces.

Supporting Multiple Provider Connectors

You can switch between an ongoing QBMS connection and another server/database connection by using get_qbms_connection() and set_qbms_connection() functions, as shown in the following example (i.e., if there is a need to switch forth and back during the same session):

# configure QBMS to connect the phenotypics server
set_qbms_config("https://www.bms-uat-test.net/ibpworkbench/controller/auth/login")

# login and retrieve data from the phenotypic server

# save current connection (phenotypic server)
con1 <- get_qbms_connection()

# configure QBMS to connect the genotypic server
set_qbms_config("https://gigwa.southgreen.fr/gigwa/", engine = "gigwa", no_auth = TRUE)

# retrieve data from the genotypic server

# save current connection (before switch)
con2 <- get_qbms_connection()

# load the saved phenotypic server connection
set_qbms_connection(con1)

# continue retrieving data from the phenotypic server

A detailed example is available in the documentation of the get_qbms_connection() and set_qbms_connection() functions.

Also, you can find a more elegant solution developed by Francisco Agosto-Perez from the Breeding Informatics team within the Innovation Lab For Crop Improvement at Cornell University available here: https://github.com/agostof/BrAPI-Provider/

Error and Debugging

If you get unexpected results or weird behavior and want to dig deep and investigate what went wrong, you can get a copy of the internal QBMS variables by calling the debug_qbms() function.

dump <- debug_qbms()

dump$config
# $crop
# [1] "maize"
# 
# $server
# [1] "https://www.bms-uat-test.net"
# 
# $path
# [1] "bmsapi"
# 
# $page_size
# [1] 1000
# 
# $time_out
# [1] 120
# 
# $base_url
# [1] "https://www.bms-uat-test.net/bmsapi"
# 
# $engine
# [1] "bms"

names(dump$state)
# [1] "token"         "program_db_id" "trial_db_id"   "study_db_id"   "user"         
# [6] "expires_in"    "errors"        ...

dump$state$token
# [1] "username:1666907125029:a312bb036cc8d9cc302bee1f0981e5ab"

Troubleshooting the Installation

  1. If the installation of QBMS generates errors saying that some of the existing packages cannot be removed, you can try to quit any R session, and try to start R in administrator (Windows) or SUDO mode (Linux/Ubuntu) then try installing again.

  2. If you get an error related to packages built under a current version of R, and updating your packages doesn’t help, you can consider overriding the error with the following code. Note: This might help you install QBMS but may result in other problems. If possible, it’s best to resolve the errors rather than ignoring them.

Sys.setenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = TRUE)

remotes::install_github("icarda-git/QBMS", upgrade = "always")
  1. If you get an error related to list or set runs in GIGWA (i.e., gigwa_list_runs() and gigwa_set_run() functions), you can try to ensure that your R session system locale is using UTF-8 character set encoding. You may consider overwriting your system locale with the following command to resolve this issue:
Sys.setlocale("LC_ALL", "English_United States.utf8")
  1. If the get_terraclimate() function takes a long time to run and the progress bar stays at 0%, it might be due to using an outdated version of the R language. Make sure you're using the latest version. For more details, please refer to this GitHub issue.

References

Copy Link

Version

Install

install.packages('QBMS')

Monthly Downloads

367

Version

1.5.0

License

GPL (>= 3)

Maintainer

Khaled Al-Shamaa

Last Published

September 18th, 2024

Functions in QBMS (1.5.0)

get_trial_obs_ontology

Get the Traits Ontology/Metadata of the Current Active Trial
get_study_data

Get the Observations Data of the Current Active Study
get_trial_data

Get the Observations Data of the Current Active Trial
get_terraclimate

Get TerraClimate Data for a Given Coordinate(s)
list_programs

Retrieve Breeding Programs for the Active Crop
gigwa_list_projects

Get the List of All Projects in the Selected GIGWA Database
scan_brapi_endpoints

Scan BrAPI Endpoints
gigwa_list_runs

Get the List of the Run Names Available in the Selected GIGWA Project
list_locations

Get the List of Locations Information of the Current Selected Crop
set_crop

Set the Current Active Crop
ini_hwsd2

Download and Setup HWSD v2.0 Data Files to Extract their Data Offline
get_program_trials

Retrieve the List of Trials for the Active Breeding Program
set_study

Set the Current Active Study
login_bms

Login to the Server
login_breedbase

Login to the BreedBase Server
get_program_studies

Get the List of Trials, Studies, and Locations Information for the Current Selected Program
gigwa_set_run

Set the Current Active GIGWA Run
set_qbms_connection

Set the QBMS Connection
get_study_info

Get the Details/Metadata of the Current Active Study
set_program

Set the Current Active Breeding Program
ini_terraclimate

Download TerraClimate netCDF Data Files to Extract their Data Offline
list_studies

Get the List of Studies in the Current Active Trial
list_crops

Retrieve Supported Crops from the Server
gigwa_get_variants

Get Available Variants in the Selected GIGWA Run
get_qbms_connection

Get the QBMS Connection
gigwa_get_metadata

Get the Metadata of the Current Active GIGWA Run
get_germplasm_attributes

Retrieve Attributes for a Specified Germplasm
login_oauth2

Login using OAuth 2.0 Authentication
gigwa_get_markers

Get Markers Map in the Selected GIGWA Run
login_gigwa

Login to the GIGWA Server
gigwa_get_samples

Get the Samples List of the Current Active GIGWA Project
gigwa_get_sequences

Get the Sequences of the Current Active GIGWA Project
gigwa_set_db

Set the Current Active GIGWA Database by Name
gigwa_set_project

Set the Current Active GIGWA Project
gigwa_get_allelematrix

Get Markers Matrix in the Selected GIGWA Run
set_token

Set Access Token Response
set_qbms_config

Configure BMS Server Settings
gigwa_list_dbs

List GIGWA Databases
set_trial

Set the Current Active Trial
rbindlistx

Make One Data.Table from a List of Many
rbindx

Combine Data Frames by Row, Filling in Missing Columns
list_trials

List Trials in the Current Active Breeding Program
calc_biovars

Calculate the Bioclimatic Variables
build_pedigree_table

Building Pedigree Table Recursively
debug_qbms

Debug Internal QBMS Status Object
brapi_post_search_allelematrix

Internal Function Used for Core BrAPI POST Calls (Allele Matrix Search)
brapi_post_search_call

Internal Function Used for Core BrAPI POST Calls
get_async_pages

Asynchronously Fetch Multiple API Pages
brapi_headers

Generate Common HTTP Headers for API Requests
brapi_get_call

Internal Function for Core BrAPI GET Calls
get_async_page

Asynchronously Fetch a Single API Page
brapi_map

BrAPI Mapping Table
get_germplasm_data

Retrieve Observations Data for a Specified Germplasm.
get_brapi_url

Get the BrAPI Endpoint URL for a given QBMS function
get_germplasm_id

Get Germplasm ID for a Specified Germplasm Name
get_germplasm_list

Get the Germplasm List of the Current Active Study
get_login_details

Login Pop-Up Window
get_pedigree_table

Get the Pedigree Table
get_hwsd2

Get HWSD v2 Soil Data for a Given Location(s)
get_parents

Get Direct Parents