示例#1
0
    def test_run_fails_cause_evaluation_is_not_found(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.evaluation = '/bin/doesnotexist'
            params.pdbdb = '/data/pdb'
            docktask = D3RTask(temp_dir, params)
            docktask.set_name('foo')
            docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)
            docktask.create_dir()
            open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            evaluation.run()
            self.assertEqual(
                evaluation.get_error(), 'Caught Exception trying to run ' +
                '/bin/doesnotexist --pdbdb /data/pdb ' + '--dockdir ' +
                docktask.get_dir() + ' --outdir ' + evaluation.get_dir() +
                ' : [Errno 2] No such file or directory')

            # test files get created
            errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE)
            self.assertEqual(os.path.isfile(errfile), True)
        finally:
            shutil.rmtree(temp_dir)
示例#2
0
    def test_run_succeeds_no_emailer(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.evaluation = 'true'
            params.pdbdb = '/data/pdb'
            docktask = D3RTask(temp_dir, params)
            docktask.set_name('foo')
            docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)
            docktask.create_dir()
            open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            evaluation.run()
            self.assertEqual(evaluation.get_error(), None)
            # test files get created
            errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE)
            self.assertEqual(os.path.isfile(errfile), False)

            compfile = os.path.join(evaluation.get_dir(),
                                    D3RTask.COMPLETE_FILE)
            self.assertEqual(os.path.isfile(compfile), True)
            stderr = os.path.join(evaluation.get_dir(), 'true.stderr')
            self.assertEqual(os.path.isfile(stderr), True)
            stdout = os.path.join(evaluation.get_dir(), 'true.stdout')
            self.assertEqual(os.path.isfile(stdout), True)
        finally:
            shutil.rmtree(temp_dir)
示例#3
0
    def test_run_fails_cause_evaluation_fails(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.evaluation = 'false'
            params.pdbdb = '/data/pdb'
            docktask = D3RTask(temp_dir, params)
            docktask.set_name('foo')
            docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)
            docktask.create_dir()
            open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            evaluation.run()
            self.assertEqual(
                evaluation.get_error(),
                'Non zero exit code: 1 received. Standard out: ' +
                ' Standard error: ')
            # test file gets created
            errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE)
            self.assertEqual(os.path.isfile(errfile), True)

            stderr = os.path.join(evaluation.get_dir(), 'false.stderr')
            self.assertEqual(os.path.isfile(stderr), True)
            stdout = os.path.join(evaluation.get_dir(), 'false.stdout')
            self.assertEqual(os.path.isfile(stdout), True)
        finally:
            shutil.rmtree(temp_dir)
示例#4
0
    def test_get_all_evaluation_tasks(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            # no evaluation tasks
            task = PostEvaluationTask(temp_dir, params)
            res = task.get_all_evaluation_tasks()
            self.assertEqual(len(res), 0)

            # directory in path that does NOT match suffix
            task.create_dir()
            os.makedirs(os.path.join(temp_dir, 'stage.x.1'), mode=0o755)
            res = task.get_all_evaluation_tasks()
            self.assertEqual(len(res), 0)

            # one task, but is file (weird case)
            weirdtaskfile = os.path.join(
                temp_dir, 'stage.7.hi.' + EvaluationTaskFactory.SCORING_SUFFIX)
            open(weirdtaskfile, 'a').close()
            res = task.get_all_evaluation_tasks()
            self.assertEqual(len(res), 0)
            self.assertEqual(
                task.get_email_log(),
                'Just a note, found a task with valid name, but '
                'it is not a directory ' + weirdtaskfile)
            # one task
            etask = EvaluationTask(temp_dir, 'foo.evaluation', None, params)
            etask.create_dir()
            res = task.get_all_evaluation_tasks()
            self.assertEqual(len(res), 1)
            self.assertTrue(res[0].get_dir_name(), etask.get_dir_name())

            # three tasks two with non complete status
            etask2 = EvaluationTask(temp_dir,
                                    'bla_dock.extsubmission.evaluation', None,
                                    params)
            etask2.create_dir()
            open(os.path.join(etask2.get_dir(), D3RTask.ERROR_FILE),
                 'a').close()

            etask3 = EvaluationTask(temp_dir, '12_x.extsubmission.evaluation',
                                    None, params)
            etask3.create_dir()
            open(os.path.join(etask3.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()

            res = task.get_all_evaluation_tasks()
            self.assertEqual(len(res), 3)
            d_name_list = []
            for entry in res:
                d_name_list.append(entry.get_dir_name())

            self.assertTrue(etask.get_dir_name() in d_name_list)
            self.assertTrue(etask2.get_dir_name() in d_name_list)
            self.assertTrue(etask3.get_dir_name() in d_name_list)
        finally:
            shutil.rmtree(temp_dir)
示例#5
0
    def test_run_succeeds_with_emailer(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.evaluation = 'true'
            params.pdbdb = '/data/pdb'
            docktask = D3RTask(temp_dir, params)
            docktask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX)
            docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)
            docktask.create_dir()
            open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            evaluation = EvaluationTask(temp_dir, docktask.get_name(),
                                        docktask, params)
            plist = [
                Participant('1name', '1d3rusername', '12345',
                            '[email protected],[email protected]')
            ]
            smtpemailer = SmtpEmailer()
            mockserver = D3RParameters()
            mockserver.sendmail = Mock()
            mockserver.quit = Mock()
            smtpemailer.set_alternate_smtp_server(mockserver)
            emailer = EvaluationEmailer(ParticipantDatabase(plist), None)
            emailer.set_alternate_smtp_emailer(smtpemailer)
            evaluation.set_evaluation_emailer(emailer)
            evaluation.run()
            self.assertEqual(evaluation.get_error(), None)
            # test files get created
            errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE)
            self.assertEqual(os.path.isfile(errfile), False)

            compfile = os.path.join(evaluation.get_dir(),
                                    D3RTask.COMPLETE_FILE)
            self.assertEqual(os.path.isfile(compfile), True)
            stderr = os.path.join(evaluation.get_dir(), 'true.stderr')
            self.assertEqual(os.path.isfile(stderr), True)
            stdout = os.path.join(evaluation.get_dir(), 'true.stdout')
            self.assertEqual(os.path.isfile(stdout), True)
            res = evaluation.get_email_log().endswith('\nSent evaluation '
                                                      'email to: [email protected],'
                                                      ' [email protected]\n')
            self.assertTrue(res)

        finally:
            shutil.rmtree(temp_dir)
示例#6
0
 def test_run_fails_cause_evaluation_not_set(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         docktask = D3RTask(temp_dir, params)
         docktask.set_name('foo')
         docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)
         docktask.create_dir()
         open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE),
              'a').close()
         evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                     params)
         evaluation.run()
         self.assertEqual(evaluation.get_error(), 'evaluation not set')
         # test files get created
         self.assertEqual(os.path.isdir(evaluation.get_dir()), True)
         errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE)
         self.assertEqual(os.path.isfile(errfile), True)
     finally:
         shutil.rmtree(temp_dir)
示例#7
0
    def test_run_succeeds_one_evaluation_and_no_emailer(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.postevaluation = 'echo'
            etask = EvaluationTask(
                temp_dir, 'foo_dock.' + EvaluationTaskFactory.SCORING_SUFFIX,
                None, params)
            etask.create_dir()

            task = PostEvaluationTask(temp_dir, params)
            ctask = ChallengeDataTask(temp_dir, params)
            task.run()

            self.assertEqual(task.get_error(), None)
            self.assertEqual(task.get_status(), D3RTask.COMPLETE_STATUS)
            cfile = os.path.join(task.get_dir(), D3RTask.COMPLETE_FILE)
            self.assertTrue(os.path.isfile(cfile))
            stdout_file = os.path.join(task.get_dir(),
                                       'echo' + D3RTask.STDOUT_SUFFIX)
            self.assertTrue(os.path.isfile(stdout_file))

            f = open(stdout_file, 'r')
            data = f.read()
            f.close()
            ctaskdir = os.path.join(ctask.get_dir(),
                                    ctask.get_celpp_challenge_data_dir_name())

            self.assertTrue(' --evaluationdir ' + etask.get_dir() in data)
            self.assertTrue(' --challengedir ' + ctaskdir in data)

            self.assertTrue('--stageprefix stage.7. --evaluationsuffix ' +
                            '.extsubmission.evaluation$|.evaluation$' in data)

            stderr_file = os.path.join(task.get_dir(),
                                       'echo' + D3RTask.STDERR_SUFFIX)
            self.assertTrue(os.path.isfile(stderr_file))
        finally:
            shutil.rmtree(temp_dir)
示例#8
0
    def test_get_evaluation_tasks_on_with_valid_completed_algo_dir(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            glidetask = GlideTask(temp_dir, params)
            glidetask.create_dir()

            open(os.path.join(glidetask.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()

            etask = EvaluationTask(
                temp_dir,
                glidetask.get_name() + '.' +
                EvaluationTaskFactory.SCORING_SUFFIX, glidetask, params)
            etask.create_dir()
            open(os.path.join(etask.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            stf = EvaluationTaskFactory(temp_dir, params)
            task_list = stf.get_evaluation_tasks()
            self.assertEquals(len(task_list), 0)
        finally:
            shutil.rmtree(temp_dir)
示例#9
0
    def test_get_evaluationdir_args(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            # no evaluation tasks
            task = PostEvaluationTask(temp_dir, params)
            res = task._get_evaluationdir_args()
            self.assertEqual(res, '')

            # one task
            etask = EvaluationTask(temp_dir, 'foo.evaluation', None, params)
            etask.create_dir()
            res = task._get_evaluationdir_args()
            self.assertEqual(
                res, ' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' +
                etask.get_dir())

            # three tasks
            etask2 = EvaluationTask(temp_dir,
                                    'bla_dock.extsubmission.evaluation', None,
                                    params)
            etask2.create_dir()
            open(os.path.join(etask2.get_dir(), D3RTask.ERROR_FILE),
                 'a').close()

            etask3 = EvaluationTask(temp_dir, '12_x.extsubmission.evaluation',
                                    None, params)
            etask3.create_dir()
            cfile = os.path.join(etask3.get_dir(), D3RTask.COMPLETE_FILE)
            open(cfile, 'a').close()

            res = task._get_evaluationdir_args()
            self.assertTrue(' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' +
                            etask.get_dir() in res)
            self.assertTrue(' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' +
                            etask2.get_dir() in res)
            self.assertTrue(' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' +
                            etask3.get_dir() in res)
        finally:
            shutil.rmtree(temp_dir)
示例#10
0
    def test_run_succeeds_one_evaluation_with_emailer(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            foo_script = os.path.join(temp_dir, 'foo.py')
            f = open(foo_script, 'w')
            f.write('#! /usr/bin/env python\n')
            f.write('import sys\nimport os\n')
            f.write('outdir = sys.argv[1]\n')
            f.write('sys.stdout.write(" ".join(sys.argv))\n')
            f.write('f = open(os.path.join(outdir, "summary.txt"),"w")\n')
            f.write('f.write("summary")\n')
            f.write('f.flush()\nf.close()\n')
            f.write('f = open(os.path.join(outdir, "yo.csv"), "a")\n')
            f.write('f.write("hi")\nf.flush()\nf.close()\n')
            f.write('sys.exit(0)\n')
            f.flush()
            f.close()
            os.chmod(foo_script, stat.S_IRWXU)

            params.postevaluation = foo_script
            etask = EvaluationTask(
                temp_dir, 'foo_dock.' + EvaluationTaskFactory.SCORING_SUFFIX,
                None, params)
            etask.create_dir()
            task = PostEvaluationTask(temp_dir, params)

            # setup emailer
            smtpemailer = SmtpEmailer()
            mockserver = D3RParameters()
            mockserver.sendmail = Mock()
            mockserver.quit = Mock()
            smtpemailer.set_alternate_smtp_server(mockserver)
            pee = PostEvaluationEmailer(['*****@*****.**'], smtpemailer)
            task.set_evaluation_emailer(pee)

            ctask = ChallengeDataTask(temp_dir, params)
            task.run()

            self.assertEqual(task.get_error(), None)
            self.assertEqual(task.get_status(), D3RTask.COMPLETE_STATUS)
            cfile = os.path.join(task.get_dir(), D3RTask.COMPLETE_FILE)
            self.assertTrue(os.path.isfile(cfile))
            stdout_file = os.path.join(task.get_dir(),
                                       'foo.py' + D3RTask.STDOUT_SUFFIX)
            self.assertTrue(os.path.isfile(stdout_file))

            f = open(stdout_file, 'r')
            data = f.read()
            f.close()
            ctaskdir = os.path.join(ctask.get_dir(),
                                    ctask.get_celpp_challenge_data_dir_name())

            self.assertTrue(' --evaluationdir ' + etask.get_dir() in data)
            self.assertTrue(' --challengedir ' + ctaskdir in data)

            self.assertTrue('--stageprefix stage.7. --evaluationsuffix ' +
                            '.extsubmission.evaluation$|.evaluation$' in data)

            stderr_file = os.path.join(task.get_dir(),
                                       'foo.py' + D3RTask.STDERR_SUFFIX)

            f = open(stdout_file, 'r')
            data = f.read()
            f.close()
            self.assertTrue(' --evaluationdir ' + etask.get_dir() in data)
            self.assertTrue(os.path.isfile(stderr_file))
            self.assertEqual(task.get_error(), None)
            self.assertTrue('Sent post evaluation email to: '
                            '*****@*****.**' in task.get_email_log())
        finally:
            shutil.rmtree(temp_dir)
示例#11
0
    def test_get_uploadable_files(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            task = EvaluationTask(temp_dir, 'glide',
                                  GlideTask(temp_dir, params), params)
            # try with no dir
            self.assertEqual(task.get_uploadable_files(), [])

            # try with empty dir
            task.create_dir()
            self.assertEqual(task.get_uploadable_files(), [])

            # try with final log
            final_log = os.path.join(task.get_dir(), EvaluationTask.FINAL_LOG)
            open(final_log, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 1)
            flist.index(final_log)

            # try with RMSD.txt
            rmsd = os.path.join(task.get_dir(), EvaluationTask.RMSD_TXT)
            open(rmsd, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 2)
            flist.index(rmsd)

            # try with empty pbdid dir
            pbdid = os.path.join(task.get_dir(), '8www')
            os.mkdir(pbdid)
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 2)
            flist.index(rmsd)

            # try with score/rot-LMCSS_doc_pv_complex1.pdb
            score = os.path.join(pbdid, 'score')
            os.mkdir(score)
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 2)

            LMCSS = os.path.join(score, 'LMCSS-1fcz_1fcz_docked_complex.pdb')
            open(LMCSS, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 3)
            flist.index(LMCSS)

            # try with score/rot-SMCSS_doc_pv_complex1.pdb
            SMCSS = os.path.join(score, 'SMCSS-1fcz_2lbd_docked_complex.pdb')
            open(SMCSS, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 4)
            flist.index(SMCSS)

            # try with score/rot-hiResApo_doc_pv_complex1.pdb
            hiResApo = os.path.join(score,
                                    'hiResHolo-1fcz_1fcy_docked_complex.pdb')
            open(hiResApo, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 5)
            flist.index(hiResApo)

            # try with score/rot-hiResHolo_doc_pv_complex1.pdb
            hiResHolo = os.path.join(
                score, 'hiTanimoto-1fcz_1fcz_docked_complex.pdb')
            open(hiResHolo, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 6)
            flist.index(hiResHolo)

            # try with score/crystal.pdb
            crystal = os.path.join(score, 'crystal.pdb')
            open(crystal, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 7)
            flist.index(crystal)

            # try with RMSD.pickle
            rmsdpickle = os.path.join(task.get_dir(),
                                      EvaluationTask.RMSD_PICKLE)
            open(rmsdpickle, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 8)
            flist.index(rmsdpickle)

            # try with stderr/stdout files
            errfile = os.path.join(task.get_dir(), 'evaluate.py.stderr')
            open(errfile, 'a').close()
            outfile = os.path.join(task.get_dir(), 'evaluate.py.stdout')
            open(outfile, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 10)
            flist.index(crystal)
            flist.index(hiResHolo)
            flist.index(hiResApo)
            flist.index(SMCSS)
            flist.index(LMCSS)
            flist.index(errfile)
            flist.index(outfile)
            flist.index(final_log)
            flist.index(rmsd)
            flist.index(rmsdpickle)
        finally:
            shutil.rmtree(temp_dir)
示例#12
0
    def test_can_run(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            # no dock task found so it cannot run
            docktask = D3RTask(temp_dir, params)
            docktask.set_name('foo')
            docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)

            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            self.assertEqual(evaluation.can_run(), False)
            self.assertEqual(evaluation.get_error(),
                             'foo task has notfound status')

            # docktask  running
            docktask = D3RTask(temp_dir, params)
            docktask.set_name('foo')
            docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)
            docktask.create_dir()
            open(os.path.join(docktask.get_dir(), D3RTask.START_FILE),
                 'a').close()
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            self.assertEqual(evaluation.can_run(), False)
            self.assertEqual(evaluation.get_error(),
                             'foo task has start status')

            # docktask failed
            error_file = os.path.join(docktask.get_dir(), D3RTask.ERROR_FILE)
            open(error_file, 'a').close()
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            self.assertEqual(evaluation.can_run(), False)
            self.assertEqual(evaluation.get_error(),
                             'foo task has error status')

            # docktask success
            os.remove(error_file)
            open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            self.assertEqual(evaluation.can_run(), True)
            self.assertEqual(evaluation.get_error(), None)

            # evaluation task exists already
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            evaluation.create_dir()
            self.assertEqual(evaluation.can_run(), False)
            self.assertEqual(
                evaluation.get_error(),
                evaluation.get_dir_name() +
                ' already exists and status is unknown')

            # evaluation task already complete
            evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask,
                                        params)
            open(os.path.join(evaluation.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            self.assertEqual(evaluation.can_run(), False)
            self.assertEqual(evaluation.get_error(), None)

        finally:
            shutil.rmtree(temp_dir)