Skip to content

Commit

Permalink
Port function from HPOExplorer to avoid circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
HDash committed Dec 18, 2024
1 parent b1d7794 commit a30bdd4
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 34 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Suggests:
BiocGenerics,
readxl,
htmlwidgets,
HPOExplorer,
sparklyr,
httr,
jsonlite,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
43 changes: 43 additions & 0 deletions R/get_hpo.R
Original file line number Diff line number Diff line change
@@ -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)
}
20 changes: 10 additions & 10 deletions R/map_upheno_data_i.R
Original file line number Diff line number Diff line change
Expand Up @@ -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=",
Expand All @@ -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"))
Expand All @@ -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")),
Expand All @@ -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,
Expand All @@ -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 ####
{
Expand All @@ -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[
Expand All @@ -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)){
Expand Down Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ KGExplorer
<img src='https://github.com/neurogenomics/KGExplorer/raw/master/inst/hex/hex.png' title='Hex sticker for KGExplorer' height='300'><br>
[![License:
GPL-3](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://cran.r-project.org/web/licenses/GPL-3)
[![](https://img.shields.io/badge/devel%20version-0.99.04-black.svg)](https://github.com/neurogenomics/KGExplorer)
[![](https://img.shields.io/badge/devel%20version-0.99.05-black.svg)](https://github.com/neurogenomics/KGExplorer)
[![](https://img.shields.io/github/languages/code-size/neurogenomics/KGExplorer.svg)](https://github.com/neurogenomics/KGExplorer)
[![](https://img.shields.io/github/last-commit/neurogenomics/KGExplorer.svg)](https://github.com/neurogenomics/KGExplorer/commits/master)
<br> [![R build
Expand All @@ -15,7 +15,7 @@ status](https://github.com/neurogenomics/KGExplorer/workflows/rworkflows/badge.s
Authors: <i>Brian Schilder, Hiranyamaya Dash</i>
</h4>
<h4>
README updated: <i>Dec-17-2024</i>
README updated: <i>Dec-18-2024</i>
</h4>

<!-- To modify Package/Title/Description/Authors fields, edit the DESCRIPTION file -->
Expand Down
62 changes: 44 additions & 18 deletions man/get_.Rd

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

0 comments on commit a30bdd4

Please sign in to comment.