# Connecting data to Open Tree trees

#### David Winter

#### 2019-09-28

## Combining data from OToL and other sources.

One of the major goals of `rotl` is to help users combine data from other sources with the phylogenetic trees in the Open Tree database. This examples document describes some of the ways in which a user might connect data to trees from Open Tree.

## Get Open Tree IDs to match your data.

Let’s say you have a dataset where each row represents a measurement taken from one species, and your goal is to put these measurements in some phylogenetic context. Here’s a small example: the best estimate of the mutation rate for a set of unicellular Eukaryotes along with some other property of those species which might explain the mutation rate:

    csv_path <- system.file("extdata", "protist_mutation_rates.csv", package = "rotl")
    mu <- read.csv(csv_path, stringsAsFactors = FALSE)
    mu

    ##                     species       mu pop.size genome.size
    ## 1   Tetrahymena thermophila 7.61e-12 1.12e+08    1.04e+08
    ## 2    Paramecium tetraurelia 1.94e-11 1.24e+08    7.20e+07
    ## 3 Chlamydomonas reinhardtii 2.08e-10 1.00e+08    1.12e+08
    ## 4  Dictyostelium discoideum 2.90e-11 7.40e+06    3.40e+07
    ## 5  Saccharomyces cerevisiae 3.30e-10 1.00e+08    1.25e+08
    ## 6       Saccharomyces pombe 2.00e-10 1.00e+07    1.25e+08

If we want to get a tree for these species we need to start by finding the unique ID for each of these species in the Open Tree database. We can use the Taxonomic Name Resolution Service (`tnrs`) functions to do this. Before we do that we should see if any of the taxonomic contexts, which can be used to narrow a search and avoid conflicts between different codes, apply to our group of species:

    library(rotl)

    ## Registered S3 method overwritten by 'lookup':
    ##   method         from
    ##   print.function base

    tnrs_contexts()

    ## Possible contexts:
    ##    Animals
    ##       Birds, Tetrapods, Mammals, Amphibians, Vertebrates
    ##       Arthropods, Molluscs, Nematodes, Platyhelminthes, Annelids
    ##       Cnidarians, Arachnids, Insects
    ##    Bacteria
    ##       SAR group, Archaea, Excavata, Amoebozoa, Centrohelida
    ##       Haptophyta, Apusozoa, Diatoms, Ciliates, Forams
    ##    Fungi
    ##       Basidiomycetes, Ascomycetes
    ##    Land plants
    ##       Hornworts, Mosses, Liverworts, Vascular plants, Club mosses
    ##       Ferns, Seed plants, Flowering plants, Monocots, Eudicots
    ##       Rosids, Asterids, Asterales, Asteraceae, Aster
    ##       Symphyotrichum, Campanulaceae, Lobelia
    ##    All life

Hmm, none of those groups contain all of our species. In this case we can search using the `All life` context and the function `tnrs_match_names`:

    taxon_search <- tnrs_match_names(names = mu$species, context_name = "All life")
    knitr::kable(taxon_search)

search_string | unique_name | approximate_match | ott_id | is_synonym | flags | number_matches
--- | --- | --- | --- | --- | --- | ---
tetrahymena thermophila | Tetrahymena thermophila | FALSE | 180195 | FALSE | SIBLING_HIGHER | 1
paramecium tetraurelia | Paramecium tetraurelia | FALSE | 568130 | FALSE |  | 1
chlamydomonas reinhardtii | Chlamydomonas reinhardtii | FALSE | 33153 | FALSE |  | 1
dictyostelium discoideum | Dictyostelium discoideum | FALSE | 160850 | FALSE |  | 1
saccharomyces cerevisiae | Saccharomyces cerevisiae | FALSE | 356221 | FALSE |  | 1
saccharomyces pombe | Schizosaccharomyces pombe | FALSE | 990004 | TRUE |  | 1

Good, all of our species are known to Open Tree. Note, though, that one of the names is a synonym. Saccharomyces pombe is older name for what is now called Schizosaccharomyces pombe. As the name suggests, the Taxonomic Name Resolution Service is designed to deal with these problems (and similar ones like misspellings), but it is always a good idea to check the results of `tnrs_match_names` closely to ensure the results are what you expect.

In this case we have a good ID for each of our species so we can move on. Before we do that, let’s ensure we can match up our original data to the Open Tree names and IDs by adding them to our `data.frame`:

    mu$ott_name <- unique_name(taxon_search)
    mu$ott_id <- taxon_search$ott_id

## Find a tree with your taxa

Now let’s find a tree. There are two possible options here: we can search for published studies that include our taxa or we can use the ‘synthetic tree’ from Open Tree. We can try both approaches.

### Published trees

Before we can search for published studies or trees, we should check out the list of properties we can use to perform such searches:

    studies_properties()

    ## $study_properties
    ##  [1] "ot:studyPublicationReference" "ot:curatorName"
    ##  [3] "ot:studyYear"                 "ot:focalClade"
    ##  [5] "ot:focalCladeOTTTaxonName"    "ot:dataDeposit"
    ##  [7] "ot:studyPublication"          "ot:tag"
    ##  [9] "ot:studyId"                   "ntrees"
    ## [11] "treebaseId"
    ##
    ## $tree_properties
    ##  [1] "ot:treebaseOTUId"           "ot:nodeLabelMode"
    ##  [3] "ot:originalLabel"           "oti_tree_id"
    ##  [5] "ot:inferenceMethod"         "ot:tag"
    ##  [7] "ot:treebaseTreeId"          "ot:comment"
    ##  [9] "ot:branchLengthDescription" "ot:treeModified"
    ## [11] "ot:branchLengthTimeUnits"   "ot:branchLengthMode"
    ## [13] "ot:treeLastEdited"          "ot:nodeLabelDescription"
    ## [15] "ot:ottId"                   "ot:ottTaxonName"
    ## [17] "ot:studyId"                 "ntips"

