Ejemplo n.º 1
0
    def append_result_graph(self, result):
        '''creates a graph which contains the concatenated mapped nodes.
        Then, it adds the neighbours to the new nodes following the
        original neighbours.'''

        result_graph = Graph(
            "({},{})#{}".format(self.small_g.id, self.large_g.id,
                                len(self.result_graphs) + 1), set())
        for key, value in result.items():
            cur_node = Node("{}.{}".format(key.id, value.id),
                            "{}".format(key.label))
            cur_node.mult_id = "{}.{}".format(key.mult_id, value.mult_id)

            for node in result_graph.nodes:  # f.ex. 1.2
                orig_node = Node("")
                for n in result.keys():  # original nodes from small graph
                    if node.id.split(
                            "."
                    )[:
                      -1][0] == n.id:  # comparing the first part of already mapped node id and original node id
                        orig_node = n
                        break
                if key in orig_node.neighbours:
                    node.add_neighbour(cur_node)
                    cur_node.add_neighbour(node)
            result_graph.nodes.add(cur_node)

        self.result_graphs.append(result_graph)
        self.results.append(result_graph.nodes)
Ejemplo n.º 2
0
    def clique_to_node_set( self ):
        '''repairs the edges from clique to real alignment graph,
        because cliques may contain more edges than the original graph(s)'''

        results = self.get_coopt()
        res_list = []

        for clique in results:

            for node in clique:
                for neighbour in list(node.neighbours)[:]:
                    if not neighbour in clique:
                        node.remove_neighbour(neighbour)

            curr_node_set = set()
            for node in clique:

                corr_n = self.get_corr_node( node )
                new_neighbours = set()

                for neighbour in node.neighbours:

                    for corr_neighbour in corr_n.neighbours:
                        if set(corr_neighbour.mult_id.split(".")).issubset(set(neighbour.mult_id.split("."))):
                            new_neighbours.add(neighbour)
                curr_node = Node( node.id, node.label, new_neighbours)
                curr_node.mult_id = node.mult_id
                curr_node_set.add(curr_node)

            res_list.append(curr_node_set)

        return res_list
Ejemplo n.º 3
0
    def append_result_subgraph(self, result):
        '''
        creates a graph which contains the concatenated mapped nodes from
        subgraph. Then, it adds the neighbours to the new nodes following the
        original neighbours.
        '''

        node_dict = {}  #used to reconstruct the neighbours
        final_node_set = set()
        in_l_and_mapped = set()

        node_label_len = len(next(iter(
            self.core_s)).mult_id)  # label length of nodes from smaller graph
        mapping_label_len = len(next(iter(
            self.core_l)).mult_id)  # label length of nodes from larger graph

        for node, mapping in result[0].items():

            if mapping:  # nodes that were actually mapped
                cur_node = Node(
                    "{}.{}".format(node.id, mapping.id),  #id
                    node.label + mapping.label,  #label
                )
                cur_node.mult_id = node.mult_id + mapping.mult_id
                in_l_and_mapped.add(mapping)
                node_dict[mapping] = cur_node
                node_dict[node] = cur_node
            else:  # nodes from small graph that were not mapped against a node from larger graph
                new_label = node.get_label()
                for i in range(mapping_label_len):
                    new_label.append("-")
                cur_node = Node("{}.".format(node.id), new_label)
                cur_node.mult_id = node.get_mult_id()
                for i in range(mapping_label_len):
                    cur_node.mult_id.append("_____")

                node_dict[node] = cur_node

            final_node_set.add(cur_node)

        for node, mapping in self.core_l.items():
            if node not in in_l_and_mapped:  # nodes from large graph that were not mapped against nodes from smaller graph
                cur_node = Node(".{}".format(node.id), node.get_label())
                for i in range(node_label_len):
                    cur_node.label.insert(0, "-")

                cur_node.mult_id = node.get_mult_id()
                for i in range(node_label_len):
                    cur_node.mult_id.insert(0, "_____")

                node_dict[node] = cur_node
                final_node_set.add(cur_node)

        # reconstructing the neighbours
        i = 1
        for node1 in list(node_dict.keys())[:-1]:
            for node2 in list(node_dict.keys())[i:]:
                if node2 in node1.neighbours:
                    node_dict[node1].neighbours.add(node_dict[node2])
                    node_dict[node2].neighbours.add(node_dict[node1])

            i += 1

        result_graph = Graph(
            "{}-{}#{}".format(self.small_g.id, self.large_g.id,
                              len(self.result_graphs) + 1), final_node_set)

        self.result_graphs.append(result_graph)
        self.results.append((result_graph.nodes, result[1]))