Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cosy-Bio
Drugst.One
backend
Commits
f66f3de3
Commit
f66f3de3
authored
2 years ago
by
AndiMajore
Browse files
Options
Downloads
Patches
Plain Diff
fixed connector node definition
Former-commit-id:
e8d6a3cc
parent
dc4e57dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tasks/util/scores_to_results.py
+24
-11
24 additions, 11 deletions
tasks/util/scores_to_results.py
with
24 additions
and
11 deletions
tasks/util/scores_to_results.py
+
24
−
11
View file @
f66f3de3
...
@@ -12,14 +12,14 @@ def scores_to_results(
...
@@ -12,14 +12,14 @@ def scores_to_results(
pdi_dataset
,
pdi_dataset
,
filterPaths
filterPaths
):
):
r
"""
Transforms the scores to the required result format.
"""
r
"""
Transforms the scores to the required result format.
"""
node_name_attribute
=
"
internal_id
"
# nodes in the input network which is created from RepoTrialDB have primaryDomainId as name attribute
node_name_attribute
=
"
internal_id
"
# nodes in the input network which is created from RepoTrialDB have primaryDomainId as name attribute
if
target
==
"
drug
"
:
if
target
==
"
drug
"
:
candidates
=
[(
node
,
scores
[
node
])
for
node
in
drug_ids
if
scores
[
node
]
>
0
]
candidates
=
[(
node
,
scores
[
node
])
for
node
in
drug_ids
if
scores
[
node
]
>
0
]
else
:
else
:
candidates
=
[(
node
,
scores
[
node
])
for
node
in
range
(
g
.
num_vertices
())
if
scores
[
node
]
>
0
and
node
not
in
set
(
seed_ids
)]
candidates
=
[(
node
,
scores
[
node
])
for
node
in
range
(
g
.
num_vertices
())
if
scores
[
node
]
>
0
and
node
not
in
set
(
seed_ids
)]
best_candidates
=
[
item
[
0
]
for
item
in
sorted
(
candidates
,
key
=
lambda
item
:
item
[
1
],
reverse
=
True
)[:
result_size
]]
best_candidates
=
[
item
[
0
]
for
item
in
sorted
(
candidates
,
key
=
lambda
item
:
item
[
1
],
reverse
=
True
)[:
result_size
]]
# Concatenate best result candidates with seeds and compute induced subgraph.
# Concatenate best result candidates with seeds and compute induced subgraph.
# since the result size filters out nodes, the result network is not complete anymore.
# since the result size filters out nodes, the result network is not complete anymore.
...
@@ -44,11 +44,15 @@ def scores_to_results(
...
@@ -44,11 +44,15 @@ def scores_to_results(
vertices
,
edges
=
gtt
.
shortest_path
(
g
,
candidate
,
seed_id
)
vertices
,
edges
=
gtt
.
shortest_path
(
g
,
candidate
,
seed_id
)
drug_in_path
=
False
drug_in_path
=
False
seed_in_path
=
False
for
vertex
in
vertices
:
for
vertex
in
vertices
:
if
g
.
vertex_properties
[
"
type
"
][
int
(
vertex
)]
==
"
drug
"
and
vertex
!=
candidate
:
if
g
.
vertex_properties
[
"
type
"
][
int
(
vertex
)]
==
"
drug
"
and
vertex
!=
candidate
:
drug_in_path
=
True
drug_in_path
=
True
break
break
if
drug_in_path
:
if
int
(
vertex
)
in
seed_ids
and
int
(
vertex
)
!=
seed_id
:
seed_in_path
=
True
break
if
drug_in_path
or
seed_in_path
:
continue
continue
accepted_candidates
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
candidate
)])
accepted_candidates
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
candidate
)])
for
vertex
in
vertices
:
for
vertex
in
vertices
:
...
@@ -58,7 +62,8 @@ def scores_to_results(
...
@@ -58,7 +62,8 @@ def scores_to_results(
intermediate_nodes
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
vertex
)])
intermediate_nodes
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
vertex
)])
returned_nodes
.
add
(
int
(
vertex
))
returned_nodes
.
add
(
int
(
vertex
))
for
edge
in
edges
:
for
edge
in
edges
:
if
((
edge
.
source
(),
edge
.
target
())
not
in
returned_edges
)
or
((
edge
.
target
(),
edge
.
source
())
not
in
returned_edges
):
if
(((
edge
.
source
(),
edge
.
target
())
not
in
returned_edges
)
or
(
(
edge
.
target
(),
edge
.
source
())
not
in
returned_edges
))
and
int
(
edge
.
target
())
in
returned_nodes
and
int
(
edge
.
source
())
in
returned_nodes
:
returned_edges
.
add
((
edge
.
source
(),
edge
.
target
()))
returned_edges
.
add
((
edge
.
source
(),
edge
.
target
()))
else
:
else
:
for
candidate
in
best_candidates
:
for
candidate
in
best_candidates
:
...
@@ -66,11 +71,15 @@ def scores_to_results(
...
@@ -66,11 +71,15 @@ def scores_to_results(
vertices
,
edges
=
gtt
.
shortest_path
(
g
,
candidate
,
seed_id
)
vertices
,
edges
=
gtt
.
shortest_path
(
g
,
candidate
,
seed_id
)
drug_in_path
=
False
drug_in_path
=
False
seed_in_path
=
False
for
vertex
in
vertices
:
for
vertex
in
vertices
:
if
g
.
vertex_properties
[
"
type
"
][
int
(
vertex
)]
==
"
drug
"
and
vertex
!=
candidate
:
if
g
.
vertex_properties
[
"
type
"
][
int
(
vertex
)]
==
"
drug
"
and
vertex
!=
candidate
:
drug_in_path
=
True
drug_in_path
=
True
break
break
if
drug_in_path
:
if
int
(
vertex
)
in
seed_ids
and
int
(
vertex
)
!=
seed_id
:
seed_in_path
=
True
break
if
drug_in_path
or
seed_in_path
:
continue
continue
accepted_candidates
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
candidate
)])
accepted_candidates
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
candidate
)])
for
vertex
in
vertices
:
for
vertex
in
vertices
:
...
@@ -80,18 +89,22 @@ def scores_to_results(
...
@@ -80,18 +89,22 @@ def scores_to_results(
intermediate_nodes
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
vertex
)])
intermediate_nodes
.
add
(
g
.
vertex_properties
[
node_name_attribute
][
int
(
vertex
)])
returned_nodes
.
add
(
int
(
vertex
))
returned_nodes
.
add
(
int
(
vertex
))
for
edge
in
edges
:
for
edge
in
edges
:
if
((
edge
.
source
(),
edge
.
target
())
not
in
returned_edges
)
or
((
edge
.
target
(),
edge
.
source
())
not
in
returned_edges
):
if
(((
edge
.
source
(),
edge
.
target
())
not
in
returned_edges
)
or
(
(
edge
.
target
(),
edge
.
source
())
not
in
returned_edges
))
and
int
(
edge
.
target
())
in
returned_nodes
and
int
(
edge
.
source
())
in
returned_nodes
:
returned_edges
.
add
((
edge
.
source
(),
edge
.
target
()))
returned_edges
.
add
((
edge
.
source
(),
edge
.
target
()))
for
node
in
accepted_candidates
:
for
node
in
accepted_candidates
:
if
node
in
intermediate_nodes
:
if
node
in
intermediate_nodes
:
intermediate_nodes
.
remove
(
node
)
intermediate_nodes
.
remove
(
node
)
subgraph
=
{
subgraph
=
{
"
nodes
"
:
[
g
.
vertex_properties
[
node_name_attribute
][
node
]
for
node
in
returned_nodes
],
"
nodes
"
:
[
g
.
vertex_properties
[
node_name_attribute
][
node
]
for
node
in
returned_nodes
],
"
edges
"
:
[{
"
from
"
:
g
.
vertex_properties
[
node_name_attribute
][
source
],
"
to
"
:
g
.
vertex_properties
[
node_name_attribute
][
target
]}
for
source
,
target
in
returned_edges
],
"
edges
"
:
[{
"
from
"
:
g
.
vertex_properties
[
node_name_attribute
][
source
],
"
to
"
:
g
.
vertex_properties
[
node_name_attribute
][
target
]}
for
source
,
target
in
returned_edges
],
}
}
# Compute node attributes.
# Compute node attributes.
node_types
=
{
g
.
vertex_properties
[
node_name_attribute
][
node
]:
g
.
vertex_properties
[
"
type
"
][
node
]
for
node
in
returned_nodes
}
node_types
=
{
g
.
vertex_properties
[
node_name_attribute
][
node
]:
g
.
vertex_properties
[
"
type
"
][
node
]
for
node
in
returned_nodes
}
is_seed
=
{
g
.
vertex_properties
[
node_name_attribute
][
node
]:
node
in
set
(
seed_ids
)
for
node
in
returned_nodes
}
is_seed
=
{
g
.
vertex_properties
[
node_name_attribute
][
node
]:
node
in
set
(
seed_ids
)
for
node
in
returned_nodes
}
returned_scores
=
{
g
.
vertex_properties
[
node_name_attribute
][
node
]:
scores
[
node
]
for
node
in
returned_nodes
}
returned_scores
=
{
g
.
vertex_properties
[
node_name_attribute
][
node
]:
scores
[
node
]
for
node
in
returned_nodes
}
...
...
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