diff --git a/deconvolution/evaluate.py b/deconvolution/evaluate.py index e2c0a58e6b7e2fe3180cdaccb37855a6c7ff6540..80bd1529b72f6068b209fec10c7d483c0e2f4b76 100755 --- a/deconvolution/evaluate.py +++ b/deconvolution/evaluate.py @@ -167,17 +167,13 @@ def print_path_summary(frequencies, neighborhood, light_print=False, file_pointe # ------------- D2 Graph ------------- -def parse_dg_name(name): - name = name.replace("]", "").replace(' [', '[') - header, h1, h2 = name.split('[') +def parse_dg_name(gr, name): + udg = nx.get_node_attributes(gr, 'udg')[name] + udg = udg.replace("]", "").replace(' [', '[') + central, h1, h2 = udg.split('[') - # Parse header - header = header.split(" ") - idx = central = score = -1 - if len(header) == 3: - idx, central, score = header - else: - central, score = header + idx = name + score = nx.get_node_attributes(gr, 'score')[name] # Parse hands h1 = h1.split(', ') @@ -267,7 +263,7 @@ def compute_next_nodes(d2_component): for node in d2_component.nodes(): # Parse the current node name - head, h1, h2 = parse_dg_name(node) + head, h1, h2 = parse_dg_name(d2_component,node) next_nodes[node] = {} neighbors = list(d2_component.neighbors(node)) @@ -276,7 +272,7 @@ def compute_next_nodes(d2_component): for mol_idx in molecule_idxs: nexts = [] for neighbor in neighbors: - nei_head, _, _ = parse_dg_name(neighbor) + nei_head, _, _ = parse_dg_name(d2_component,neighbor) nei_mols = mols_from_node(nei_head[1]) nei_mols = [x for x in nei_mols if x > mol_idx] @@ -401,7 +397,7 @@ def verify_graph_edges(d2_component): udg_molecules_dict=dict() for node in d2_component.nodes(): # Parse the current node name - head, c1, c2 = parse_dg_name(node) + head, c1, c2 = parse_dg_name(d2_component,node) # Construct the molecule(s) that this udg really 'reflects' #Â i.e. the udg has a central node and two cliques @@ -440,10 +436,10 @@ def verify_graph_edges(d2_component): # Then: annotate edges as to whether they're real (their udg_molecule(s) are nearby) or fake for n1, n2 , data in d2_component.edges(data=True): # Parse the current node name - head, c1, c2 = parse_dg_name(n1) + head, c1, c2 = parse_dg_name(d2_component,n1) node_udg_molecules = udg_molecules_dict[head[0]] - n_head, n_c1, n_c2 = parse_dg_name(n2) + n_head, n_c1, n_c2 = parse_dg_name(d2_component,n2) neighbor_udg_molecules = udg_molecules_dict[n_head[0]] if nearby_udg_molecules(node_udg_molecules, neighbor_udg_molecules): @@ -456,7 +452,7 @@ def verify_graph_edges(d2_component): # also, annotate nodes by their putative molecule found for n, data in d2_component.nodes(data=True): # Parse the current node name - head, c1, c2 = parse_dg_name(n) + head, c1, c2 = parse_dg_name(d2_component,n) node_udg_molecules = udg_molecules_dict[head[0]] data['udg_molecule']= '_'.join(list(map(str,node_udg_molecules))) @@ -468,7 +464,7 @@ def verify_graph_edges(d2_component): nodes_to_remove = [] for n, data in d2_component.nodes(data=True): # Parse the current node name - head, c1, c2 = parse_dg_name(n) + head, c1, c2 = parse_dg_name(d2_component,n) if "_" in data['udg_molecule'] or data['udg_molecule'] == '': if "_" in data['udg_molecule']: m1, m2 = list(map(int,data['udg_molecule'].split("_")))