Beispiel #1
0
    def _handle_error_txt(self, error_path, work_dir_path, context, main_domain_alignment):
        with open(error_path, 'r') as f:
            msg = f.read()

            if 'reward for reporting' in msg.lower():
                model_name = model_storage.get_model_name(context.get_main_target_sequence(),
                                                          context.target_species_id,
                                                          main_domain_alignment,
                                                          TemplateID(context.template_pdbid,
                                                                     context.main_target_chain_id))
                tar_path = model_storage.get_error_tar_path(context.get_main_target_sequence(),
                                                            context.target_species_id,
                                                            main_domain_alignment,
                                                            TemplateID(context.template_pdbid,
                                                                       context.main_target_chain_id))
                with tarfile.open(tar_path, mode="w:gz") as ar:
                    ar.add(work_dir_path, arcname=model_name)

            raise ModelRunError(msg)
Beispiel #2
0
    def _handle_error_txt(self, error_path, work_dir_path, context, main_domain_alignment):
        with open(error_path, 'r') as f:
            msg = f.read()

            if 'reward for reporting' in msg.lower():
                model_name = model_storage.get_model_name(context.get_main_target_sequence(),
                                                          context.target_species_id,
                                                          main_domain_alignment,
                                                          TemplateID(context.template_pdbid,
                                                                     context.main_target_chain_id))
                tar_path = model_storage.get_error_tar_path(context.get_main_target_sequence(),
                                                            context.target_species_id,
                                                            main_domain_alignment,
                                                            TemplateID(context.template_pdbid,
                                                                       context.main_target_chain_id))
                with tarfile.open(tar_path, mode="w:gz") as ar:
                    ar.add(work_dir_path, arcname=model_name)

            raise ModelRunError(msg)
Beispiel #3
0
    def _wrap_template(self, main_target_sequence, target_species_id,
                       main_domain_alignment, template_id):
        model_name = model_storage.get_model_name(main_target_sequence,
                                                  target_species_id,
                                                  main_domain_alignment,
                                                  template_id)

        work_dir_path = tempfile.mkdtemp()
        align_fasta_path = os.path.join(work_dir_path, 'align.fa')

        try:
            os.chdir(work_dir_path)

            write_fasta(
                align_fasta_path, {
                    'target': main_domain_alignment.target_alignment,
                    str(template_id): main_domain_alignment.template_alignment
                })

            model_path = os.path.join(work_dir_path, 'target.pdb')
            with open(model_path, 'w') as f:
                f.write(get_pdb_contents(template_id.pdbid))

            self._write_selected_targets(
                {template_id.chain_id: main_domain_alignment},
                os.path.join(work_dir_path, 'selected-targets.txt'))

            tar_path = model_storage.get_tar_path(main_target_sequence,
                                                  target_species_id,
                                                  main_domain_alignment,
                                                  template_id)
            with tarfile.open(tar_path, mode="w:gz") as ar:
                ar.add(work_dir_path, arcname=model_name)

            return tar_path
        finally:
            if os.path.isdir(work_dir_path):
                shutil.rmtree(work_dir_path)
Beispiel #4
0
    def _wrap_template(self, main_target_sequence, target_species_id, main_domain_alignment, template_id):
        model_name = model_storage.get_model_name(main_target_sequence, target_species_id,
                                                  main_domain_alignment, template_id)

        work_dir_path = tempfile.mkdtemp()
        align_fasta_path = os.path.join(work_dir_path, 'align.fa')
        full_target_path = os.path.join(work_dir_path, 'target.fa')

        write_fasta(full_target_path, {'target': main_target_sequence})

        try:
            os.chdir(work_dir_path)

            write_fasta(align_fasta_path, {'target': main_domain_alignment.target_alignment,
                                           str(template_id): main_domain_alignment.template_alignment})

            model_path = os.path.join(work_dir_path, 'target.pdb')
            with open(model_path, 'w') as f:
                f.write(get_pdb_contents(template_id.pdbid))

            self._write_selected_targets({template_id.chain_id: main_domain_alignment},
                                         os.path.join(work_dir_path, 'selected-targets.txt'))

            log_path = os.path.join(work_dir_path, 'model.log')
            ModelLogger.get_current().write(log_path)

            tar_path = model_storage.get_tar_path(main_target_sequence,
                                                  target_species_id,
                                                  main_domain_alignment,
                                                  template_id)
            with tarfile.open(tar_path, mode="w:gz") as ar:
                ar.add(work_dir_path, arcname=model_name)

            return tar_path
        finally:
            if os.path.isdir(work_dir_path):
                shutil.rmtree(work_dir_path)
