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, ...)
Return the object as a sparseMatrix.
ggnetwork object (or an igraph/tbl_graph to be converted to ggnetwork format).
Column containing the unique identifier for each node in a graph (e.g. "name").
Arguments passed on to ggnetwork::fortify
An ontology of class ontology_DAG.
A character string specifying the format to convert to.
Term IDs to include. Can alternatively be an integer, which will be used to randomly sample N terms from the data.
Character vector of term IDs to exclude.
A character string specifying the format to convert to.
Return the object as a data.table.
Return the object as a tbl_graph.
Return the object as a GRanges.
Converted data.
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_
dt <- data.table::as.data.table(mtcars, keep.rownames = TRUE)
X <- dt_to_matrix(dt)
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
dat <- graph_to_dt(g)
#> Converting tidygraph to data.table.
g <- igraph::graph.atlas(10)
ggn <- graph_to_ggnetwork(g)
#> Converting graph to ggnetwork.
ont <- get_ontology()
#> ℹ All local files already up-to-date!
#> Importing cached file: /github/home/.cache/R/KGExplorer/mondo.owl
#> Adding term metadata.
#> IC_method: IC_offspring
#> Adding ancestor metadata.
#> Getting absolute ontology level for 31,550 IDs.
#> 2412 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 31,550 IDs.
obj <- ontology_to(ont=ont, to="dendrogram")
#>
#> going through 1000 / 27730 nodes ...
#>
#> going through 2000 / 27730 nodes ...
#>
#> going through 3000 / 27730 nodes ...
#>
#> going through 4000 / 27730 nodes ...
#>
#> going through 5000 / 27730 nodes ...
#>
#> going through 6000 / 27730 nodes ...
#>
#> going through 7000 / 27730 nodes ...
#>
#> going through 8000 / 27730 nodes ...
#>
#> going through 9000 / 27730 nodes ...
#>
#> going through 10000 / 27730 nodes ...
#>
#> going through 11000 / 27730 nodes ...
#>
#> going through 12000 / 27730 nodes ...
#>
#> going through 13000 / 27730 nodes ...
#>
#> going through 14000 / 27730 nodes ...
#>
#> going through 15000 / 27730 nodes ...
#>
#> going through 16000 / 27730 nodes ...
#>
#> going through 17000 / 27730 nodes ...
#>
#> going through 18000 / 27730 nodes ...
#>
#> going through 19000 / 27730 nodes ...
#>
#> going through 20000 / 27730 nodes ...
#>
#> going through 21000 / 27730 nodes ...
#>
#> going through 22000 / 27730 nodes ...
#>
#> going through 23000 / 27730 nodes ...
#>
#> going through 24000 / 27730 nodes ...
#>
#> going through 25000 / 27730 nodes ...
#>
#> going through 26000 / 27730 nodes ...
#>
#> going through 27000 / 27730 nodes ...
#>
#> going through 27730 / 27730 nodes ... Done.
#> Converted ontology to: dendrogram
g <- igraph::graph.full(10)
g2 <- to_graph(g)