def process_file( filename ): if os.path.isdir(filename): print("parsing .graph files in the given directory\n") return process_directory(filename) else: if not filename.endswith('.graph'): raise Exception("{} is not a valid input (not a .graph file)!".format(filename)) return parse_graph( filename ) # this is what is done to the parsed command-line arguments (graphs)
def pytest_generate_tests(metafunc): cfg = None with open('./tests.json') as fp: cfg = json.load(fp) for graph_cfg in cfg['graphs']: graph_cfg['mv_graph'] = parse_graph(graph_cfg['mv_graph']) metafunc.parametrize('graph', cfg['graphs'])
def process_directory( directory_name ): graphs = [] for filename in os.listdir(directory_name)[:]: # print(filename) if filename.endswith('.graph'): graphs.append(parse_graph((filename))) # print(graphs) if not graphs: raise Exception("No .graph file found in the given directory! Aborting...") return graphs
f.write( '\t\t{{"atom": "{0}", "size": {1}, "score": "{0}{2}", "alignment": "{3}" }}' .format(consensus_labels[node], get_size_by_element(consensus_labels[node]), score_dict[node], label_str)) b_first = False f.write('\n\t],\n\t"links":[\n') b_first = True for edge in graph.edges: if not b_first: f.write(',\n') f.write('\t\t{{"source": {}, "target": {}, "bond": 1 }}'.format( node_num[edge.node1], node_num[edge.node2])) b_first = False f.write('\n\t]\n}') ret = f.getvalue() f.close() return ret #create flag to save json to disk if __name__ == '__main__': try: g = parse_graph(sys.argv[1]) generate_html_vis(os.getcwd(), g) write_graph(g, os.getcwd(), "{}.test.graph".format(g.id)) except Exception as e: print( "Please provide a graph you want to test the graphwriter with \n \t example: python3 graph_writer.py graph1.graph" ) raise (e)
"." )[: -1][0] == n.id: # comparing the first part of already mapped node id and original node id orig_node = n break if key in orig_node.neighbours: node.add_neighbour(cur_node) cur_node.add_neighbour(node) result_graph.nodes.add(cur_node) self.result_graphs.append(result_graph) self.results.append(result_graph.nodes) if __name__ == "__main__": large_g = parse_graph(sys.argv[1]) small_g = parse_graph(sys.argv[2]) vf2 = VF2(large_g, small_g) vf2.match() print("") print( "********************************************************************") print( "* *") print(" RESULTS for {} and {}".format( vf2.g.id, vf2.h.id)) print( "* *") print(
cur_max = len(result) for result in self.results: if len(result) == cur_max and not result in res: res.append(result) return res def get_corr_node( self, clique_node ): old_id = clique_node.mult_id.split(".") for node in self.g.nodes: if set( node.mult_id.split(".") ).issubset(set( old_id )): return node if __name__ == '__main__': try: mp = MP (parse_graph(sys.argv[1]), parse_graph(sys.argv[2])) bk = BK(mp.g, mp.h) r = set() x = set() p = list(mp.modp) bk.bk_pivot ( r, p, x ) pprint.pprint(bk.results) except Exception as e: print(e) print( 'Please provide a graph file as argument \n example: python3 bk_pivot.py graph.graph' )