Beispiel #5
0
    def _model_run(self, main_domain_alignment, chain_alignments, context, main_target_sequence, require_resnum):

        model_name = model_storage.get_model_name(context.get_main_target_sequence(),
                                                  context.target_species_id,
                                                  main_domain_alignment,
                                                  TemplateID(context.template_pdbid,
                                                             context.main_target_chain_id))

        work_dir_path = tempfile.mkdtemp()
        full_target_path = os.path.join(work_dir_path, 'target.fa')
        align_fasta_path = os.path.join(work_dir_path, 'align.fa')
        output_yob_path = os.path.join(work_dir_path, 'target.yob')
        error_path = os.path.join(work_dir_path, 'errorexit.txt')
        error_scene_path = os.path.join(work_dir_path, 'errorexit.sce')
        before_scene_path =  os.path.join(work_dir_path, 'beforemodel.sce')

        write_fasta(full_target_path, {'target': context.get_main_target_sequence()})

        try:
            context.yasara.CD(work_dir_path)

            context.yasara.SaveSce(before_scene_path)

            chain_ids_before_model = context.get_chain_ids()
            sequences_before_model = {chain_id: context.get_sequence(chain_id) for chain_id in chain_ids_before_model}

            self._write_model_alignment_fasta(context, chain_alignments, align_fasta_path)

            context.yasara.Processors(1)

            context.yasara.ExperimentHomologyModeling(templateobj=context.template_obj,
                                                      alignfile=align_fasta_path,
                                                      templates="1, sameseq = 1",
                                                      alignments=1,
                                                      termextension=0,
                                                      oligostate=32,
                                                      looplenmax=10,
                                                      animation='fast',
                                                      speed='fast',
                                                      loopsamples=20,
                                                      resultfile='target')
            context.yasara.Experiment("On")
            context.yasara.Wait("Expend")

            if os.path.isfile(error_path):
                self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment)
            elif os.path.isfile(error_scene_path):
                raise ModelRunError("yasara exited with an error")

            if not os.path.isfile(output_yob_path):
                chain_ids_after_failure = context.get_chain_ids()

                if chain_ids_before_model != chain_ids_after_failure:
                    raise ModelRunError("During modeling, yasara changed the chains {} to {}"
                                        .format(chain_ids_before_model, chain_ids_after_failure))

                for chain_id in chain_ids_before_model:
                    sequence_after_failure = context.get_sequence(chain_id)
                    if sequence_after_failure != sequences_before_model[chain_id]:
                        raise ModelRunError("During modeling, yasara changed chain {} sequence {} to {}"
                                            .format(chain_id, sequences_before_model[chain_id], sequence_after_failure))

                raise ModelRunError("yasara generated no output yob, check the console for further details")

            chain_ids_after_build = context.get_chain_ids()
            if context.main_target_chain_id not in chain_ids_after_build:
                raise ModelRunError(f"The chain {context.main_target_chain_id} is not in the final model output by yasara")

            _log.debug("after modeling {}".format([(chain_id, context.get_sequence(chain_id))
                                                   for chain_id in context.get_chain_ids()]))
            _log.debug("input target aligned sequence:\n{}".format(main_domain_alignment.get_target_sequence_without_insertions()))

            if not any([context.get_sequence(chain_id) == main_domain_alignment.get_target_sequence_without_insertions()
                        for chain_id in context.get_chain_ids()]):
                if require_resnum is not None and not self._model_covers_residue(context, main_target_sequence, require_resnum):
                    raise ModelRunError("yasara generated a model that doesn't match the input alignment")

            model_path = os.path.join(work_dir_path, 'target.pdb')
            context.yasara.SavePDB(context.template_obj, model_path)

            self._write_selected_targets(chain_alignments, os.path.join(work_dir_path, 'selected-targets.txt'))

            log_path = os.path.join(work_dir_path, 'model.log')
            ModelLogger.get_current().write(log_path)

            tar_path = model_storage.get_tar_path(context.get_main_target_sequence(),
                                                  context.target_species_id,
                                                  main_domain_alignment,
                                                  TemplateID(context.template_pdbid,
                                                             context.main_target_chain_id))
            with tarfile.open(tar_path, mode="w:gz") as ar:
                ar.add(work_dir_path, arcname=model_name)

            return tar_path
        except RuntimeError as e:
            self._log_additional_error_info(e, chain_alignments, context)

            if os.path.isfile(error_path):
                self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment)
            elif os.path.isfile(error_scene_path):
                raise ModelRunError("yasara exited with an error")
            else:
                raise e
        finally:
            if os.path.isdir(work_dir_path):
                shutil.rmtree(work_dir_path)
