Commit 77a7113e authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

Merge branch 'repo_update' into 'master'

an improvement in the access script and a small diagram correction

See merge request !282
parents 916f8453 216912a9
...@@ -7,66 +7,33 @@ ...@@ -7,66 +7,33 @@
options(stringsAsFactors = F) options(stringsAsFactors = F)
library(httr) ### Helper functions to access and retrieve content from MINERVA-hosted diagrams
library(jsonlite) source("https://git-r3lab.uni.lu/covid/models/-/raw/master/Integration/MINERVA_access/minerva_access_functions.R")
library(here)
setwd(paste0(here(),"/Integration/MINERVA_build/"))
### Map and pathway enrichment analysis.
### Requires commandline input or file "input.txt" to be present in the script directory.
### A convenience function to handle API queries
ask_GET <- function(furl, fask) {
resp <- httr::GET(url = paste0(furl, fask),
httr::add_headers('Content-Type' = "application/x-www-form-urlencoded"))
if(httr::status_code(resp) == 200) {
return(httr::content(resp, as = "text"))
}
return(NULL)
}
### The address of the COVID-19 Disease Map in MINERVA ### The address of the COVID-19 Disease Map in MINERVA
map <- "https://covid19map.elixir-luxembourg.org/minerva/api/" map <- "https://covid19map.elixir-luxembourg.org/minerva/api/"
### Get configuration of the COVID-19 Disease Map, to obtain the latest (default) version components <- get_map_components(map)
cfg <- ask_GET(map, "configuration/")
cfg <- fromJSON(cfg)
project_id <- cfg$options[cfg$options$type == "DEFAULT_MAP","value"]
### The address of the latest (default) build
mnv_base <- paste0(map,"projects/",project_id,"/")
message(paste0("Asking for diagrams in: ", mnv_base, "models/"))
### Get diagrams
models <- ask_GET(mnv_base, "models/")
models <- fromJSON(models, flatten = F)
### Get elements of diagrams ### You may want to save components to JSON if you want to explore the structure of MINERVA's output
model_elements <- lapply(models$idObject,
function(x) fromJSON(ask_GET(paste0(mnv_base,"models/",x,"/"),
"bioEntities/elements/?columns=id,name,type,references"),
flatten = F))
all_hgncs <- c() get_annotations <- function(model_elements, annotation_type) {
### Go through all diagram elements and:
for(me in model_elements) {
### For erroneous response, skip to next diagram ### For erroneous response, skip to next diagram
if(is.null(me)) { next } if(is.null(model_elements)) { return(NULL) }
### Only elements that have annotations ### Only elements that have annotations
these_refs <- me$references[sapply(me$references, length) > 0] these_refs <- model_elements$references[sapply(model_elements$references, length) > 0]
### For empty list, skip to next diagram ### For empty list, skip to next diagram
if(length(these_refs) == 0) { next } if(length(these_refs) == 0) { return(NULL) }
### Get all HGNC symbols, for elements that have annotations ### Get all identifiers, for elements that have the requested annotation
all_hgncs <- c(all_hgncs, sapply(these_refs, identifiers <- sapply(these_refs,
function(x) x[x$type == "HGNC_SYMBOL", "resource"])) function(x) x[x$type == annotation_type, "resource"])
all_hgncs <- all_hgncs[sapply(all_hgncs, identifiers <- identifiers[sapply(identifiers,
function(x) ifelse(is.character(x) & length(x) > 0, TRUE, FALSE))] function(x) ifelse(is.character(x) & length(x) > 0, TRUE, FALSE))]
return(identifiers)
} }
### Get unique HGNC symbols ### Get all HGNC symbols
all_hgncs <- unique(all_hgncs) all_hgncs <- sapply(components$map_elements, get_annotations, "HGNC_SYMBOL")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment