---
title: traits introduction
author: Scott Chamberlain
date: "2020-08-25"
output: rmarkdown::html_vignette
vignette: >
    %\VignetteIndexEntry{traits introduction}
    %\VignetteEngine{knitr::rmarkdown}
    %\VignetteEncoding{UTF-8}
---





```r
library("traits")
```

## BetyDB

Get trait data for Willow (_Salix_ spp.)


```r
(salix <- betydb_search("Salix Vcmax"))
#> # A tibble: 14 x 36
#>    checked result_type    id citation_id site_id treatment_id sitename city 
#>      <int> <chr>       <int>       <int>   <int>        <int> <chr>    <chr>
#>  1       1 traits      39217         430     645         1342 ""       Saare
#>  2       1 traits      39218         430     645         1343 ""       Saare
#>  3       1 traits      39219         430     645         1344 ""       Saare
#>  4       1 traits      39220         430     645         1345 ""       Saare
#>  5       1 traits      25405          51      NA            1  <NA>    <NA> 
#>  6       1 traits      39213         430     645         1342 ""       Saare
#>  7       1 traits      39214         430     645         1343 ""       Saare
#>  8       1 traits      39215         430     645         1344 ""       Saare
#>  9       1 traits      39216         430     645         1345 ""       Saare
#> 10       1 traits      39221         430     645         1342 ""       Saare
#> 11       1 traits      39222         430     645         1343 ""       Saare
#> 12       1 traits      39223         430     645         1344 ""       Saare
#> 13       1 traits      39224         430     645         1345 ""       Saare
#> 14       1 traits      37519         381     602         1220  <NA>    <NA> 
#> # … with 28 more variables: lat <dbl>, lon <dbl>, scientificname <chr>,
#> #   commonname <chr>, genus <chr>, species_id <int>, cultivar_id <int>,
#> #   author <chr>, citation_year <int>, treatment <chr>, date <chr>, time <chr>,
#> #   raw_date <chr>, month <int>, year <int>, dateloc <chr>, trait <chr>,
#> #   trait_description <chr>, mean <dbl>, units <chr>, n <int>, statname <chr>,
#> #   stat <dbl>, notes <chr>, access_level <int>, cultivar <chr>, entity <lgl>,
#> #   method_name <lgl>
# equivalent:
# (out <- betydb_search("willow"))
```

Summarise data from the output `data.frame`


```r
library("dplyr")
salix %>%
  group_by(scientificname, trait) %>%
  mutate(.mean = as.numeric(mean)) %>%
  summarise(mean = round(mean(.mean, na.rm = TRUE), 2),
            min = round(min(.mean, na.rm = TRUE), 2),
            max = round(max(.mean, na.rm = TRUE), 2),
            n = length(n))
#> # A tibble: 4 x 6
#> # Groups:   scientificname [4]
#>   scientificname                  trait  mean   min   max     n
#>   <chr>                           <chr> <dbl> <dbl> <dbl> <int>
#> 1 Salix                           Vcmax  65    65    65       1
#> 2 Salix dasyclados                Vcmax  46.1  34.3  56.7     4
#> 3 Salix sachalinensis × miyabeana Vcmax  79.3  79.3  79.3     1
#> 4 Salix viminalis                 Vcmax  43.0  20.0  61.3     8
```

## NCBI sequence data

Get sequences by id


```r
ncbi_byid(ids = "360040093")
#>                  taxon
#> 1 Eristalis transversa
#>                                                                                                                                                                                       taxonomy
#> 1 Eukaryota; Metazoa; Ecdysozoa; Arthropoda; Hexapoda; Insecta; Pterygota; Neoptera; Holometabola; Diptera; Brachycera; Muscomorpha; Syrphoidea; Syrphidae; Eristalinae; Eristalini; Eristalis
#>                                                                                                             gene_desc
#> 1 Eristalis transversa voucher CNC:Diptera:102013 cytochrome oxidase subunit 1 (COI) gene, partial cds; mitochondrial
#>       organelle     gi_no     acc_no keyword   specimen_voucher
#> 1 mitochondrion 360040093 JN991986.1 BARCODE CNC:Diptera:102013
#>               lat_lon
#> 1 38.4623 N 79.2417 W
#>                                                       country
#> 1 USA: Virginia, Reddish Knob Lookout, 14.5km W Briery Branch
#>                                                              paper_title
#> 1 The evolution of imperfect mimicry in hover flies (Diptera: Syrphidae)
#>       journal first_author uploaded_date length
#> 1 Unpublished   Penny,H.D.   03-NOV-2012    658
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             sequence
#> 1  
```