We have `ottIds` for our taxa, so let’s use those IDs to search for trees that contain them. Starting with our first species Tetrahymena thermophila we can use `studies_find_trees` to do this search.

    studies_find_trees(property = "ot:ottId", value = as.character(ott_id(taxon_search)[1]))

    ##    study_ids n_trees                                              tree_ids
    ## 1    ot_1044       1                                                 tree1
    ## 2    ot_1662       8                tree1, tree2, tree3, tree4, tree5, ...
    ## 3     ot_560       3                             Tr80090, Tr80091, Tr80092
    ## 4     ot_575       3                                   tree1, tree2, tree3
    ## 5     ot_650       1                                                 tree1
    ## 6     ot_651       1                                                 tree2
    ## 7     ot_705       1                                               Tr93612
    ## 8     ot_760       2                                           g0n0, tree1
    ## 9     ot_762       2                                          tree2, tree3
    ## 10     ot_89       2                                        Tr1003, Tr1004
    ## 11     ot_91       2                                      Tr46259, Tr46258
    ## 12     ot_96       2                                          tree1, tree2
    ## 13     ot_97       9                tree1, tree2, tree3, tree4, tree5, ...
    ## 14   pg_1272       1                                              tree2564
    ## 15   pg_1913       1                                              tree3903
    ## 16    pg_236       1                                              tree6285
    ## 17    pg_237       7       tree99, tree100, tree101, tree102, tree103, ...
    ## 18   pg_2412       4                tree5089, tree5090, tree5091, tree6403
    ## 19   pg_2435      24 tree5147, tree5148, tree5149, tree5150, tree5151, ...
    ## 20   pg_2533       6 tree5451, tree5452, tree5453, tree5454, tree5455, ...
    ## 21   pg_2618       2                                    tree6129, tree6130
    ## 22   pg_2702       3                          tree6272, tree6273, tree6274
    ## 23   pg_2762       3                          tree6384, tree6385, tree6386
    ## 24   pg_2924       1                                              tree6755
    ## 25    pg_301       2                                     tree205, tree5482
    ## 26    pg_310       3                             tree259, tree260, tree261
    ## 27    pg_315       1                                               tree266
    ## 28    pg_316       3                             tree267, tree268, tree269
    ## 29    pg_317       1                                               tree270
    ## 30    pg_424       1                                               tree532
    ## 31    pg_427       5          tree535, tree536, tree537, tree538, tree5574
    ## 32    pg_435       1                                              tree5995
    ## 33    pg_650       1                                              tree1147
    ## 34    pg_652       2                                    tree1152, tree5628
    ## 35    pg_655       1                                              tree1157
    ##                                                        candidate
    ## 1
    ## 2
    ## 3                                                        Tr80090
    ## 4                                                          tree3
    ## 5                                                          tree1
    ## 6                                                          tree2
    ## 7                                                        Tr93612
    ## 8                                                           g0n0
    ## 9                                                          tree3
    ## 10
    ## 11
    ## 12                                                         tree1
    ## 13 tree1, tree2, tree3, tree4, tree5, tree6, tree7, tree8, tree9
    ## 14
    ## 15
    ## 16
    ## 17
    ## 18
    ## 19
    ## 20
    ## 21                                                      tree6130
    ## 22                                                      tree6274
    ## 23
    ## 24                                                      tree6755
    ## 25
    ## 26
    ## 27
    ## 28
    ## 29
    ## 30                                                       tree532
    ## 31
    ## 32                                                      tree5995
    ## 33                                                      tree1147
    ## 34
    ## 35
    ##    study_year
    ## 1        2017
    ## 2        2017
    ## 3        2014
    ## 4        2007
    ## 5        2015
    ## 6        2010
    ## 7        2015
    ## 8        2013
    ## 9        2012
    ## 10       2007
    ## 11       2012
    ## 12       2014
    ## 13       2011
    ## 14       2009
    ## 15       2000
    ## 16       2000
    ## 17       2005
    ## 18       1999
    ## 19       2010
    ## 20       2010
    ## 21       2011
    ## 22       2014
    ## 23       2014
    ## 24       2014
    ## 25       2006
    ## 26       2011
    ## 27       2010
    ## 28       2012
    ## 29       2012
    ## 30       2010
    ## 31       2005
    ## 32       2008
    ## 33       2010
    ## 34       2012
    ## 35       2010
    ##                                                                                                                                                                                  title
    ## 1                         Eggshell palaeogenomics: Palaeognath evolutionary history revealed through ancient nuclear and mitochondrial DNA from Madagascan elephant bird (Aepyornis sp
    ## 2                                                                                                        'Ultraconserved elements resolve the phylogeny of potoos (Aves: Nyctibiidae)'
    ## 3                            'Phylogenetic Relationships and Morphological Character Evolution of Photosynthetic Euglenids (Excavata) Inferred from Taxon-rich Analyses of Five Genes'
    ## 4
    ## 5                                                                                                      The evolution of annelids reveals two adaptive routes to the interstitial realm
    ## 6                                                                                                      'Molecular phylogenetics and biogeography of Pollicipes (Crustacea: Cirripedia)
    ## 7                                            ' A DNA barcoding approach for identification of hidden diversity in Parmeliaceae (Ascomycota): P armelia sensu stricto as a case study '
    ## 8   'Phylogenetic relationships of the South American ground beetle subgenus <i>Chilioperyphus</i> Jeannel (Coleoptera: Carabidae: Trechinae: Bembidiini: <i>Bembidion</i> Latreille)'
    ## 9                                                                       'Phylogeny of Bembidion and related ground beetles (Coleoptera: Carabidae: Trechinae: Bembidiini: Bembidiina)'
    ## 10                                                                                                           Erysiphe abbreviata on cherry bark oak?morphology, phylogeny and taxonomy
    ## 11                                                                                        Taxonomic revisions of morphologically similar species from two euglenoid genera: Euglena (E
    ## 12 Phylogeny and taxonomy of sculpins, sandfishes, and snailfishes (Perciformes: Cottoidei) with comments on the phylogenetic significance of their early-life-history specializations
    ## 13                   'Multigene phylogenetic analyses including diverse radiolarian species support the “Retaria” hypothesis — The sister relationship of Radiolaria and Foraminifera'
    ## 14
    ## 15                                                                                                 Molecular phylogeny of Coriaria, with special emphasis on the disjunct distribution
    ## 16                                                                                                           Phylogeny of basal angiosperms: analyses of five genes from three genomes
    ## 17                                                                                    Phylogenetic analysis of basal angiosperms based on nine plastid mitochondrial and nuclear genes
    ## 18                                                                                                       Trochophore concepts: Evolution of larvae in polychaetes and other spiralians
    ## 19
    ## 20                                                     Species delimitation using a combined coalescent and information theoretic approach: An example from North American Myotis bats
    ## 21                                                      'Ultrastructure and LSU rDNA-based Phylogeny of Peridinium lomnickii and Description of Chimonodinium gen. nov. (Dinophyceae)'
    ## 22                                                                            Resolving deep lineage divergences in core corvoid passerine birds supports a proto-Papuan island origin
    ## 23                                                         Genome sequencing and comparative analysis of three Chlamydia pecorum strains associated with different pathogenic outcomes
    ## 24                                                                                                A comprehensive multilocus assessment of sparrow (Aves: Passerellidae) relationships
    ## 25                                                                                                                                                  Perspectives in the new Russulales
    ## 26                                                                                                                                                        Subulatomonas tetraspora nov
    ## 27                                                                                                      Molecular phylogenetics and taxonomy of the genus Thysanocarpus (Brassicaceae)
    ## 28
    ## 29
    ## 30                                                             Combining historical biogeography with niche modeling in the Caprifolium clade of Lonicera (Caprifoliaceae, Dipsacales)
    ## 31
    ## 32                                                                                                   Strong mitochondrial DNA support for a Cretaceous origin of modern avian lineages
    ## 33                                                                                                        Biogeography of Cedrela (Meliaceae, Sapindales) in Central and South America
    ## 34                                                                                                                                                           Annulatascus aquatorba sp
    ## 35                                                Tracing the Temporal and Spatial Origins of Island Endemics in the Mediterranean Region: A Case Study from the Citrus Family (Ruta L
    ##                                               study_doi n_matched_trees
    ## 1         http://dx.doi.org/10.1016/j.ympev.2017.01.005               1
    ## 2                   http://dx.doi.org/10.1111/jav.01313               1
    ## 3                   http://dx.doi.org/10.1111/jeu.12192               1
    ## 4    http://dx.doi.org/10.1111/j.1096-3642.2007.00306.x               1
    ## 5           http://dx.doi.org/10.1016/j.cub.2015.06.007               1
    ## 6         http://dx.doi.org/10.1016/j.jembe.2010.04.024               1
    ## 7                   http://dx.doi.org/10.1111/boj.12358               1
    ## 8           http://dx.doi.org/10.11646/zootaxa.3636.4.3               1
    ## 9         http://dx.doi.org/10.1016/j.ympev.2012.01.015               1
    ## 10         http://dx.doi.org/10.3852/mycologia.99.5.655               1
    ## 11   http://dx.doi.org/10.1111/j.1529-8817.2012.01140.x               2
    ## 12        http://dx.doi.org/10.1016/j.ympev.2014.06.028               2
    ## 13     http://dx.doi.org/10.1016/j.marmicro.2011.06.007               5
    ## 14   http://dx.doi.org/10.1111/j.1558-5646.2008.00567.x               1
    ## 15             http://dx.doi.org/10.1006/mpev.1999.0672               1
    ## 16                     http://dx.doi.org/10.1086/317584               1
    ## 17                     http://dx.doi.org/10.1086/431800               1
    ## 18 http://dx.doi.org/10.1111/j.1095-8312.1999.tb01920.x               2
    ## 19           http://dx.doi.org/10.1186/1471-2148-10-234               1
    ## 20              http://dx.doi.org/10.1093/sysbio/syq024               2
    ## 21       http://dx.doi.org/10.1016/j.protis.2011.03.003               1
    ## 22        http://dx.doi.org/10.1016/j.ympev.2013.09.027               1
    ## 23            http://dx.doi.org/10.1186/1471-2164-15-23               1
    ## 24        http://dx.doi.org/10.1016/j.ympev.2014.04.025               1
    ## 25         http://dx.doi.org/10.3852/mycologia.98.6.960               2
    ## 26       http://dx.doi.org/10.1016/j.protis.2011.05.002               1
    ## 27         http://dx.doi.org/10.1600/036364410792495926               1
    ## 28                                                                    2
    ## 29                                                                    1
    ## 30              http://dx.doi.org/10.1093/sysbio/syq011               1
    ## 31        http://dx.doi.org/10.3852/mycologia.97.5.1140               3
    ## 32              http://dx.doi.org/10.1186/1741-7007-6-6               1
    ## 33                http://dx.doi.org/10.3732/ajb.0900229               1
    ## 34                     http://dx.doi.org/10.3852/11-238               2
    ## 35              http://dx.doi.org/10.1093/sysbio/syq046               1
    ##                  match_tree_ids
    ## 1                          NULL
    ## 2                          NULL
    ## 3                          NULL
    ## 4                          NULL
    ## 5                          NULL
    ## 6                          NULL
    ## 7                          NULL
    ## 8                          NULL
    ## 9                          NULL
    ## 10                         NULL
    ## 11                   NULL, NULL
    ## 12                   NULL, NULL
    ## 13 NULL, NULL, NULL, NULL, NULL
    ## 14                         NULL
    ## 15                         NULL
    ## 16                         NULL
    ## 17                         NULL
    ## 18                   NULL, NULL
    ## 19                         NULL
    ## 20                   NULL, NULL
    ## 21                         NULL
    ## 22                         NULL
    ## 23                         NULL
    ## 24                         NULL
    ## 25                   NULL, NULL
    ## 26                         NULL
    ## 27                         NULL
    ## 28                   NULL, NULL
    ## 29                         NULL
    ## 30                         NULL
    ## 31             NULL, NULL, NULL
    ## 32                         NULL
    ## 33                         NULL
    ## 34                   NULL, NULL
    ## 35                         NULL

