From 13ba56372ad8ce274d6091771518baff8d006000 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Wed, 9 Oct 2024 16:16:08 +0200 Subject: [PATCH] first commit --- src/bioflowinsighterror.py | 1 + src/call.py | 3 +-- src/outils_graph.py | 45 +++++++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/bioflowinsighterror.py b/src/bioflowinsighterror.py index 3a2f3d4..82c3a65 100644 --- a/src/bioflowinsighterror.py +++ b/src/bioflowinsighterror.py @@ -54,6 +54,7 @@ class BioFlowInsightError(Exception): #* [9] -> Tuple with call (ch1, ch2) = wf() #* [11] -> Failed to extract the operation or call at the line x. Try rewriting it in a simplified version. #* [13] -> Multiple scripts with the same name were defined in the source code -> don't know which one to extract then when calling 'get_external_scripts_code' +#* [15] -> Failed to extract the call at the line x. Try rewriting it in a simplified version. diff --git a/src/call.py b/src/call.py index 8c0f576..4e53b82 100644 --- a/src/call.py +++ b/src/call.py @@ -382,8 +382,7 @@ class Call(Executor): raise Exception("No first call found!!") self.called.append(self.first_element_called) else: - print(self.get_file_address()) - raise Exception(f"Call didn't match pattern '{call}'") + raise BioFlowInsightError(f"Failed to extract the call{self.get_string_line(self.get_code())}. Try rewriting it in a simplified version.", num = 15, origin=self) def get_called(self): diff --git a/src/outils_graph.py b/src/outils_graph.py index 4f17a58..5a4f5d6 100644 --- a/src/outils_graph.py +++ b/src/outils_graph.py @@ -17,10 +17,22 @@ def is_operation(node_id): def fill_dot(dot, dico, label_node = True, label_edge = True): for n in dico["nodes"]: + try: + color = n["color"] + except: + color = "" + try: + xlabel = n["xlabel"] + except: + xlabel = "" + try: + fillcolor = n["fillcolor"] + except: + fillcolor = "" if(label_node): - dot.node(n["id"], n["name"], shape=n["shape"], xlabel= n["xlabel"], fillcolor=n["fillcolor"]) + dot.node(n["id"], n["name"], shape=n["shape"], xlabel= xlabel, fillcolor=fillcolor, color = color, style="filled") else: - dot.node(n["id"], n["name"], shape=n["shape"], fillcolor=n["fillcolor"]) + dot.node(n["id"], n["name"], shape=n["shape"], fillcolor=fillcolor, color=color, style="filled") for e in dico["edges"]: if(label_edge): dot.edge(e['A'], e['B'], label= e['label']) @@ -534,6 +546,17 @@ def get_name_new_node(new_nodes, relevant_modules): def check_same_elements(list1, list2): return set(list1)==set(list2) +def rgb_to_hex(r, g, b): + return '#{:02x}{:02x}{:02x}'.format(r, g, b) + +def get_color_node(node, new_nodes): + max = len(new_nodes[0]) + for n in new_nodes: + if(len(n)>max): + max = len(n) + prop = 256- int(127*len(node)/max) + return rgb_to_hex(prop, prop, prop) + def relev_user_view_builder(dico, relevant_modules): R = [] for r in relevant_modules: @@ -639,11 +662,15 @@ def relev_user_view_builder(dico, relevant_modules): new_dico["subworkflows"] = [] for i in range(len(new_nodes)): new_nodes[i].sort() + new_name = get_name_new_node(get_names_tab(dico, new_nodes[i]), relevant_modules) node = {"id": ''.join(new_nodes[i]).replace('<', '').replace('>', ''), - "name": get_name_new_node(get_names_tab(dico, new_nodes[i]), relevant_modules), + "name": new_name, "shape": "ellipse", - "xlabel": "", - "fillcolor": ""} + "xlabel": f"{len(new_nodes[i])}", + "fillcolor": get_color_node(new_nodes[i], new_nodes)} + #If relevant module -> color it differently + if(new_name in relevant_modules): + node["color"] = "yellow" new_dico["nodes"].append(node) added_edges = [] for edge in dico["edges"]: @@ -662,6 +689,14 @@ def relev_user_view_builder(dico, relevant_modules): "label": "" }) added_edges.append(edge_string) + outputs = get_output_nodes(new_dico) + inputs = get_input_nodes(new_dico) + new_dico["nodes"].append({"id": "input","name": "i","shape": "triangle", "fillcolor":"#ffffff"}) + new_dico["nodes"].append({"id": "output","name": "o","shape": "triangle", "fillcolor":"#ffffff"}) + for out in outputs: + new_dico["edges"].append({'A':out, 'B':'output', "label": ""}) + for input in inputs: + new_dico["edges"].append({'A':"input", 'B':input, "label": ""}) return new_dico -- GitLab