Functions to convert one object type to another.

dt_to_matrix(dat, omit_cols = NULL, rownames = NULL, as_sparse = TRUE)

graph_to_dt(
  g,
  what = c("nodes", "edges"),
  id_col = c("id", "name"),
  prefixes = c("subject", "object")
)

graph_to_ggnetwork(g, ...)

ontology_to(
  ont,
  to = c("adjacency", "adjacency_dist", "adjacency_dist_hclust",
    "adjacency_dist_hclust_dendrogram", "adjacency_dist_hclust_clusters", "similarity",
    "dendrogram", "igraph", "dot", "adjacency_igraph", "igraph_dist",
    "igraph_dist_hclust", "igraph_dist_hclust_dendrogram", "tbl_graph", "data.frame",
    "data.table", "list"),
  terms = ont@terms,
  remove_terms = grep(":", terms, invert = TRUE, value = TRUE),
  as_sparse = FALSE,
  ...
)

ontology_to_graph(ont, ...)

to_graph(g, ...)

Arguments

as_sparse

Return the object as a sparseMatrix.

g

tbl_graph object.

id_col

Column containing the unique identifier for each node in a graph (e.g. "name").

...

Arguments passed on to ggnetwork::fortify

ont

An ontology of class ontology_DAG.

to

A character string specifying the format to convert to.

terms

A vector of ontology term IDs.

remove_terms

Character vector of term IDs to exclude.

as

A character string specifying the format to convert to.

as_dt

Return the object as a data.table.

as_graph

Return the object as a tbl_graph.

as_granges

Return the object as a GRanges.

Value

Converted data.

Functions

  • dt_to_matrix(): to_

  • graph_to_dt(): to_

  • graph_to_ggnetwork(): to_

  • ontology_to(): to_ Convert ontology

    Convert an ontology_DAG to a number of other useful formats.

  • ontology_to_graph(): to_

  • to_graph(): to_

Examples

dt <- data.table::as.data.table(mtcars, keep.rownames = TRUE)
X <- dt_to_matrix(dt)
ont <- get_ontology("hp", terms=10)
#> Loading cached ontology: /github/home/.cache/R/KGExplorer/hp.rds
#> Randomly sampling 10 term(s).
g <- ontology_to(ont, to="tbl_graph")
#> Translating ontology terms to ids.
#> Converted ontology to: tbl_graph 
dat <- graph_to_dt(g)
#> Converting tidygraph to data.table.
g <- igraph::graph.atlas(10)
#> Warning: `graph.atlas()` was deprecated in igraph 2.1.0.
#>  Please use `graph_from_atlas()` instead.
ggn <- graph_to_ggnetwork(g)
#> Converting graph to ggnetwork.
ont <- get_ontology()
#> Loading cached ontology: /github/home/.cache/R/KGExplorer/mondo.rds
obj <- ontology_to(ont=ont, to="dendrogram")
#> Translating ontology terms to ids.
#> 
#> going through 1000 / 46354 nodes ...
#> 
#> going through 2000 / 46354 nodes ...
#> 
#> going through 3000 / 46354 nodes ...
#> 
#> going through 4000 / 46354 nodes ...
#> 
#> going through 5000 / 46354 nodes ...
#> 
#> going through 6000 / 46354 nodes ...
#> 
#> going through 7000 / 46354 nodes ...
#> 
#> going through 8000 / 46354 nodes ...
#> 
#> going through 9000 / 46354 nodes ...
#> 
#> going through 10000 / 46354 nodes ...
#> 
#> going through 11000 / 46354 nodes ...
#> 
#> going through 12000 / 46354 nodes ...
#> 
#> going through 13000 / 46354 nodes ...
#> 
#> going through 14000 / 46354 nodes ...
#> 
#> going through 15000 / 46354 nodes ...
#> 
#> going through 16000 / 46354 nodes ...
#> 
#> going through 17000 / 46354 nodes ...
#> 
#> going through 18000 / 46354 nodes ...
#> 
#> going through 19000 / 46354 nodes ...
#> 
#> going through 20000 / 46354 nodes ...
#> 
#> going through 21000 / 46354 nodes ...
#> 
#> going through 22000 / 46354 nodes ...
#> 
#> going through 23000 / 46354 nodes ...
#> 
#> going through 24000 / 46354 nodes ...
#> 
#> going through 25000 / 46354 nodes ...
#> 
#> going through 26000 / 46354 nodes ...
#> 
#> going through 27000 / 46354 nodes ...
#> 
#> going through 28000 / 46354 nodes ...
#> 
#> going through 29000 / 46354 nodes ...
#> 
#> going through 30000 / 46354 nodes ...
#> 
#> going through 31000 / 46354 nodes ...
#> 
#> going through 32000 / 46354 nodes ...
#> 
#> going through 33000 / 46354 nodes ...
#> 
#> going through 34000 / 46354 nodes ...
#> 
#> going through 35000 / 46354 nodes ...
#> 
#> going through 36000 / 46354 nodes ...
#> 
#> going through 37000 / 46354 nodes ...
#> 
#> going through 38000 / 46354 nodes ...
#> 
#> going through 39000 / 46354 nodes ...
#> 
#> going through 40000 / 46354 nodes ...
#> 
#> going through 41000 / 46354 nodes ...
#> 
#> going through 42000 / 46354 nodes ...
#> 
#> going through 43000 / 46354 nodes ...
#> 
#> going through 44000 / 46354 nodes ...
#> 
#> going through 45000 / 46354 nodes ...
#> 
#> going through 46000 / 46354 nodes ...
#> 
#> going through 46354 / 46354 nodes ... Done.
#> Converted ontology to: dendrogram 
g <- igraph::graph.full(10)
#> Warning: `graph.full()` was deprecated in igraph 2.1.0.
#>  Please use `make_full_graph()` instead.
g2 <- to_graph(g)