Well… that’s not very promising. We can repeat that process for all of the IDs to see if the other species are better represented.

    hits <- lapply(mu$ott_id, studies_find_trees, property = "ot:ottId", detailed = FALSE)
    sapply(hits, function(x) sum(x[["n_matched_trees"]]))

    ## [1]  48  51 128  70  17  87

OK, most of our species are not in any of the published trees available. You can help fix this sort of problem by making sure you submit your published trees to Open Tree.

### A part of the synthesis tree

Thankfully, we can still use the complete Tree of Life made from the combined results of all of the published trees and taxonomies that go into Open Tree. The function `tol_induced_subtree` will fetch a tree relating a set of IDs.

Using the default arguments you can get a tree object into your R session:

    ott_in_tree <- ott_id(taxon_search)[is_in_tree(ott_id(taxon_search))]
    tr <- tol_induced_subtree(ott_ids = ott_in_tree)

    ## Warning in collapse_singles(tr, show_progress): Dropping singleton
    ## nodes with labels: mrcaott2ott276, mrcaott2ott142555, mrcaott2ott3043,
    ## mrcaott2ott7623, Chloroplastida ott361838, Chlorophyta ott979501,
    ## mrcaott185ott23323, mrcaott185ott599, mrcaott1427ott25671,
    ## mrcaott1427ott1544, mrcaott1544ott15345, mrcaott1544ott1795,
    ## mrcaott9389ott365252, mrcaott9389ott23557, mrcaott23557ott527099,
    ## mrcaott149ott902, SAR ott5246039, Alveolata ott266751, Ciliophora (phylum
    ## in subkingdom SAR) ott302424, Intramacronucleata ott340382, Conthreep
    ## ott5248773, Peniculia ott5257364, Paramecium (genus in subkingdom SAR)
    ## ott568126, Hymenostomatia ott5257367, Tetrahymena ott47284, Amoebozoa
    ## ott1064655, mrcaott3973ott5765, mrcaott3973ott26103, mrcaott26103ott273110,
    ## mrcaott26103ott229626, Dictyostelia ott835575, Dictyostelium ott999665,
    ## Opisthokonta ott332573, Nucletmycea ott5246132, Fungi ott352914,
    ## mrcaott48ott3465, mrcaott48ott67172, mrcaott48ott1423, mrcaott48ott4814,
    ## h2007-2 ott5576447, h2007-1 ott5584405, Dikarya ott656316,
    ## mrcaott48ott1053, Saccharomycetales ott5976840, Saccharomycetaceae
    ## ott989994, Saccharomyces ott908546, Taphrinomycotina ott656312,
    ## Schizosaccharomycetes ott921286, Schizosaccharomycetidae ott5670481,
    ## Schizosaccharomycetales ott508517, Schizosaccharomycetaceae ott990009,
    ## Schizosaccharomyces ott990008

    plot(tr)

