Skip to content
Snippets Groups Projects
Commit f9d947fd authored by George Marchment's avatar George Marchment
Browse files

Added functionnality that the dot positions for the nodes are added in the json

parent 67a4eeb5
No related branches found
No related tags found
No related merge requests found
Pipeline #14618 failed with stage
in 2 minutes and 24 seconds
......@@ -1254,3 +1254,41 @@ def remove_artificial_nodes(param_dico):
edge = {"A" : source['source'], "B" : sink['sink'], "label" : source['label']}
dico["edges"].append(edge)
return dico
def enrich_json_with_positions(file):
import json
with open(file, 'r') as JSON:
dico = json.load(JSON)
pos_file = file[:-len(".json")]+"_pos.dot"
try:
f=open(pos_file)
contents_pos =f.read()
f.close()
except:
return
def search_for_pos(id, text):
import re
pattern = re.escape(id)+r'.+\n.+\s+pos="([^,]+),([^"]+)",'
for match in re.finditer(pattern, text):
return match.group(1), match.group(2)
return -1, -1
def enrich_nodes(wf_dico):
for node in wf_dico["nodes"]:
id = node['id']
x_pos, y_pos = search_for_pos(id, contents_pos)
if(x_pos==-1 and y_pos==-1):
return
else:
node['position'] = {}
node['position']['x'] = x_pos
node['position']['y'] = y_pos
for sub in wf_dico['subworkflows']:
enrich_nodes(wf_dico['subworkflows'][sub])
enrich_nodes(dico)
with open(file, 'w') as output_file :
json.dump(dico, output_file, indent=4)
......@@ -4,7 +4,7 @@ from .nextflow_file import Nextflow_File
from .ro_crate import RO_Crate
from . import constant
from .outils import is_git_directory, format_with_tabs, replace_thing_by_call, replace_group1, group_together_ifs, extract_curly, remove_extra_jumps, get_channels_to_add_in_false_conditions, extract_conditions, remove_empty_conditions_place_anker
from .outils_graph import get_flatten_dico, initia_link_dico_rec, get_number_cycles, generate_graph
from .outils_graph import get_flatten_dico, initia_link_dico_rec, get_number_cycles, generate_graph, enrich_json_with_positions
from .outils_annotate import get_tools_commands_from_user_for_process
from .bioflowinsighterror import BioFlowInsightError
from .graph import Graph
......@@ -197,17 +197,29 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
self.iniatilise_tab_processes_2_remove()
self.graph.initialise(processes_2_remove = self.processes_2_remove)
self.graph.get_specification_graph(render_graphs = render_graphs)
self.enrich_json_files_with_positions()
def generate_process_dependency_graph(self, render_graphs = True):
self.iniatilise_tab_processes_2_remove()
self.graph.initialise(processes_2_remove = self.processes_2_remove)
self.graph.render_process_dependency_graph(render_graphs = render_graphs)
self.enrich_json_files_with_positions()
#TODO -> update this
def generate_all_graphs(self, render_graphs = True):
self.generate_specification_graph(render_graphs = render_graphs)
self.generate_process_dependency_graph(render_graphs = render_graphs)
self.enrich_json_files_with_positions()
#This function takes the json files and searches for the corrresponding dot pos files
#And adds the information regarding the position of the nodes
def enrich_json_files_with_positions(self):
jsons = glob.glob(f'{self.get_output_dir()/"graphs"}/*.json', recursive=False)
for file in jsons:
enrich_json_with_positions(file)
#Method that checks if a given graph sepcification is an isomorphism with the workflows
def check_if_json_equal_to_full_structure(self, file):
self.iniatilise_tab_processes_2_remove()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment