#!/usr/bin/env python3 import networkx as nx import argparse import sys from deconvolution.d2graph import d2_graph as d2 def parse_arguments(): parser = argparse.ArgumentParser(description='Transform a barcode graph into a lcp graph. The program dig for a set of lcps and then merge them into a lcp graph.') parser.add_argument('barcode_graph', help='The barcode graph file. Must be a gefx formated file.') parser.add_argument('--output_prefix', '-o', default="", help="Output file prefix.") parser.add_argument('--threads', '-t', default=8, type=int, help='Number of thread to use for dgraph computation') parser.add_argument('--debug', '-d', action='store_true', help="Debug") parser.add_argument('--verbose', '-v', action='store_true', help="Verbose") parser.add_argument('--edge_divergence_threshold', '-dt', default=0.25, type=float, help='Divergence threshold value to link two udgs in the d2-graph') parser.add_argument('--maxclq', '-c', action='store_true', help="Enable max clique community detection (default behaviour)") parser.add_argument('--louvain', '-l', action='store_true', help="Enable Louvain community detection instead of all max-cliques") args = parser.parse_args() if args.output_prefix == "": args.output_prefix = ".".join(args.barcode_graph.split(".")[:-1]) + "_lcpg" return args def main(): # Parsing the input file args = parse_arguments() # debug = args.debug filename = args.barcode_graph barcode_graph = nx.read_gexf(filename) if args.louvain: clique_mode = "louvain" else: clique_mode = None # Debug config debug = False debug_path = "/dev/null" if args.debug: debug = True debug_path = f"{args.output_prefix}_debug" import os, shutil if os.path.isdir(debug_path): shutil.rmtree(debug_path) os.mkdir(debug_path) d2g = d2.D2Graph(debug=debug, debug_path=debug_path) d2g.construct_from_barcodes( barcode_graph, neighbor_threshold=args.edge_divergence_threshold, clique_mode=clique_mode, threads=args.threads, verbose=args.verbose ) nx.write_gexf(d2g, f"{args.output_prefix}.gexf") if __name__ == "__main__": main()