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 @@
options(stringsAsFactors = F)
library(httr)
library(jsonlite)
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)
}
### Helper functions to access and retrieve content from MINERVA-hosted diagrams
source("https://git-r3lab.uni.lu/covid/models/-/raw/master/Integration/MINERVA_access/minerva_access_functions.R")
### The address of the COVID-19 Disease Map in MINERVA
map <- "https://covid19map.elixir-luxembourg.org/minerva/api/"
### Get configuration of the COVID-19 Disease Map, to obtain the latest (default) version
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)
components <- get_map_components(map)
### Get elements of diagrams
model_elements <- lapply(models$idObject,
function(x) fromJSON(ask_GET(paste0(mnv_base,"models/",x,"/"),
"bioEntities/elements/?columns=id,name,type,references"),
flatten = F))
### You may want to save components to JSON if you want to explore the structure of MINERVA's output
all_hgncs <- c()
### Go through all diagram elements and:
for(me in model_elements) {
get_annotations <- function(model_elements, annotation_type) {
### For erroneous response, skip to next diagram
if(is.null(me)) { next }
if(is.null(model_elements)) { return(NULL) }
### 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
if(length(these_refs) == 0) { next }
if(length(these_refs) == 0) { return(NULL) }
### Get all HGNC symbols, for elements that have annotations
all_hgncs <- c(all_hgncs, sapply(these_refs,
function(x) x[x$type == "HGNC_SYMBOL", "resource"]))
all_hgncs <- all_hgncs[sapply(all_hgncs,
### Get all identifiers, for elements that have the requested annotation
identifiers <- sapply(these_refs,
function(x) x[x$type == annotation_type, "resource"])
identifiers <- identifiers[sapply(identifiers,
function(x) ifelse(is.character(x) & length(x) > 0, TRUE, FALSE))]
return(identifiers)
}
### Get unique HGNC symbols
all_hgncs <- unique(all_hgncs)
### Get all HGNC symbols
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