Skip to content
Snippets Groups Projects
Commit ef7bbee1 authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

hypothetical complexes via API

parent 0ea12b23
No related branches found
No related tags found
1 merge request!260hypothetical complexes via API
Pipeline #36543 passed
......@@ -9,47 +9,30 @@ library(httr)
library(jsonlite)
### A convenience function to handle API queries
ask_GET <- function(furl, fask, unpack = T) {
print(URLencode(paste0(furl, fask)))
resp <- httr::GET(url = URLencode(paste0(furl, fask)), write_memory(),
httr::add_headers('Content-Type' = "application/x-www-form-urlencoded"),
### Currently ignoring SSL!
httr::set_config(config(ssl_verifypeer = 0L)))
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) {
### 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(NULL)
}
### Define the source file (GitLab, raw link)
diagram <- "https://git-r3lab.uni.lu/covid/models/-/raw/master/Curation/ER%20Stress/ER_Stress_stable.xml"
### Define the source diagram name
diag_name <- "Endoplasmatic Reticulum stress"
### 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"),
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
### 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 <- fromJSON(ask_GET(map, "configuration/"))
cfg <- fromJSON(ask_GET(paste0(map, "configuration/")))
project_id <- cfg$options[cfg$options$type == "DEFAULT_MAP","value"]
### The address of the latest (default) build
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/"))
### Get diagrams
models <- ask_GET(mnv_base, "models/")
models <- ask_GET(paste0(mnv_base, "models/"))
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
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"),
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,hypothetical")),
flatten = F)
message("Fetching entrez ids...")
......@@ -92,48 +74,25 @@ group_elements <- function(feid, felements, fentrez) {
}
}
### A workaround 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_groups <- function(fname) {
message(paste0("Getting groups for ", fname, "..."))
library(xml2)
## Currently comment out the MINERVA download, some content dlded as binary!
cd_map <- read_xml(ask_GET(mnv_base,
paste0("models/",
models$idObject[models$name == fname],
":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)
### A function to get information about hypothetical complexes
get_role <- function(feid, felements) {
fpos <- which(felements$elementId == feid)
if(length(fpos) == 0) return(NA)
role <- ifelse(felements[fpos, "type"] == "Complex",
ifelse(felements[fpos, "hypothetical"], "group", "complex"),
"node")
return(role)
}
cgroups <- get_groups(diag_name)
message("Translating...")
### Create a copy
translated_sif <- raw_sif
### Retrieve Entrez and type for the entire columns of sources and targets
s.entrez <- sapply(raw_sif[,1], group_elements, model_elements, entrez)
s.type <- sapply(raw_sif[,1], function(x) { ifelse(x %in% names(cgroups),
ifelse(is.na(cgroups[x]), "complex", "group"),
"node") })
s.type <- sapply(raw_sif[,1], get_role, model_elements)
t.entrez <- sapply(raw_sif[,3], group_elements, model_elements, entrez)
t.type <- sapply(raw_sif[,3], function(x) { ifelse(x %in% names(cgroups),
ifelse(is.na(cgroups[x]), "complex", "group"),
"node") })
t.type <- sapply(raw_sif[,3], get_role, model_elements)
### Collect x.y information
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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment