Type: | Package |
Title: | Visualising Sets of Ontological Terms |
Version: | 1.7 |
Date: | 2024-02-20 |
Encoding: | UTF-8 |
Author: | Daniel Greene <dg333@cam.ac.uk> |
Maintainer: | Daniel Greene <dg333@cam.ac.uk> |
Description: | Create R plots visualising ontological terms and the relationships between them with various graphical options - Greene et al. 2017 <doi:10.1093/bioinformatics/btw763>. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Depends: | R (≥ 3.0.0) |
Imports: | methods, ontologyIndex, paintmap, Rgraphviz |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
RoxygenNote: | 7.3.1 |
NeedsCompilation: | no |
Packaged: | 2024-02-20 22:22:34 UTC; dg |
Repository: | CRAN |
Date/Publication: | 2024-02-20 22:40:02 UTC |
Functions for Visualising Sets of Ontological Terms
Description
Functions for visualising sets of ontological terms using the ‘graphviz’ layout system.
Author(s)
Daniel Greene <dg333@cam.ac.uk>
Maintainer: Daniel Greene <dg333@cam.ac.uk>
References
Greene D, Richardson S, Turro E (2017). 'ontologyX: a suite of R packages for working with ontological data. _Bioinformatics_, 33(7), 1104–1106.
‘The Human Phenotype Ontology project: linking molecular biology and disease through phenotype data’, Nucl. Acids Res. (1 January 2014) 42 (D1): D966-D974 doi:10.1093/nar/gkt1026 Westbury, S. K. et al. (2015). Human Phenotype Ontology annotation and cluster analysis to un- ravel genetic defects in 707 cases with unexplained bleeding and platelet disorders. Genome Medicine. 7 (2015)
Get logical matrix of term annotation for group of cases
Description
Get logical matrix of term annotation for group of cases
Usage
annotation_grid(
ontology,
term_sets,
all_terms = grid_terms(ontology, term_sets),
remove_unanimous = FALSE,
cluster_rows = TRUE,
cluster_cols = TRUE
)
Arguments
ontology |
|
term_sets |
List of character vectors of ontological term IDs |
all_terms |
Character vector giving terms to use in annotation. |
remove_unanimous |
Logical value determining whether to remove terms present in all |
cluster_rows |
Logical value rows determining whether to use hclust to cluster |
cluster_cols |
Logical value rows determining whether to use hclust to cluster terms (based on correlation of inclusion in |
Value
Logical matrix.
Function to scale values between two given limits
Description
Could be useful to modify a vector of sizes to between, say 1 and 3, before passing to 'onto_plot'.
Usage
calibrate_sizes(x, high, low)
Arguments
x |
Numeric vector |
high |
Numeric value of largest size |
low |
Numeric value of smallest size |
Value
Numeric vector
Examples
calibrate_sizes(c("HP:0000001"=10, "HP:0000006"=5), high=3, low=1)
Function to assign colours to terms based on frequency with which terms appear in term_sets
Description
Function to assign colours to terms based on frequency with which terms appear in term_sets
Usage
colour_by_frequency(
ontology,
terms,
term_sets,
colour_func = colorRampPalette(c("Yellow", "Green", "#0099FF"))
)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
term_sets |
List of character vectors of ontological term IDs |
colour_func |
Function capable of returning a set of colours, given the number of colours it needs to return |
Value
Character vector of colours, named by term
See Also
colour_by_term_set
, colour_by_population_frequency
Function to assign colours to terms based on population frequency of terms
Description
Function to assign colours to terms based on population frequency of terms
Usage
colour_by_population_frequency(
ontology,
terms,
frequencies,
colour_palette = colorRampPalette(c("Yellow", "Green", "#0099FF"))(10),
max_colour_freq = max(terms_freq),
min_colour_freq = min(terms_freq)
)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
frequencies |
Numeric vector of term frequencies named by term IDs |
colour_palette |
Character vector of colours for the different information contents of the terms to be plotted, going from rare to common |
max_colour_freq |
Numeric value in [0, 1] giving the maximum frequency (to which the dullest color will be assigned) |
min_colour_freq |
Numeric value in [0, 1] giving the minimum frequency (to which the brightest color will be assigned) |
Value
Character vector of colours, named by term
See Also
colour_by_term_set
, colour_by_frequency
Function to set colours of nodes in plot to distinguish terms belonging to different term sets
Description
Function to set colours of nodes in plot to distinguish terms belonging to different term sets
Usage
colour_by_term_set(
ontology,
terms,
term_sets,
colour_generator = rainbow,
alpha = 0.5
)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
term_sets |
List of character vectors of ontological term IDs |
colour_generator |
Function which returns a vector of colours, e.g. |
alpha |
|
Value
Character vector of colours, named by term.
See Also
colour_by_frequency
, colour_by_population_frequency
ontology_plot
object to dot string
Description
ontology_plot
object to dot string
Usage
dot_string(ontology_plot)
Arguments
ontology_plot |
Object of class 'ontology_plot' to export. |
Value
String
See Also
Get an adjacency matrix for a set of ontological terms
Description
Get an adjacency matrix for a set of ontological terms
Usage
get_adjacency_matrix(ontology, terms)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
Value
A logical matrix representing the adjacency matrix of terms
based on the directed acyclic graph of ontology
. A TRUE
entry means the term correspnding to the column is a parent of the row term in ontology
.
See Also
Examples
library(ontologyIndex)
data(hpo)
get_adjacency_matrix(hpo, c("HP:0000118", "HP:0001873", "HP:0011877"))
Split up node labels across lines so they fit in nodes better
Description
Split up node labels across lines so they fit in nodes better
Usage
get_node_friendly_long_names(ontology, terms, official_names = FALSE)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
official_names |
Logical value indicating whether to use the exact names from the ontology. Otherwise, shortened, capitalised names are used. |
Value
Character vector.
Examples
library(ontologyIndex)
data(hpo)
get_node_friendly_long_names(hpo, c("HP:0001873", "HP:0011877"))
Get ontology_plot
object
Description
Function to create ontology_plot
objects where all graphical parameters to be used must be specified.
Usage
get_ontology_plot(
ontology,
terms,
edge_attributes = list(color = "#000000", lty = "solid"),
...
)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
edge_attributes |
List of properties to set for arrows (note, these properties will be used for all arrow). |
... |
Named graphical parameters. These must either be vectors of values the same length as |
Value
ontology_plot
object.
Get an adjacency matrix for a set of ontological terms
Description
Get an adjacency matrix for a set of ontological terms
Usage
get_pseudo_adjacency_matrix(ontology, terms)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
Value
A logical matrix representing the adjacency matrix of terms
based on the directed acyclic graph of ontology
. A TRUE
entry means the term correspnding to the column is a parent of the row term within terms
.
See Also
Examples
library(ontologyIndex)
data(hpo)
get_pseudo_adjacency_matrix(hpo, c("HP:0000118", "HP:0001873", "HP:0011877"))
Get human readable, shortened (where possible) ontological term names
Description
Get human readable, shortened (where possible) ontological term names
Usage
get_shortened_names(ontology, terms)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
Value
Character vector
Examples
library(ontologyIndex)
data(hpo)
get_shortened_names(hpo, c("HP:0001873", "HP:0011877"))
Get set of HPO terms appropriate for showing in a grid
Description
Get set of HPO terms appropriate for showing in a grid
Usage
grid_terms(ontology, term_sets)
Arguments
ontology |
|
term_sets |
List of character vectors of ontological term IDs |
Value
Character vector of terme IDs.
Function to get plot labels for terms based on frequency in term_sets
Description
Function to get plot labels for terms based on frequency in term_sets
Usage
label_by_frequency(ontology, terms, term_sets)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
term_sets |
List of character vectors of ontological term IDs |
Value
Character vector of labels, named by term.
See Also
Function to label nodes by term_set
Description
Function to label nodes by term_set
Usage
label_by_term_set(ontology, terms, term_sets)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
term_sets |
List of character vectors of ontological term IDs |
Value
Character vector of colours, named by term.
See Also
simple_labels
, label_by_frequency
, long_labels
Function to assign detailed node labels to terms
Description
Label includes term ID, term name, number of instances of term amongst term_sets
and percentage frequency in population.
Usage
long_labels(ontology, terms, term_sets, frequencies)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
term_sets |
List of character vectors of ontological term IDs |
frequencies |
Numeric vector of term frequencies named by term IDs |
Value
Character vector of labels, named by term.
See Also
simple_labels
, label_by_frequency
, label_by_term_set
Select n
most prevalent terms in term_sets
Description
Selects n
most prevalent terms in set of term sets/annotations including implicit terms. If more than one term are tied at the n
th position, all terms are included in the result.
Usage
n_most_frequent_terms(
ontology,
term_sets,
n,
terms = unique(unlist(term_sets))
)
Arguments
ontology |
|
term_sets |
List of character vectors of ontological term IDs |
n |
Integer |
terms |
Character vector of ontological terms |
Value
Character vector of length at most n
See Also
remove_terms_with_less_than_n_occurrences
Examples
library(ontologyIndex)
data(hpo)
n_most_frequent_terms(hpo, c("HP:0001873"),
list(term_sets=list("HP:0001873", "HP:0001902")), n=2)
Get official names for terms
Description
Get official names for terms
Usage
official_labels(ontology, terms)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
Value
Character vector of labels, named by term.
See Also
Get ontology_plot
object
Description
A convenience wrapper for the get_ontology_plot
function, enabling functions to be passed to generate graphical parameters for terms
automatically.
Usage
onto_plot(
ontology,
term_sets = NULL,
frequencies = NULL,
terms = remove_uninformative_terms(ontology, term_sets),
edge_attributes = list(color = "#000000", lty = "solid"),
fillcolor = "powderblue",
label = simple_labels,
color = "transparent",
width = 0.75,
fontsize = 30,
style = "filled",
fixedsize = "true",
shape = "circle",
...
)
Arguments
ontology |
|
term_sets |
List of character vectors of ontological term IDs |
frequencies |
Numeric vector of term frequencies named by term IDs |
terms |
Character vector of ontological terms |
edge_attributes |
List of properties to set for arrows (note, these properties will be used for all arrow). |
fillcolor |
Character vector of colours to fill nodes corresponding to |
label |
Character vector of labels (or function to set them). |
color |
Character vector of colours for borders of nodes representing |
width |
Numeric vector of widths for nodes (of function to set them). |
fontsize |
Numeric vector of font sizes for the text to be placed in the nodes (or function to set them). |
style |
Display style for nodes, defaults to |
fixedsize |
Character indicating whether nodes should be fixed size, |
shape |
Character vector of shape names for nodes (or function to set them). Defaults to |
... |
Other node attributes for dot format. |
Value
ontology_plot
object.
See Also
Examples
library(ontologyIndex)
data(hpo)
hpo_phenotypes <- c(
A=c("HP:0001382","HP:0004272","HP:0007917","HP:0004912","HP:0001596"),
B=c("HP:0001382","HP:0004272","HP:0002165","HP:0004800","HP:0004912"),
C=c("HP:0004800","HP:0001382","HP:0004912","HP:0007917","HP:0008743"),
D=c("HP:0001257","HP:0001382","HP:0007917","HP:0012623","HP:0002165"),
E=c("HP:0007917","HP:0004800","HP:0004272","HP:0001596","HP:0002165")
)
onto_plot(
ontology=hpo,
term_sets=hpo_phenotypes
)
Get p-values for observing at least as many of each term as occur in term_sets
given the population frequencies of the terms
Description
Get p-values for observing at least as many of each term as occur in term_sets
given the population frequencies of the terms
Usage
p_values_for_occurrence_of_term_in_group(ontology, term_sets, terms_freq)
Arguments
ontology |
|
term_sets |
List of character vectors of ontological term IDs |
terms_freq |
Numeric vector of population frequencies of terms. |
Value
Numeric vector of log p-values named by correspnding term.
See Also
Plotting function for ontology_plot
object
Description
Plotting function for ontology_plot
object
Usage
## S3 method for class 'ontology_plot'
plot(x, ...)
Arguments
x |
Object of class ontologicalPlot. |
... |
Other options passed to plot(). |
Value
Nothing, side-effect: plots a graph.
Plot a logical matrix of term annotation
Description
Plot a logical matrix of term annotation
Usage
plot_annotation_grid(..., on_colour = "#FF0000FF", off_colour = "#FFFFBFFF")
Arguments
... |
Arguments to be passed to |
on_colour |
Colour to use to show presence of term. |
off_colour |
Colour to use to show absence of term. |
Value
Plots heatmap.
Print function for ontology_plot
object
Description
Print function for ontology_plot
object
Usage
## S3 method for class 'ontology_plot'
print(x, ...)
Arguments
x |
Object of class ontologicalPlot. |
... |
Other options passed to be passed to plot(). |
Value
Nothing. Side-effect: plots graphs.
Remove terms which just link two other terms together in a subontology
Description
Remove terms which just link two other terms together in a subontology
Usage
remove_links(ontology, terms, hard = FALSE)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
hard |
Logical value determining whether to multiple edges to leaf terms are kept - |
Value
Character vector.
See Also
Examples
library(ontologyIndex)
data(hpo)
remove_links(hpo, c("HP:0001873","HP:0001872","HP:0011873","HP:0011877"))
Remove terms with less than certain number of occurrences
Description
Remove terms with less than certain number of occurrences
Usage
remove_terms_with_less_than_n_occurrences(
ontology,
term_sets,
n,
terms = unique(unlist(term_sets))
)
Arguments
ontology |
|
term_sets |
List of character vectors of ontological term IDs |
n |
Integer |
terms |
Character vector of ontological terms |
Value
Character vector
See Also
Examples
library(ontologyIndex)
data(hpo)
remove_terms_with_less_than_n_occurrences(hpo,
term_sets=list("HP:0001873", "HP:0001902"), n=2)
Remove uninformative terms from union of all terms in set of annotations
Description
For a set of ontological annotation sets, remove terms annotated to the same objects as all their children. Useful for selecting terms for summarising a set of annotation sets, as it can lead to a significant reduction in the number of terms.
Usage
remove_uninformative_terms(ontology, term_sets)
Arguments
ontology |
|
term_sets |
List of character vectors of ontological term IDs |
Value
Character vector of terms
Examples
library(ontologyIndex)
data(hpo)
remove_uninformative_terms(hpo, list(Patient1=c("HP:0001873","HP:0000118")))
Capitalise words in character vector
Description
Capitalise words in character vector
Usage
simple_cap(x)
Arguments
x |
Character vector |
Value
Character vector
Examples
simple_cap(c("a simple test", "Another-test"))
Get simplified labels for terms
Description
Get simplified labels for terms
Usage
simple_labels(ontology, terms)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
Value
Character vector of labels, named by term.
See Also
Convert ontology_plot
to SVG string
Description
Note that by setting "id"
and "class"
attributes it enables nodes to be selected for manipulation using Javascript if interactivity is desired.
Usage
to_svg_string(op)
Arguments
op |
Object of class |
Value
Character vector of length 1 containing SVG representation of node.
See Also
Function to get node sizes for terms based on frequency in term_sets
Description
Function to get node sizes for terms based on frequency in term_sets
Usage
width_by_frequency(ontology, terms, term_sets)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
term_sets |
List of character vectors of ontological term IDs |
Value
Character vector of sizes, named by term
See Also
Function to get node sizes for terms based on statistical significance of seeing at least this number of each term in term_sets
Description
Function to get node sizes for terms based on statistical significance of seeing at least this number of each term in term_sets
Usage
width_by_significance(ontology, terms, term_sets, frequencies)
Arguments
ontology |
|
terms |
Character vector of ontological terms |
term_sets |
List of character vectors of ontological term IDs |
frequencies |
Numeric vector of term frequencies named by term IDs |
Value
Character vector of sizes, named by term
See Also
Export ontology_plot
object as dot file
Description
Export ontology_plot
object as dot file
Usage
write_dot(ontology_plot, file)
Arguments
ontology_plot |
Object of class 'ontology_plot' to export. |
file |
Character value of target file path. |
Value
Nothing, side effect - writes to file.