Reads an ontology from an OBO (.obo) or OWL (.owl, RDF/XML)
file and returns a children function for renderTree(lazy =
TRUE), so even a large ontology such as the Gene Ontology is shown a level
at a time. Reading OWL needs the xml2 package.
Value
A list for renderTree(lazy = TRUE): children, the
function giving a node's children, and search, which finds terms
whose name or identifier contains the search text and returns the path
to each place a matching term appears (a term with several parents
appears in several). It also has an attribute "ontology": a data
frame of the terms, with columns id, name,
definition and obsolete, and a list column parents.
Details
The hierarchy is formed by is_a (in OWL, rdfs:subClassOf
between named classes). Each node is labelled with the term's name and
carries its identifier as stid and its definition, if any, as
sttooltip, so it is shown on hover.
- Several parents
A term with more than one parent is shown under each of them, with the same
stidin every place, and search finds it in each.- Obsolete terms
Terms marked obsolete (
is_obsolete: true, orowl:deprecated) have no parent, so they are gathered under one extra top-level node,obsolete, and shown greyed out (stdisabled). Withobsolete = NULLthey are left out, and a live term whose only parents are obsolete is shown at the top level.- Terms left out
OWL classes with no label, and OBO stanzas with no name and no parent, are placeholders – typically left behind when terms are merged or replaced – and are not shown.
- Parents outside the file
Only terms in the file are shown. A term whose parents are all outside it – in an ontology it imports, say – appears at the top level.
- OBO and OWL
The OWL release of an ontology usually includes every class it imports from other ontologies, which its OBO release leaves out, so the two can have different top levels. The OBO file usually gives the tidier tree.
- Cycles
A term caught in a cycle of
is_a– A is_a B, B is_a A – with no way up to a root is shown at the top level, so nothing in the file is lost.- Names
Siblings can share a name; they are told apart by
stid, so the function takesnodeas well aspath. Names are shown as they are in the file, as HTML (seerenderTree).- Size
The Gene Ontology's 48,000 terms are read in a few seconds, and each branch is fetched only when opened. A branch with thousands of children, such as its obsolete terms, takes a few seconds to open.
See also
renderTree, whose Lazy loading section
describes the children function
Examples
# The Anatomical Entity Ontology, which comes with the 28-ontology example
aeo <- ontologyToTree(system.file("examples/28-ontology/aeo.obo", package = "shinyTree"))
names(aeo$children(character(0)))
#> [1] "anatomical entity" "cell" "obsolete"
head(attr(aeo, "ontology")[, c("id", "name")])
#> id name
#> 1 AEO:0000013 single-cell tissue
#> 2 AEO:0000078 lumen of tube
#> 3 AEO:0000079 lumen of epithelial sac
#> 4 AEO:0000080 foramen
#> 5 AEO:0000081 matrix-based tissue
#> 6 AEO:0000082 bone
if (interactive()) {
library(shiny)
ui <- fluidPage(shinyTree("tree", search = TRUE))
server <- function(input, output, session) {
output$tree <- renderTree(lazy = TRUE, aeo)
}
shinyApp(ui, server)
}
# The 28-ontology example browses this ontology, or one you upload, such as
# the Gene Ontology (go-basic.obo from https://geneontology.org):
if (interactive()) {
shiny::runApp(system.file("examples/28-ontology", package = "shinyTree"))
}