Skip to content

Commit 121e3c7

Browse files
kimberlyh66dlebauer
authored andcommitted
Traits tutorials (#39)
* fixed link to agronomic metadata tutorial * Updated tutorial. Added a summary showing the 3 ways to access API data. * Further updated the tutorial on how to access API using URL query and bash shell. * Further updated tutorial. Added short comment on the use of the fromJSON function. * Further updated R jsonlite portion of tutorial * Update traits/01-web-access.Rmd Co-Authored-By: kimberlyh66 <44081116+kimberlyh66@users.noreply.github.com> * added comment. link to traitvis webapp not working. * fixed links to terraref and pecan sites, betydb schemas, and doi reference. also updated comment on embedded shiny app (link to traitvis app does work). * updated beta user program link, and fixed links to agronomic metadata tutorial and terraref bety home page * made changes according to previous comments * made minor edits - assuming betykey in traits directory since ~ does not work on Windows * minor edit - removed comment * -changed trait in sorghum height search from 'canopy_cover' to 'canopy_height' -removed geom_smooth layer from ggplot * made minor edits. changed api version from 'beta' to 'v1' and hid the results of the 'query-danforth' r chunk * changed image name from 'betydb-postgis' to 'bety-postgis' * changed ~ (home directory) to . (current directory) * changed ~ (home directory) to . (current directory) * Removed YAML metadata header. Added Chapter title. * Removed YAML header. Added chapter title. * Changed chapter title to be more specific. Chapter 6 title is also Phenotype Analysis. * Removed text comment * updated chapter title - made more specific * commented out all chunks that were related to the traits-05-get-variables chunk (running this chunk results in a HTTP 504 Gateway Timeout) * set betydb_query parameters using options * loaded in some needed packages; set betydb_query function parameters using options * set options for chunks to improve look of output * changed headers to level 2 so not treated like a chapter title * set warning option to FALSE * removed .Rmd files that are not ready to be built into book * changed path to .betykey file * added tutorial 07 to rmd_files * minor edit to rmd_files * minor edits * removed extra parentheses; commented out portion of code that called the 'yields' object (object not ever created - and no rows returned for yields table query) * rearranged chunks and added some chunk options to improve output * added chunk option * Traits tutorials revisions (#41) * added some context to index * updated / added some stubs where we need more details * updated rmd_files (added tutorials 5 and 6) * added section header; added pointer urls * added some context to traits/06 * changed files to include in rmd_files * removed section header - not supposed to be in this file * created section header * changed some chunk parameters and added repository for traits installation * changed chunk parameters * changed chunk parameters and commented out sections that were not running correctly (HTTP 504) * fix canopy_height query ... using sitename now. * remove cache from canopy_height chunk * remove cache from canopy_height chunk
1 parent 7695c57 commit 121e3c7

11 files changed

Lines changed: 402 additions & 335 deletions

_bookdown.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ output_dir: "docs"
33
language:
44
ui:
55
chapter_name: "Chapter "
6-
rmd_files: ["index.Rmd", "traits/00-BETYdb-getting-started.Rmd",
7-
"traits/01-web-access.Rmd", "traits/02-betydb-api-access.Rmd", "traits/03-access-r-traits.Rmd",
8-
"traits/04-danforth-indoor-phenotyping-facility.Rmd", "traits/05-maricopa-field-scanner.Rmd",
9-
"traits/06-agronomic-metadata.Rmd"]#, "10-simulated-sorghum.Rmd"
6+
rmd_files: ["index.Rmd", "traits/00-BETYdb-getting-started.Rmd", "traits/01-web-access.Rmd",
7+
"traits/02-betydb-api-access.Rmd", "traits/03-access-r-traits.Rmd", "traits/04-danforth-indoor-phenotyping-facility.Rmd",
8+
"traits/06-agronomic-metadata.Rmd", "traits/07-betydb-sql-access.Rmd", "traits/10-simulated-sorghum.Rmd"]#, "10-simulated-sorghum.Rmd"
109

index.Rmd

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,74 @@ date: "`r Sys.Date()`"
66
documentclass: book
77
output:
88
bookdown::gitbook: default
9-
bookdown::pdf_book: default
109
---
1110

12-
# Preamble
1311

14-
```{r}
12+
# Overview
13+
14+
This book is intended to introduce users to TERRA REF data as quickly as possible.
15+
16+
It introduces to the wide range of phenomics datasets generated by the TERRA Reference program. Not only does TERRA REF have a large number of data sets, but many of the databases can be accessed in a number of different ways. While this makes it more complicated to learn, the goal is to provide users with the flexibility to access data in the most useful way.
17+
18+
## User Accounts and permission to access TERRA REF data
19+
20+
TODO: link to relevant parts of docs.terraref.org
21+
22+
* Info on how to [request access to data](https://docs.terraref.org/user-manual/how-to-access-data/using-betydb-trait-data-experimental-metadata)
23+
24+
## Ways of Acessing Data
25+
26+
* Web Interfaces
27+
+ [Clowder](https://docs.terraref.org/user-manual/how-to-access-data/using-clowder-sensor-and-genoomics-data) (sensor and genomic data)
28+
+ [Globus](https://docs.terraref.org/user-manual/how-to-access-data/using-globus-sensor-and-genomics-data) (sensor and genomic data)
29+
+ [BETYdb](https://docs.terraref.org/user-manual/how-to-access-data/using-betydb-trait-data-experimental-metadata) (trait data and experimental metadata)
30+
+ [CoGe](https://docs.terraref.org/user-manual/how-to-access-data/using-coge-genomics) (genomic data)
31+
* Files
32+
* Programming APIs
33+
+ [BETYdb API](https://pecan.gitbook.io/betydb-data-access/api-for-url-based-queries)
34+
* API Clients
35+
+ [rOpenSci traits package](https://pecan.gitbook.io/betydb-data-access/ropensci-traits-package)
36+
37+
## Other Resources
38+
39+
The TERRA REF website: [terraref.org](http://terraref.org/)
40+
41+
The TERRA REF Technical Documentation: [docs.terraref.org](docs.terraref.org)
42+
43+
## Contents
44+
45+
Scope ...
46+
47+
Audience ...
48+
49+
50+
## Pre-requisites
51+
52+
While we assume that readers will have some familiarity with the nature of the problem - remote sensing of crop plants - for the most part, these tutorials assume that the user will bring their own scientific questions and a sense of curiosity and are eager to learn.
53+
54+
Some of the lessons only require a web browser; others will assume familarity with programming at the command line in (typically only one of) Python, R, and / or SQL. You should be willing to find help (see finding help, below).
55+
56+
## Technical Requirements
57+
58+
At a minimum, you should have:
59+
60+
* An internet connection
61+
* Web Browser
62+
* A TERRA REF Beta User account
63+
+ If you have not done so, please sign up at [terraref.org/beta](terraref.org/beta)
64+
* Access to the data that you are using
65+
+ The tutorials will state which databases you will need access to
66+
* Software:
67+
+ Software requirements vary with the tutorials, and may be complex
68+
69+
70+
## Finding help
71+
72+
- [Slack](terra-ref.slack.com)
73+
- [GitHub](https://github.com/terraref/tutorials)
74+
- [Google](https://www.google.com/)
75+
76+
```{r, include = FALSE}
1577
knitr::opts_chunk$set(echo = FALSE, cache = TRUE)
1678
options(warn = -1)
1779
```

traits/00-BETYdb-getting-started.Rmd

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
---
2-
title: "Getting Started with BETYdb"
3-
author: "David LeBauer"
4-
date: "`r Sys.Date()`"
5-
output: html_document
6-
---
1+
# (PART\*) Secton 1: Traits {-}
2+
3+
# Getting Started with BETYdb
74

85
## TERRA Ref Trait Database
96

@@ -40,5 +37,5 @@ The traitvis webapp provides an interface for exploring available data that is u
4037
* website: https://traitvis.workbench.terraref.org
4138

4239
```{r}
43-
knitr::include_app("https://traitvis.workbench.terraref.org", height = "1400px") #not working; shiny app is not being displayed in html output
40+
knitr::include_app("https://traitvis.workbench.terraref.org", height = "1400px")
4441
```

traits/01-web-access.Rmd

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
---
2-
title: "Accessing Trait Data Via the BETYdb Web Interface"
3-
author: "David LeBauer"
4-
date: "`r Sys.Date()`"
5-
output: html_document
6-
---
7-
8-
1+
# Accessing Trait Data Via the BETYdb Web Interface
92

103
## Getting an account for the TERRA trait database
114

traits/02-betydb-api-access.Rmd

Lines changed: 110 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,110 @@
1-
---
2-
title: "Accessing Trait Data Via the BETYdb API"
3-
author: "David LeBauer"
4-
date: "11/7/2017"
5-
output: html_document
6-
---
7-
8-
9-
## Using URLs to construct Queries
10-
11-
The first step toward reproducible pipelines is to automate the process of searching the database and returning results. This is one of the key roles of an Application programming interface, or 'API'. You can learn to use the API in less than 20 minutes, starting now.
12-
13-
### What is an API?
14-
15-
An API is an 'Application Programming Interface'. An API is a way that you and your software can connect to and access data.
16-
17-
All of our databases have web interfaces for humans to browse as well as APIs that are constructed as URLs.
18-
19-
20-
### Using Your API key to Connect
21-
22-
An API key is like a password. It allows you to access data, and should be kept private.
23-
Therefore, we are not going to put it in code that we share. The one exception is the key 9999999999999999999999999999999999999999 that will allow you to access metadata tables (all tables except _traits_ and _yields_). It will also allow you to access all of the simulated data in the https://terraref.ncsa.illinois.edu/bety-test database.
24-
25-
A common way of handling private API keys is to place it in a text file in your current directory.
26-
Don't put it in a project directory where it might be inadvertently shared.
27-
28-
Here is how to find and save your API key:
29-
30-
* click file --> new --> text file
31-
* copy the api key that was sent when you registered into the file
32-
* file --> save as '.betykey'
33-
34-
For the public key, you can call this file `.betykey_public`.
35-
36-
### Ways to access API data
37-
38-
1. Through a URL query
39-
2. Using the bash shell
40-
3. Using the R jsonlite package
41-
42-
43-
### Accessing data using a URL query
44-
45-
46-
## Components of a URL query
47-
48-
* base url: `terraref.ncsa.illinois.edu/bety`
49-
* path to the api: `/api/v1`
50-
* api endpoint: `/search` or `traits` or `sites`. For BETYdb, these are the names of database tables.
51-
* Query parameters: `genus=Sorghum`
52-
* Authentication: `key=9999999999999999999999999999999999999999` is the public key for the TERRA REF traits database.
53-
54-
## Constructing a URL query
55-
56-
First, lets construct a query by putting together a URL.
57-
58-
1. start with the database url: `terraref.ncsa.illinois.edu/bety`
59-
* this url brings you to the home page
60-
2. Add the path to the API, `/api/v1`
61-
* now we have terraref.ncsa.illinois.edu/bety/api/v1, which points to the API documentation
62-
3. Add the name of the table you want to query. Lets start with `variables`
63-
* terraref.ncsa.illinois.edu/bety/api/v1/variables
64-
4. add query terms by appending a `?` and combining with `&`, for example:
65-
* `key=9999999999999999999999999999999999999999`
66-
* `type=trait` where the variable type is 'trait'
67-
* `name=~height` where the variable name contains 'height'
68-
5. This is your complete query:
69-
* `terraref.ncsa.illinois.edu/bety/api/v1/variables?type=trait&name=~height&key=9999999999999999999999999999999999999999`
70-
* it will query all variables that are type trait and have 'height' in the name
71-
* Does it return the expected values?
72-
73-
## Your Turn
74-
75-
> What will the URL https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=9999999999999999999999999999999999999999 return?
76-
77-
> Write a URL that will query the database for sites with "Field Scanner" in the name field. Hint: combine two terms with a `+` as in `Field+Scanner`
78-
79-
What do you see? Do you think that this is all of the records? What happens if you add `&limit=none`?
80-
81-
82-
83-
#### Accessing data using the Shell
84-
85-
Type the following command into a bash shell (the `-o` option names the output file):
86-
87-
```sh
88-
curl -o sorghum.json \
89-
"https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=9999999999999999999999999999999999999999"
90-
```
91-
92-
If you want to write the query without exposing the key in plain text, you can construct it like this:
93-
94-
```sh
95-
curl -o sorghum.json \
96-
"https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=`cat .betykey_public`"
97-
```
98-
99-
### Accessing API data using the R jsonlite package
100-
101-
```{r text-api}
102-
sorghum.json <- readLines(
103-
paste0("https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=",
104-
readLines('.betykey')))
105-
106-
## print(sorghum.json)
107-
## not a particularly useful format
108-
## lets convert to a data frame
109-
sorghum <- jsonlite::fromJSON(sorghum.json)
110-
```
111-
112-
More on how to use the rOpenSci traits package coming up in the [next tutorial](03-access-r-traits.Rmd)
1+
# Accessing Trait Data Via the BETYdb API
2+
3+
This will teach you how to query trait data using a browser as well as using the command line tool `curl`. This interface is the primary way in which you can access data from the command line.
4+
5+
## What is an API?
6+
7+
An API is an 'Application Programming Interface'. An API is a way that you and your software can connect to and access data.
8+
9+
All of our databases have web interfaces for humans to browse as well as APIs that are constructed as URLs.
10+
11+
## Tutorial Contents
12+
13+
In this tutorial, we will describe three ways to access data using:
14+
15+
1. A URL typed into your browser
16+
2. The command line, or terminal
17+
3. The R jsonlite package
18+
19+
We also have interfaces using R 'traits' package or the Python 'terrautils' package that return data in a more familiar and ready to analyze tabular format; these will be described later. You can skip ahead to those chapters, but this chapter will provide some insight into the methods that underlie those libraries.
20+
21+
## Using URLs to construct Queries
22+
23+
The first step toward reproducible pipelines is to automate the process of searching the database and returning results. This is one of the key roles of an Application programming interface, or 'API'. You can learn to use the API in less than 20 minutes, starting now.
24+
25+
26+
### Using Your API key to Connect
27+
28+
An API key is like a password. It allows you to access data, and should be kept private.
29+
Therefore, we are not going to put it in code that we share. The one exception is the key 9999999999999999999999999999999999999999 that will allow you to access metadata tables (all tables except _traits_ and _yields_). It will also allow you to access all of the simulated data in the https://terraref.ncsa.illinois.edu/bety-test database.
30+
31+
A common way of handling private API keys is to place it in a text file in your current directory.
32+
Don't put it in a project directory where it might be inadvertently shared.
33+
34+
Here is how to find and save your API key:
35+
36+
* click file --> new --> text file
37+
* copy the api key that was sent when you registered into the file
38+
* file --> save as '.betykey'
39+
40+
For the public key, you can call this file `.betykey_public`.
41+
42+
43+
## Accessing data using a URL query
44+
45+
46+
### Components of a URL query
47+
48+
* base url: `terraref.ncsa.illinois.edu/bety`
49+
* path to the api: `/api/v1`
50+
* api endpoint: `/search` or `traits` or `sites`. For BETYdb, these are the names of database tables.
51+
* Query parameters: `genus=Sorghum`
52+
* Authentication: `key=9999999999999999999999999999999999999999` is the public key for the TERRA REF traits database.
53+
54+
### Constructing a URL query
55+
56+
First, lets construct a query by putting together a URL.
57+
58+
1. start with the database url: `terraref.ncsa.illinois.edu/bety`
59+
* this url brings you to the home page
60+
2. Add the path to the API, `/api/v1`
61+
* now we have terraref.ncsa.illinois.edu/bety/api/v1, which points to the API documentation
62+
3. Add the name of the table you want to query. Lets start with `variables`
63+
* terraref.ncsa.illinois.edu/bety/api/v1/variables
64+
4. add query terms by appending a `?` and combining with `&`, for example:
65+
* `key=9999999999999999999999999999999999999999`
66+
* `type=trait` where the variable type is 'trait'
67+
* `name=~height` where the variable name contains 'height'
68+
5. This is your complete query:
69+
* `terraref.ncsa.illinois.edu/bety/api/v1/variables?type=trait&name=~height&key=9999999999999999999999999999999999999999`
70+
* it will query all variables that are type trait and have 'height' in the name
71+
* Does it return the expected values?
72+
73+
## Your Turn
74+
75+
> What will the URL https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=9999999999999999999999999999999999999999 return?
76+
77+
> Write a URL that will query the database for sites with "Field Scanner" in the name field. Hint: combine two terms with a `+` as in `Field+Scanner`
78+
79+
What do you see? Do you think that this is all of the records? What happens if you add `&limit=none`?
80+
81+
## Accessing data using the Command Line Terminal
82+
83+
Type the following command into a bash shell (the `-o` option names the output file):
84+
85+
```sh
86+
curl -o sorghum.json \
87+
"https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=9999999999999999999999999999999999999999"
88+
```
89+
90+
If you want to write the query without exposing the key in plain text, you can construct it like this:
91+
92+
```sh
93+
curl -o sorghum.json \
94+
"https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=`cat .betykey_public`"
95+
```
96+
97+
## Using the R jsonlite package to access the API with a URL query
98+
99+
```{r text-api, warning = FALSE}
100+
sorghum.json <- readLines(
101+
paste0("https://terraref.ncsa.illinois.edu/bety/api/v1/species?genus=Sorghum&key=",
102+
readLines('traits/.betykey')))
103+
104+
## print(sorghum.json)
105+
## not a particularly useful format
106+
## lets convert to a data frame
107+
sorghum <- jsonlite::fromJSON(sorghum.json)
108+
```
109+
110+
More on how to use the rOpenSci traits package coming up in the [next tutorial](03-access-r-traits.Rmd)

0 commit comments

Comments
 (0)