ragtag_utilities/ScaffoldGraph.py
def max_weight_matching(self):
        """
        Return a new PatchScaffoldGraph that is a matching
        :return: Matching PatchScaffoldGraph
        """
        undirected_sg = nx.Graph()
        for u, v in self.edges:
            undirected_sg.add_edge(u, v, weight=self.graph[u][v]["weight"])
        matching = nx.max_weight_matching(G=undirected_sg)

        # Remove any cycles that would result from adding intra-sequence edges
        # Make a new graph
        cover_graph = nx.Graph()
        cover_graph.add_nodes_from(undirected_sg.nodes(data=True))

        # Add edges connecting contig ends
        node_base_set = set([i[:-2] for i in list(cover_graph.nodes)])
        for node in node_base_set:
            cover_graph.add_edge(node + "_b", node + "_e", weight=np.inf)

        # Add the edges that form the matching
        for u, v in matching:
            cover_graph.add_edge(u, v, **undirected_sg[u][v])

        # Remove any potential cycles
        edges_to_delete = []
        for cc in nx.connected_components(G=cover_graph):
            cc = cover_graph.subgraph(cc).copy()
            if cc.number_of_nodes() == cc.number_of_edges():
                assembly_edges = cc.edges(data=True)
                edge_to_delete = min(assembly_edges, key=lambda entry: entry[2]["weight"])
                edges_to_delete.append((edge_to_delete[0], edge_to_delete[1]))

        # Add the edges that form the matching into a new PatchScaffoldGraph
        new_psg = PatchScaffoldGraph(self.components_fn)
        for u, v in matching:
            if (u, v) not in edges_to_delete and (v, u) not in edges_to_delete:
                new_psg.add_edge(u, v, self.graph[u][v]["alignment"])
                new_psg.add_edge(v, u, self.graph[v][u]["alignment"])

        return new_psg

        Return a new PatchScaffoldGraph that is a matching
        :return: Matching PatchScaffoldGraph
        
Return a new PatchScaffoldGraph that is a matching
Return a new PatchScaffoldGraph that is a matching
def max_weight_matching(self):
        undirected_sg = nx.Graph()
        for u, v in self.edges:
            undirected_sg.add_edge(u, v, weight=self.graph[u][v]["weight"])
        matching = nx.max_weight_matching(G=undirected_sg)
        cover_graph = nx.Graph()
        cover_graph.add_nodes_from(undirected_sg.nodes(data=True))
        node_base_set = set([i[:-2] for i in list(cover_graph.nodes)])
        for node in node_base_set:
            cover_graph.add_edge(node + "_b", node + "_e", weight=np.inf)
        for u, v in matching:
            cover_graph.add_edge(u, v, **undirected_sg[u][v])
        edges_to_delete = []
        for cc in nx.connected_components(G=cover_graph):
            cc = cover_graph.subgraph(cc).copy()
            if cc.number_of_nodes() == cc.number_of_edges():
                assembly_edges = cc.edges(data=True)
                edge_to_delete = min(assembly_edges, key=lambda entry: entry[2]["weight"])
                edges_to_delete.append((edge_to_delete[0], edge_to_delete[1]))
         into a new PatchScaffoldGraph
        new_psg = PatchScaffoldGraph(self.components_fn)
        for u, v in matching:
            if (u, v) not in edges_to_delete and (v, u) not in edges_to_delete:
                new_psg.add_edge(u, v, self.graph[u][v]["alignment"])
                new_psg.add_edge(v, u, self.graph[v][u]["alignment"])
        return new_psg
def max_weight_matching ( self ) : undirected_sg = nx . Graph ( ) for u , v in self . edges : undirected_sg . add_edge ( u , v , weight = self . graph [ u ] [ v ] [ "weight" ] ) matching = nx . max_weight_matching ( G = undirected_sg ) cover_graph = nx . Graph ( ) cover_graph . add_nodes_from ( undirected_sg . nodes ( data = True ) ) node_base_set = set ( [ i [ : - 2 ] for i in list ( cover_graph . nodes ) ] ) for node in node_base_set : cover_graph . add_edge ( node + "_b" , node + "_e" , weight = np . inf ) for u , v in matching : cover_graph . add_edge ( u , v , ** undirected_sg [ u ] [ v ] ) edges_to_delete = [ ] for cc in nx . connected_components ( G = cover_graph ) : cc = cover_graph . subgraph ( cc ) . copy ( ) if cc . number_of_nodes ( ) == cc . number_of_edges ( ) : assembly_edges = cc . edges ( data = True ) edge_to_delete = min ( assembly_edges , key = lambda entry : entry [ 2 ] [ "weight" ] ) edges_to_delete . append ( ( edge_to_delete [ 0 ] , edge_to_delete [ 1 ] ) ) new_psg = PatchScaffoldGraph ( self . components_fn ) for u , v in matching : if ( u , v ) not in edges_to_delete and ( v , u ) not in edges_to_delete : new_psg . add_edge ( u , v , self . graph [ u ] [ v ] [ "alignment" ] ) new_psg . add_edge ( v , u , self . graph [ v ] [ u ] [ "alignment" ] ) return new_psg
Return a new PatchScaffoldGraph that is a matching
Return a new PatchScaffoldGraph that is a matching
"""
        Return a new PatchScaffoldGraph that is a matching
        :return: Matching PatchScaffoldGraph
        """ # Remove any cycles that would result from adding intra-sequence edges # Make a new graph # Add edges connecting contig ends # Add the edges that form the matching # Remove any potential cycles # Add the edges that form the matching into a new PatchScaffoldGraph
None
self