def main(): args = read_args() ncs, msg = find_ncs(args.ncs, script_path) if not ncs: print(msg) exit() result, blocks, ncs_name, deuterated = read_blocks(args.elb_file) if result: exit() product_finder = ProductFinder(blocks, args.samples, args.min_patterns) products = product_finder.find_products() schemes_total = sum([len(product) for product in products]) blocks_total = {} print("{} products found".format(schemes_total)) output = "[NCS = {}]\n".format(ncs_name) output += "[Deuterated = {}]\n".format(deuterated) for product in products: for scheme in product: scheme.simplify() blocks_total = add_block(blocks_total, scheme.samples, len(scheme.patterns)) output += scheme.full_str() output += "\n" stats_total = make_block_stats(blocks_total) if args.output: with open(args.output, mode="w") as f: f.write(output) print("{} blocks were written to the file \'{}\'".format( schemes_total, args.output)) else: print(output) print("Statistics of generated blocks:") print(stats_total["str"])
def get_params(args, logger): ncs, msg = find_ncs(args.ncs, script_path) if not ncs: logger.error(msg) exit() else: logger.info(msg) samples = args.samples if samples < 1 or samples > 9: logger.error( "Number of samples '{}' is not in range 1-9".format(samples)) exit() min_patterns = 0 exact_patterns = False if args.minpatterns: min_patterns = args.minpatterns exact_patterns = True min_t_free = -1 check_t_free = False if args.min_t_free: if args.min_t_free >= 0: min_t_free = args.min_t_free check_t_free = True else: min_t_free = -1 if check_t_free: exact_patterns = True params = { "ncs": ncs, "samples": samples, "exact_patterns": exact_patterns, "min_patterns": min_patterns, "check_t_free": check_t_free, "min_t_free": min_t_free, "verbose": args.verbose, "silent": args.silent } return params
def read_parameters(args, logger): ncs, msg = find_ncs(args.ncs, script_path) if not ncs: logger.error(msg) exit() result, blocks, ncs_name, deuterated = read_blocks(args.elb_file, logger) if result: exit() prices = {} if os.path.isfile(args.price_file): prices, msg = read_prices(args.price_file) if not prices: logger.error(msg) exit() else: logger.error("Error! Price file '{}' not found".format(args.price_file)) max_block_samples = max(blocks.keys()) jobname = args.jobname if args.aminoacids: residues = extract_residues(args.aminoacids) else: residues = Constants.RES_TYPES_LIST if args.notaminoacids: not_residues = extract_residues(args.notaminoacids) else: not_residues = [] final_residues = [] for res in residues: if res not in not_residues: final_residues.append(res) if not jobname: jobname = "{}_{}".format(ncs.name, max_block_samples) parameters = { "blocks": blocks, "ncs": ncs, "prices": prices, "residues": final_residues, "jobname": jobname, "verbose": args.verbose, "silent": args.silent } return parameters
def get_params(args): script_path = os.path.split(os.path.realpath(__file__))[0] ncs, msg = find_ncs(args.ncs, script_path) if not ncs: print(msg) exit() print("NCS '{}' read".format(ncs.name)) protein_sequence, msg = read_sequence(args.sequence) print("Protein sequence: {}".format(protein_sequence)) if len(protein_sequence) == 0: exit() if len(protein_sequence) < 3: print("Protein sequence is too short({})".format( len(protein_sequence))) exit() sequence = CLSequence(protein_sequence) print("Protein sequence file '{}' read".format(args.sequence)) solution = read_solution(args.solution) if not solution: exit() solution = add_unlabeled_residues(solution, sequence) print("Solution file '{}' read".format(args.solution)) label_options = get_stock_from_solution(solution) pairs_table = PairsTable(sequence, label_options) all_label_options = set(sum(list(label_options.values()), [])) new_label_types = [] for label_type in Constants.BASIC_TYPES: if label_type in all_label_options or label_type in ncs.label_types: new_label_types.append(label_type) show_price = False price_dict = {} if args.prices: show_price = True price_dict, msg = read_prices(args.prices) if not price_dict: print(msg) exit() new_ncs = NCS("", ncs.spec_list, new_label_types, deuterated=ncs.deuterated) new_ncs.name = auto_name_ncs(new_ncs) name = "{}_{}".format(args.sequence.split(".")[0], new_ncs.name) output_solution = name + "_solution_c.txt" output_dictionary = name + "_dictionary_c.txt" params = { "ncs": new_ncs, "name": name, "label_options": label_options, "sequence": sequence, "solution": solution, "pairs_table": pairs_table, "show_price": show_price, "price_dict": price_dict, "output_solution": output_solution, "output_dictionary": output_dictionary } return params
def read_parameters(args, logger): logger.info("Reading NCS") ncs, msg = find_ncs(args.ncs, script_path) if not ncs: logger.error(msg) exit() logger.info("NCS: {}".format(ncs.name)) sequence = "" logger.info("Reading sequence: '{}'".format(args.sequence_file)) if os.path.isfile(args.sequence_file): sequence, msg = read_sequence(args.sequence_file) if not sequence: logger.error(msg) exit() else: logger.error("Error! Sequence file '{}' not found".format(args.sequence_file)) if len(sequence) < 3: print("Sequence length ({}) is too short".format(len(sequence))) exit() logger.info("Sequence length - {} residues".format(len(sequence))) stock = {} if os.path.isfile(args.stock_file): logger.info("Reading stock: '{}'".format(args.stock_file)) stock, msg = read_stock(args.stock_file) if not stock: logger.error(msg) exit() else: logger.error("Error! Stock file '{}' not found".format(args.stock_file)) logger.info("Stock - OK") optimize_price = True if not args.price: optimize_price = False prices = {} if optimize_price: logger.info("Reading prices: '{}'".format(args.price)) if os.path.isfile(args.price): prices, msg = read_prices(args.price) if not prices: logger.error(msg) exit() else: logger.error("Error! Price file '{}' not found".format(args.price)) exit() logger.info("Prices - OK") assignment = True if not args.assignment: assignment = False assignment_numbers = set() if assignment: logger.info("Reading assignment: '{}'".format(args.assignment)) if os.path.isfile(args.assignment): assignment_numbers, msg = read_assignment(args.assignment) else: logger.error("Error! Assignment file '{}' not found".format(args.assignment)) for assignment_num in assignment_numbers: if assignment_num > len(sequence): warning_msg = "Warning! Residue number {} is exceeding sequence length ({})".format(assignment_num, len(sequence)) logger.error(warning_msg) if assignment: logger.info("{} backbone assignments read".format(len(assignment_numbers))) jobname = args.jobname seq_name = args.sequence_file.split(".")[0] if not jobname: jobname = "{}_{}".format(seq_name, ncs.name) samples = args.number_samples # default value is 1 if samples < 1 or samples > 9: msg = "Error! Number of samples is not in range 1-9" logger.error(msg) exit() parameters = { "ncs": ncs, "sequence": sequence, "stock": stock, "optimize_price": optimize_price, "prices": prices, "samples": samples, "jobname": jobname, "verbose": args.verbose, "silent": args.silent, "assignment": assignment_numbers } return parameters