示例#1
0
    def test_get_external_submitter_email_valid(self):

        params = D3RParameters()
        dtask = D3RTask('/foo', params)
        dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX)
        task = EvaluationTask('/foo', dtask.get_name(), dtask, params)
        plist = [Participant('1name', '1d3rusername', '12345', '*****@*****.**')]
        # try single email address
        emailer = EvaluationEmailer(ParticipantDatabase(plist), None)
        emails = emailer._get_external_submitter_email(task)
        self.assertEqual(emails[0], '*****@*****.**')
        self.assertEqual(len(emails), 1)
        self.assertEqual(emailer.get_message_log(), None)

        # try multiple email address
        plist = [
            Participant('1name', '1d3rusername', '12345',
                        '[email protected],[email protected]')
        ]
        # try single email address
        emailer = EvaluationEmailer(ParticipantDatabase(plist), None)
        emails = emailer._get_external_submitter_email(task)
        self.assertEqual(emails[0], '*****@*****.**')
        self.assertEqual(emails[1], '*****@*****.**')
        self.assertEqual(len(emails), 2)
        self.assertEqual(emailer.get_message_log(), None)
示例#2
0
    def test_send_external_submission_email_sendmail_exception(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.program = 'foo'
            params.version = '1'
            dtask = D3RTask('/foo', params)
            dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX)
            task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params)
            plist = [
                Participant('1name', '1d3rusername', '12345', '*****@*****.**')
            ]
            # try single email address
            smtpemailer = SmtpEmailer()
            mockserver = D3RParameters()
            mockserver.sendmail = Mock(side_effect=IOError('ha'))
            mockserver.quit = Mock()
            smtpemailer.set_alternate_smtp_server(mockserver)
            emailer = EvaluationEmailer(ParticipantDatabase(plist), None)
            emailer.set_alternate_smtp_emailer(smtpemailer)
            emailer.send_evaluation_email(task)
            mockserver.quit.assert_any_call()
            self.assertEqual(
                emailer.get_message_log(),
                '\nCaught exception trying to email '
                'participant : Caught exception ha\n')

        finally:
            shutil.rmtree(temp_dir)
示例#3
0
    def test_send_external_submission_email_success(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.program = 'foo'
            params.version = '1'
            dtask = D3RTask('/foo', params)
            dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX)
            task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params)
            task.create_dir()
            f = open(task.get_rmsd_txt(), 'w')
            f.write('hi\n')
            f.flush()
            f.close()
            plist = [
                Participant('1name', '1d3rusername', '12345', '*****@*****.**')
            ]
            # try single email address
            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)
            emailer.send_evaluation_email(task)
            mockserver.quit.assert_any_call()
            self.assertEqual(emailer.get_message_log(),
                             '\nSent evaluation email to: [email protected]\n')
            self.assertEqual(mockserver.sendmail.call_count, 1)

        finally:
            shutil.rmtree(temp_dir)
示例#4
0
    def test_get_external_submitter_email_no_participant_email(self):

        params = D3RParameters()
        dtask = D3RTask('/foo', params)
        dtask.set_name('444' + EvaluationTask.EXT_SUBMISSION_SUFFIX)
        task = EvaluationTask('/foo', dtask.get_name(), dtask, params)
        plist = [Participant('1name', '1d3rusername', '444', None)]
        emailer = EvaluationEmailer(ParticipantDatabase(plist), None)
        self.assertEqual(emailer._get_external_submitter_email(task), None)
        self.assertEqual(emailer.get_message_log(),
                         '\nEmail not set for participant\n')
示例#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_send_external_submission_email_no_submitter_email(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         params.program = 'foo'
         params.version = '1'
         dtask = D3RTask('/foo', params)
         dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX)
         task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params)
         plist = [
             Participant('1name', '1d3rusername', '1234', '*****@*****.**')
         ]
         # try single email address
         emailer = EvaluationEmailer(ParticipantDatabase(plist), None)
         smtpemailer = SmtpEmailer()
         emailer.set_alternate_smtp_emailer(smtpemailer)
         emailer.send_evaluation_email(task)
         self.assertEqual(emailer.get_message_log(),
                          '\nNo participant found with guid: 12345\n')
     finally:
         shutil.rmtree(temp_dir)
示例#7
0
    def test_participant_database(self):

        pdb = ParticipantDatabase(None)
        self.assertEqual(pdb.get_participants(), None)
        self.assertEqual(pdb.get_participant_by_guid('bob'), None)

        pdb = ParticipantDatabase([])
        self.assertEqual(len(pdb.get_participants()), 0)
        self.assertEqual(pdb.get_participant_by_guid('bob'), None)
        self.assertEqual(pdb.get_participant_by_guid('bob', exact_match=True),
                         None)
        self.assertEqual(pdb.get_participant_by_guid('guidx'), None)
        self.assertEqual(pdb.get_participant_by_guid('xguid'), None)
        self.assertEqual(pdb.get_participant_by_guid('GUID'), None)

        plist = [
            Participant('1name', '1d3rusername', 'guid', '*****@*****.**'),
            Participant('2name', '2d3rusername', 'guidy', '*****@*****.**'),
            Participant('3name', '3d3rusername', '12345', '*****@*****.**'),
            Participant('4name', '4d3rusername', '567890_foo',
                        '*****@*****.**')
        ]

        pdb = ParticipantDatabase(plist)
        self.assertEqual(pdb.get_participant_by_guid(None), None)
        self.assertEqual(pdb.get_participant_by_guid('bob'), None)
        self.assertEqual(pdb.get_participant_by_guid('guidx'), None)
        self.assertEqual(pdb.get_participant_by_guid('xguid'), None)
        self.assertEqual(pdb.get_participant_by_guid('GUID'), None)

        p = pdb.get_participant_by_guid('guid')
        self.assertEqual(p.get_name(), '1name')

        p = pdb.get_participant_by_guid('guidy')
        self.assertEqual(p.get_name(), '2name')

        p = pdb.get_participant_by_guid('12345')
        self.assertEqual(p.get_name(), '3name')

        p = pdb.get_participant_by_guid('12345', exact_match=True)
        self.assertEqual(p.get_name(), '3name')

        p = pdb.get_participant_by_guid('12345_2')
        self.assertEqual(p.get_name(), '3name')

        p = pdb.get_participant_by_guid('12345_2', exact_match=False)
        self.assertEqual(p.get_name(), '3name')

        p = pdb.get_participant_by_guid('12345_mydock', exact_match=False)
        self.assertEqual(p.get_name(), '3name')

        p = pdb.get_participant_by_guid('12345_my-dock', exact_match=False)
        self.assertEqual(p.get_name(), '3name')

        # Suffixes can't contain underscores
        p = pdb.get_participant_by_guid('12345_my_dock', exact_match=False)
        self.assertEqual(p, None)

        p = pdb.get_participant_by_guid('12345_2', exact_match=True)
        self.assertEqual(p, None)

        p = pdb.get_participant_by_guid('12345_2_b')
        self.assertEqual(p, None)

        # test a longer guid works
        p = pdb.get_participant_by_guid('567890_foo')
        self.assertEqual(p.get_name(), '4name')

        p = pdb.get_participant_by_guid('4567890_foo')
        self.assertEqual(p, None)
    def test_permute_chains_and_take_min_rmsd(self):
        if not (self.has_oechem) or not (self.has_schrodinger):
            sys.stdout.write("Missing essential component. Skipping test.\n")
            return
        test_scale = 'github'
        method_list = ['autodockvina']
        try:
            temp_dir = tempfile.mkdtemp()
            for method in method_list:
                params = D3RParameters()
                params.evaluation = 'evaluate.py'
                params.pdbdb = os.path.abspath('tests/celpp/eval_test_data/'
                                               '%s_test_data/mini_pdb/' %
                                               test_scale)

                # Make blastnfilter task
                blastnfiltertask = BlastNFilterTask(temp_dir, params)
                blastnfiltertask.create_dir()
                open(
                    os.path.join(blastnfiltertask.get_dir(),
                                 D3RTask.COMPLETE_FILE), 'a').close()
                source_dir = os.path.abspath('tests/celpp/eval_test_data/'
                                             '%s_test_data/stage.3.'
                                             'blastnfilter/' % test_scale)
                os.system('cp -r %s/* %s' %
                          (source_dir, blastnfiltertask.get_dir()))

                # Make challengedata task
                challengedatatask = ChallengeDataTask(temp_dir, params)
                challengedatatask.create_dir()
                open(
                    os.path.join(challengedatatask.get_dir(),
                                 D3RTask.COMPLETE_FILE), 'a').close()
                source_dir = os.path.abspath('tests/celpp/eval_test_data/'
                                             '%s_test_data/stage.4.'
                                             'challengedata/' % test_scale)
                os.system('cp -r %s/* %s' %
                          (source_dir, challengedatatask.get_dir()))

                # Make dock task
                docktask = D3RTask(temp_dir, params)
                docktask.set_name(method)
                docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE)
                docktask.create_dir()
                open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE),
                     'a').close()

                source_dir = os.path.abspath('tests/celpp/eval_test_data/'
                                             '%s_test_data/stage.6.%s/' %
                                             (test_scale, method))
                os.system('cp -r %s/* %s' % (source_dir, docktask.get_dir()))
                print 'docktask.get_dir()', docktask.get_dir()
                print 'temp_dir', temp_dir
                task = EvaluationTask(temp_dir, '%s.evaluation' % (method),
                                      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)
                task.set_evaluation_emailer(emailer)

                task.run()
                val = task.get_evaluation_summary()
                self.assertEqual(
                    val, '\nEvaluation of docking\n==================='
                    '==\nTarge'
                    't_PDBID        LMCSS            SMCSS       '
                    '     h'
                    'iResApo         hiResHolo        hiTanimoto '
                    '      '
                    'LMCSS_ori_distance \n\nSummary Statistics\n'
                    '\nNumber_of'
                    '_cases     0                0               '
                    ' 1    '
                    '            0                0              '
                    '  \nAve'
                    'rage                                        '
                    '      '
                    ' 6.447                                     '
                    '       '
                    '  \nMaximum                                '
                    '        '
                    '       6.447                               '
                    '       '
                    '        \nMinimum                           '
                    '       '
                    '             6.447                          '
                    '      '
                    '              \nMedian                      '
                    '       '
                    '                   6.447                    '
                    '      '
                    '                    \n\nIndividual Results\n'
                    '\n5t6d    '
                    '                                            '
                    '  6.44'
                    '7 (2.176 )                                  '
                    '      '
                    '              \n\n')
                self.assertEqual(task.get_error(), None)
        finally:
            # pass
            shutil.rmtree(temp_dir)
示例#9
0
    def test_participant_database(self):

        pdb = ParticipantDatabase(None)
        self.assertEqual(pdb.get_participants(), None)
        self.assertEqual(pdb.get_participant_by_guid('bob'), None)

        pdb = ParticipantDatabase([])
        self.assertEqual(len(pdb.get_participants()), 0)
        self.assertEqual(pdb.get_participant_by_guid('bob'), None)
        self.assertEqual(pdb.get_participant_by_guid('guidx'), None)
        self.assertEqual(pdb.get_participant_by_guid('xguid'), None)
        self.assertEqual(pdb.get_participant_by_guid('GUID'), None)

        plist = [
            Participant('1name', '1d3rusername', 'guid', '*****@*****.**'),
            Participant('2name', '2d3rusername', 'guidy', '*****@*****.**'),
            Participant('3name', '3d3rusername', '12345', '*****@*****.**')
        ]

        pdb = ParticipantDatabase(plist)
        self.assertEqual(pdb.get_participant_by_guid(None), None)
        self.assertEqual(pdb.get_participant_by_guid('bob'), None)
        self.assertEqual(pdb.get_participant_by_guid('guidx'), None)
        self.assertEqual(pdb.get_participant_by_guid('xguid'), None)
        self.assertEqual(pdb.get_participant_by_guid('GUID'), None)

        p = pdb.get_participant_by_guid('guid')
        self.assertEqual(p.get_name(), '1name')

        p = pdb.get_participant_by_guid('guidy')
        self.assertEqual(p.get_name(), '2name')

        p = pdb.get_participant_by_guid('12345')
        self.assertEqual(p.get_name(), '3name')