Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
models
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COVID-19
models
Commits
55bae3ad
Commit
55bae3ad
authored
4 years ago
by
Marek Ostaszewski
Browse files
Options
Downloads
Patches
Plain Diff
Alias resolver
parent
f8484408
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!165
Alias resolver
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Resources/Hipathia/resolve_aliases.R
+91
-0
91 additions, 0 deletions
Resources/Hipathia/resolve_aliases.R
with
91 additions
and
0 deletions
Resources/Hipathia/resolve_aliases.R
0 → 100644
+
91
−
0
View file @
55bae3ad
##################################################
## Project: COVID-19 Disease Map
## Script purpose: Translate raw CellDesigner SIF to Entrez identifiers using MINERVA
## Date: 05.06.2020
## Author: Marek Ostaszewski
##################################################
library
(
httr
)
library
(
jsonlite
)
### A convenience function to handle API queries
ask_GET
<-
function
(
furl
,
fask
)
{
resp
<-
httr
::
GET
(
url
=
paste0
(
furl
,
fask
),
httr
::
add_headers
(
'Content-Type'
=
"application/x-www-form-urlencoded"
),
### Currently ignoring SSL!
httr
::
set_config
(
config
(
ssl_verifypeer
=
0L
)))
if
(
httr
::
status_code
(
resp
)
==
200
)
{
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/Apoptosis/Apoptosis_03.06.2020.xml"
### Read in the raw SIF version (here straight from the github of Aurelien)
raw_sif
<-
read.table
(
url
(
"https://raw.githubusercontent.com/aurelien-naldi/preliminary-covid-modeling/master/covid-models/Apoptosis_03.06.2020_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/"
))
project_id
<-
cfg
$
options
[
cfg
$
options
$
type
==
"DEFAULT_MAP"
,
"value"
]
### The address of the latest (default) build
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
<-
fromJSON
(
models
,
flatten
=
F
)
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"
),
flatten
=
F
)
message
(
"Fetching entrez ids..."
)
### Get information about Entrez identifiers from MINERVA elements
entrez
<-
sapply
(
model_elements
$
references
,
function
(
x
)
ifelse
(
length
(
x
)
==
0
,
NA
,
x
[
x
$
type
==
"ENTREZ"
,
"resource"
]))
names
(
entrez
)
<-
model_elements
$
elementId
### An utility function to retrieve Entrez based on the species id
### if the id is a complex, the function goes recursively and fetches the ids of elements in this complex
group_elements
<-
function
(
feid
,
felements
,
fentrez
)
{
pos
<-
which
(
felements
$
elementId
==
feid
)
### Any elements that may be nested in the 'feid' (CellDesigner alias)
incs
<-
felements
$
elementId
[
felements
$
complexId
%in%
felements
$
id
[
pos
]]
if
(
length
(
incs
)
>
0
)
{
### If nested elements found, run the function recursively for the contained elements
return
(
paste
(
unlist
(
sapply
(
incs
,
group_elements
,
felements
,
fentrez
)),
collapse
=
";"
))
}
else
{
### If no nested elements, return Entrez
rid
<-
fentrez
[[
feid
]]
if
(
is.na
(
rid
))
{
### If Entrez not available, return name
rid
<-
felements
$
name
[
pos
]
}
return
(
rid
)
}
}
message
(
"Translating..."
)
### Create a copy
translated_sif
<-
raw_sif
### Retrieve Entrez for the entire columns of sources and targets
translated_sif
[,
1
]
<-
sapply
(
raw_sif
[,
1
],
group_elements
,
model_elements
,
entrez
)
translated_sif
[,
3
]
<-
sapply
(
raw_sif
[,
3
],
group_elements
,
model_elements
,
entrez
)
write.table
(
translated_sif
,
file
=
"translated_sif.txt"
,
sep
=
"\t"
,
quote
=
F
,
col.names
=
F
,
row.names
=
F
)
message
(
"Done."
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment