Skip to content

Commit 2efbe2b

Browse files
KristinaRiemerdlebauer
authored andcommitted
Add complete notes for last walkthrough (#215)
1 parent 732a3ef commit 2efbe2b

2 files changed

Lines changed: 461 additions & 0 deletions

File tree

videos/fourth_walkthrough.Rmd

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: "Fourth Walkthrough Notes"
3+
author: "Kristina Riemer"
4+
output: github_document
5+
urlcolor: blue
6+
---
7+
8+
Objectives: introduction to what BrAPI is and how it works, and then looking at and accessing the TERRA REF data available through BrAPI
9+
10+
## Video 1: BrAPI intro
11+
12+
The [BrAPI website](https://brapi.docs.apiary.io) is a very useful, well-laid out resource for learning about and using this API.
13+
14+
BrAPI stands for Breeding API. It is a free and open source tool.
15+
16+
The purpose of BrAPI is to provide standardization of large amounts of phenotypic and genotypic data for planting breeding research. It is a grassroots effort that is used around the globe and is a community development project.
17+
18+
In general, an API is a way of storing data online and accessing it. For example, when you type in a website URL in your browser, you are using an API to view the website's data.
19+
20+
BrAPI is an API that stores plant breeding phenotype and genotype data for a growing number of databases. It uses a RESTful format, which is a certain convention and set of guidelines for how to create APIs that is popular. Data are accessed and put up with HTTP verbs. Outputs are all in the JSON format. This is a lot of jargon that we'll be going through more thoroughly.
21+
22+
Some of the other intended downstream uses of BrAPI, besides data storage and format consistency, includes:
23+
24+
* integration with field data collection apps
25+
* automating visualization and analysis
26+
* integrating breeding data datasets
27+
28+
## Video 2: Browsing BrAPI Data with BRAVA
29+
30+
One way to look through the databases that use BrAPI are with the [API validator](http://webapps.ipk-gatersleben.de/brapivalidator/). It's called BRAVA. Purpose is for people using BrAPI to check that their implementation works.
31+
32+
But can also look through databases. Under BrAPI resources, lists some of the databases. Sweetpotatobase is one that's well tested. TERRA REF is actually not here right now.
33+
34+
Go to "Test your own" tab. Put TERRA REF URL into Server URL line: https://brapi.workbench.terraref.org/brapi/v1
35+
36+
All BrAPI URLS have same format. Server name for specific database (brapi.workbench.terraref.org), then brapi, and finally version.
37+
38+
Current major version of BrAPI is 1, minor versions from 1.1 - 1.3. Leave on v1.3 for "BrAPI Version". Hit "Test it now!" button and wait.
39+
40+
Returns all the different categories of TERRA REF data available. BrAPI only has trait and genotype data for TERRA REF, and metadata for those data. These data are rearranged differently than on Clowder and Globus also.
41+
42+
There are about a dozen categories, also called endpoints. Ones for type of crop, locations where data collected, seasons, and which studies conducted.
43+
44+
They all use the GET HTTP verb. This means that you can point at the endpoint and get a response of data. Can also specify parameters in request to endpoint to get subset of data. There are other verbs, like POST and DELETE, but those aren't used here.
45+
46+
## Video 3: TERRA REF BrAPI JSON Structure
47+
48+
Can look at these categories of data in browser. Use base URL and add on name of category. Start with "Calls", it contains info about all TERRA REF categories.
49+
50+
Returns a JSON. JSON is a text file format that's both machine and human readable. It stores data and metadata. Like Python dictionaries, made up of key with a corresponding value.
51+
52+
Each JSON returned by BrAPI have same structure. Have metadata section and result section. Metadata contains additional data files with empty square brackets if there are none. Information about how many pages are shown in the current version, which we'll change later. And status will have errors in structure if any.
53+
54+
Data are in result section. Each piece of data in calls is for each TERRA REF endpoint. Shows what kind of data each returns, which is JSON for all, what verb can be used, which is GET for all, and which minor version of BrAPI it's compatible with.
55+
56+
Looking at nicer interface of the JSON. Click on Raw Data tab to look at actual JSON contents. Formatting is structure with curly and square brackets for different parts. Key and values separated by colon.
57+
58+
## Video 4: Get Trait Data With BrAPI and R
59+
60+
Go back to JSON tab. Look at TERRA REF trait data to start with. This is in the observationunits endpoint, scroll down to it.
61+
62+
Look at this JSON in same way, by adding endpoint name to end of base URL: https://brapi.workbench.terraref.org/brapi/v1/observationunits. Metadata at top. Click on result, then data, then 0. Each of these holds a single observation.
63+
64+
Let's actually download these data into R to use them.
65+
66+
I'm going to do this in the CyVerse Discovery Environment, in the TERRA REF RStudio app that I've used all in previous webinars. Could also do on local computer.
67+
68+
There is an R package that is in development for accessing data through BrAPI, including TERRA REF. We're not going to use it here.
69+
70+
We're instead going to use an R package that we used before to get weather data from Clowder, `jsonlite`. The purpose of this package is to pull down JSON files from the web and turn them into R objects.
71+
72+
In a new R script, read in the library. Using `fromJSON` with the URL we just typed in to pull down the data.
73+
74+
Look at this, which is a list of lists. There are the same groupings as seen in the JSON in the browser.
75+
76+
```{r}
77+
library(jsonlite)
78+
pheno_all <- fromJSON("https://brapi.workbench.terraref.org/brapi/v1/observationunits")
79+
```
80+
81+
We want the actual trait observations, so will use the $ operator to get out the data chunk. Returns a dataframe that contains information about the plots. This has the season and plot in observationUnitName column and experimental treatment in observationtreatment.
82+
```{r}
83+
pheno_plots <- pheno_all$result$data
84+
```
85+
86+
There can be multiple rows for each plot, as the same plot could be sampled many times in a season. Each row has one observation in observations column. Let's pull these out.
87+
88+
Get observations column, but it's in another list of lists. Use do.call on each object of the list and put them together by row using `rbind`.
89+
90+
```{r}
91+
pheno_obs_list <- pheno_plots$observations
92+
pheno_obs <- do.call(rbind, pheno_obs_list)
93+
```
94+
95+
This contains the time of the data collection, the type of variable collected, and the value. Anyone know why these values are zero? Go to traitvis.workbench.terraref.org, season 6, canopy cover, and map. Range 1 Column 1 is plot in lower left corner, they might not be growing anything there.
96+
97+
## Video 5: Using Parameters with BrAPI URLs
98+
99+
First though, you'll notice there are only 1,000 of these rows. That's because there are limits on the amount of data that the base URL returns. There can be a lot, getting it all at once can cause crashes.
100+
101+
Go back to [browser window for observationunits JSON](https://brapi.workbench.terraref.org/brapi/v1/observationunits). Under pagination in metadata, the pageSize is set at 1,000. That means the default is 1,000 records returned at one time. There are more than 2 million possible records in the totalCount though.
102+
103+
Can subset different parts of data in an API by specifying a parameter in the URL. Added on to end. For example, could return only first ten records by adding ?pageSize=10. Can also specify page parameter, which is page to start on, e.g., page=15. By combining these can return any set of pages. For example, page=10000&pageSize=10. This will return the 10000 page and the following 9 pages. These are now in the sixth season.
104+
105+
Can just get these data into a dataframe using this new URL.
106+
107+
## Video 6: Cleaning & Plotting Trait Data from BrAPI
108+
109+
Can pull down, rearrange/clean, and plot these data like before.
110+
111+
Let's say we subset the data to one plot in season 4. Use `dplyr` for this. Have to go back to plots dataframe and subset that first. Getting a plot that's more in the middle of the field.
112+
113+
```{r}
114+
library(dplyr)
115+
pheno_plot <- pheno_plots %>%
116+
filter(observationUnitName == "MAC Field Scanner Season 4 Range 2 Column 16")
117+
```
118+
119+
This only has 34 observations. Pull out trait names and values again. Combine the two steps into one line.
120+
121+
Under `observationVariableName`, there are two types of values. Canopy cover, like before, and also surface temperature which was taken by another instrument on the gantry.
122+
123+
```{r}
124+
pheno_plot_obs <- do.call(rbind, pheno_plot$observations)
125+
```
126+
127+
Let's plot these two variables across time like before. Use `lubridate` to get date into better format, and `ggplot2` with `facet_wrap` to plot variables separately. Both canopy cover and temp increased across summer.
128+
129+
```{r}
130+
library(lubridate)
131+
pheno_plot_obs <- pheno_plot_obs %>%
132+
mutate(formatted_date = ymd_hms(observationTimeStamp))
133+
134+
library(ggplot2)
135+
ggplot(pheno_plot_obs, aes(x = formatted_date, y = value)) +
136+
geom_point() +
137+
facet_wrap(~observationVariableName, scales = "free_y")
138+
```
139+
140+
Might to be easier to combine these two dataframes in a different way.
141+
142+
## Video 7: Accessing Genotype Data Using BrAPI
143+
144+
I said genotype data is also available in BrAPI for TERRA REF. Go to browser and replace endpoint with germplasm. Under result and data, each observation is for a different genotype of plant.
145+
146+
Can pull these into R like for the trait data. Use this URL and `fromJSON`. Same format as before, but can get observation with one step. This also only returns 1,000 pages/observations, can subset by page parameters like before.
147+
148+
```{r}
149+
geno_all <- fromJSON("https://brapi.workbench.terraref.org/brapi/v1/germplasm")
150+
geno_obs <- geno_all$result$data
151+
```
152+
153+
Some possibly important columns are genus and species ones. The xref.source column also links to the page in the BETYdb for that cultivar.
154+
155+
```{r}
156+
head(geno_obs$xref)
157+
```
158+
159+
You'll notice the "Name" section on BETYdb, which corresponds to the accessionNumber column in the data. This is what links to the actual genotypic data, which is located elsewhere.
160+
161+
These data are also stored in another CyVerse program called the Data Commons. Navigate to CyVerse Products and select Data Commons. Browse Data/Community Released -> terraref -> genomics -> derived_data -> bap -> resquencing -> danforth_center -> version1
162+
163+
The gvfc folder has individual files, which contain accessionNumber. Copy and paste first row's from R and control+F for the file. These VCF files, which stands for varianct call format. They contain single nucleotide polymorphisms (SNPs).
164+
165+
Backing up one level, the hapmap folder contains a file that combines all of those other files.

0 commit comments

Comments
 (0)