Package 'ontologyPlot'

Title: Visualising Sets of Ontological Terms
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>.
Authors: Daniel Greene <[email protected]>
Maintainer: Daniel Greene <[email protected]>
License: GPL (>= 2)
Version: 1.7
Built: 2024-11-17 03:09:13 UTC
Source: https://github.com/cran/ontologyPlot

Help Index


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

ontology_index object

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 term_sets.

cluster_rows

Logical value rows determining whether to use hclust to cluster term_sets.

cluster_cols

Logical value rows determining whether to use hclust to cluster terms (based on correlation of inclusion in term_sets).

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

ontology_index object

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

ontology_index object

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

ontology_index object

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. rainbow or heat.colors.

alpha

alpha parameter to pass to colour_generator.

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

onto_plot


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

ontology_index object

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

get_pseudo_adjacency_matrix

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

ontology_index object

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

ontology_index object

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 terms, or of length 1 if they should be used for all terms.

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

ontology_index object

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

get_adjacency_matrix

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

ontology_index object

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

ontology_index object

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

ontology_index object

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

simple_labels, long_labels


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

ontology_index object

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

ontology_index object

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 nth position, all terms are included in the result.

Usage

n_most_frequent_terms(
  ontology,
  term_sets,
  n,
  terms = unique(unlist(term_sets))
)

Arguments

ontology

ontology_index object

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

ontology_index object

terms

Character vector of ontological terms

Value

Character vector of labels, named by term.

See Also

simple_labels


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

ontology_index object

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 terms with. Alternatively a function to set the colours of the nodes in the graph based on term_sets.

label

Character vector of labels (or function to set them).

color

Character vector of colours for borders of nodes representing terms (or function to set them).

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 "filled".

fixedsize

Character indicating whether nodes should be fixed size, "true", or adjusted to fit around the contained text, "false".

shape

Character vector of shape names for nodes (or function to set them). Defaults to "circle".

...

Other node attributes for dot format.

Value

ontology_plot object.

See Also

get_ontology_plot, write_dot

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
)

Functions for Visualising Sets of Ontological Terms

Description

Functions for visualising sets of ontological terms using the ‘graphviz’ layout system.

Author(s)

Daniel Greene <[email protected]>

Maintainer: Daniel Greene <[email protected]>

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 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

ontology_index object

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

width_by_significance


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 annotation_grid.

on_colour

Colour to use to show presence of term.

off_colour

Colour to use to show absence of term.

Value

Plots heatmap.


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.


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 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

ontology_index object

term_sets

List of character vectors of ontological term IDs

n

Integer

terms

Character vector of ontological terms

Value

Character vector

See Also

n_most_frequent_terms

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

ontology_index object

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

ontology_index object

terms

Character vector of ontological terms

Value

Character vector of labels, named by term.

See Also

official_labels


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 ontology_plot.

Value

Character vector of length 1 containing SVG representation of node.

See Also

onto_plot, get_ontology_plot


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

ontology_index object

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

width_by_significance


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

ontology_index object

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

width_by_frequency


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.

See Also

dot_string