Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
API scripts
Commits
cefcb263
Commit
cefcb263
authored
Mar 18, 2020
by
Marek Ostaszewski
Browse files
Upload New File
parent
0f6ca0ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/API_retrieve_neighbors_of_degs.R
0 → 100644
View file @
cefcb263
##################################################
## 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"
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment