Skip to content

Commit

Permalink
allow add_ancestors to set name
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Feb 7, 2024
1 parent 6687e93 commit f27c580
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
23 changes: 14 additions & 9 deletions R/add_ancestors.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
#' @inheritParams simona::dag_offspring
#' @examples
#' ont <- get_ontology("hp")
#' ont2 <- add_ancestors(ont)
#' ont2 <- add_ancestors(ont, lvl=4)
add_ancestors <- function(ont,
lvl=2,
include_self=TRUE,
prefix="ancestor",
fill_na=TRUE,
force_new=FALSE){
term <- ancestor <- NULL;
term <- NULL;

if(is.null(lvl)) return (ont)
messager("Adding ancestor metadata.")
#### Check if ancestor metadata already present
if(all(c("ancestor","ancestor_name") %in% colnames(ont@elementMetadata)) &&
prefix_name <- paste0(prefix,"_name")
if(all(c(prefix,prefix_name) %in% colnames(ont@elementMetadata)) &&
isFALSE(force_new)){
messager("Ancestor metadata already present.",
"Use force_new=TRUE to overwrite.")
Expand All @@ -39,16 +42,18 @@ add_ancestors <- function(ont,
term=simona::dag_offspring(ont, term = x,
include_self = include_self)
)
}) |> data.table::rbindlist(idcol = "ancestor", fill = TRUE)
}) |> data.table::rbindlist(idcol = prefix, fill = TRUE)
#### Ensure one row per term ####
ancestors_groups <- ancestors_groups[, .SD[1], keyby = "term"]
ancestors_groups <- ancestors_groups[ont@terms][is.na(ancestor),
ancestor:=term]
ont@elementMetadata$ancestor <- ancestors_groups$ancestor
if(isTRUE(fill_na)){
ancestors_groups <- ancestors_groups[ont@terms][is.na(get(prefix)),
(prefix):=term]
}
ont@elementMetadata[[prefix]] <- ancestors_groups[[prefix]]
#### Add ancestor_name col
ont@elementMetadata$ancestor_name <- map_ontology_terms(
ont@elementMetadata[[prefix_name]] <- map_ontology_terms(
ont = ont,
terms = ont@elementMetadata$ancestor,
terms = ont@elementMetadata[[prefix]],
to = "name")
#### Return ####
return(ont)
Expand Down
2 changes: 1 addition & 1 deletion R/add_hoverboxes.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @export
#' @importFrom stringr str_wrap
#' @examples
#' ont <- get_ontology("hp", terms=10)
#' ont <- get_ontology("hp")
#' g <- ontology_to(ont, to="tbl_graph")
#' g2 <- add_hoverboxes(g)
add_hoverboxes <- function(g,
Expand Down
5 changes: 3 additions & 2 deletions R/plot_clinvar.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ plot_clinvar <- function(hits,
x="region",
y="N",
fill="Type",
by=c("build","region","Type","ClinSigSimple"),
rows="ClinSigSimple"){
rows="ClinSigSimple",
by=c("build",x,fill,rows)
){

requireNamespace("ggplot2")
requireNamespace("forcats")
Expand Down
3 changes: 1 addition & 2 deletions R/plot_ontology.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ plot_ontology <- function(ont,
"graphviz",
"tidygraph",
"visnetwork"),
...){
requireNamespace("DiagrammeR")
...){
#### Filter ont ####
ont <- filter_ontology(ont,
terms=terms)
Expand Down
3 changes: 2 additions & 1 deletion R/plot_ontology_circular.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' @keywords internal
plot_ontology_circular <- function(ont,
...){
requireNamespace("DiagrammeR")
simona::dag_circular_viz(ont,
...)
}
}

0 comments on commit f27c580

Please sign in to comment.