Skip to content

Commit 793bbf2

Browse files
committed
export get_gencc
1 parent c4832fe commit 793bbf2

15 files changed

+243
-19
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ export(add_tier)
2121
export(adjacency_matrix)
2222
export(annotate_phenos)
2323
export(assign_tiers)
24+
export(clear_cache)
2425
export(example_phenos)
26+
export(get_gencc)
2527
export(get_gene_lists)
2628
export(get_hpo)
2729
export(get_hpo_id_direct)
2830
export(get_mondo)
2931
export(get_ont_lvls)
3032
export(get_ont_lvls2)
33+
export(get_version)
3134
export(ggnetwork_plot)
3235
export(gpt_annot_check)
3336
export(gpt_annot_codify)

NEWS.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
## New features
44

55
* `get_hpo`
6-
- Updated to lates release: 2023-08-01
6+
- Updated to latest release: 2023-08-01
77
* `gpt_annot_*`
88
- Ensure consistent use of updated column names.
99
* Add version attribute data within HPO objects
1010
- `get_hpo`: already built in to `ontologyIndex` objects.
1111
- `load_phenotypes_to_genes`: new attribute.
12-
* Add `update_hpo` internal function.
12+
- New exported helper function: `get_version`
13+
- New exported helper function: `clear_cache`
14+
* Add `make_hpo` internal function.
1315
* Ensure consistent function naming:
14-
- `create_node_data` --> `make_node_data`
15-
* New internal function: `clear_cache`
16+
- `create_node_data` --> `make_node_data`
17+
* `get_gencc`
18+
- Export
19+
- Add version info
20+
* Increase code coverage throughout
21+
1622

1723
# HPOExplorer 0.99.11
1824

R/clear_cache.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
#' Clear cache
22
#'
3+
#' Remove all data cached by \pkg{HPOExplorer}.
34
#' @param save_dir Path to cache directory.
5+
#' @param verbose Print messages.
46
#' @inheritParams base::unlink
57
#' @inheritDotParams base::unlink
8+
#' @returns Null.
69
#'
7-
#' @keywords internal
10+
#' @export
811
#' @importFrom tools R_user_dir
12+
#' @examples
13+
#' \dontrun{
14+
#' clear_cache()
15+
#' }
916
clear_cache <- function(save_dir=tools::R_user_dir(package = "HPOExplorer",
1017
which = "cache"),
11-
recursive = TRUE,
18+
recursive=TRUE,
19+
verbose=TRUE,
1220
...
1321
){
22+
23+
f <- list.files(save_dir,recursive = recursive)
24+
messager("Clearing",length(f),"cached files from:",save_dir,v=verbose)
1425
unlink(x = save_dir,recursive = recursive,...)
1526
}

R/get_gencc.R

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1+
#' Get GenCC
2+
#'
3+
#' Get phenotype-gene evidence score from the
4+
#' \href{https://thegencc.org/}{Gene Curation Coalition}.
5+
#' Data downloaded from \href{https://search.thegencc.org/download}{here}.\cr
6+
#' \emph{NOTE:} Due to licensing restrictions, a GenCC download does not
7+
#' include OMIM data. OMIM data can be accessed and downloaded through
8+
#' \href{https://omim.org/downloads/}{OMIM}.\cr
9+
#' \emph{NOTE:} GenCC does not currently have any systematic versioning.
10+
#' There for the \code{attr(obj,"version")} attribute is set to the date it was
11+
#' downloaded and cached by \link[HPOExplorer]{get_gencc}.
12+
#'
13+
#' @param dict A named vector of evidence score mappings.
14+
#' See \href{https://thegencc.org/faq.html#validity-termsdelphi-survey}{here}
15+
#' for more information.
16+
#' @inheritParams add_evidence
17+
#' @inheritParams get_data
18+
#' @returns \link[data.table]{data.table} with columns:
19+
#' \itemize{
20+
#' \item{"disease_id": }{Disease ID.}
21+
#' \item{"gene_symbol": }{Gene symbol.}
22+
#' \item{"evidence_score": }{Evidence score.}
23+
#' }
24+
#'
25+
#' @export
26+
#' @import data.table
27+
#' @importFrom utils download.file
28+
#' @examples
29+
#' d <- get_gencc()
130
get_gencc <- function(agg_by=c("disease_id",
231
"gene_symbol"),
32+
dict = c("Definitive"=6,# GENCC:100001
33+
"Strong"=5, # GENCC:100002
34+
"Moderate"=4, # GENCC:100003
35+
"Supportive"=3, # GENCC:100009
36+
"Limited"=2, # GENCC:100004
37+
"Disputed Evidence"=1, # GENCC:100005
38+
"Refuted Evidence"=0, # GENCC:100006
39+
"No Known Disease Relationship"=0 # GENCC:100008
40+
),
341
save_dir=tools::R_user_dir("HPOExplorer",
442
which="cache"),
543
verbose=TRUE){
44+
# devoptera::args2vars(get_gencc)
645

746
disease_id <- disease_original_curie <- classification_title <-
847
evidence_score <- NULL;
@@ -19,16 +58,6 @@ get_gencc <- function(agg_by=c("disease_id",
1958
d <- data.table::fread(f)
2059
d[,disease_id:=gsub("^Orphanet","ORPHA",disease_original_curie)]
2160
#### Encode evidence numerically ####
22-
# https://thegencc.org/faq.html#validity-termsdelphi-survey
23-
dict <- c("Definitive"=6,# GENCC:100001
24-
"Strong"=5, # GENCC:100002
25-
"Moderate"=4, # GENCC:100003
26-
"Supportive"=3, # GENCC:100009
27-
"Limited"=2, # GENCC:100004
28-
"Disputed Evidence"=1, # GENCC:100005
29-
"Refuted Evidence"=0, # GENCC:100006
30-
"No Known Disease Relationship"=0 # GENCC:100008
31-
)
3261
d[,evidence_score:=dict[classification_title]]
3362
#### Aggregate so that there's 1 entry/gene/disease ####
3463
if(!is.null(agg_by)){
@@ -37,5 +66,9 @@ get_gencc <- function(agg_by=c("disease_id",
3766
evidence_score_mean=mean(evidence_score, na.rm=TRUE)),
3867
by=agg_by]
3968
}
69+
#### Add version ####
70+
attr(d,"version") <- format(file.info(f)$mtime, "%Y-%m-%d")
71+
get_version(obj=d, verbose=verbose)
72+
#### Return ####
4073
return(d)
4174
}

R/get_version.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#' Get version
2+
#'
3+
#' Extract the precise version of the HPO release that the data object
4+
#' was built from. All HPO Releases can be found at the official
5+
#' \href{https://github.com/obophenotype/human-phenotype-ontology/releases}{
6+
#' HPO GitHub Releases page}.
7+
#' @param obj An object from
8+
#' \link[HPOExplorer]{get_hpo} or
9+
#' \link[HPOExplorer]{load_phenotype_to_genes}.
10+
#' @param verbose Print messages.
11+
#' @param return_version Return the version as a character string.
12+
#' @returns HPO Release version a character string.
13+
#'
14+
#' @export
15+
#' @examples
16+
#' obj <- get_hpo()
17+
#' get_version(obj=obj)
18+
get_version <- function(obj,
19+
return_version = FALSE,
20+
verbose = TRUE){
21+
## Extract
22+
if(methods::is(obj,"ontology_index")){
23+
x <- grep("data-version:",attr(obj,"version"),value=TRUE)
24+
v <- paste0("v",
25+
trimws(gsub("data-version:|hp/releases/|/hp-base.owl","",x))
26+
)
27+
} else {
28+
v <- attr(obj,"version")
29+
}
30+
## Print
31+
messager("+ Version:",v,v=verbose)
32+
## Return
33+
if(isTRUE(return_version)) return(v)
34+
}

R/hpo_api.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
#' @returns A named list or data.frame of metadata for a given HPO ID.
1111
#'
1212
#' @export
13+
#' @import data.table
1314
#' @examples
1415
#' dat <- hpo_api(hpo_id="HP:0011420", type="diseases")
1516
hpo_api <- function(hpo_id,
1617
type = list(NULL,"genes","diseases")[[1]],
1718
url = paste("hpo.jax.org/api/hpo/term",hpo_id,type,sep="/")
1819
){
1920

21+
requireNamespace("httr")
22+
requireNamespace("jsonlite")
23+
2024
hpo_termdetails <- tryCatch(expr = {
2125
httr::GET(url = url)
2226
},
@@ -26,5 +30,7 @@ hpo_api <- function(hpo_id,
2630
})
2731
hpo_termdetails_char <- rawToChar(hpo_termdetails$content)
2832
hpo_termdetails_data <- jsonlite::fromJSON(hpo_termdetails_char)
33+
hpo_termdetails_data$diseases <-
34+
data.table::data.table(hpo_termdetails_data$diseases)
2935
return(hpo_termdetails_data)
3036
}

R/load_phenotype_to_genes.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ load_phenotype_to_genes <- function(file = c("phenotype_to_genes.txt",
4646
!overwrite){
4747
messager("Reading cached RDS file:",file,v=verbose)
4848
obj <- readRDS(path_rds)
49-
messager("+ Version:",attr(obj,"version"),v=verbose)
49+
get_version(obj,verbose=verbose)
5050
return(obj)
5151
}
5252
#### Stored in GitHub Releases ####
@@ -66,8 +66,10 @@ load_phenotype_to_genes <- function(file = c("phenotype_to_genes.txt",
6666
} else {
6767
phenotype_to_genes <- data.table::fread(input = f)
6868
}
69+
#### Add version ####
6970
if(!is.null(attr(f,"version"))){
7071
attr(phenotype_to_genes,"version") <- attr(f,"version")
72+
get_version(phenotype_to_genes,verbose=verbose)
7173
}
7274
#### Save RDS ####
7375
## This lets up keep track of the version of the data without having to

man/clear_cache.Rd

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_gencc.Rd

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_version.Rd

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-add_disease.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
test_that("add_disease works", {
2+
3+
phenos <- example_phenos()
4+
phenos2 <- add_disease(phenos = phenos, add_definitions = TRUE)
5+
testthat::expect_true(
6+
all(phenos$hpo_id %in% phenos2$hpo_id)
7+
)
8+
testthat::expect_gte(
9+
nrow(phenos2),7000
10+
)
11+
})

tests/testthat/test-get_gencc.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_that("get_gencc works", {
2+
3+
d <- get_gencc()
4+
})

tests/testthat/test-gpt_annot_check.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test_that("gpt_annot_check works", {
2+
3+
checks <- gpt_annot_check()
4+
testthat::expect_true(all(
5+
c("annot","annot_mean","annot_consist","annot_check","checkable_rate",
6+
"checkable_count","true_pos_rate","false_neg_rate") %in% names(checks)
7+
))
8+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test_that("gpt_annot_codify works", {
2+
3+
coded <- gpt_annot_codify()
4+
testthat::expect_true(
5+
all(
6+
c("annot","annot_coded","annot_weighted") %in% names(coded)
7+
)
8+
)
9+
})

tests/testthat/test-hpo_api.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test_that("hpo_api works", {
2+
3+
dat <- hpo_api(hpo_id="HP:0011420", type="diseases")
4+
testthat::expect_true(
5+
all(c("diseases","diseaseCount","offset","max" ) %in% names(dat))
6+
)
7+
testthat::expect_true(
8+
methods::is(dat$diseases,"data.table")
9+
)
10+
})

0 commit comments

Comments
 (0)