Get sequences searching by taxonomic name


```r
out <- ncbi_searcher(taxa = "Umbra limi", seqrange = "1:2000")
#> using sleep: 0
#> ══  1 queries  ═══════════════
#> ✔  Found:  Umbra+limi
#> ══  Results  ═════════════════
#> 
#> ● Total: 1 
#> ● Found: 1 
#> ● Not Found: 0
head(out)
#>        taxon length
#> 1 Umbra limi    298
#> 2 Umbra limi    761
#> 3 Umbra limi    765
#> 4 Umbra limi    764
#> 5 Umbra limi    743
#> 6 Umbra limi    758
#>                                                                                                gene_desc
#> 1 Umbra limi voucher Umbra_limi_GLF16S large subunit ribosomal RNA gene, partial sequence; mitochondrial
#> 2                                        Umbra limi voucher NXG2012264 rhodopsin (Rho) gene, partial cds
#> 3                                         Umbra limi voucher NXG201250 rhodopsin (Rho) gene, partial cds
#> 4                                        Umbra limi voucher NXG2012183 rhodopsin (Rho) gene, partial cds
#> 5                                         Umbra limi voucher NXG201252 rhodopsin (Rho) gene, partial cds
#> 6                                        Umbra limi voucher NXG2012231 rhodopsin (Rho) gene, partial cds
#>     acc_no      gi_no
#> 1 MT549086 1847697133
#> 2 KX146134 1049488959
#> 3 KX146015 1049488721
#> 4 KX145969 1049488629
#> 5 KX145777 1049488245
#> 6 KX145759 1049488209
```

## EOL's traitbank trait data


```r
traitbank(query = "MATCH (n:Trait) RETURN n LIMIT 1;")
#> $columns
#> [1] "n"
#> 
#> $data
#> $data[[1]]
#>   metadata.id metadata.labels    data.eol_pk data.object_page_id
#> 1    22529388           Trait R20-PK20910350            46581789
#>                                                    data.resource_pk
#> 1 ReverseOf_globi:assoc:7296029-FBC:FB:SpecCode:4755-ATE-EOL_V2:281
#>   data.scientific_name
#> 1              Plantae
#>                                                                                                                                                                                                                                                             data.source
#> 1 Froese, R. and D. Pauly. Editors. 2019. FishBase. World Wide Web electronic publication. www.fishbase.org, version (08/2019). Accessed at <https://github.com/globalbioticinteractions/fishbase/archive/6ebceaacea18c6ff6c247182f9af8ad6fc05cc82.zip> on 25 May 2020.
```

## Birdlife International

Habitat data


```r
birdlife_habitat(22721692)
#>         id Habitat (level 1)                  Habitat (level 2) Importance
#> 1 22721692            Forest           Subtropical/Tropical Dry      major
#> 2 22721692            Forest Subtropical/Tropical Moist Montane      major
#> 3 22721692            Forest                          Temperate   suitable
#> 4 22721692         Shrubland Subtropical/Tropical High Altitude   suitable
#>     Occurrence
#> 1     breeding
#> 2 non-breeding
#> 3     breeding
#> 4     breeding
```

Threats data


```r
birdlife_threats(22721692)
#>          id                                                  threat1
#> 1  22721692                                Agriculture & aquaculture
#> 2  22721692                                Agriculture & aquaculture
#> 3  22721692                                  Biological resource use
#> 4  22721692                          Climate change & severe weather
#> 5  22721692                          Climate change & severe weather
#> 6  22721692                          Climate change & severe weather
#> 7  22721692 Invasive and other problematic species, genes & diseases
#> 8  22721692 Invasive and other problematic species, genes & diseases
#> 9  22721692 Invasive and other problematic species, genes & diseases
#> 10 22721692 Invasive and other problematic species, genes & diseases
#> 11 22721692 Invasive and other problematic species, genes & diseases
#> 12 22721692 Invasive and other problematic species, genes & diseases
#> 13 22721692                             Natural system modifications
#> 14 22721692                             Natural system modifications
#> 15 22721692                     Residential & commercial development
#> 16 22721692                       Transportation & service corridors
#>                                                                                   threat2
#> 1                             Annual & perennial non-timber crops - Agro-industry farming
#> 2                              Annual & perennial non-timber crops - Small-holder farming
#> 3  Logging & wood harvesting - Unintentional effects: (subsistence/small scale) [harvest]
#> 4                                                                                Droughts
#> 5                                                           Habitat shifting & alteration
#> 6                                                                       Storms & flooding
#> 7                                 Invasive non-native/alien species/diseases - Sus scrofa
#> 8                        Invasive non-native/alien species/diseases - Unspecified species
#> 9                            Problematic native species/diseases - Dendroctonus frontalis
#> 10                           Problematic native species/diseases - Odocoileus virginianus
#> 11                              Problematic native species/diseases - Unspecified species
#> 12                    Problematic species/disease of unknown origin - Unspecified species
#> 13                                     Fire & fire suppression - Trend Unknown/Unrecorded
#> 14                                                          Other ecosystem modifications
#> 15                                                                  Housing & urban areas
#> 16                                                                      Roads & railroads
#>                                                                 stresses
#> 1                     Ecosystem degradation, Ecosystem conversion, Other
#> 2                     Ecosystem degradation, Ecosystem conversion, Other
#> 3                                                  Ecosystem degradation
#> 4                                                  Ecosystem degradation
#> 5                            Ecosystem degradation, Ecosystem conversion
#> 6                                                  Ecosystem degradation
#> 7                            Ecosystem degradation, Ecosystem conversion
#> 8                                                      Species mortality
#> 9                                                  Ecosystem degradation
#> 10                                                 Ecosystem degradation
#> 11                   Ecosystem degradation, Reduced reproductive success
#> 12                                                     Species mortality
#> 13                           Ecosystem degradation, Ecosystem conversion
#> 14                           Ecosystem degradation, Ecosystem conversion
#> 15 Ecosystem degradation, Ecosystem conversion, Species mortality, Other
#> 16                                                     Species mortality
#>                                                      timing
#> 1                                 Agriculture & aquaculture
#> 2                                 Agriculture & aquaculture
#> 3                                   Biological resource use
#> 4                           Climate change & severe weather
#> 5                           Climate change & severe weather
#> 6                           Climate change & severe weather
#> 7  Invasive and other problematic species, genes & diseases
#> 8  Invasive and other problematic species, genes & diseases
#> 9  Invasive and other problematic species, genes & diseases
#> 10 Invasive and other problematic species, genes & diseases
#> 11 Invasive and other problematic species, genes & diseases
#> 12 Invasive and other problematic species, genes & diseases
#> 13                             Natural system modifications
#> 14                             Natural system modifications
#> 15                     Residential & commercial development
#> 16                       Transportation & service corridors
#>                                                                                     scope
#> 1                             Annual & perennial non-timber crops - Agro-industry farming
#> 2                              Annual & perennial non-timber crops - Small-holder farming
#> 3  Logging & wood harvesting - Unintentional effects: (subsistence/small scale) [harvest]
#> 4                                                                                Droughts
#> 5                                                           Habitat shifting & alteration
#> 6                                                                       Storms & flooding
#> 7                                 Invasive non-native/alien species/diseases - Sus scrofa
#> 8                        Invasive non-native/alien species/diseases - Unspecified species
#> 9                            Problematic native species/diseases - Dendroctonus frontalis
#> 10                           Problematic native species/diseases - Odocoileus virginianus
#> 11                              Problematic native species/diseases - Unspecified species
#> 12                    Problematic species/disease of unknown origin - Unspecified species
#> 13                                     Fire & fire suppression - Trend Unknown/Unrecorded
#> 14                                                          Other ecosystem modifications
#> 15                                                                  Housing & urban areas
#> 16                                                                      Roads & railroads
#>    severity  impact
#> 1   Ongoing Ongoing
#> 2   Ongoing Ongoing
#> 3   Ongoing Ongoing
#> 4   Ongoing Ongoing
#> 5    Future  Future
#> 6   Ongoing Ongoing
#> 7   Ongoing Ongoing
#> 8   Ongoing Ongoing
#> 9   Ongoing Ongoing
#> 10  Ongoing Ongoing
#> 11  Ongoing Ongoing
#> 12  Ongoing Ongoing
#> 13  Ongoing Ongoing
#> 14   Future  Future
#> 15  Ongoing Ongoing
#> 16  Ongoing Ongoing
```
