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

Upload New File

parent 0f6ca0ef
##################################################
## Script purpose: An example of MINERVA API call to retrieve
## neighbors of 10 most differentially expressed molecules
## in a given data overlay
## Date: 17/03/2019
## Author: Marek Ostaszewski (marek.ostaszewski@uni.lu)
## MINERVA API version: 14.0
##################################################
### A convenience function to handle GET and POST requests to MINERVA API
library(httr)
library(jsonlite)
### Utility function using httr:GET to send queries to a given MINERVA Platform instance
ask_GET <- function(mnv_base, query) {
resp <- httr::GET(url = paste0(mnv_base, query),
httr::add_headers('Content-Type' = "application/x-www-form-urlencoded"))
if(httr::status_code(resp) == 200) {
return(httr::content(resp, as = "text"))
}
return(NULL)
}
### Base URL of the map, we use Parkinson's disease map
base_url <- "https://pdmap.uni.lu/minerva/api/projects/pd_map_autumn_19/"
### Request for the list of public overlays in the Parkinson's disease map
overlays <- fromJSON(ask_GET(base_url,"overlays/?publicOverlay=true"))
### Request for the identifier of one of them, "PD substantia nigra"
ovid <- overlays$idObject[overlays$name == "PD substantia nigra"]
### Retrieve values of the overlay
overlay_data <- fromJSON(ask_GET(base_url,paste0("overlays/",ovid,"/models/*/bioEntities/")))$overlayContent
### Sort by decreasing value of absolute differential expression (they can be poistive and negative)
overlay_data <- overlay_data[order(abs(overlay_data$value), decreasing = T),]
top_values <- c()
### An element with the same name can have many aliases; to select top 10 distinct elements,
### we look at 10 unique differential expression values
for(r in 10:nrow(overlay_data)) {
top_values <- overlay_data[1:r, ]
### Finish the for loop when we have top 10 (for equal values, this number may be higher)
if(length(unique(top_values$value)) >= 10) { break }
}
### Paste all the identifiers into a single string
query_string <- paste(top_values$idObject, collapse = ",")
### Request for reactions that have at least one top 10 element as participant
reactions <- fromJSON(ask_GET(base_url,
paste0("models/*/bioEntities/reactions/?participantId=",
query_string,
"&columns=modifiers,products,reactants")))
### Retrieve all elements participating in reactios selected above
neighbors <- c(unlist(sapply(reactions$modifiers, function(x) x$aliasId)),
unlist(sapply(reactions$products, function(x) x$aliasId)),
unlist(sapply(reactions$reactants, function(x) x$aliasId)))
### Make identifiers unique, as they can overlap
neighbors <- unique(neighbors)
### Retrieve and print the names of the elements
fromJSON(ask_GET(base_url,
paste0("models/*/bioEntities/elements/?id=",
paste(neighbors, collapse = ","),
"&columns=name")))
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