Beispiel #6
0
    def _model_run(self, main_domain_alignment, chain_alignments, context):

        model_name = model_storage.get_model_name(
            context.get_main_target_sequence(), context.target_species_id,
            main_domain_alignment,
            TemplateID(context.template_pdbid, context.main_target_chain_id))

        work_dir_path = tempfile.mkdtemp()
        align_fasta_path = os.path.join(work_dir_path, 'align.fa')
        output_yob_path = os.path.join(work_dir_path, 'target.yob')
        error_path = os.path.join(work_dir_path, 'errorexit.txt')
        error_scene_path = os.path.join(work_dir_path, 'errorexit.sce')
        before_scene_path = os.path.join(work_dir_path, 'beforemodel.sce')
        try:
            context.yasara.CD(work_dir_path)

            context.yasara.SaveSce(before_scene_path)

            self._write_model_alignment_fasta(context, chain_alignments,
                                              align_fasta_path)

            context.yasara.Processors(1)

            context.yasara.ExperimentHomologyModeling(
                templateobj=context.template_obj,
                alignfile=align_fasta_path,
                templates="1, sameseq = 1",
                alignments=1,
                termextension=0,
                oligostate=32,
                looplenmax=10,
                animation='fast',
                speed='fast',
                loopsamples=20,
                resultfile='target')
            context.yasara.Experiment("On")
            context.yasara.Wait("Expend")

            if os.path.isfile(error_path):
                self._handle_error_txt(error_path, work_dir_path, context,
                                       main_domain_alignment)
            elif os.path.isfile(error_scene_path):
                raise ModelRunError("yasara exited with an error")

            if not os.path.isfile(output_yob_path):
                raise ModelRunError("yasara generated no output yob")

            model_path = os.path.join(work_dir_path, 'target.pdb')
            context.yasara.SavePDB(context.template_obj, model_path)

            self._write_selected_targets(
                chain_alignments,
                os.path.join(work_dir_path, 'selected-targets.txt'))

            tar_path = model_storage.get_tar_path(
                context.get_main_target_sequence(), context.target_species_id,
                main_domain_alignment,
                TemplateID(context.template_pdbid,
                           context.main_target_chain_id))
            with tarfile.open(tar_path, mode="w:gz") as ar:
                ar.add(work_dir_path, arcname=model_name)

            return tar_path
        except RuntimeError as e:
            self._log_additional_error_info(e, chain_alignments, context)

            if os.path.isfile(error_path):
                self._handle_error_txt(error_path, work_dir_path, context,
                                       main_domain_alignment)
            elif os.path.isfile(error_scene_path):
                raise ModelRunError("yasara exited with an error")
            else:
                raise e
        finally:
            if os.path.isdir(work_dir_path):
                shutil.rmtree(work_dir_path)
