Commit d799e3a3 authored by cylon-x's avatar cylon-x 🤖
Browse files

Merge branch 'repo_update' of https://git-r3lab.uni.lu/covid/models into repo_update

parents ff0b14aa b69666e8
##################################################
## Project: COVID-19 Disease Map
## Script purpose: Get drug targets for unique UniProt identifiers
## Date: 22.01.2021
## Author: Marek Ostaszewski
##################################################
### Helper functions to access and retrieve content from MINERVA-hosted diagrams
source("minerva_access_functions.R")
### The address of the COVID-19 Disease Map in MINERVA
map <- "https://covid19map.elixir-luxembourg.org/minerva/api/"
### Get the components of MINERVA and WikiPathways (see minerva_access.R)
map_components <- get_map_components(map)
message("Retrieving MINERVA Uniprot collection")
refs <- lapply(map_components$map_elements, function(x) data.frame(id = x$id,
uniprot = get_annotation(x$references, "UNIPROT")))
names(refs) <- map_components$models$name
message("Done.")
##################################################
## Project: COVID-19 Disease Map
## Script purpose: Get different formats of the MINERVA diagrams
## Date: 25.01.2021
## Author: Marek Ostaszewski
##################################################
### 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/"
library(jsonlite)
### Get config to obtain the default map and different format handlers
cfg <- fromJSON(ask_GET(paste0(map, "configuration/")))
### Get the default (most recent) project id
project_id <- cfg$options[cfg$options$type == "DEFAULT_MAP","value"]
### The address of the latest (default) build
mnv_base <- paste0(map, "projects/",project_id,"/")
### Get model information
models <- fromJSON(ask_GET(paste0(mnv_base, "models/")))
### Format handler;
### see cfg$modelFormats for available handlers, we will use the SBGNML handler
this_handler <- with(cfg$modelFormats, handler[name == "SBGN-ML"])
this_extension <- with(cfg$modelFormats, extension[name == "SBGN-ML"])
### Iterate over all model ids, get them in the format defined by the handler and add the handler-associated extension
for(i in 1:nrow(models)) {
lines <- ask_GET(paste0(mnv_base, "models/", models$idObject[i],":downloadModel?handlerClass=",this_handler))
cat(lines, file = paste0(models$name[i], ".", this_extension))
}
message("Done.")
\ No newline at end of file
##################################################
## Project: COVID-19 Disease Map
## Script purpose: Convenience functions for accessing the MINERVA Platform
## Date: 24.12.2020
## Author: Marek Ostaszewski
##################################################
library(httr)
library(jsonlite)
### A convenience function to handle API queries
ask_GET <- function(fask_url, verbose = F) {
if(verbose) {
message(URLencode(fask_url))
}
resp <- httr::GET(url = URLencode(fask_url),
httr::add_headers('Content-Type' = "application/x-www-form-urlencoded"))
if(httr::status_code(resp) == 200) {
return(httr::content(resp, as = "text"))
}
return(NULL)
}
### Get the id of the default project for this MINERVA instance
get_default_project <- function(map_api) {
cfg <- fromJSON(ask_GET(paste0(map_api, "configuration/")))
return(cfg$options[cfg$options$type == "DEFAULT_MAP","value"])
}
### Get the components of a given map/project on the MINERVA Platform
get_map_components <- function(map_api, project_id = NULL) {
if(is.null(project_id)) {
### If project id not given, get configuration of the map, to obtain the latest (default) version
project_id <- get_default_project
}
### The address of the latest (default) build
mnv_base <- paste0(map_api, "projects/",project_id,"/")
message(paste0("Asking for diagrams in: ", mnv_base, "models/"))
### Get diagrams
models <- fromJSON(ask_GET(paste0(mnv_base, "models/")))
### Get elements of the chosen diagram
model_elements <- lapply(models$idObject,
function(x)
fromJSON(ask_GET(paste0(mnv_base,"models/",x,"/",
"bioEntities/elements/?columns=id,name,type,references,elementId,complexId")),
flatten = F))
### Request for reactions that have at least one top 10 element as participant
model_reactions <- lapply(models$idObject,
function(x)
fromJSON(ask_GET(paste0(mnv_base,"models/",x,"/",
"bioEntities/reactions/?columns=modifiers,products,reactants")),
flatten = F))
### Pack all into a list and return
return(list(models = models, map_elements = model_elements, map_reactions = model_reactions))
}
### Get annotation of a given type, from element/reaction references
get_annotation <- function(freferences, ftype) {
sapply(freferences,
function(x) {
ifelse(any(x$type == ftype), x$resource[x$type == ftype], NA)
})
}
\ No newline at end of file
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