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
0f6ca0ef
Commit
0f6ca0ef
authored
Mar 18, 2020
by
Marek Ostaszewski
Browse files
Update API_retrieve.R
parent
e5b2a8f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/API_retrieve.R
View file @
0f6ca0ef
...
...
@@ -23,53 +23,30 @@ ask_GET <- function(mnv_base, query) {
### 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 identifiers of models for a given project (main map and submaps)
models
<-
ask_GET
(
base_url
,
"models/"
)
models
<-
fromJSON
(
models
,
flatten
=
F
)
### For each model, retrieve elements with columns including references
model_elements
<-
lapply
(
models
$
idObject
,
function
(
x
)
fromJSON
(
ask_GET
(
paste0
(
base_url
,
"models/"
,
x
,
"/
"
),
"bioEntities/elements/?columns=id,name,type,references"
),
flatten
=
F
))
model_elements
<-
fromJSON
(
ask_GET
(
paste0
(
base_url
,
"models/*/"
)
,
"bioEntities/elements/?columns=id,name,type,references
"
),
flatten
=
F
)
#Define UniProt identifiers to be matched in model elements
uniprot_examples
<-
c
(
"O43521"
,
"P63167"
)
### For each model, retrieve reactions
model_reactions
<-
lapply
(
models
$
idObject
,
function
(
x
)
fromJSON
(
ask_GET
(
paste0
(
base_url
,
"models/"
,
x
,
"/"
),
"bioEntities/reactions/?columns=id,type,reactionId,products,reactants,modifiers"
),
flatten
=
F
))
### For results in each model, find element identifiers that have the selected uniprot id
### then find reactions having at least one of these elements, and append them to the output vector
reaction_identifiers
<-
c
()
for
(
m
in
1
:
length
(
model_elements
))
{
### In "resources" of each element, find those which have requested UniProt identifiers
hits
<-
sapply
(
model_elements
[[
m
]]
$
references
,
function
(
x
)
any
(
uniprot_examples
%in%
x
$
resource
[
x
$
type
==
"UNIPROT"
]))
### In "resources" of each element, find those which have requested UniProt identifiers
hits
<-
sapply
(
model_elements
$
references
,
function
(
x
)
any
(
uniprot_examples
%in%
x
$
resource
[
x
$
type
==
"UNIPROT"
]))
### Identifiers of the elements matching the search criteria
identifiers
<-
model_elements
[[
m
]]
$
id
[
hits
]
### Look for reaction identifiers only for non-zero results and models with existing reactions
if
(
length
(
identifiers
)
>
0
&&
length
(
model_reactions
[[
m
]])
>
0
)
{
### Which reactions have at least one modifier, product and reactant matching the list
hits
<-
which
(
sapply
(
model_reactions
[[
m
]]
$
modifiers
,
function
(
x
)
ifelse
(
length
(
x
)
==
0
,
F
,
any
(
x
$
aliasId
%in%
identifiers
))))
hits
<-
c
(
hits
,
which
(
sapply
(
model_reactions
[[
m
]]
$
products
,
function
(
x
)
ifelse
(
length
(
x
)
==
0
,
F
,
any
(
x
$
aliasId
%in%
identifiers
)))))
hits
<-
c
(
hits
,
which
(
sapply
(
model_reactions
[[
m
]]
$
reactants
,
function
(
x
)
ifelse
(
length
(
x
)
==
0
,
F
,
any
(
x
$
aliasId
%in%
identifiers
)))))
### Append the data frame by these reaction identifiers
reaction_identifiers
<-
rbind
(
reaction_identifiers
,
data.frame
(
reaction_id
=
model_reactions
[[
m
]]
$
reactionId
[
unique
(
hits
)],
model_id
=
models
$
idObject
[
m
],
stringsAsFactors
=
F
))
}
}
### Identifiers of the elements matching the search criteria
identifiers
<-
model_elements
$
id
[
hits
]
### Request for reactions that have one of the identifiers as a 'participantId' (reactant, product or modifier)
model_reactions
<-
fromJSON
(
ask_GET
(
base_url
,
paste0
(
"models/*/bioEntities/reactions/?participantId="
,
paste
(
identifiers
,
collapse
=
","
),
"&columns=reactionId"
)))
### Create a validation URL for the disease map these identifiers come from
visualize_reactions
<-
"https://pdmap.uni.lu/minerva/?search="
...
...
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