Commit cfaa54e9 authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

Merge branch 'repo_update' into 'master'

hypothetical complexes via API

See merge request !260
parents 0ea12b23 ef7bbee1
...@@ -9,47 +9,30 @@ library(httr) ...@@ -9,47 +9,30 @@ library(httr)
library(jsonlite) library(jsonlite)
### A convenience function to handle API queries ### A convenience function to handle API queries
ask_GET <- function(furl, fask, unpack = T) { ask_GET <- function(fask_url, verbose = F) {
print(URLencode(paste0(furl, fask))) if(verbose) {
resp <- httr::GET(url = URLencode(paste0(furl, fask)), write_memory(), message(URLencode(fask_url))
httr::add_headers('Content-Type' = "application/x-www-form-urlencoded"), }
### Currently ignoring SSL! resp <- httr::GET(url = URLencode(fask_url),
httr::set_config(config(ssl_verifypeer = 0L))) httr::add_headers('Content-Type' = "application/x-www-form-urlencoded"))
if(httr::status_code(resp) == 200) { if(httr::status_code(resp) == 200) {
### when the content is sent as a zip file, it needs to be handled differently,
### i.e. saved to a tmp file and unzipped
if(headers(resp)$`content-type` == "application/zip") {
tmp <- tempfile()
tmpc <- file(tmp, "wb")
writeBin(httr::content(resp, as = "raw"), con = tmpc)
close(tmpc)
unzipped <- unzip(tmp)
file.remove(tmp)
return(unzipped)
}
return(httr::content(resp, as = "text")) return(httr::content(resp, as = "text"))
} }
return(NULL) return(NULL)
} }
### Define the source file (GitLab, raw link) ### Define the source diagram name
diagram <- "https://git-r3lab.uni.lu/covid/models/-/raw/master/Curation/ER%20Stress/ER_Stress_stable.xml" diag_name <- "Endoplasmatic Reticulum stress"
### Read in the raw SIF version (here straight from the github of Aurelien) ### Read in the raw SIF version (here straight from the github of Aurelien)
raw_sif <- read.table(url("https://git-r3lab.uni.lu/covid/models/-/raw/master/Executable%20Modules/SBML_qual_build/sif/ER_Stress_stable_raw.sif"), raw_sif <- read.table(url("https://git-r3lab.uni.lu/covid/models/-/raw/master/Executable%20Modules/SBML_qual_build/sif/ER_Stress_stable_raw.sif"),
sep = " ", header = F, stringsAsFactors = F) sep = " ", header = F, stringsAsFactors = F)
### Read the list of resources to be integrated, from the MINERVA build scripts
res <- read.csv(url("https://git-r3lab.uni.lu/covid/models/raw/master/Integration/MINERVA_build/resources.csv"),
header = T, stringsAsFactors = F)
diag_name <- res[res$Resource == diagram, "Name"]
### Get MINERVA elements ### Get MINERVA elements
### 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 ### Get configuration of the COVID-19 Disease Map, to obtain the latest (default) version
cfg <- fromJSON(ask_GET(map, "configuration/")) cfg <- fromJSON(ask_GET(paste0(map, "configuration/")))
project_id <- cfg$options[cfg$options$type == "DEFAULT_MAP","value"] project_id <- cfg$options[cfg$options$type == "DEFAULT_MAP","value"]
### The address of the latest (default) build ### The address of the latest (default) build
mnv_base <- paste0(map,"projects/",project_id,"/") mnv_base <- paste0(map,"projects/",project_id,"/")
...@@ -57,14 +40,13 @@ mnv_base <- paste0(map,"projects/",project_id,"/") ...@@ -57,14 +40,13 @@ mnv_base <- paste0(map,"projects/",project_id,"/")
message(paste0("Asking for diagrams in: ", mnv_base, "models/")) message(paste0("Asking for diagrams in: ", mnv_base, "models/"))
### Get diagrams ### Get diagrams
models <- ask_GET(mnv_base, "models/") models <- ask_GET(paste0(mnv_base, "models/"))
models <- fromJSON(models, flatten = F) models <- fromJSON(models, flatten = F)
this_refs <- models[models$name == diag_name] this_refs <- models[models$name == diag_name,]
### Get elements of the chosen diagram ### Get elements of the chosen diagram
model_elements <- fromJSON(ask_GET(paste0(mnv_base,"models/",models$idObject[models$name == diag_name],"/"), model_elements <- fromJSON(ask_GET(paste0(mnv_base,"models/",models$idObject[models$name == diag_name],"/",
"bioEntities/elements/?columns=id,name,type,references,elementId,complexId,bounds"), "bioEntities/elements/?columns=id,name,type,references,elementId,complexId,bounds,hypothetical")),
flatten = F) flatten = F)
message("Fetching entrez ids...") message("Fetching entrez ids...")
...@@ -92,48 +74,25 @@ group_elements <- function(feid, felements, fentrez) { ...@@ -92,48 +74,25 @@ group_elements <- function(feid, felements, fentrez) {
} }
} }
### A workaround function to get information about hypothetical complexes; ### A function to get information about hypothetical complexes
### currently MINERVA API does not support this, we need to get the entire CD file and parse it get_role <- function(feid, felements) {
get_groups <- function(fname) { fpos <- which(felements$elementId == feid)
message(paste0("Getting groups for ", fname, "...")) if(length(fpos) == 0) return(NA)
library(xml2)
## Currently comment out the MINERVA download, some content dlded as binary! role <- ifelse(felements[fpos, "type"] == "Complex",
cd_map <- read_xml(ask_GET(mnv_base, ifelse(felements[fpos, "hypothetical"], "group", "complex"),
paste0("models/", "node")
models$idObject[models$name == fname], return(role)
":downloadModel?handlerClass=lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser")))
### CellDesigner namespace
ns_cd <- xml_ns_rename(xml_ns(read_xml("<root>
<sbml xmlns = \"http://www.sbml.org/sbml/level2/version4\"/>
<cd xmlns = \"http://www.sbml.org/2001/ns/celldesigner\"/>
</root>")),
d1 = "sbml", d2 = "cd")
### Get complex ids
cids <- xml_attr(xml_find_all(cd_map, "//cd:complexSpeciesAlias", ns_cd), "species")
### For each check, which is hypothetical
hypocs <- sapply(cids,
function(x) {
tcid <- xml_find_first(cd_map, paste0("//sbml:species[@id='", x, "']"), ns_cd)
ifelse(length(tcid) > 0, xml_text(xml_find_first(tcid, ".//cd:hypothetical", ns_cd)), NA)
})
names(hypocs) <- gsub("s_id_", "",names(hypocs))
return(hypocs)
} }
cgroups <- get_groups(diag_name)
message("Translating...") message("Translating...")
### Create a copy ### Create a copy
translated_sif <- raw_sif translated_sif <- raw_sif
### Retrieve Entrez and type for the entire columns of sources and targets ### Retrieve Entrez and type for the entire columns of sources and targets
s.entrez <- sapply(raw_sif[,1], group_elements, model_elements, entrez) s.entrez <- sapply(raw_sif[,1], group_elements, model_elements, entrez)
s.type <- sapply(raw_sif[,1], function(x) { ifelse(x %in% names(cgroups), s.type <- sapply(raw_sif[,1], get_role, model_elements)
ifelse(is.na(cgroups[x]), "complex", "group"),
"node") })
t.entrez <- sapply(raw_sif[,3], group_elements, model_elements, entrez) t.entrez <- sapply(raw_sif[,3], group_elements, model_elements, entrez)
t.type <- sapply(raw_sif[,3], function(x) { ifelse(x %in% names(cgroups), t.type <- sapply(raw_sif[,3], get_role, model_elements)
ifelse(is.na(cgroups[x]), "complex", "group"),
"node") })
### Collect x.y information ### Collect x.y information
s.xy <- t(sapply(raw_sif[,1], function(x) unlist(model_elements$bounds[model_elements$elementId == x, c(3,4)]))) s.xy <- t(sapply(raw_sif[,1], function(x) unlist(model_elements$bounds[model_elements$elementId == x, c(3,4)])))
colnames(s.xy) <- c("source.x", "source.y") colnames(s.xy) <- c("source.x", "source.y")
......
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