def get_metadata(job_id): """ Get the metadata of the model, created by the modeling job. :param jobid: the job_id returned by 'submit' :return: The json metadata object. If the job status is not SUCCESS, this method returns an error. """ from hommod.application import celery result = celery.AsyncResult(job_id) if result.status != 'SUCCESS': return jsonify({'error': "{} has status {}".format(job_id, result.status)}), 400 try: path = result.get() except Exception: return jsonify({'error': result.traceback}), 500 if path is None: message = 'Job %s finished, but without creating a model. This could be due to lack of a suitable template.' % job_id return jsonify({'error': message}), 500 try: data = {} data['selected_targets'] = model_storage.extract_selected_targets(path) data['alignments'] = [alignment.as_dict() for alignment in model_storage.extract_alignments(path)] return jsonify(data) except: return jsonify({'error': traceback.format_exc()}), 500
def test_create_model_cox(): from hommod.tasks import create_model path = create_model( "MLATRVFSLVGKRAISTSVCVRAHESVVKSEDFSLPAYMDRRDHPLPEVAHVKHLSASQKALKEKEKASWSS" + "LSMDEKVELYRIKFKESFAEMNRGSNEWKTVVGGAMFFIGFTALVIMWQKHYVYGPLPQSFDKEWVAKQTKR" + "MLDMKVNPIQGLASKWDYEKNEWKK", "HUMAN", None, TemplateID('2y69', 'D')) ok_(path is not None) name = os.path.splitext(os.path.basename(path))[0] pdb_name = os.path.join(name, 'target.pdb') with tarfile.open(path) as tf: ok_(pdb_name in tf.getnames()) alignments = model_storage.extract_alignments(path) ok_(len(alignments) >= 13)
def select_best_model(tar_paths): best_path = None best_pid = 0.0 for tar_path in tar_paths: model_name = model_storage.get_model_name_from_path(tar_path) sequence_id = model_storage.get_sequence_id_from_name(model_name) pdb_str = model_storage.extract_model(tar_path) chain_order = parse_chain_order_from_string(pdb_str) chain_alignments = model_storage.extract_alignments(tar_path) if len(chain_order) != len(chain_alignments): _log.error("{}: {} chains in pdb file, vs. {} alignments in fasta" .format(tar_path, len(chain_order), len(chain_alignments))) continue chain_targets = model_storage.extract_selected_targets(tar_path) chain_ids = list(filter(lambda chain_id: chain_targets[chain_id] == sequence_id, chain_targets.keys())) if len(chain_ids) <= 0: _log.error("no main target {} in selected targets of {}".format(sequence_id, tar_path)) continue if chain_ids[0] not in chain_order: _log.error("chain {} not in {}".format(chain_ids[0], tar_path)) continue chain_i = chain_order.index(chain_ids[0]) alignment = chain_alignments[chain_i] keys = list(alignment.aligned_sequences.keys()) if len(keys) != 2: _log.error("alignment for chain {} in {} has too many keys: {}".format(chain_ids[0], tar_path, keys)) continue pid = alignment.get_percentage_identity(keys[0], keys[1]) if pid > best_pid: best_pid = pid best_path = tar_path return best_path
def get_metadata_by_model_id(model_id): """ Get the metadata of the model, created by the modeling job. :param model_id: the id returned by 'get_model_if_exists' :return: The json metadata object. """ path = model_storage.get_tar_path_from_name(model_id) if not os.path.isfile(path): return jsonify({'error': "no such model"}), 400 try: data = {} data['selected_targets'] = model_storage.extract_selected_targets(path) data['alignments'] = [alignment.as_dict() for alignment in model_storage.extract_alignments(path)] return jsonify(data) except: return jsonify({'error': traceback.format_exc()}), 500
def get_metadata_by_model_id(model_id): """ Get the metadata of the model, created by the modeling job. :param model_id: the id returned by 'get_model_if_exists' :return: The json metadata object. """ path = model_storage.get_tar_path_from_name(model_id) if not os.path.isfile(path): return jsonify({'error': "no such model"}), 400 try: data = {} data['selected_targets'] = model_storage.extract_selected_targets(path) data['alignments'] = [ alignment.as_dict() for alignment in model_storage.extract_alignments(path) ] return jsonify(data) except: return jsonify({'error': traceback.format_exc()}), 500
def select_best_model(tar_paths): best_path = None best_pid = 0.0 for tar_path in tar_paths: model_name = model_storage.get_model_name_from_path(tar_path) sequence_id = model_storage.get_sequence_id_from_name(model_name) pdb_str = model_storage.extract_model(tar_path) chain_order = parse_chain_order_from_string(pdb_str) chain_alignments = model_storage.extract_alignments(tar_path) chain_targets = model_storage.extract_selected_targets(tar_path) chain_ids = list(filter(lambda chain_id: chain_targets[chain_id] == sequence_id, chain_targets.keys())) if len(chain_ids) <= 0: _log.error("no main target {} in selected targets of {}".format(sequence_id, tar_path)) continue chain_i = chain_order.index(chain_ids[0]) if chain_i == -1: _log.error("chain {} not in {}".format(chain_ids[0], tar_path)) continue alignment = chain_alignments[chain_i] keys = alignment.aligned_sequences.keys() if len(keys) != 2: _log.error("alignment for chain {} in {} has too many keys: {}".format(chain_ids[0], tar_path, keys)) continue pid = alignment.get_percentage_identity(keys[0], keys[1]) if pid > best_pid: best_pid = pid best_path = tar_path return best_path
def get_metadata(job_id): """ Get the metadata of the model, created by the modeling job. :param jobid: the job_id returned by 'submit' :return: The json metadata object. If the job status is not SUCCESS, this method returns an error. """ from hommod.application import celery result = celery.AsyncResult(job_id) if result.status != 'SUCCESS': return jsonify( {'error': "{} has status {}".format(job_id, result.status)}), 400 try: path = result.get() except Exception: return jsonify({'error': result.traceback}), 500 if path is None: message = 'Job %s finished, but without creating a model. This could be due to lack of a suitable template.' % job_id return jsonify({'error': message}), 500 try: data = {} data['selected_targets'] = model_storage.extract_selected_targets(path) data['alignments'] = [ alignment.as_dict() for alignment in model_storage.extract_alignments(path) ] return jsonify(data) except: return jsonify({'error': traceback.format_exc()}), 500