Commit ba61e7d2 authored by Yoann Dufresne's avatar Yoann Dufresne
Browse files

refactor mains and subgraph definition to be coherent with nx graph heritage

parent 3474f04e
......@@ -23,6 +23,14 @@ class D2Graph(nx.Graph):
self.barcode_edge_idxs[(edge[1], edge[0])] = idx
""" Redefine subgraph to avoid errors type instantiation errors.
"""
def subgraph(self, nodes):
G = nx.Graph()
G.add_edges_from(self.edges())
return G.subgraph(nodes)
def construct_from_barcodes(self, index_size=3, verbose=True, debug=False):
# Compute all the d-graphs
if verbose:
......
......@@ -34,8 +34,8 @@ def main():
d2g.load(d2_file)
# Take the principal component
largest_component_nodes = max(nx.connected_components(d2g.nx_graph), key=len)
largest_component = d2g.nx_graph.subgraph(largest_component_nodes)
largest_component_nodes = max(nx.connected_components(d2g), key=len)
largest_component = d2g.subgraph(largest_component_nodes)
unitigs = compute_unitigs(largest_component)
# Write the simplificated graph
......
......@@ -37,7 +37,7 @@ def main():
d2a.transitive_reduction(d2g)
# Write the simplificated graph
nx.write_gexf(d2g.nx_graph, args.output_d2_name)
nx.write_gexf(d2g, args.output_d2_name)
if __name__ == "__main__":
......
......@@ -29,10 +29,9 @@ def main():
# Index size must be changed for general purpose. 8 is good for d=5
d2g = d2.D2Graph(G)
d2g.construct_from_barcodes(index_size=8)
d2g.save(f"{args.output_prefix}.tsv")
G, names = d2g.to_nx_graph()
nx.write_gexf(G, f"{args.output_prefix}.gexf")
d2g.save(f"{args.output_prefix}.tsv")
nx.write_gexf(d2g, f"{args.output_prefix}.gexf")
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment