Functions to add extra metadata to an ontology or data.table object.
add_ancestors(ont, lvl = 2, include_self = TRUE, force_new = FALSE)
add_db(
dat,
input_col,
output_col = paste0(input_col, "_db"),
split = ":",
keep = 1
)
add_hoverboxes(
g,
columns = get_graph_colnames(g),
hoverbox_column = c("hover", "title", "label"),
width = 60,
digits = 3,
decorators = c("<b>", "</b>"),
as_html = TRUE,
force_new = FALSE
)
add_ontology_metadata(
ont,
add_ancestors = 2,
add_n_edges = TRUE,
add_ontology_levels = TRUE
)
An ontology of class ontology_DAG.
Depth of the ancestor terms to add. Will get the closest ancestor to this level if none have this exact level.
For dag_offspring()
and dag_ancestors()
, this controls whether to also include the query term itself.
Add the data again even if the associated column already exists.
data.table or tbl_graph.
Column containing IDs.
Column to add.
character vector (or object which can be coerced to such)
containing regular expression(s) (unless fixed = TRUE
)
to use for splitting. If empty matches occur, in particular if
split
has length 0, x
is split into single characters.
If split
has length greater than 1, it is re-cycled along
x
.
Specify indices corresponding to just those list elements to retain in the transposed result. Default is to return all.
ggnetwork object (or an igraph/tbl_graph to be converted to ggnetwork format).
Character vector of column names to include in the hoverbox.
Name of the new hoverbox column to add.
Positive integer giving target line width (in number of characters). A width less than or equal to 1 will put each word on its own line.
integer indicating the number of decimal places
(round
) or significant digits (signif
) to be used.
For round
, negative values are allowed (see ‘Details’).
Left and right decorators to add to the hoverbox titles.
Provide the hoverbox in HTML format.
Add ancestors for each term.
Add the number of edges (connections) for each term.
Add the ontology level for each term.
Added data.
tidygraph with additional metadata column named "hover".
add_ancestors()
: add_
Add ancestor
For each term, get its ancestor at a given level
and add the ID and name of the ancestor to the ontology metadata.
By default, lower numbers are higher in the ontology
(e.g. level 0 includes the most broad ontology term).
When a terms does not have an ancestor at a given level
(e.g. lvl=3
but the term itself is at level 1) the term is assigned
to itself as its own ancestor.
When a term has multiple ancestors at a given level,
the first ancestor is arbitrarily chosen.
add_db()
: add_
Extract a database identifier from an ID column and add it
as a separate column.
add_hoverboxes()
: add_
Add hoverboxes
A hoverbox is a box of text that shows up when the cursor hovers over something. These can be useful when making interactive network plots of the HPO phenotypes because we can include a hoverbox that gives information and data associated with each phenotype.
add_ontology_metadata()
: add_
Add per-term metadata to ontology.
ont <- get_ontology("hp")
#> Loading required namespace: piggyback
#> ℹ All local files already up-to-date!
#> Importing cached file: /github/home/.cache/R/KGExplorer/hp-international.owl
#> Adding term metadata.
#> IC_method: IC_offspring
#> Adding ancestor metadata.
#> Getting absolute ontology level for 25,301 IDs.
#> 900 ancestors found at level 2
#> Translating all terms to names.
#> + Returning a vector of terms (same order as input).
#> Converted ontology to: adjacency
#> Getting absolute ontology level for 25,301 IDs.
ont2 <- add_ancestors(ont)
#> Adding ancestor metadata.
#> Ancestor metadata already present. Use force_new=TRUE to overwrite.
ont <- get_ontology("hp", terms=10)
#> ℹ All local files already up-to-date!
#> Importing cached file: /github/home/.cache/R/KGExplorer/hp-international.owl
#> Adding term metadata.
#> IC_method: IC_offspring
#> Adding ancestor metadata.
#> Getting absolute ontology level for 25,301 IDs.
#> 900 ancestors found at level 2
#> Translating all terms to names.
#> + Returning a vector of terms (same order as input).
#> Converted ontology to: adjacency
#> Getting absolute ontology level for 25,301 IDs.
#> Randomly sampling 10 term(s).
g <- ontology_to(ont, to="tbl_graph")
#> Converted ontology to: tbl_graph
g2 <- add_hoverboxes(g)
#> Making hoverboxes from: 'name', 'short_id', 'label', 'namespace', 'definition', 'IC', 'depth', 'n_children', 'n_ancestors', 'n_parents', 'n_offspring', 'n_connected_leaves', 'ancestor', 'ancestor_name', 'n_edges', 'ontLvl'
#> Adding hoverboxes to data.table.
ont <- get_ontology("hp", terms=10)
#> ℹ All local files already up-to-date!
#> Importing cached file: /github/home/.cache/R/KGExplorer/hp-international.owl
#> Adding term metadata.
#> IC_method: IC_offspring
#> Adding ancestor metadata.
#> Getting absolute ontology level for 25,301 IDs.
#> 900 ancestors found at level 2
#> Translating all terms to names.
#> + Returning a vector of terms (same order as input).
#> Converted ontology to: adjacency
#> Getting absolute ontology level for 25,301 IDs.
#> Randomly sampling 10 term(s).
ont2 <- add_ontology_metadata(ont)
#> Adding term metadata.
#> IC_method: IC_offspring
#> Adding ancestor metadata.
#> Ancestor metadata already present. Use force_new=TRUE to overwrite.
#> Converted ontology to: adjacency
#> Getting absolute ontology level for 67 IDs.