def get_pattern_infos(pattern_paths): patterns = [] OBDPatterns = [] root_nodes_patterns = [] indices = [] equiv = [] non_equiv = [] for pattern_path in pattern_paths: print pattern_path pattern = nx.read_gml(os.path.join(pattern_path, 'pattern.gml')) patterns.append(pattern) with open(os.path.join(pattern_path, 'startNodeId.info')) as f: start_node = int(f.readline().rstrip()) OBD = OBDsearch.get_heuristic4_OBD(pattern, startNode=start_node) OBDPatterns.append(OBD) with open(os.path.join(pattern_path, 'rootNode.info')) as f: root_node = f.readline().rstrip() root_nodes_patterns.append(root_node) ind = [] with open(os.path.join(pattern_path, 'indices.info')) as f: for line in f: ind.append(int(line.rstrip())) indices.append(ind) if not os.path.isfile(os.path.join(pattern_path, 'equivalence.info')): equiv.append(None) else: indices_equiv = [] with open(os.path.join(pattern_path, 'equivalence.info')) as f: for line in f: a = [] l = line.rstrip().split(" ") for elem in l: a.append(int(elem)) indices_equiv.append(a) equiv.append(indices_equiv) if not os.path.isfile( os.path.join(pattern_path, 'non_equivalence.info')): non_equiv.append(None) else: indices_equiv = [] with open(os.path.join(pattern_path, 'non_equivalence.info')) as f: for line in f: a = [] l = line.rstrip().split(" ") for elem in l: a.append(int(elem)) indices_equiv.append(a) non_equiv.append(indices_equiv) return patterns, OBDPatterns, root_nodes_patterns, indices, equiv, non_equiv
if __name__ == '__main__': #dict_path='/home/irma/work/DATA/DATA/yeast/exhaustive_approach/fdict_exhaustive_pattern4.pickle' #pkl_file = open(dict_path, 'rb') #count_combinations_arity_2(pickle.load(pkl_file),0,2) #data_graph = '/home/irma/work/DATA/DATA/yeast/YEAST_equiv.gpickle' #data_graph = nx.read_gpickle(data_graph) data_graph = '/home/irma/work/DATA/DATA/yeast/dummy_yeast.gml' data_graph = nx.read_gml(data_graph) #Target target_attr = 'function' target_constant = 'constant' root_node_target = 'function' target = gtp.get_target_graph(target_constant, target_attr) OBD1 = OBDsearch.get_heuristic4_OBD(target, startNode=2) print OBD1 OBDTarget = [[2], [1]] print OBDTarget # pattern=nx.read_gml('/home/irma/work/DATA/DATA/yeast/pattern4.gml') # #ground_pattern = gtp.ground_pattern(tg, pattern) # OBD1 = OBDsearch.get_heuristic4_OBD(pattern, startNode = 6) # patterns=[pattern] # OBDPatterns=[OBD1] # root_nodes_patterns=['function'] # indices=[[1,6]] # csvfile = '/home/irma/work/DATA/DATA/yeast/testFurer.csv' # fieldnames = ['dummy','target', 'patt2'] # generate_csv_furerOBD_count(data_graph, target, OBDTarget, root_node_target, patterns,OBDPatterns,indices, root_nodes_patterns, csvfile, fieldnames)
for pattern,OBD,root_node in zip(patterns,OBDPatterns,root_nodes_patterns): ground_pattern = gtp.ground_pattern(target, pattern) nr_pat=exact_counting(ground_pattern, data_graph, OBD, root_node) dict_res[fieldnames[fieldcounter]]=nr_pat fieldcounter=fieldcounter+1 writer.writerow(dict_res) if __name__ == '__main__': data_graph = '/home/irma/work/DATA/DATA/YEAST_equiv.gpickle' data_graph = nx.read_gpickle(data_graph) tg=gtp.find_all_groundings_of_predicates(data_graph, 'function','constant')[0] pattern=nx.read_gml('/home/irma/work/DATA/DATA/yeast/pattern2.gml') ground_pattern = gtp.ground_pattern(tg, pattern) OBD1 = OBDsearch.get_heuristic4_OBD(pattern, startNode = 0) target_attr='function' target_constant='constant' root_node_target='function' OBDTarget=[[1],[2]] patterns=[pattern] OBDPatterns=[OBD1] root_nodes_patterns=['protein_class'] csvfile='/home/irma/work/DATA/DATA/yeast/test.csv' fieldnames=['target','patt2'] print "Pattern OBD:",OBD1 #generate_csv_furerOBD_counts(data_graph, target_attr, target_constant, OBDTarget, root_node_target, patterns,OBDPatterns, root_nodes_patterns, csvfile, fieldnames) generate_csv_exact_counts(data_graph, target_attr, target_constant, OBDTarget, root_node_target, patterns, OBDPatterns, root_nodes_patterns, csvfile, fieldnames) #print exact_counting(tg, data_graph,OBD,'function')
output_train_csv = os.path.join(args.o, experiment, 'train.csv') output_test_csv = os.path.join(args.o, experiment, 'test.csv') time_dict_train_csv = os.path.join(args.o, experiment, 'time_dict_train.csv') time_dict_test_csv = os.path.join(args.o, experiment, 'time_dict_test.csv') pattern_path = args.p patterns, OBDPatterns, root_nodes_patterns, indices, pattern_equivalence, non_equivalence = get_pattern_infos( pattern_path) target = gtp.get_target_graph(args.const, args.attr) for i in target: print i, target.node[i] print "Equal: ", pattern_equivalence print "Not equal: ", non_equivalence OBDTarget = OBDsearch.get_heuristic4_OBD(target, startNode=int(args.sT)) root_node_target = args.rT fieldnames = ['dummy', 'target', patterns[0].name] if args.e == "exact": print "HERE" if args.t == None or (args.t != None and args.t == "train"): exact.generate_csv_exact_counts( train_data, target, args.const, args.attr, OBDTarget, root_node_target, patterns, OBDPatterns, indices, root_nodes_patterns, pattern_equivalence, non_equivalence, output_train_csv, fieldnames, time_dict_train_csv, args.max_time) print "Training data counted ..." if args.t == None or (args.t != None and args.t == "test"):