def build_args_parser(): parser = argparse_ArgumentParser( prog='rpcompletion', description= 'Python wrapper to parse RP2 to generate rpSBML collection of unique and complete (cofactors) pathways' ) parser = _add_arguments(parser) return parser
def main(): parser = argparse_ArgumentParser("Input parameters") parser.add_argument("--input_file_name", default="input_toy.yaml", help="Input parameters file name") parser.add_argument("--graph_files_dir", default="", help="Graph files' folder path") parser.add_argument("--out_dir_name", default="/results", help="Output directory name") args = parser.parse_args() with open(args.input_file_name, 'r') as f: inputs = yaml_load(f, yaml_Loader) # Override output directory name if same as gen if args.out_dir_name or inputs['out_comp_nm'] == "/results/res": if not os_path.exists(inputs['dir_nm'] + args.out_dir_name): os_mkdir(inputs['dir_nm'] + args.out_dir_name) inputs['out_comp_nm'] = args.out_dir_name + "/res" inputs['graph_files_dir'] = '' if args.graph_files_dir: if not os_path.exists(inputs['dir_nm'] + args.graph_files_dir): os_mkdir(inputs['dir_nm'] + args.graph_files_dir) inputs['graph_files_dir'] = args.graph_files_dir with open(inputs['dir_nm'] + inputs['out_comp_nm'] + "_input.yaml", 'w') as outfile: yaml_dump(inputs, outfile, default_flow_style=False) logging_basicConfig(filename=inputs['dir_nm'] + inputs['out_comp_nm'] + "_logs.yaml", level=logging_INFO) start_time_read = time_time() myGraph = read_graphs(inputs) read_time = time_time() - start_time_read myGraphName = inputs['dir_nm'] + inputs['graph_files_dir'] + "/res_myGraph" with open(myGraphName, 'wb') as f: pickle_dump(myGraph, f) tot_time = time_time() - start_time out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm'] # Write to yaml file instead with open(out_comp_nm + '_runtime_performance.out', "a") as fid: print("Read network time (s) = ", read_time, "[", round(100 * float(read_time) / tot_time, 2), "%]", file=fid) print("Total time (s) = ", tot_time, file=fid)
def parse_options(): '''Get and parse program input arguments.''' arg_parser = argparse_ArgumentParser() arg_parser.version = CONST.APP_VERSION arg_parser.add_argument("file", help=TEXT.OPT_FILE, action='store', nargs=1, type=str) arg_parser.add_argument("-v", "--version", action='version') args = arg_parser.parse_args() return vars(args)
def parse_options(): '''Get and parse program input arguments.''' arg_parser = argparse_ArgumentParser() arg_parser.version = CONST.APP_VERSION arg_parser.add_argument("-p", "--port", help=TEXT.OPT_PORT, action='store', nargs=1, type=str) arg_parser.add_argument("-b", "--bauds", help=TEXT.OPT_BAUDS, action='store', nargs=1, type=int) arg_parser.add_argument("-l", "--log", help=TEXT.OPT_LOG, action='store', nargs=1, type=str) arg_parser.add_argument("-v", "--version", action='version') args = arg_parser.parse_args() return vars(args)
def main(): parser = argparse_ArgumentParser("Input parameters") parser.add_argument("--main_folder", help="Folder of the results") args = parser.parse_args() main_folder = "./humap/results_73_neg_same_size_distmetropolis/" #main_folder="./humap/results_73_neg_same_size_distisa/" #main_folder="./humap/results_73_neg_same_size_distcliques/" #main_folder="./humap/results_73_neg_same_size_distsearch_top_neigs/" if args.main_folder: main_folder = args.main_folder filename = main_folder + "res_pred.out" figname = main_folder + "res_sizewise_scores_pred.png" sizewise_scores(filename, figname)
def build_parser(): parser = argparse_ArgumentParser( description='Visualizing a network from sbml') parser.add_argument('inputtarfolder', help='Input folder with sbml files as in tar format.') parser.add_argument('outfile', help='html file.') parser.add_argument( '--choice', default="2", help= 'What kind of input do you want ? \n 1/Single HTML file \n 2/Separated HTML files \n 3/View directly in Cytoscape \n 4/Generate a file readable in Cytoscape \n' ) parser.add_argument( '--selenzyme_table', default="N", help='Do you want to display the selenzyme information ? Y/N') return parser
def build_parser(): return add_arguments( argparse_ArgumentParser('Python script to pre-compute data'))
import numpy as np import math import cv2 import heatmap from datetime import datetime from keras.models import model_from_yaml from keras.optimizers import Adam, SGD from glob import glob from libs.common import my_resize from libs.pavement_common import to_patches from argparse import ArgumentParser as argparse_ArgumentParser ap = argparse_ArgumentParser() ap.add_argument("-inputdir", required=False, help="Path of input images") ap.add_argument("-outputdir", required=False, help="Path of output images") args = vars(ap.parse_args()) image_files_path = args["inputdir"] nrootdir = args["outputdir"] if image_files_path is None: image_files_path = './input_images/' if nrootdir is None: nrootdir = "./images_dst/" ################################################################ # change these parameters: destination_directory = '../../Dataset/GAPs/GAPs-dataset/images/'
def main(): parser = argparse_ArgumentParser("Input parameters") parser.add_argument("--input_file_name", default="input_toy.yaml", help="Input parameters file name") parser.add_argument("--out_dir_name", default="/results", help="Output directory name") parser.add_argument("--train_test_files_dir", default="", help="Train test file path") parser.add_argument("--graph_files_dir", default="", help="Graph files' folder path") parser.add_argument("--n_pts", default=1, help="number of partitions (computers)") parser.add_argument( "--seed_mode", help="Seed mode - specify 'cliques' for the cliques algo") parser.add_argument("--search_method", help="Sampling algorithm") parser.add_argument("--model_dir", help="Directory containing model") parser.add_argument("--ptnum", default='0', help="partition number") parser.add_argument("--explore_prob", default=0.01, help="probability of exploring") parser.add_argument("--prob_metropolis", default=0.1, help="metropolis probability") parser.add_argument("--T0", default=0.88, help="isa T0") parser.add_argument("--alpha", default=1.8, help="isa alpha") parser.add_argument("--classi_thresh", default=0.5, help="Classification threshold") parser.add_argument("--transfer2tmp", default=True, help="Transfer to tmp folder") args = parser.parse_args() with open(args.input_file_name, 'r') as f: inputs = yaml_load(f, yaml_Loader) if args.classi_thresh: inputs['classi_thresh'] = float(args.classi_thresh) if args.seed_mode: inputs['seed_mode'] = args.seed_mode if args.search_method: inputs['search_method'] = args.search_method if args.model_dir: inputs['model_dir'] = args.model_dir if args.explore_prob: inputs['explore_prob'] = float(args.explore_prob) if args.prob_metropolis: inputs['prob_metropolis'] = float(args.prob_metropolis) if args.T0: inputs['T0'] = float(args.T0) if args.alpha: inputs['alpha'] = float(args.alpha) # Override output directory name if same as gen if args.out_dir_name or inputs['out_comp_nm'] == "/results/res": if not os_path.exists(inputs['dir_nm'] + args.out_dir_name): os_mkdir(inputs['dir_nm'] + args.out_dir_name) inputs['out_comp_nm'] = args.out_dir_name + "/res" inputs['train_test_files_dir'] = '' if args.train_test_files_dir: if not os_path.exists(inputs['dir_nm'] + args.train_test_files_dir): os_mkdir(inputs['dir_nm'] + args.train_test_files_dir) inputs['train_test_files_dir'] = args.train_test_files_dir inputs['graph_files_dir'] = '' if args.graph_files_dir: if not os_path.exists(inputs['dir_nm'] + args.graph_files_dir): os_mkdir(inputs['dir_nm'] + args.graph_files_dir) inputs['graph_files_dir'] = args.graph_files_dir with open(inputs['dir_nm'] + inputs['out_comp_nm'] + "_input_sample.yaml", 'w') as outfile: yaml_dump(inputs, outfile, default_flow_style=False) logging_basicConfig(filename=inputs['dir_nm'] + inputs['out_comp_nm'] + "_logs.yaml", level=logging_INFO) # fin_list_graphs = control(myGraph,inputs,n=50) out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm'] out_comp_nm_model = inputs['dir_nm'] + inputs['model_dir'] modelfname = out_comp_nm_model + "_model" scalerfname = out_comp_nm_model + "_scaler" max_sizeF = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_max_size_search_par" with open(max_sizeF, 'rb') as f: max_size = pickle_load(f) with open(scalerfname, 'rb') as f: scaler = pickle_load(f) myGraph = None if inputs['seed_mode'] == "cliques": myGraphName = inputs['dir_nm'] + inputs[ 'graph_files_dir'] + "/res_myGraph" with open(myGraphName, 'rb') as f: myGraph = pickle_load(f) ptns = int(args.n_pts) if inputs['seed_mode'] == 'n_nodes': seed_nodes_dir = out_comp_nm + "_seed_nodes" else: seed_nodes_dir = inputs['dir_nm'] + inputs[ 'graph_files_dir'] + "/" + inputs['seed_mode'] + "_n_pts_" + str( ptns) + "/res_seed_nodes" seed_nodes_F = seed_nodes_dir + args.ptnum with open(seed_nodes_F, 'rb') as f: seed_nodes = pickle_load(f) start_time_sample = time_time() out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm'] num_comp = sample(inputs, myGraph, modelfname, scaler, seed_nodes, max_size, args.transfer2tmp) sample_time = time_time() - start_time_sample sample_time_avg = sample_time / num_comp folNm_out = "/tmp/" + out_comp_nm + "_orig_comps" # CHECK WHICH NODE's TMP IS BEING USED pred_comp_list = [ pickle_load(open(folNm_out + "/" + seed_node, 'rb')) for seed_node in seed_nodes if os_path.exists(folNm_out + "/" + seed_node) ] with open(out_comp_nm + "_pred_comp_list" + args.ptnum, "wb") as f: pickle_dump(pred_comp_list, f) tot_time = time_time() - start_time with open(out_comp_nm + '_runtime_performance.out', "a") as fid: print("--- Runtime performance ---", file=fid) print("Sample time (s) = ", sample_time, "[", round(100 * float(sample_time) / tot_time, 2), "%]", file=fid) print("Average sample time (s) = ", sample_time_avg, file=fid) print("Total time (s) = ", tot_time, file=fid)
def main(): parser = argparse_ArgumentParser("Input parameters") parser.add_argument("--input_file_name", default="input_toy.yaml", help="Input parameters file name") parser.add_argument("--out_dir_name", default="/results", help="Output directory name") parser.add_argument("--train_test_files_dir", default="", help="Train test file path") parser.add_argument("--n_pts", default=1, help="number of partitions (computers)") parser.add_argument("--over_t", help="Overlap threshold") parser.add_argument("--model_dir", help="Directory containing model") parser.add_argument("--sample_dir", help="Sample files dir + /res") parser.add_argument("--sample_folders_prefix", help="Input parameters file name /results..") parser.add_argument( "--sample_folders_prefix_final", help="Input file name to use final merged results Use as /results..") parser.add_argument( "--sample_folders_list", nargs='+', help="Input parameters file name /results.. separated by commas") parser.add_argument("--graph_files_dir", default="", help="Graph files' folder path") parser.add_argument("--overlap_method", default=1, help="Overlap method option: qi, default: jaccard") parser.add_argument("--infer_overlap_threshold", default='n', help="y or n") args = parser.parse_args() with open(args.input_file_name, 'r') as f: inputs = yaml_load(f, yaml_Loader) if args.overlap_method: inputs['overlap_method'] = args.overlap_method if args.over_t: inputs['over_t'] = float(args.over_t) if args.sample_dir: inputs['sample_dir'] = args.sample_dir if args.model_dir: inputs['model_dir'] = args.model_dir if args.infer_overlap_threshold: inputs['infer_overlap_threshold'] = args.infer_overlap_threshold # Override output directory name if same as gen if args.out_dir_name or inputs['out_comp_nm'] == "/results/res": if not os_path.exists(inputs['dir_nm'] + args.out_dir_name): os_mkdir(inputs['dir_nm'] + args.out_dir_name) inputs['out_comp_nm'] = args.out_dir_name + "/res" inputs['train_test_files_dir'] = '' if args.train_test_files_dir: if not os_path.exists(inputs['dir_nm'] + args.train_test_files_dir): os_mkdir(inputs['dir_nm'] + args.train_test_files_dir) inputs['train_test_files_dir'] = args.train_test_files_dir inputs['graph_files_dir'] = '' if args.graph_files_dir: if not os_path.exists(inputs['dir_nm'] + args.graph_files_dir): os_mkdir(inputs['dir_nm'] + args.graph_files_dir) inputs['graph_files_dir'] = args.graph_files_dir logging_basicConfig(filename=inputs['dir_nm'] + inputs['out_comp_nm'] + "_logs.yaml", level=logging_INFO) # fin_list_graphs = control(myGraph,inputs,n=50) if "sample_dir" not in inputs: inputs['sample_dir'] = inputs['out_comp_nm'] myGraphName = inputs['dir_nm'] + inputs['graph_files_dir'] + "/res_myGraph" with open(myGraphName, 'rb') as f: myGraph = pickle_load(f) if 'infer_overlap_threshold' in inputs: if inputs['infer_overlap_threshold'] == 'y': pp_flag = 0 if inputs['dir_nm'] == 'yeast': pp_flag = 1 if 'overlap_method' in inputs: if inputs['overlap_method'] == 'qi': inputs['over_t'] = get_overlap_threshold_qi( inputs, pp_flag, myGraph) else: inputs['over_t'] = get_overlap_threshold( inputs, pp_flag, myGraph) with open(inputs['dir_nm'] + inputs['out_comp_nm'] + "_input_pp.yaml", 'w') as outfile: yaml_dump(inputs, outfile, default_flow_style=False) out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm'] out_comp_nm_sample = inputs['dir_nm'] + inputs['sample_dir'] out_comp_nm_model = inputs['dir_nm'] + inputs['model_dir'] modelfname = out_comp_nm_model + "_model" scalerfname = out_comp_nm_model + "_scaler" with open(scalerfname, 'rb') as f: scaler = pickle_load(f) pred_comp_list = [] sdndap = pred_comp_list.append if args.sample_folders_list: for folder in args.sample_folders_list: allfiles = './' + inputs['dir_nm'] + folder + '/res_pred_comp_list*' for fname in glob(allfiles, recursive=True): with open(fname, 'rb') as f: pred_comp_tmp = pickle_load(f) for snode in pred_comp_tmp: sdndap(snode) elif args.sample_folders_prefix_final: allsubd = './' + inputs[ 'dir_nm'] + args.sample_folders_prefix_final + '*/res_pred.out' for fname in glob(allsubd, recursive=True): with open(fname) as f: complexes_score = [ line.rstrip().split() for line in f.readlines() ] pred_comp_tmp = [(frozenset(comp[:-1]), float(comp[-1])) for comp in complexes_score] for snode in pred_comp_tmp: sdndap(snode) elif args.sample_folders_prefix: allsubd = './' + inputs[ 'dir_nm'] + args.sample_folders_prefix + '*/res_pred_comp_list*' for fname in glob(allsubd, recursive=True): with open(fname, 'rb') as f: pred_comp_tmp = pickle_load(f) for snode in pred_comp_tmp: sdndap(snode) else: for i in range(int(args.n_pts)): with open(out_comp_nm_sample + "_pred_comp_list" + str(i), 'rb') as f: pred_comp_tmp = pickle_load(f) for snode in pred_comp_tmp: sdndap(snode) len_pred_comp_list = 'No. of complexes before pp = ' + str( len(pred_comp_list)) logging_info(len_pred_comp_list) test_complex_path = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_test_known_complex_nodes_list" test_prot_list = get_prot_list(test_complex_path) train_complex_path = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_train_known_complex_nodes_list" train_prot_list = get_prot_list(train_complex_path) protlistfname = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_protlist" with open(protlistfname, 'rb') as f: prot_list = pickle_load(f) start_time_pp = time_time() fin_list_graphs = postprocess(pred_comp_list, modelfname, scaler, inputs, myGraph, prot_list, train_prot_list, test_prot_list) pp_time = time_time() - start_time_pp tot_time = time_time() - start_time # Write to yaml file instead with open(out_comp_nm + '_runtime_performance.out', "a") as fid: print("--- Runtime performance ---", file=fid) print("Post processing complex time (s) = ", pp_time, "[", round(100 * float(pp_time) / tot_time, 2), "%]", file=fid) print("Total time (s) = ", tot_time, file=fid)
def main(): parser = argparse_ArgumentParser("Input parameters") parser.add_argument("--input_file_name", default="input_toy.yaml", help="Input parameters file name") parser.add_argument("--out_dir_name", default="/results", help="Output directory name, by default - /results") parser.add_argument( "--seed_mode", help="Seed mode - specify 'cliques' for the cliques algo") parser.add_argument("--train_test_files_dir", default="", help="Train test file path") parser.add_argument("--search_method", help="Sampling algorithm") parser.add_argument("--model_dir", help="Directory containing model") parser.add_argument("--python_command", default="python", help="python / python3") parser.add_argument( "--read_flag", default=0, help="1 when you want to read from file for evaluation") parser.add_argument( "--complex_file_name", default= "humap/results_2stageclustering_comparison/humap_2stage_clustering_res.txt", help="complexes file name") parser.add_argument("--evaluate_additional_metrics", default=1, help="complexes file name") args = parser.parse_args() rf = args.read_flag rf_nm = args.complex_file_name with open(args.input_file_name, 'r') as f: inputs = yaml_load(f, yaml_Loader) if args.model_dir: inputs['model_dir'] = args.model_dir # Override output directory name if same as gen if args.out_dir_name or inputs['out_comp_nm'] == "/results/res": if not os_path.exists(inputs['dir_nm'] + args.out_dir_name): os_mkdir(inputs['dir_nm'] + args.out_dir_name) inputs['out_comp_nm'] = args.out_dir_name + "/res" inputs['train_test_files_dir'] = '' if args.train_test_files_dir: if not os_path.exists(inputs['dir_nm'] + args.train_test_files_dir): os_mkdir(inputs['dir_nm'] + args.train_test_files_dir) inputs['train_test_files_dir'] = args.train_test_files_dir with open(inputs['dir_nm'] + inputs['out_comp_nm'] + "_input_eval.yaml", 'w') as outfile: yaml_dump(inputs, outfile, default_flow_style=False) logging_basicConfig(filename=inputs['dir_nm'] + inputs['out_comp_nm'] + "_logs.yaml", level=logging_INFO) # fin_list_graphs = control(myGraph,inputs,n=50) # eval_complex(rf,rf_nm,inputs,known_complex_nodes_list,prot_list,myGraph,fin_list_graphs) known_complex_nodes_listfname = inputs[ 'dir_nm'] + "/res_known_complex_nodes_list" protlistfname = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_protlist" with open(protlistfname, 'rb') as f: prot_list = pickle_load(f) with open(known_complex_nodes_listfname, 'rb') as f: known_complex_nodes_list = pickle_load(f) out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm'] if not rf: with open(inputs['dir_nm'] + inputs["out_comp_nm"] + '_pred.out', "r") as fn: lines = fn.readlines() fin_list_graphs = [] for line in lines: words = line.split() fin_list_graphs.append((set(words[:-1]), words[-1])) N_pred_complexes = len(fin_list_graphs) with open(out_comp_nm + '_metrics.out', "a") as fid: print("No. of predicted complexes = ", N_pred_complexes, file=fid) if N_pred_complexes == 0: print("0 predicted complexes") return pythonCommand = args.python_command if rf == 1: if rf_nm == 0: rf_nm = out_comp_nm + '_pred.out' with open(rf_nm) as fn: fin_list_graphs = [(set(line.rstrip('\n').split()), 1) for line in fn] # Space separated text only # TRAINING SET EVALUATION with open(out_comp_nm + '_metrics.out', "a") as fid: print("\n --- On training set ---", file=fid) train_complex_path = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_train_known_complex_nodes_list" try: with open(train_complex_path + "_prot_list", 'rb') as f: train_prot_list = pickle_load(f) except: train_prot_list = get_prot_list(train_complex_path) with open(train_complex_path, 'rb') as f: train_complex_list = pickle_load(f) eval_complex(rf, rf_nm, inputs, train_complex_list, train_prot_list, fin_list_graphs, "_train") if args.evaluate_additional_metrics: try: run_metrics(train_complex_list, fin_list_graphs, out_comp_nm, "_train") except: print("Error in running additional metrics for train") # TEST SET EVALUATION with open(out_comp_nm + '_metrics.out', "a") as fid: print("\n --- On test set ---", file=fid) test_complex_path = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_test_known_complex_nodes_list" try: with open(test_complex_path + "_prot_list", 'rb') as f: test_prot_list = pickle_load(f) except: test_prot_list = get_prot_list(test_complex_path) with open(test_complex_path, 'rb') as f: test_complex_list = pickle_load(f) eval_complex(rf, rf_nm, inputs, test_complex_list, test_prot_list, fin_list_graphs, "_test") if args.evaluate_additional_metrics: try: run_metrics(test_complex_list, fin_list_graphs, out_comp_nm, "_test") except: print("Error in running additional metrics for test") # ON BOTH SETS with open(out_comp_nm + '_metrics.out', "a") as fid: print("\n --- On both sets ---", file=fid) eval_complex(rf, rf_nm, inputs, known_complex_nodes_list, prot_list, fin_list_graphs, "_both") if args.evaluate_additional_metrics: try: run_metrics(known_complex_nodes_list, fin_list_graphs, out_comp_nm, "") except: print("Error in running additional metrics for both") else: start_time_eval = time_time() # TRAINING SET EVALUATION with open(out_comp_nm + '_metrics.out', "a") as fid: print("\n --- On training set ---", file=fid) train_complex_path = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_train_known_complex_nodes_list" try: with open(train_complex_path + "_prot_list", 'rb') as f: train_prot_list = pickle_load(f) except: train_prot_list = get_prot_list(train_complex_path) with open(train_complex_path, 'rb') as f: train_complex_list = pickle_load(f) eval_complex(rf, rf_nm, inputs, train_complex_list, train_prot_list, fin_list_graphs, "_train") if args.evaluate_additional_metrics: try: run_metrics(train_complex_list, fin_list_graphs, out_comp_nm, "_train") except: print("Error in running additional metrics for train") # TEST SET EVALUATION with open(out_comp_nm + '_metrics.out', "a") as fid: print("\n --- On test set ---", file=fid) test_complex_path = inputs['dir_nm'] + inputs[ 'train_test_files_dir'] + "/res_test_known_complex_nodes_list" try: with open(test_complex_path + "_prot_list", 'rb') as f: test_prot_list = pickle_load(f) except: test_prot_list = get_prot_list(test_complex_path) with open(test_complex_path, 'rb') as f: test_complex_list = pickle_load(f) eval_complex(rf, rf_nm, inputs, test_complex_list, test_prot_list, fin_list_graphs, "_test") if args.evaluate_additional_metrics: try: run_metrics(test_complex_list, fin_list_graphs, out_comp_nm, "_test") except: print("Error in running additional metrics for test") # BOTH SETS EVALUATION with open(out_comp_nm + '_metrics.out', "a") as fid: print("\n --- On both sets ---", file=fid) eval_complex(rf, rf_nm, inputs, known_complex_nodes_list, prot_list, fin_list_graphs, "_both") if args.evaluate_additional_metrics: try: run_metrics(known_complex_nodes_list, fin_list_graphs, out_comp_nm, "") except: print("Error in running additional metrics for both") if not os_path.exists(out_comp_nm + "_edge_pr_files"): os_mkdir(out_comp_nm + "_edge_pr_files") for pref in ["", "_train", "_test"]: # model dir not outcompnm out_comp_nm_model = inputs['dir_nm'] + inputs['model_dir'] results_wprob = out_comp_nm + '_tot_pred_edges_unique_max_comp_prob_inKnown' + pref + '.out' input_pos = out_comp_nm_model + pref + '_tot_known_edges_unique.out' outfname = out_comp_nm + "_edge_pr_files/res" + '_edge_pr_curve' + pref os_system(pythonCommand + " functions_py3/prcurve_overlay_noneg.py --labels All " + "--results_wprob " + results_wprob + " --input_positives " + input_pos + " --output_file " + outfname) fname = out_comp_nm + "_pred.out" figname = out_comp_nm + "_sizewise_scores_pred.png" sizewise_scores(fname, figname) eval_time = time_time() - start_time_eval tot_time = time_time() - start_time # Write to yaml file instead with open(out_comp_nm + '_runtime_performance.out', "a") as fid: print("--- Runtime performance ---", file=fid) print("Evaluate complex time (s) = ", eval_time, "[", round(100 * float(eval_time) / tot_time, 2), "%]", file=fid) print("Total time (s) = ", tot_time, file=fid)
def main(): parser = argparse_ArgumentParser("Input parameters") parser.add_argument("--input_file_name", default="input_toy.yaml", help="Input parameters file name") parser.add_argument("--out_dir_name", default="/results", help="Output directory name") parser.add_argument("--train_test_files_dir", default="", help="Train test file path") parser.add_argument("--graph_files_dir", default="", help="Graph files' folder path") parser.add_argument("--seed_mode", help="Seed mode - specify 'cliques' for the cliques algo") parser.add_argument("--max_size_thres", help="Max size threshold") parser.add_argument("--n_pts", default=1, help="number of partitions (computers)") args = parser.parse_args() with open(args.input_file_name, 'r') as f: inputs = yaml_load(f, yaml_Loader) if args.seed_mode: inputs['seed_mode'] = args.seed_mode if args.max_size_thres: inputs['max_size_thres'] = int(args.max_size_thres) # Override output directory name if same as gen if args.out_dir_name or inputs['out_comp_nm'] == "/results/res": if not os_path.exists(inputs['dir_nm'] + args.out_dir_name): os_mkdir(inputs['dir_nm'] + args.out_dir_name) inputs['out_comp_nm'] = args.out_dir_name + "/res" inputs['train_test_files_dir'] = '' if args.train_test_files_dir: if not os_path.exists(inputs['dir_nm'] + args.train_test_files_dir): os_mkdir(inputs['dir_nm'] + args.train_test_files_dir) inputs['train_test_files_dir'] = args.train_test_files_dir inputs['graph_files_dir'] = '' if args.graph_files_dir: if not os_path.exists(inputs['dir_nm'] + args.graph_files_dir): os_mkdir(inputs['dir_nm'] + args.graph_files_dir) inputs['graph_files_dir'] = args.graph_files_dir with open(inputs['dir_nm'] + inputs['out_comp_nm'] + "_input_sample_partition.yaml", 'w') as outfile: yaml_dump(inputs, outfile, default_flow_style=False) logging_basicConfig(filename=inputs['dir_nm'] + inputs['out_comp_nm'] + "_logs.yaml", level=logging_INFO) neig_dicts_folder = inputs['dir_nm'] +inputs['graph_files_dir']+ "/neig_dicts" num_comp = inputs['num_comp'] max_size_thres = inputs['max_size_thres'] max_size_trainF = inputs['dir_nm'] + inputs['train_test_files_dir']+ "/res_max_size_train" with open(max_size_trainF, 'rb') as f: max_size_train = pickle_load(f) max_size = max_size_train max_sizeF_feat = inputs['dir_nm'] + inputs['train_test_files_dir']+ "/res_max_size_search" if os_path.exists(max_sizeF_feat): with open(max_sizeF_feat, 'rb') as f: max_size = pickle_load(f) else: with open(inputs['dir_nm'] + inputs['comf_nm']) as f: sizes = [len(line.rstrip().split()) for line in f.readlines()] max_size = max(sizes) q1 = np_percentile(sizes, 25) q3 = np_percentile(sizes, 75) max_wo_outliers = math_ceil(q3 + 4.5*(q3-q1)) # Maximum after removing outliers max_size = min(max_size,max_wo_outliers) if max_size >= max_size_thres: max_size = max_size_thres out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm'] with open(out_comp_nm + '_metrics.out', "a") as fid: print("Max number of steps for complex growth = ", max_size, file=fid) # NOT actual max size since you merge later max_sizeF = inputs['dir_nm'] + inputs['train_test_files_dir']+ "/res_max_size_search_par" with open(max_sizeF, 'wb') as f: pickle_dump(max_size, f) seed_mode = inputs['seed_mode'] if seed_mode == "all_nodes": #graph_nodes = list(myGraph.nodes()) seed_nodes = rand_perm(os_listdir(neig_dicts_folder)) elif seed_mode == "n_nodes": seed_nodes = rand_perm(os_listdir(neig_dicts_folder))[:num_comp] elif seed_mode == "all_nodes_known_comp": protlistfname = inputs['dir_nm']+ inputs['train_test_files_dir'] + "/res_protlist" with open(protlistfname, 'rb') as f: prot_list = pickle_load(f) seed_nodes = list(prot_list) elif seed_mode == "cliques": myGraphName = inputs['dir_nm'] + inputs['graph_files_dir']+ "/res_myGraph" with open(myGraphName, 'rb') as f: myGraph = pickle_load(f) clique_list = list(nx_find_cliques(myGraph)) to_rem = [] # Removing 2 node and big complexes for comp in clique_list: if len(comp) <= 2 or len(comp) >= max_size: to_rem.append(comp) for comp in to_rem: clique_list.remove(comp) seed_nodes = clique_list # Remove duplicates later. # partition ptns = int(args.n_pts) nc = len(seed_nodes) if seed_mode == 'n_nodes': seed_nodes_F = out_comp_nm + "_seed_nodes" each_ptn = nc // ptns for i in range(ptns - 1): with open(seed_nodes_F + str(i), 'wb') as f: pickle_dump(seed_nodes[i * each_ptn:(i + 1) * each_ptn], f) with open(seed_nodes_F + str(ptns - 1), 'wb') as f: pickle_dump(seed_nodes[(ptns - 1) * each_ptn:], f) else: seed_nodes_dir = inputs['dir_nm'] + inputs['graph_files_dir']+ "/" + seed_mode + "_n_pts_" + str(ptns) if not os_path.exists(seed_nodes_dir): os_mkdir(seed_nodes_dir) seed_nodes_F = seed_nodes_dir + "/res_seed_nodes" each_ptn = nc // ptns for i in range(ptns - 1): with open(seed_nodes_F + str(i), 'wb') as f: pickle_dump(seed_nodes[i * each_ptn:(i + 1) * each_ptn], f) with open(seed_nodes_F + str(ptns - 1), 'wb') as f: pickle_dump(seed_nodes[(ptns - 1) * each_ptn:], f)
def build_args_parser(): parser = argparse_ArgumentParser( prog='rpfba', description='Calculate FBA to generate rpFBA collection') parser = _add_arguments(parser) return parser
# pdf_merging.py from PyPDF3 import PdfFileReader, PdfFileWriter from argparse import ArgumentParser as argparse_ArgumentParser commands = argparse_ArgumentParser(description='merge pdf') commands.add_argument('-a', help='first pdf') commands.add_argument('-b', help='second pdf') commands, unknown = commands.parse_known_args() pdf1 = commands.a pdf2 = commands.b def merge_pdfs(paths, output): pdf_writer = PdfFileWriter() for path in paths: pdf_reader = PdfFileReader(path) for page in range(pdf_reader.getNumPages()): # Add each page to the writer object pdf_writer.addPage(pdf_reader.getPage(page)) # Write out the merged PDF with open(output, 'wb') as out: pdf_writer.write(out) if __name__ == '__main__': paths = [pdf1, pdf2] merge_pdfs(paths, output='merged.pdf')
from glob import glob from argparse import ArgumentParser as argparse_ArgumentParser parser = argparse_ArgumentParser("Input parameters") parser.add_argument("--main_folder", default="/*", help="Input parameters file name") args = parser.parse_args() def get_f1_score(file_name): res = 0 with open(file_name) as f: lines = f.readlines() for line in lines[::-1]: # Reverse order words = line.strip().split("=") if words[0] == "Prediction F1 score ": if float(words[1]) > 0: res = float(words[1]) break return res # level1subd = './humap/*/res_metrics*' allsubd = './humap' + args.main_folder + '*/res_metrics*' # fname = "./humap/results_73_neg_same_size_distmetropolis/res_metrics.out" max_f1_score = 0 max_fname = "" all_sets = [] for fname in glob(allsubd, recursive=True): f1score = get_f1_score(fname) all_sets.append((fname, f1score))
def build_parser(): parser = argparse_ArgumentParser(description='SeqFind script for Selenzy') parser = add_arguments(parser) return parser
'', #string - FQDN or IP we get from DNS for reverse or forward lookup 'commandList': '', #list of strings - to store command parameters to run with subprocess module 'hostIndex': hostIndex, #indeger, reference to index in defaultCommand to replace it with target IP or name 'results': '', #string - probe run results to print on screen 'logFile': '' #file object - file to store logs to for this particular target } splitChar = ',' #character used to split data in SrcFile formatter = '' #string, used to format results output for cli printing header = '' #string, used to contain header information for priniting to cli #build argparser based menu: parser = argparse_ArgumentParser(description=""" Concurrent Command to Multiple Destinations - run commands against targets in semi-parallel fashion. """) parser.add_argument('-c', action='store', dest='PROBECOUNT', default=100, type=int, help='Number of probes to run, default - 100') parser.add_argument('-b', action='store', dest='barLen', default=60, type=int, help='Length of probe history bar, default - 60') parser.add_argument('-i', action='store',