Skip to content
Snippets Groups Projects
Select Git revision
  • a5b46d07c5db4452c8bd486de61368dd36166d04
  • main default protected
2 results

AlphaFold.ipynb

Blame
  • d2_to_path.py 1.53 KiB
    #!/usr/bin/env python3
    
    import networkx as nx
    import argparse
    import sys
    
    from deconvolution.d2graph import d2_graph as d2, path_optimization as po
    
    
    def parse_arguments():
        parser = argparse.ArgumentParser(description='Greedy construction of a path through the d2 graph.')
        parser.add_argument('lcp_graph', help='d2 graph to reduce. Must be a gexf formatted file.')
        parser.add_argument('--outfile', '-o', default="", help="Output file prefix.")
        parser.add_argument('--verbose', '-v', action="store_true", help="Verbose")
    
        args = parser.parse_args()
    
        if args.outfile == "":
            args.outfile = '.'.join(args.lcp_graph.split('.')[:-1]) + "_path.gexf"
    
        return args
    
    
    def main():
        # Parsing the arguments and validate them
        args = parse_arguments()
    
        lcpg_name = args.lcp_graph
        if not lcpg_name.endswith(".gexf"):
            print("Inputs file must be gexf formatted", file=sys.stderr)
            exit(1)
        
        # Loading
        lcpg = d2.D2Graph()
        lcpg.load(lcpg_name)
    
        # Take the principal component
        largest_component_nodes = max(nx.connected_components(lcpg), key=len)
        largest_component = lcpg.subgraph(largest_component_nodes)
    
        # Start optimization
        optimizer = po.Optimizer(largest_component)
        path = optimizer.bb_solution(verbose=args.verbose)
    
        for barcodes in path.barcode_order:
            print(len(barcodes), ' ', end="")
        print()
        print()
        print(f"covering score: {path.covering_score()}")
        path.save_gexf(args.outfile)
        print("Solution saved")
    
    
    if __name__ == "__main__":
        main()