### Connect your data to the tips of your tree

Now we have a tree for of our species, how can we use the tree and the data together?

The package `phylobase` provide an object class called `phylo4d`, which is designed to represent a phylogeny and data associated with its tips. In oder to get our tree and data into one of these objects we have to make sure the labels in the tree and in our data match exactly. That’s not quite the case at the moment (tree labels have underscores and IDs appended):

    mu$ott_name[1]

    ## $`Tetrahymena thermophila`
    ## [1] "Tetrahymena thermophila"

    tr$tip.label[4]

    ## [1] "Dictyostelium_discoideum_ott160850"

`rotl` provides a convienence function `strip_ott_ids` to deal with these.

    tr$tip.label <- strip_ott_ids(tr$tip.label, remove_underscores = TRUE)
    tr$tip.label %in% mu$ott_name

    ## [1] TRUE TRUE TRUE TRUE TRUE TRUE

Ok, now the tips are together we can make a new dataset. The `phylo4d()` functions matches tip labels to the row names of a `data.frame`, so let’s make a new dataset that contains just the relevant data and has row names to match the tree

    library(phylobase)
    mu_numeric <- mu[, c("mu", "pop.size", "genome.size")]
    rownames(mu_numeric) <- mu$ott_name
    tree_data <- phylo4d(tr, mu_numeric)

And now we can plot the data and the tree together

    plot(tree_data)

## Find external data associated with studies, trees and taxa from Open Tree

In the above example we looked for a tree that related species in another dataset. Now we will go the other way, and try to find data associated with Open Tree records in other databases.

### Get external data from a study

Let’s imagine you were interested in extending or reproducing the results of a published study. If that study is included in Open Tree you can find it via `studies_find_studies` or `studies_find_trees` and retrieve the published trees with `get_study`. `rotl` will also help you find external. The function `study_external_IDs` retrieves the DOI for a given study, and uses that to gather some more data:

    extra_data <- try(study_external_IDs("pg_1980"), silent = TRUE)
    if (!inherits(extra_data, "try-error")) {
      extra_data
    }

    ## External data identifiers for study
    ##  $doi:  10.1016/j.ympev.2006.04.016
    ##  $pubmed_id:  16762568
    ##  $nucleotide_ids: vector of 58 IDs
    ##  $external_data_url http://purl.org/phylo/treebase/phylows/study/TB2:S1575

Here the returned object contains an `external_data_url` (in this case a link to the study in Treebase), a pubmed ID for the paper and a vector IDs for the NCBI’s nuleotide database. The packages `treebase` and `rentrez` provide functions to make use of these IDs within R.

As an example, let’s use `rentrez` to download the first two DNA seqences and print them.

    library(rentrez)
    seqs <- try(entrez_fetch(db = "nucleotide", id = extra_data$nucleotide_ids[1:2], rettype = "fasta"), silent = TRUE)

    if (inherits(seqs, "try-error")) {
      cat("NCBI temporarily down.")
    } else {
      cat(seqs)
    }

    ## >AM181011.1 Plectroninia neocaledoniense partial 28S rRNA gene, specimen voucher G316300 (Queensland Museum)
    ## GCTAGCAAGCGCGTCGGTGGTTCAGCCGGCTGGTCTCGTCGAGTTGTCGGTGTGCGGATCCGAACGGACC
    ## GCGGCCGATGGCGTCGGCGGGCAAGCTGTGGTGCACTCTGTCGGCGTGCGCGTCAGCGTCGGTTTCGGCC
    ## GGACGACGAGGCGCTCGGGGAAGGTAGCTGGACCGGTCTTCGGTGCAGTGTTATAGCCCTGGGCCGCTGG
    ## GTTCGGCGTTTGGGACCGAGGAGAGAGATGATCGCTGCAGCGCCTGTCTCCCTCTCGAGGGGGGCTAGCC
    ## AGCCGCTGTTTGGGTGGCGTCACTGGCGGAGGACTGCACGCAGTGCTTCGCCGGTGGTCGTGTCCAGGCG
    ## GGCGGTGTGGGTATAGAGGCGCTTAGGACGCTGGCGTCCAAATGGCCGTGCGCGACCCGTCTTGAAACAC
    ## GGACCAAGGAGTCTAGCATGTGCGCGAGTCTTAGGGTGTGGAAGCCCTCGGGCGCAATGAAAGTGAAGGG
    ## CCGTCGTCTCTCGGGGCTGCGGTGTGAGGTGAGAGCCGTCGCCGTCGGGTGGCGGTGCATCATCGGCCGG
    ## TCCATCCTGCTCTCAGGAGGATCTGCGCAAGAGCGTGTTTGCTGGGACCCGAAAGATGGTGAACTATGCC
    ## TGAATAGGGTGAAGCCAGAGGAAACTCTGGTGGAGGCTCGTAGCGGTTCTGACGTGCAAATCGATCGTCA
    ## AATTTGGGTATAGGGGCGAAAGACTAATCGAACCATCTAGTAGCTGGTTCCCTCCGAAGTTTCCCTCAGG
    ## ATAGCTGGAACTCGTCTTGACACAGTTTTATCAGGTAAAGCGAATGATTAGAGGTCTTGGGGGTGAAACA
    ## CCCTCAACCTATTCTCAAACTTTAAATAGGTAAGAAGCGCGACTTGCTCAATTGAAGTGGCGCGCAGTGA
    ## ATGTGAGTTCCAAGTGGGCCATTTTTGGTAAGCAGAACTGGCGATGCGGGATGAACCGAACGCTCGGTTA
    ## AGGTGCCCAAGTCGACGCTCATCAGACCCCAGAAAAGGTGTTGGTCGATATAGACAGCAGGACGGTGGCC
    ## ATGGAAGTCGGAATCCGCTAAGGAGTGTGTAACAACTCACCTGCCGAATCAACTAGCCCTGAAAATGGAT
    ## GGCGCTCAAGCGTCGCACCTATACCGAGCCGTCGTGGTAAATGCCAGGCCACGACGAGTAGGAGGGCGCG
    ## GTGGTCGTGACGCAGCCCTTGGCGCGAGCCTGGGCGAAACGGCCTCCGGTGCAGATCTTGGTGGTAGTAG
    ## CAAATATTCAAATGAGAGCTTTGAAGACCGAAGTGGAGAAAGGTTCCATGTGAACAGCAGTTGGACATGG
    ## GTTAGTCGATCCTAAGAGATAGGGAAGTTCCGTGTGAAAGTGCGCAATGCGCTTCTGTGCTGCGCGCCTC
    ## CTATCGAAAGGGAATCGGGTTAATATTCCCGAACCGGAAGGCGGATATCTCTGGCTCTCGGGTCAGGAGC
    ## GGCAACGCAAGCGTACTGCGAGACGTCGGCGGGGGCTCCGGGAAGAGTTGTCTTTTCTTTTTAACGCAGT
    ## CGCCATCCCTGGAATCGGTTTGCCCGGAGATAGGGTTGGCTGGCTCGGTAAAGCAGCACACTTCATGTGC
    ## TGTCCGGTGCGCTCTCGACGGCCCTTGAAAATCGCAGGTGTGCATCGATTCTCGCATCCGGTCGTACTCA
    ## TAACCGCATCAGGTCTCCAAGGT
    ##
    ## >AM181010.1 Eilhardia schulzei partial 28S rRNA gene, specimen voucher G316071 (Queensland Museum)
    ## GCTAGTAATGTACGTTGGTGGTTCAGCCGGCTAGTCTTGTCGAGTCGTCGTGTGGTGGATCCGACTGGAC
    ## CGTCCGCGGTGGTGTCGGCGGGCGAGCTGTGGTGCACTCTACGGACGTGCGCGTCAGCGTCGGTTCTCGA
    ## TGGGCGATAAGGTGCGTGGGGGAAGGTGGCTCGGTCCTTGGGAACTGAGTGTTACAGACCCTGGTGCTGG
    ## GCTCGTCGTGGGACCGAGGAGAGAGAGAGATGATCGCTGCGGCACCTGCCCCGTTGTCATTTTTCGGGGC
    ## TAGCCAGCCGTTTGTCAGGTGTGCGTCGGACGTTGAGGACTGCACGCAGTGCTGGACGTGGAGGCGTGAT
    ## CTGATGGCGGTGTGGGCATTAGAGGTGCCTAGGACGCTGGCGTCCAAATGGCCGTGCGCGACCCGTCTTG
    ## AAACACGGACCAAGGAGTCTAACATGTGCGCGAGTCTTAGGGTGTGCAAGCCCTCGGGCGCAATGAAAGT
    ## GAAGGCTCGGCGGCGCTAGTCGAGCTGAGGTGAGAGCCGTGGCCGTTGCATGTGGCGGCGGCGGCGCATC
    ## ATCGGCCGGTCCATCCTGCTCTCAGGGGGATCCGAGCAAGAGCGTATTTGTTGGGACCCGAAAGATGGTG
    ## AACTATGCCTGAATAGGGTGAAGCCAGAGGAAACTCTGGTGGAGGCTCGTAGCGATTCTGACGTGCAAAT
    ## CGATCGTCAAATTTGGGTATAGGGGCGAAAGACTAATCGAACCATCTAGTAGCTGGTTCCCTCCGAAGTT
    ## TCCCTCAGGATAGCTGGAGCTCTTGGACACAGTTTTATCAGGTAAAGCGAATGATCAGAGGTCTTGGGGG
    ## TGAAACACCCTCAACCTATTCTCAAACTTTAAATCGGTAAGAAGCGCGACTTGCTGAATTGAAGCCGCGC
    ## GCAAGCAATGTGAGTTCCAAGTGGGCCATTTTTGGTAAGCAGAACTGGCGATGCGGGATGAACCGAACGC
    ## TGGGTTAAGGTGCCAAAGTCGACGCTCATCAGACCCCAGAAAAGGTGTTGGTTGATATAGACAGCAGGAC
    ## GATGGCCATGGAAGTCGGAATCCGCTAAGGAGTGTGTAACAACTCACCTGCCGAATCAACTAGCCCTGAA
    ## AATGGATGGCGCTCAAGCGTCGCACCTATACCGGGCCGTCGTCGCAAATGCCAGGCGACGACGAGTAGGA
    ## GGGCGCAGTGGTCGTCATGCAGCCCTTGGCGTGAGCCTGGGTCAAACGGCCTCTGGTGCAGATCTTGGTG
    ## GTAGTAGCAAATATTCAAATGAGAGCTTTGAAGACCGAAGTGGAGAAAGGTTCCATGTGAACAGCAGTTG
    ## GACATGGGTTAGTCGATCCTAAGTGATAGGGGAGCTCCGTATGAAAGTGCGCAATCGGCCCTGCTTGTGT
    ## CGCCTTGCGCCACCTATCGAAAGGGAATCGGGTTAATATTCCCGAACCGGAAGGCGGATTTTCTCTGGCT
    ## CTCGGGTCAGGAGCGGCAACGCTAGCGAACCGCGAGACGTCGGCGGGGGCTCCGGGAAGAGTTGTCTTTT
    ## CTTTTTAACGCAGTCGCCATCCCTGGAATCGGTTTGCCCGGAGATAGGGTTGGCTGGCTCGGTAAAGCAG
    ## CACACTTCATGTGCTGTCCGGTGCGCTCTCGACGGCCCTTGAAAATCGCGGCGAGTGTAGTCTGATTTTC
    ## GCATCCGTTCGTACTCATAACCGCATCAGGTCTCCAAGGT

You could further process these sequences in R with the function `read.dna` from `ape` or save them to disk by specifying a file name with `cat`.

### Find a OTT taxon in another taxonomic database

It is also possible map an Open Tree taxon to a record in another taxonomic database. For instance, if we wanted to search for data about one of the tips of the sub-tree we fetched in the example above we could do so using `taxon_external_IDs`:

    Tt_ids <- taxon_external_IDs(mu$ott_id[2])
    Tt_ids

    ##   source       id
    ## 1  silva AY102613
    ## 2   ncbi     5888
    ## 3   gbif  7415807

A user could then use `rgbif` to find locality records using the gbif ID or `rentrez` to get genetic or bibliometric data about from the NCBI’s databases.

## What next

The demonstration gets you to the point of visualizing your data in a phylogenetic context. But there’s a lot more you do with this sort of data in R. For instance, you could use packages like `ape`, `caper`, `phytools` and `mcmcGLMM` to perform phylogenetic comparative analyses of your data. You could gather more data on your species using packages that connect to trait databases like `rfishbase`, `AntWeb` or `rnpn` which provides data from the US National Phenology Network. You could also use `rentrez` to find genetic data for each of your species, and use that data to generate branch lengths for the phylogeny.