Skip to content

Commit

Permalink
update get_opentargets [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Apr 21, 2024
1 parent 7f953d7 commit 943911b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions R/filter_ontology.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ filter_ontology <- function(ont,
to = "id") |> stats::na.omit()
if(length(keep_descendants)>0){
messager("Keeping descendants of",length(keep_descendants),"term(s).")
keep_descendants <- simona::dag_offspring(dag = ont,
include_self = include_self,
term = keep_descendants)
ont <- simona::dag_filter(ont,
terms=keep_descendants,
root=as.character(keep_descendants),
...)
messager(formatC(ont@n_terms,big.mark = ","),
"terms remain after filtering.")
Expand Down Expand Up @@ -64,9 +61,12 @@ filter_ontology <- function(ont,
}
#### Use custom filtering methods ####
if(!is.null(terms)){
terms <- map_ontology_terms(ont = ont,
terms = terms,
to = "id") |> stats::na.omit()
## Characters
if(is.character(terms)){
terms <- terms[terms %in% ont@terms] |> unique()
terms <- terms[simona::dag_has_terms(dag=ont, terms = unique(terms))]
if(length(terms)==0) {
stopper("None of the supplied terms found in the ontology.")
}
Expand Down
10 changes: 6 additions & 4 deletions R/get_opentargets.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Get Open Targets
#'
#' Get Open Targets disease-gene associations data
#' NOTE: If you get an error like " Cannot call parquet...",
#' try running \code{arrow::install_arrow},
#' restarting the R session, and trying again.
#' @source \href{https://community.opentargets.org/t/r-script-for-graphql-query-query-targetdiseaseevidence/662/5}{OpenTargets GraphQL queries in R}
#' @param release Open Targets release version.
#' @param data_type Type of data to download.
Expand Down Expand Up @@ -59,13 +62,12 @@ get_opentargets <- function(release="latest",
d <- BiocParallel::bplapply(stats::setNames(tbl$Name,
tbl$Name),
BPPARAM = BPPARAM,
function(f){

function(f){
if(endsWith(f,".json")){
j <- jsonlite::fromJSON(file.path(ftp, f))
j <- jsonlite::fromJSON(paste0(ftp,"/",f))
jsonlite::fromJSON(j$serialisedSchema)
} else if (endsWith(f,".parquet")){
arrow::read_parquet(file.path(ftp, f)) |>
arrow::read_parquet(paste0(ftp,f)) |>
data.table::data.table()
}
}) |> data.table::rbindlist(idcol = "file")
Expand Down
3 changes: 3 additions & 0 deletions man/get_opentargets.Rd

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

0 comments on commit 943911b

Please sign in to comment.