From a34d482ca575186960d66d0629f77ebf027f7c68 Mon Sep 17 00:00:00 2001 From: "Hartung, Michael" <michael.hartung@uni-hamburg.de> Date: Fri, 30 Sep 2022 17:38:00 +0200 Subject: [PATCH] Allow custom edges in algorithms Former-commit-id: ad71d012193bb8d90111913de38f4eed9da0d2e1 [formerly 021789265e1ef492a0aa343d3de5017a302c9ce6] Former-commit-id: a6d19bab20f8144379c3632ce7349eff83856ce2 --- tasks/trust_rank.py | 2 +- tasks/util/custom_edges.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tasks/trust_rank.py b/tasks/trust_rank.py index 2283d74..0b3d677 100755 --- a/tasks/trust_rank.py +++ b/tasks/trust_rank.py @@ -213,7 +213,7 @@ def trust_rank(task_hook: TaskHook): if custom_edges: edges = task_hook.parameters.get("input_network")['edges'] g = add_edges(g, edges) - + task_hook.set_progress(1 / 4.0, "Computing edge weights.") weights = edge_weights(g, hub_penalty, inverse=True) diff --git a/tasks/util/custom_edges.py b/tasks/util/custom_edges.py index d0b8ea2..713f679 100644 --- a/tasks/util/custom_edges.py +++ b/tasks/util/custom_edges.py @@ -11,8 +11,10 @@ def add_edges(g, edge_list): mapping = make_node_id_map(g) edge_id_list = [] for edge in edge_list: - a = mapping[edge['from']] - b = mapping[edge['to']] - edge_id_list.append((a, b)) - g.add_edge_list(edge_list) + a = mapping[edge['from']] if edge['from'] in mapping else False + b = mapping[edge['to']] if edge['to'] in mapping else False + if a and b: + edge_id_list.append((a, b, 'protein-protein')) + e_type = g.edge_properties["type"] + g.add_edge_list(edge_id_list, eprops=[e_type]) return g \ No newline at end of file -- GitLab