## ----echo = FALSE------------------------------------------------------------- knitr::knit_hooks$set(pngquant = knitr::hook_pngquant) knitr::opts_chunk$set( message = FALSE, dev = "ragg_png", fig.align = "center", pngquant = "--speed=10 --quality=30" ) ## ----------------------------------------------------------------------------- library(simona) parents = c("a", "a", "b", "b", "c", "d") children = c("b", "c", "c", "d", "e", "f") dag_small = create_ontology_DAG(parents, children) ## ----------------------------------------------------------------------------- dag_graphviz(dag_small) ## ----------------------------------------------------------------------------- color = 2:7 shape = c("polygon", "box", "oval", "egg", "diamond", "parallelogram") dag_graphviz(dag_small, node_param = list(color = color, shape = shape)) ## ----------------------------------------------------------------------------- color = c("a" = "red", "d" = "blue") dag_graphviz(dag_small, node_param = list(color = color)) ## ----------------------------------------------------------------------------- parents = c("a", "a", "b", "b", "c", "d") children = c("b", "c", "c", "d", "e", "f") relations = c("is_a", "is_a", "part_of", "part_of", "is_a", "is_a") dag_small = create_ontology_DAG(parents, children, relations = relations) ## ----------------------------------------------------------------------------- edge_color = c("is_a" = "red", "part_of" = "blue") dag_graphviz(dag_small, edge_param = list(color = edge_color)) ## ----------------------------------------------------------------------------- edge_color = c("a -> b" = "red", "c -> e" = "blue") dag_graphviz(dag_small, edge_param = list(color = edge_color)) ## ----comment = ''------------------------------------------------------------- dag_as_DOT(dag_small, node_param = list(color = color, shape = shape)) |> cat() ## ----------------------------------------------------------------------------- dag = create_ontology_DAG_from_GO_db() dag_graphviz(dag[, "GO:0010228"], node_param = list( fillcolor = c("GO:0010228" = "pink"), style = c("GO:0010228" = "filled") ), edge_param = list( color = c("is_a" = "purple", "part_of" = "darkgreen"), style = c("is_a" = "solid", "part_of" = "dashed") ), width = 600, height = 600) ## ----fig.width = 9, fig.height = 7-------------------------------------------- dag_circular_viz(dag) ## ----fig.width = 9, fig.height = 7-------------------------------------------- dag_circular_viz(dag, partition_by_size = 5000) ## ----fig.width = 10, fig.height = 7------------------------------------------- tree = dag_treelize(dag) dag_circular_viz(tree) ## ----fig.width = 10, fig.height = 7------------------------------------------- go_tb = readRDS(system.file("extdata", "sig_go_tb.rds", package = "simona")) sig_go_ids = go_tb$ID[go_tb$p.adjust < 0.01] # make sure `sig_go_ids` all in current GO.db version sig_go_ids = intersect(sig_go_ids, dag_all_terms(dag)) dag_circular_viz(dag, highlight = sig_go_ids) ## ----------------------------------------------------------------------------- p.adjust = go_tb$p.adjust[go_tb$p.adjust < 0.01] ## ----------------------------------------------------------------------------- node_size_fun = function(x, range = c(2, 10)) { s = (range[2] - range[1])/(quantile(x, 0.95) - min(x)) * (x - min(x)) + range[1] s[s > range[2]] = range[2] s } ## ----------------------------------------------------------------------------- library(ComplexHeatmap) lgd = Legend(title = "p.adjust", at = -log10(c(0.01, 0.001, 0.0001)), labels = c("0.01", "0.001", "0.0001"), type = "points", size = unit(node_size_fun(-log10(c(0.01, 0.001, 0.0001))), "pt")) ## ----------------------------------------------------------------------------- node_size = rep(2, dag_n_terms(dag)) names(node_size) = dag_all_terms(dag) node_size[sig_go_ids] = node_size_fun(-log10(p.adjust)) ## ----fig.width = 10, fig.height = 7------------------------------------------- dag_circular_viz(dag, highlight = sig_go_ids, node_size = node_size, edge_transparency = 0.92, other_legends = lgd) ## ----------------------------------------------------------------------------- sessionInfo()