Skip to content
Snippets Groups Projects
Commit be448d6c authored by rchikhi's avatar rchikhi
Browse files

some debug info to d2 graph construction

parent 47b4117e
No related branches found
No related tags found
No related merge requests found
...@@ -59,7 +59,7 @@ class D2Graph(nx.Graph): ...@@ -59,7 +59,7 @@ class D2Graph(nx.Graph):
import debug_disct as dd import debug_disct as dd
# Compute all the d-graphs # Compute all the d-graphs
if verbose: if verbose:
print("Compute the unit d-graphs") print("Computing the unit d-graphs..")
self.d_graphs_per_node = compute_all_max_d_graphs(self.barcode_graph, debug=debug) self.d_graphs_per_node = compute_all_max_d_graphs(self.barcode_graph, debug=debug)
if verbose: if verbose:
counts = sum(len(x) for x in self.d_graphs_per_node.values()) counts = sum(len(x) for x in self.d_graphs_per_node.values())
......
...@@ -242,6 +242,8 @@ def compute_all_max_d_graphs(graph, debug=False): ...@@ -242,6 +242,8 @@ def compute_all_max_d_graphs(graph, debug=False):
# Find all the cliques (equivalent to compute all the candidate half d-graph) # Find all the cliques (equivalent to compute all the candidate half d-graph)
cliques = list(nx.find_cliques(neighbors_graph)) cliques = list(nx.find_cliques(neighbors_graph))
if debug: print("node",node,"has",len(cliques),"cliques")
# Pair halves to create d-graphes # Pair halves to create d-graphes
for idx, clq1 in enumerate(cliques): for idx, clq1 in enumerate(cliques):
for clq2_idx in range(idx+1, len(cliques)): for clq2_idx in range(idx+1, len(cliques)):
......
...@@ -10,25 +10,41 @@ import d2_graph as d2 ...@@ -10,25 +10,41 @@ import d2_graph as d2
def parse_arguments(): def parse_arguments():
parser = argparse.ArgumentParser(description='Transform a 10X barcode graph into a d2 graph. The program dig for the d-graphs and then merge them into a d2-graph.') parser = argparse.ArgumentParser(description='Transform a 10X barcode graph into a d2 graph. The program dig for the d-graphs and then merge them into a d2-graph.')
parser.add_argument('barcode_graph', help='The barcode graph file. Must be a gefx formated file.') parser.add_argument('barcode_graph', help='The barcode graph file. Must be a gefx formated file.')
parser.add_argument('--output_prefix', '-o', default="d2_graph", help="Output file prefix.") parser.add_argument('--output_prefix', '-o', default="d2_graph", help="Output file prefix.")
parser.add_argument('--debug', '-d', action='store_true', help="Debug")
args = parser.parse_args() args = parser.parse_args()
return args return args
def main(): def main():
# Parsing the input file # Parsing the input file
args = parse_arguments() args = parse_arguments()
debug = args.debug
filename = args.barcode_graph filename = args.barcode_graph
if not filename.endswith('.gexf'):
print("Input file must be gexf formatted", file=sys.stderr) def dprint(s):
from datetime import datetime
t = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
if debug: print(t,"[debug]",s)
dprint("loading barcode graph")
if filename.endswith('.gexf'):
G = nx.read_gexf(filename)
elif filename.endswith('.graphml'):
G = nx.read_graphml(filename)
else:
print("Input file must be gexf or graphml formatted", file=sys.stderr)
exit(1) exit(1)
dprint("barcode graph loaded")
G = nx.read_gexf(filename)
# Index size must be changed for general purpose. 8 is good for d=5 # Index size must be changed for general purpose. 8 is good for d=5
dprint("creating D2graph object")
d2g = d2.D2Graph(G) d2g = d2.D2Graph(G)
d2g.construct_from_barcodes(index_size=8) dprint("D2 graph object created")
dprint("constructing d2 graph from barcode graph")
d2g.construct_from_barcodes(index_size=8, debug=debug)
dprint("[debug] d2 graph constructed")
d2g.save(f"{args.output_prefix}.tsv") d2g.save(f"{args.output_prefix}.tsv")
nx.write_gexf(d2g, f"{args.output_prefix}.gexf") nx.write_gexf(d2g, f"{args.output_prefix}.gexf")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment