From a30bdd441f7431ce6742b3f7929ff79ce7100156 Mon Sep 17 00:00:00 2001
From: HDash <16350928+HDash@users.noreply.github.com>
Date: Wed, 18 Dec 2024 11:35:39 +0000
Subject: [PATCH] Port function from HPOExplorer to avoid circular dependency
---
DESCRIPTION | 1 -
NAMESPACE | 1 +
NEWS.md | 7 ++---
R/get_hpo.R | 43 ++++++++++++++++++++++++++++++
R/map_upheno_data_i.R | 20 +++++++-------
README.md | 4 +--
man/get_.Rd | 62 ++++++++++++++++++++++++++++++-------------
7 files changed, 104 insertions(+), 34 deletions(-)
create mode 100644 R/get_hpo.R
diff --git a/DESCRIPTION b/DESCRIPTION
index eaf227d..95f7a27 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -73,7 +73,6 @@ Suggests:
BiocGenerics,
readxl,
htmlwidgets,
- HPOExplorer,
sparklyr,
httr,
jsonlite,
diff --git a/NAMESPACE b/NAMESPACE
index 8111e39..20f5822 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -22,6 +22,7 @@ export(get_gencc)
export(get_gene_lengths)
export(get_genes_disease)
export(get_graph_colnames)
+export(get_hpo)
export(get_monarch)
export(get_monarch_files)
export(get_monarch_kg)
diff --git a/NEWS.md b/NEWS.md
index 8447174..90ad69a 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,11 +1,12 @@
# KGExplorer 0.99.05
+## New features
+* `get_hpo`
+ - Port function from `HPOExplorer` package to prevent circular dependency.
+
## Bug fixes
* `DESCRIPTION`
- Update remote for `monarchr`.
- - Add `HPOExplorer` to Suggests and remotes.
- - Add `KGExplorer` (self) to remote to fix circular dependency with
- `HPOExplorer` installation.
# KGExplorer 0.99.04
diff --git a/R/get_hpo.R b/R/get_hpo.R
new file mode 100644
index 0000000..00f526c
--- /dev/null
+++ b/R/get_hpo.R
@@ -0,0 +1,43 @@
+#' @describeIn get_ get_
+#' Get Human Phenotype Ontology (HPO)
+#'
+#' Updated version of Human Phenotype Ontology (HPO).
+#' Created from the OBO files distributed by the HPO project's
+#' \href{https://github.com/obophenotype/human-phenotype-ontology}{GitHub}.
+#' Adapted from \link[HPOExplorer]{get_hpo}.
+#'
+#' By comparison, the \code{hpo} data from \pkg{ontologyIndex} is from 2016.
+#' Note that the maximum ontology level depth in the 2016 version was 14,
+#' whereas in the 2023 version the maximum ontology level depth is 16
+#' (due to an expansion of the HPO).
+#' @inheritParams get_ontology
+#' @inheritDotParams get_ontology
+#' @returns \link[simona]{ontology_DAG} object.
+#'
+#' @export
+#' @examples
+#' hpo <- get_hpo()
+get_hpo <- function(lvl = 2,
+ force_new = FALSE,
+ terms=NULL,
+ ## rols imports the international version for some reason
+ method="github",
+ save_dir=cache_dir(package = "KGExplorer"),
+ ...){
+
+ file <- file.path(save_dir,"hp.rds")
+ if(!file.exists(file) || isTRUE(force_new)){
+ ont <- get_ontology(name = "hp",
+ lvl = lvl,
+ force_new = force_new,
+ terms = terms,
+ method = method,
+ save_dir = save_dir,
+ ...)
+ saveRDS(ont,file)
+ } else {
+ ont <- readRDS(file)
+ }
+ ont <- filter_ontology(ont = ont, terms = terms)
+ return(ont)
+}
diff --git a/R/map_upheno_data_i.R b/R/map_upheno_data_i.R
index f104977..da5104a 100644
--- a/R/map_upheno_data_i.R
+++ b/R/map_upheno_data_i.R
@@ -12,7 +12,7 @@ map_upheno_data_i <- function(pheno_map_method,
n_genes_db1 <- object <- gene_label <- db <- . <-
n_genes_db2 <- subject_taxon_label1 <- subject_taxon_label2 <-
phenotype_genotype_score <- equivalence_score <- NULL;
-
+
pheno_map_method <- pheno_map_method[1]
gene_map_method <- gene_map_method[1]
messager(paste0("map_upheno_data: pheno_map_method=",
@@ -26,10 +26,10 @@ map_upheno_data_i <- function(pheno_map_method,
names(pheno_map) <-gsub("^object","id2",names(pheno_map))
pheno_map[,db1:=gsub("*:.*","",basename(id1))]
} else if(pheno_map_method=="monarch"){
-
- hpo <- HPOExplorer::get_hpo()
+
+ hpo <- get_hpo()
out <- monarchr::monarch_search(query = NULL,
- category = "biolink:PhenotypicFeature",
+ category = "biolink:PhenotypicFeature",
limit = 500)
pheno_map <- get_monarch(queries = "phenotype_to_phenotype") |>
data.table::setnames(c("label_x","label_y"),c("label1","label2"))
@@ -47,7 +47,7 @@ map_upheno_data_i <- function(pheno_map_method,
}
}
}
-
+
## Gene-phenotype associations across 8 species
{
genes <- get_monarch(maps = list(c("phenotype","gene")),
@@ -65,7 +65,7 @@ map_upheno_data_i <- function(pheno_map_method,
## Create an db-species map for each Ontology
species_map <- genes_map[,.SD[1], keyby="db"][,.(db,subject_taxon_label)]
}
-
+
#### Map non-human genes onto human orthologs ####
{
genes_homol <- map_genes_monarch(dat=genes,
@@ -75,7 +75,7 @@ map_upheno_data_i <- function(pheno_map_method,
data.table::uniqueN(genes$subject_taxon_label),
"species remain after cross-species gene mapping.")
}
-
+
#### Map non-human phenotypes onto human phenotypes ####
#### Merge nonhuman ontology genes with human HPO genes ####
{
@@ -94,7 +94,7 @@ map_upheno_data_i <- function(pheno_map_method,
all.y = keep_nogenes,
suffixes = c(1,2),
allow.cartesian = TRUE
- )
+ )
pheno_map_genes[,db2:=id2_db]
## Fill in missing species for those without gene data
pheno_map_genes[
@@ -113,7 +113,7 @@ map_upheno_data_i <- function(pheno_map_method,
## Remove
# remove(genes_human,genes_nonhuman,pheno_map)
}
-
+
#### Count the number of overlapping genes
{
if(isFALSE(keep_nogenes)){
@@ -154,4 +154,4 @@ map_upheno_data_i <- function(pheno_map_method,
## less than or equal to the number of total HPO genes.
# pheno_map_genes_match[n_genes>n_genes_hpo,]
return(pheno_map_genes_match)
-}
\ No newline at end of file
+}
diff --git a/README.md b/README.md
index c680fe0..a70d374 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ KGExplorer
[](https://cran.r-project.org/web/licenses/GPL-3)
-[](https://github.com/neurogenomics/KGExplorer)
+[](https://github.com/neurogenomics/KGExplorer)
[](https://github.com/neurogenomics/KGExplorer)
[](https://github.com/neurogenomics/KGExplorer/commits/master)
[![R build
@@ -15,7 +15,7 @@ status](https://github.com/neurogenomics/KGExplorer/workflows/rworkflows/badge.s
Authors: Brian Schilder, Hiranyamaya Dash