Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
API scripts
Commits
9083bd51
Commit
9083bd51
authored
Aug 13, 2020
by
Marek Ostaszewski
Browse files
Calculate overlay hits for a given user
parent
b901c4c6
Changes
4
Show whitespace changes
Inline
Side-by-side
R/API_calculate_overlay_hits.R
0 → 100644
View file @
9083bd51
##################################################
## Script purpose: An example of MINERVA API call to retrieve overlays of a give user
## and calculate "hits" of each element in the map
## Date: 12/08/2020
## Author: Marek Ostaszewski (marek.ostaszewski@uni.lu)
## MINERVA API version: 15.0
##################################################
### A convenience function to handle GET and POST requests to MINERVA API
library
(
httr
)
library
(
jsonlite
)
### Utility function using httr:POST to send queries to a given MINERVA Platform instance
ask_POST
<-
function
(
mnv_base
,
query
,
body
)
{
resp
<-
httr
::
POST
(
url
=
paste0
(
mnv_base
,
query
),
body
=
body
,
httr
::
add_headers
(
'Content-Type'
=
"application/x-www-form-urlencoded"
),
httr
::
verbose
())
if
(
httr
::
status_code
(
resp
)
==
200
)
{
return
(
httr
::
content
(
resp
,
as
=
"text"
))
}
return
(
NULL
)
}
### Base URL of this MINERVA instance
base
<-
"https://pdmap.uni.lu/minerva/api/"
### Provide the username and password of a given user - this is to access this user's overlays
login
<-
"username"
password
<-
"userpassword"
### log in the user
resp
<-
ask_POST
(
base
,
"doLogin"
,
body
=
paste0
(
"login="
,
login
,
"&password="
,
password
))
### Get the cookie token from the login response; if NULL the loogin was unsuccessfull
token
<-
fromJSON
(
resp
)
$
token
map_base
<-
paste0
(
base
,
"projects/pd_map_autumn_19/"
)
### Utility function using httr:GET to send queries to a given MINERVA Platform instance with the given token (logged user)
ask_GET
<-
function
(
mnv_base
,
query
)
{
resp
<-
httr
::
GET
(
url
=
paste0
(
mnv_base
,
query
),
httr
::
add_headers
(
'Content-Type'
=
"application/x-www-form-urlencoded"
),
### Currently ignoring SSL!
httr
::
set_config
(
config
(
ssl_verifypeer
=
0L
)),
httr
::
verbose
())
if
(
httr
::
status_code
(
resp
)
==
200
)
{
return
(
httr
::
content
(
resp
,
as
=
"text"
))
}
return
(
NULL
)
}
### Utility function using httr:GET to send queries to a given MINERVA Platform instance with the given token (logged user)
token_GET
<-
function
(
mnv_base
,
query
,
token
)
{
resp
<-
httr
::
GET
(
url
=
paste0
(
mnv_base
,
query
),
httr
::
add_headers
(
'Content-Type'
=
"application/x-www-form-urlencoded"
),
httr
::
set_cookies
(
MINERVA_AUTH_TOKEN
=
token
),
# ### Currently ignoring SSL!
# httr::set_config(config(ssl_verifypeer = 0L)),
httr
::
verbose
())
if
(
httr
::
status_code
(
resp
)
==
200
)
{
return
(
httr
::
content
(
resp
,
as
=
"text"
))
}
return
(
NULL
)
}
### Retrieve all overlays
overlays
<-
fromJSON
(
token_GET
(
map_base
,
"overlays/"
,
token
))
### Select only overlays of this user (not public) that have data behind them
selected_overlays
<-
overlays
[
!
overlays
$
publicOverlay
&
overlays
$
inputDataAvailable
,
c
(
"idObject"
,
"name"
)]
### Retrieve all elements' ids and names, for later resolution
models
<-
fromJSON
(
token_GET
(
map_base
,
"models/"
,
token
),
flatten
=
F
)
### Get elements of diagrams
model_elements
<-
lapply
(
models
$
idObject
,
function
(
x
)
fromJSON
(
token_GET
(
map_base
,
paste0
(
"models/"
,
x
,
"/"
,
"bioEntities/elements/?columns=id,name"
),
token
),
flatten
=
F
))
### Name elements by id for easier referencing
names
(
model_elements
)
<-
models
$
idObject
### Calculate hits for each overlay
for
(
i
in
1
:
nrow
(
selected_overlays
))
{
### GET all bioentities selected by this overlay
hits
<-
fromJSON
(
token_GET
(
base
,
paste0
(
"projects/pd_map_autumn_19/overlays/"
,
selected_overlays
[
i
,
1
],
"/models/*/bioEntities/"
),
token
),
flatten
=
T
)
#fromJSON() behaves strangely, forced 'flatten' because unflattened result gets coerced to a compound data.frame
### Create a column for element name
hits
<-
cbind
(
hits
,
element_name
=
""
)
### From model_elements, take the element name and assig int to 'hits'
for
(
j
in
1
:
nrow
(
hits
))
{
res
<-
with
(
model_elements
[[
as.character
(
hits
[
j
,
2
])]],
name
[
id
==
hits
[
j
,
"overlayContent.idObject"
]])
hits
[
j
,
"element_name"
]
<-
res
}
### Combine with map/submap names for a detailed breakdown of hits
hits
<-
merge
(
hits
,
models
[,
c
(
"name"
,
"idObject"
)],
by.x
=
"overlayContent.modelId"
,
by.y
=
"idObject"
)
### Write down the table with the element hits by map/submap
### A single element can have many instances, so there can be multiple hits
write.table
(
table
(
hits
[,
c
(
"element_name"
,
"name"
)]),
file
=
paste0
(
"hits_of_"
,
selected_overlays
[
i
,
2
],
".txt"
),
sep
=
"\t"
,
quote
=
F
)
}
R/API_find_drug_targets.R
View file @
9083bd51
...
...
@@ -2,7 +2,7 @@
## Script purpose: An example of MINERVA API call to retrieve
## HGNC symbols of elements targetted by a given drug,
## and to retrieve drugs targetting elements with a given UniProt
## Date: 17/03/20
19
## Date: 17/03/20
20
## Author: Marek Ostaszewski (marek.ostaszewski@uni.lu)
## MINERVA API version: 14.0
##################################################
...
...
R/API_retrieve.R
View file @
9083bd51
##################################################
## Script purpose: An example of MINERVA API call to retrieve elements with a
## given uniprot id and their interactions
## Date: 17/03/20
19
## Date: 17/03/20
20
## Author: Marek Ostaszewski (marek.ostaszewski@uni.lu)
## MINERVA API version: 14.0
##################################################
...
...
R/API_retrieve_neighbors_of_degs.R
View file @
9083bd51
...
...
@@ -2,7 +2,7 @@
## 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/20
19
## Date: 17/03/20
20
## Author: Marek Ostaszewski (marek.ostaszewski@uni.lu)
## MINERVA API version: 14.0
##################################################
...
...
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