This package is under development. It has not yet been exhaustively tested for all calls neither. Usage may also still change. If you have suggestions please use the issue tracker.

Get started with real data

Here we use as an example the sweetpotatobase.org database since it has currently one of the most complete implementations. Also, data are public and no login credentials are needed. It is part of the white list of the internal databases, too. So no further knowledge of configuration details are needed.

Get the database handle

The package comes with a list of known databases (white list). Both the white list and the handle can be printed in summary form to the console. The $ sign can be used to access individual slots and overwrite values. This can also be used as a template to configure a handle to another brapi compliant database.

## Please note that current supports 44/44 BrAPI calls of version 1.1.
## 
##      Please note that current support is partially complete for BrAPI version 1.2
##       - the additional calls in version 1.2 are not yet supported.
## 
##      Also, checks on response objects and fields are only loosely implemented to accomodate differences
##       between BrAPI versions.
##     If you find issues please 
## 
##     - turn on comments with ba_show_info()
## .
##     - You can double check against the database by copy/paste of the reported BrAPI URL
## 
##       at: http://webapps.ipk-gatersleben.de/brapivalidator!
## 
##  0.9.4 
## 
##  Please register any further issues at:
##         https://github.com/CIP-RIU/brapi/issues
## apiary
## bms_test
## cassavabase
## cropontology
## eu_sol
## germinate_test
## icrisat_prod
## mgis
## musabase
## ricebase
## snpseek
## sweetpotatobase
## t3s
## testserver
## tto
## ttw
## yambase
## Crop = sweetpotato
## 
## Addres:Port = sweetpotatobase.org:80
## User =

Listing available crops

This is interesting if you have multicrop databases. In the case of sweetpotatobase there is only one crop on that server.

## # A tibble: 1 x 1
##   crops      
##   <chr>      
## 1 sweetpotato

Switching on information on server connectiviy

In many cases when exploring a new database it will be useful to get any feedback from the server. The package provides a switch that allows to turn on or off such log information.

Listing available calls

The brapi community and standard allows currently a large degree of freedom on implementation of individual parts of the standard (or calls). One call lists the functionality supported by the server.

ba_calls(sp_base)
## URL call was: https://sweetpotatobase.org/brapi/v1/calls/?
## Waiting for response from server: ...
## Server status:  ok!
## Status details from Server:
## 
## Infos:
## BrAPI base call found with page=0, pageSize=10
## Loading CXGN::BrAPI::v1::Calls
## 
## Successes:
## Calls result constructed
## 
## Errors:
## 
## No encoding supplied: defaulting to UTF-8.
## Returning page 0 (max. 0) with max. 1000 items (out of a total of 48).
## # A tibble: 48 x 4
##    versions  methods      datatypes call                                  
##  * <list>    <chr>        <chr>     <chr>                                 
##  1 <chr [1]> POST; DELETE json      token                                 
##  2 <chr [1]> GET          json      calls                                 
##  3 <chr [1]> GET          json      observationlevels                     
##  4 <chr [1]> GET; POST    json      germplasm-search                      
##  5 <chr [1]> GET          json      germplasm/{germplasmDbId}             
##  6 <chr [2]> GET          json      germplasm/{germplasmDbId}/pedigree    
##  7 <chr [2]> GET          json      germplasm/{germplasmDbId}/progeny     
##  8 <chr [1]> GET          json      germplasm/{germplasmDbId}/markerprofi~
##  9 <chr [1]> GET          json      germplasm/{germplasmDbId}/attributes  
## 10 <chr [1]> GET          json      attributes                            
## # ... with 38 more rows

As you notice, the table is presented as a tibble. This has the advantage that it fits on the screen always even though there are big tables. But sometimes it may be useful to just print out the whole table. How to do that is the topic of the next section.

Function design

All functions always have two parameters: the first is always the database handle or connection details (‘con’), the last is always the R class of the returned object. Most parameters should be of class ‘character’. Exceptions are: the con parameter is always a list; the parameters ‘page’ and ‘pageSize’ if applicable are integers. For details see individual functions.

Output formats

This is by default a tibble. However, there are several others supported. An alternative is the ‘data.frame’. In addition and mainly for debugging purposes you can set the value to ‘json’ which will return the full response json object; or you can set it to ‘list’ which will return a list equivalent.

So, let’s just print out the whole data.frame.

ba_calls(con = sp_base, rclass = "data.frame")
## No encoding supplied: defaulting to UTF-8.
##    versions      methods           datatypes
## 1       1.0 POST; DELETE                json
## 2       1.0          GET                json
## 3       1.0          GET                json
## 4       1.0    GET; POST                json
## 5       1.0          GET                json
## 6  1.0, 1.2          GET                json
## 7  1.0, 1.2          GET                json
## 8       1.0          GET                json
## 9       1.0          GET                json
## 10      1.0          GET                json
## 11      1.0          GET                json
## 12      1.0          GET                json
## 13      1.0          GET                json
## 14      1.0          GET                json
## 15      1.0    GET; POST json; tsv; csv; xls
## 16      1.0    GET; POST json; tsv; csv; xls
## 17      1.0    GET; POST                json
## 18      1.0          GET                json
## 19      1.0    GET; POST                json
## 20      1.0    GET; POST                json
## 21      1.0    GET; POST                json
## 22      1.0          GET                json
## 23      1.0    GET; POST                json
## 24      1.0          GET                json
## 25      1.0          GET                json
## 26      1.0          GET                json
## 27      1.0          GET                json
## 28      1.0          GET json; csv; xls; tsv
## 29      1.0          GET                json
## 30      1.0          GET                json
## 31      1.0    GET; POST                json
## 32      1.0    GET; POST                json
## 33      1.0    GET; POST                json
## 34      1.0    GET; POST                json
## 35      1.0          GET                json
## 36      1.0          GET                json
## 37      1.0          GET                json
## 38      1.0          GET                json
## 39      1.0          GET                json
## 40      1.0          GET                json
## 41      1.0          GET                json
## 42      1.0          GET                json
## 43      1.0          GET                json
## 44      1.0          GET                json
## 45      1.0          GET                json
## 46      1.0    GET; POST                json
## 47      1.0    GET; POST                json
## 48      1.0          GET                json
##                                        call
## 1                                     token
## 2                                     calls
## 3                         observationlevels
## 4                          germplasm-search
## 5                 germplasm/{germplasmDbId}
## 6        germplasm/{germplasmDbId}/pedigree
## 7         germplasm/{germplasmDbId}/progeny
## 8  germplasm/{germplasmDbId}/markerprofiles
## 9      germplasm/{germplasmDbId}/attributes
## 10                               attributes
## 11                    attributes/categories
## 12                           markerprofiles
## 13       markerprofiles/{markerprofileDbId}
## 14                   markerprofiles/methods
## 15                      allelematrix-search
## 16                    allelematrices-search
## 17                                 programs
## 18                                    crops
## 19                                  seasons
## 20                               studytypes
## 21                                   trials
## 22                       trials/{trialDbId}
## 23                           studies-search
## 24                      studies/{studyDbId}
## 25            studies/{studyDbId}/germplasm
## 26 studies/{studyDbId}/observationvariables
## 27     studies/{studyDbId}/observationunits
## 28                studies/{studyDbId}/table
## 29               studies/{studyDbId}/layout
## 30         studies/{studyDbId}/observations
## 31                        phenotypes-search
## 32                  phenotypes-search/table
## 33                    phenotypes-search/tsv
## 34                    phenotypes-search/csv
## 35                                   traits
## 36                       traits/{traitDbId}
## 37                                     maps
## 38                           maps/{mapDbId}
## 39                 maps/{mapDbId}/positions
## 40              maps/{mapDbId}/positions/id
## 41                                locations
## 42                      variables/datatypes
## 43                               ontologies
## 44                                variables
## 45      variables/{observationVariableDbId}
## 46                         variables-search
## 47                           samples-search
## 48                     samples/{sampleDbId}

Getting phenotypic data

The brapi models trial data in a three layer hierarchy: a) breeding program which has b) trials that c) may consist of one or more studies at one or more locations. A study at one location is also often referred to as a fieldbook.

Which breeding programs are there?

ba_programs(sp_base, rclass = "data.frame")
## No encoding supplied: defaulting to UTF-8.
##    commonCropName leadPerson       name programDbId abbreviation
## 1     SweetPotato            Mozambique         135             
## 2     SweetPotato                Uganda         137             
## 3     SweetPotato                 Ghana         140             
## 4     SweetPotato                  NCSU         132             
## 5     SweetPotato                  Lima         167             
## 6     SweetPotato             GT4SP-CIP         293             
## 7     SweetPotato                 Kenya        1264             
## 8     SweetPotato                   RAB        1282             
## 9     SweetPotato                 INERA        1286             
## 10    SweetPotato                  AARC        1288             
##                            objective
## 1                         Mozambique
## 2                             Uganda
## 3                              Ghana
## 4  NCSU Sweetpotato Breeding Program
## 5   Sweetpotato Breeding program CIP
## 6     Genomics Tools for Sweetpotato
## 7              Demo Breeding Program
## 8                             Rubona
## 9                        Ouagadougou
## 10                           Hawassa

Which studies are there?

ba_studies_search(sp_base, programDbId = "140")
## Using GET
## No encoding supplied: defaulting to UTF-8.
## # A tibble: 210 x 15
##    seasons active programName name         locationDbId trialDbId endDate 
##  * <chr>   <chr>  <chr>       <chr>        <chr>        <chr>     <chr>   
##  1 2015    ""     Ghana       15FOD07Tono  18           230       2015-Ju~
##  2 2015    ""     Ghana       15FOD07Wa    26           230       2015-Ju~
##  3 2015    ""     Ghana       15HST03Ny    28           230       2015-Ju~
##  4 2015    ""     Ghana       15HST04Wa    26           230       <NA>    
##  5 2015    ""     Ghana       15ayt7SP_Im~ 16           230       <NA>    
##  6 2016    ""     Ghana       16CIP-Ghana~ 16           232       2016-Au~
##  7 2016    ""     Ghana       16CIP-Ghana~ 22           232       2016-Ma~
##  8 2010    ""     Ghana       2010ASPGH_A~ 38           284       2010-Ma~
##  9 2010    ""     Ghana       2010ASPGH_A~ 16           284       2010-Ap~
## 10 2010    ""     Ghana       2010ASPGH_A~ 39           284       2010-Ju~
## # ... with 200 more rows, and 8 more variables: trialName <chr>,
## #   locationName <chr>, programDbId <chr>, startDate <chr>,
## #   studyDbId <chr>, studyType <chr>, additionalInfo.design <chr>,
## #   additionalInfo.description <chr>