Skip to content

Commit

Permalink
use rols package
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Feb 2, 2024
1 parent 608fe22 commit 6687e93
Show file tree
Hide file tree
Showing 26 changed files with 233 additions and 123 deletions.
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ BugReports: https://github.com/neurogenomics/KGExplorer/issues
Encoding: UTF-8
Depends: R (>= 4.2)
biocViews:
Software,
Network,
GraphAndNetwork
Imports:
simona,
rols,
data.table,
ggplot2,
plotly,
Expand Down Expand Up @@ -78,7 +82,7 @@ Remotes:
github::RajLabMSSM/echogithub,
github::RajLabMSSM/downloadR,
github::kwstat/pals
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
VignetteBuilder: knitr
License: GPL-3
Config/testthat/edition: 3
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export(get_monarch_files)
export(get_monarch_kg)
export(get_monarch_models)
export(get_mondo_maps)
export(get_ols_options)
export(get_ontology)
export(get_ontology_dict)
export(get_ontology_github)
export(get_ontology_levels)
export(get_pli)
export(get_prevalence)
Expand Down Expand Up @@ -57,13 +57,15 @@ export(plot_graph_visnetwork)
export(plot_ontology)
export(plot_ontology_heatmap)
export(plot_save)
export(plot_ttd)
export(plot_upheno)
export(query_monarch)
export(query_oard)
export(to_graph)
import(data.table)
import(orthogene)
import(pals)
import(rols)
import(rvest)
import(simona)
import(tidygraph)
Expand Down
1 change: 1 addition & 0 deletions R/0docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ NULL
#' @inheritParams map_
#' @inheritParams simona::dag_ancestors
#' @inheritParams data.table::merge.data.table
#' @import rols
#' @description
#' Functions to get data resources.
#' @family get_
Expand Down
2 changes: 1 addition & 1 deletion R/add_ancestors.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @export
#' @inheritParams simona::dag_offspring
#' @examples
#' ont <- get_ontology("hpo")
#' ont <- get_ontology("hp")
#' ont2 <- add_ancestors(ont)
add_ancestors <- function(ont,
lvl=2,
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("hpo", terms=10)
#' ont <- get_ontology("hp", terms=10)
#' g <- ontology_to(ont, to="tbl_graph")
#' g2 <- add_hoverboxes(g)
add_hoverboxes <- function(g,
Expand Down
2 changes: 1 addition & 1 deletion R/add_ontology_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @import simona
#' @importFrom Matrix colSums
#' @examples
#' ont <- get_ontology("hpo", terms=10)
#' ont <- get_ontology("hp", terms=10)
#' ont2 <- add_ontology_metadata(ont)
add_ontology_metadata <- function(ont,
add_ancestors=2,
Expand Down
4 changes: 2 additions & 2 deletions R/get_definitions.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#' and add the ID and name of the ancestor to the ontology metadata.
#' @export
#' @examples
#' ont <- get_ontology("hpo", terms=10)
#' ont <- get_ontology("hp", terms=10)
#' def <- get_definitions(ont)
get_definitions <- function(ont,
from="id",
to="definition"){
get_ontology_dict(ont=ont,
from=from,
to=to)
}
}
2 changes: 1 addition & 1 deletion R/get_monarch.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#'
#' @export
#' @examples
#' dat <- get_monarch()
#' dat <- get_monarch(maps=list(c("gene","disease")))
get_monarch <- function(queries=NULL,
maps=NULL,
domain="https://data.monarchinitiative.org",
Expand Down
3 changes: 3 additions & 0 deletions R/get_monarch_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ get_monarch_files <- function(maps=NULL,
if(!is.null(maps)){
messager("Filtering with `maps`.")
files <- lapply(maps, function(m){
if(length(m)<2) {
stopper("Each map elements must be a vector of at least 2 items.")
}
if(!is.null(m)){
files[(subject==m[1] & object==m[2]) |
(subject==m[2] & object==m[1])]
Expand Down
8 changes: 8 additions & 0 deletions R/get_ols_options.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' @describeIn get_ get_
#' Get a complete up=to-date list of ontologies available via the
#' \href{https://www.ebi.ac.uk/ols4}{EBML-EBI Ontology Lookup Service} API.
#' @param ol An \link[rols]{Ontologies} object.
#' @export
get_ols_options <- function(ol = rols::Ontologies()){
sort(rols::olsNamespace(ol))
}
57 changes: 39 additions & 18 deletions R/get_ontology.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#' @describeIn get_ get_
#' @describeIn get_ get_ontology
#' Get ontology
#'
#' Import an up-to-date ontology directly from from the creators.
#' Import an up-to-date ontology directly from from the creators or via the
#' \href{https://www.ebi.ac.uk/ols4}{EBML-EBI Ontology Lookup Service} API.
#' @param name
#' \itemize{
#' \item{<...>}{Any ontology name from \link{get_ols_options}}
#' \item{"mondo"}{
#' Import the \href{https://mondo.monarchinitiative.org/}{Mondo} ontology.
#' \href{https://github.com/monarch-initiative/mondo/release}{
Expand All @@ -13,66 +15,85 @@
#' \href{https://github.com/obophenotype/human-phenotype-ontology/release}{
#' GitHub.}}
#' }
#' @param filetype File type to search for.
#' @param method Whether to import ontology via the \code{rols} package or
#' via the \link{get_ontology_github}/link{get_ontology_url} functions.
#' @param add_metadata Add metadata to the resulting ontology object.
#' @inheritDotParams get_ontology_github
#' @returns \link[simona]{ontology_DAG}
#'
#' @export
#' @examples
#' mondo <- get_ontology(name="mondo")
#' hpo <- get_ontology(name="hpo")
#' upheno <- get_ontology(name="upheno")
#' \dontrun{
#' hp <- get_ontology(name="hp")
#' upheno <- get_ontology(name="upheno")
#' }
get_ontology <- function(name=c("mondo",
"hpo",
"hp",
"upheno",
"uberon",
"cl"),
method=c("rols",
"github"),
terms=NULL,
filetype="-base.obo",
method=c("github",
"bioportal"),
add_metadata=TRUE,
add_ancestors=2,
add_n_edges=TRUE,
add_ontology_levels=TRUE,
save_dir=cache_dir(),
force_new=FALSE,
...){
name <- match.arg(name)
method <- match.arg(method)
name <- name[1]
method <- match.arg(method)

if(method=="github"){
ol <- rols::Ontologies()
rols_opts <- get_ols_options(ol=ol)
if(method=="rols" &&
!name %in% rols_opts){
messager("Ontology not found via 'rols.' Trying method='github'.'")
method <- "github"
}
#### via EMBL-EBI Ontology Lookup Service ####
if(method=="rols"){
ol_ont <- ol[[name]]
get_ontology_robot()
ont <- get_ontology_url(
URL = ol_ont@config$fileLocation,
force_new = force_new,
save_dir = save_dir,
...)
#### Via manually coded functions ####
} else if(method=="github"){
if(name=="mondo"){
ont <- get_ontology_github(file=paste0(name,filetype),
ont <- get_ontology_github(name=name,
repo="monarch-initiative/mondo",
save_dir=save_dir,
force_new=force_new,
...)
} else if(name %in% c("hp","hpo")){
if(name=="hpo") name <- "hp"
ont <- get_ontology_github(file=paste0(name,filetype),
ont <- get_ontology_github(name=name,
repo="obophenotype/human-phenotype-ontology",
save_dir=save_dir,
force_new=force_new,
...)
} else if (name %in% c("cl","cellontology","cell-ontology") ){
ont <- get_ontology_github(file=paste0(name,filetype),
ont <- get_ontology_github(name=name,
repo="obophenotype/cell-ontology",
save_dir=save_dir,
force_new=force_new,
...)
} else if(name=="upheno"){
get_ontology_robot()
ont <- get_ontology_url(
ont <- get_ontology_url(URL =
# "https://github.com/obophenotype/upheno/raw/master/upheno.owl",
"https://purl.obolibrary.org/obo/upheno/v2/upheno.owl",
import_func = simona::import_owl,
# import_func = simona::import_owl,
force_new = force_new,
save_dir = save_dir,
...)
} else if (name %in% c("uberon") ){
ont <- get_ontology_github(file=paste0(name,filetype),
ont <- get_ontology_github(name=name,
repo="obophenotype/uberon",
save_dir=save_dir,
force_new=force_new,
Expand Down
4 changes: 2 additions & 2 deletions R/get_ontology_dict.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @export
#' @examples
#' ont <- get_ontology("hpo", terms=10)
#' ont <- get_ontology("hp", terms=10)
#' dict <- get_ontology_dict(ont)
get_ontology_dict <- function(ont,
from="id",
Expand All @@ -25,4 +25,4 @@ get_ontology_dict <- function(ont,
)
}
return(dict)
}
}
16 changes: 8 additions & 8 deletions R/get_ontology_github.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#' @describeIn get_ get_
#'
#' Get ontology from GitHub
#' Get ontology from GitHub and import it via \link[simona]{import_ontology}.
#' @param filetype File type to search for.
#' @inheritParams get_
#' @inheritDotParams simona::import_ontology
#' @inheritParams piggyback::pb_download_url
#' @returns \link[simona]{ontology_DAG}
#'
#' @export
#' @examples
#' mondo <- get_ontology_github()
get_ontology_github <- function(file="mondo-base.obo",
repo="monarch-initiative/mondo",
#' @keywords internal
get_ontology_github <- function(name,
repo,
filetype="-base.obo",
file=paste0(name,filetype),
tag="latest",
save_dir=cache_dir(),
force_new=FALSE,
Expand Down
2 changes: 2 additions & 0 deletions R/get_ontology_robot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @inheritDotParams get_data
#' @keywords internal
get_ontology_robot <- function(...){
simona_opt <- utils::getFromNamespace(x = "simona_opt",
ns = "simona")
robot <- get_data(file = "robot.jar",
repo = "ontodev/robot",
...)
Expand Down
2 changes: 1 addition & 1 deletion R/graph_to_plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'
#' @export
#' @examples
#' ont <- get_ontology("hpo", terms=10)
#' ont <- get_ontology("hp", terms=10)
#' g <- ontology_to(ont, to="tbl_graph")
#' p <- graph_to_plotly(g)
graph_to_plotly <- function(g,
Expand Down
2 changes: 1 addition & 1 deletion R/map_ontology_terms.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#'
#' @export
#' @examples
#' ont <- get_ontology("hpo")
#' ont <- get_ontology("hp")
#' terms <- c("Focal motor seizure","HP:0000002","HP:0000003")
#' term_names <- map_ontology_terms(ont=ont, terms=terms)
#' term_ids <- map_ontology_terms(ont=ont, terms=terms, to="id")
Expand Down
2 changes: 1 addition & 1 deletion R/plot_graph_3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @importFrom stringr str_wrap
#' @importFrom methods show
#' @examples
#' ont <- get_ontology("hpo", terms=10, add_ancestors=TRUE)
#' ont <- get_ontology("hp", terms=10, add_ancestors=TRUE)
#' g <- ontology_to(ont, to="tbl_graph")
#' plt <- plot_graph_3d(g=g, show_plot=FALSE)
plot_graph_3d <- function(g,
Expand Down
4 changes: 2 additions & 2 deletions R/plot_graph_visnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @inheritParams visNetwork::visNetwork
#' @export
#' @examples
#' ont <- get_ontology("hpo", terms=10)
#' ont <- get_ontology("hp", terms=10)
#' g <- ontology_to(ont, to="tbl_graph")
#' out <- plot_graph_visnetwork(g)
plot_graph_visnetwork <- function(g,
Expand Down Expand Up @@ -135,4 +135,4 @@ plot_graph_visnetwork <- function(g,
data=g,
plot=visnet
))
}
}
2 changes: 1 addition & 1 deletion R/plot_ontology_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#'
#' @export
#' @examples
#' ont <- get_ontology("hpo", terms=2)
#' ont <- get_ontology("hp", terms=2)
#' hm <- plot_ontology_heatmap(ont)
plot_ontology_heatmap <- function(ont,
annot = data.table::data.table(
Expand Down
6 changes: 3 additions & 3 deletions man/add_.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6687e93

Please sign in to comment.