Beispiel #7
0
    def _model_run(self, main_domain_alignment, chain_alignments, context):

        model_name = model_storage.get_model_name(context.get_main_target_sequence(),
                                                  context.target_species_id,
                                                  main_domain_alignment,
                                                  TemplateID(context.template_pdbid,
                                                             context.main_target_chain_id))

        work_dir_path = tempfile.mkdtemp()
        full_target_path = os.path.join(work_dir_path, 'target.fa')
        align_fasta_path = os.path.join(work_dir_path, 'align.fa')
        output_yob_path = os.path.join(work_dir_path, 'target.yob')
        error_path = os.path.join(work_dir_path, 'errorexit.txt')
        error_scene_path = os.path.join(work_dir_path, 'errorexit.sce')
        before_scene_path =  os.path.join(work_dir_path, 'beforemodel.sce')

        write_fasta(full_target_path, {'target': context.get_main_target_sequence()})

        try:
            context.yasara.CD(work_dir_path)

            context.yasara.SaveSce(before_scene_path)

            chain_ids_before_model = context.get_chain_ids()
            sequences_before_model = {chain_id: context.get_sequence(chain_id) for chain_id in chain_ids_before_model}

            self._write_model_alignment_fasta(context, chain_alignments, align_fasta_path)

            context.yasara.Processors(1)

            context.yasara.ExperimentHomologyModeling(templateobj=context.template_obj,
                                                      alignfile=align_fasta_path,
                                                      templates="1, sameseq = 1",
                                                      alignments=1,
                                                      termextension=0,
                                                      oligostate=32,
                                                      looplenmax=10,
                                                      animation='fast',
                                                      speed='fast',
                                                      loopsamples=20,
                                                      resultfile='target')
            context.yasara.Experiment("On")
            context.yasara.Wait("Expend")

            if os.path.isfile(error_path):
                self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment)
            elif os.path.isfile(error_scene_path):
                raise ModelRunError("yasara exited with an error")

            if not os.path.isfile(output_yob_path):
                chain_ids_after_failure = context.get_chain_ids()

                if chain_ids_before_model != chain_ids_after_failure:
                    raise ModelRunError("During modeling, yasara changed the chains {} to {}"
                                        .format(chain_ids_before_model, chain_ids_after_failure))

                for chain_id in chain_ids_before_model:
                    sequence_after_failure = context.get_sequence(chain_id)
                    if sequence_after_failure != sequences_before_model[chain_id]:
                        raise ModelRunError("During modeling, yasara changed chain {} sequence {} to {}"
                                            .format(chain_id, sequences_before_model[chain_id], sequence_after_failure))

                raise ModelRunError("yasara generated no output yob, check the console for further details")

            model_path = os.path.join(work_dir_path, 'target.pdb')
            context.yasara.SavePDB(context.template_obj, model_path)

            self._write_selected_targets(chain_alignments, os.path.join(work_dir_path, 'selected-targets.txt'))

            log_path = os.path.join(work_dir_path, 'model.log')
            ModelLogger.get_current().write(log_path)

            tar_path = model_storage.get_tar_path(context.get_main_target_sequence(),
                                                  context.target_species_id,
                                                  main_domain_alignment,
                                                  TemplateID(context.template_pdbid,
                                                             context.main_target_chain_id))
            with tarfile.open(tar_path, mode="w:gz") as ar:
                ar.add(work_dir_path, arcname=model_name)

            return tar_path
        except RuntimeError as e:
            self._log_additional_error_info(e, chain_alignments, context)

            if os.path.isfile(error_path):
                self._handle_error_txt(error_path, work_dir_path, context, main_domain_alignment)
            elif os.path.isfile(error_scene_path):
                raise ModelRunError("yasara exited with an error")
            else:
                raise e
        finally:
            if os.path.isdir(work_dir_path):
                shutil.rmtree(work_dir_path)