Example #1
0
    def test_run_succeeds(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.chimeraprep = 'true'
            params.pdbdb = '/foo'
            chall = ChallengeDataTask(temp_dir, params)
            chall.create_dir()
            open(os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            task = ChimeraProteinLigPrepTask(temp_dir, params)

            task.run()
            self.assertEqual(task.get_error(), None)
            # test files get created
            errfile = os.path.join(task.get_dir(), D3RTask.ERROR_FILE)
            self.assertEqual(os.path.isfile(errfile), False)

            compfile = os.path.join(task.get_dir(), D3RTask.COMPLETE_FILE)
            self.assertEqual(os.path.isfile(compfile), True)
            stderr = os.path.join(task.get_dir(), 'true.stderr')
            self.assertEqual(os.path.isfile(stderr), True)
            stdout = os.path.join(task.get_dir(), 'true.stdout')
            self.assertEqual(os.path.isfile(stdout), True)
        finally:
            shutil.rmtree(temp_dir)
Example #2
0
    def test_run_fails_cause_chimeraprep_fails(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.chimeraprep = 'false'
            params.pdbdb = '/foo'
            chall = ChallengeDataTask(temp_dir, params)
            chall.create_dir()
            open(os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            task = ChimeraProteinLigPrepTask(temp_dir, params)

            task.run()
            self.assertEqual(
                task.get_error(),
                'Non zero exit code: 1 received. Standard out: ' +
                ' Standard error: ')
            # test file gets created
            errfile = os.path.join(task.get_dir(), D3RTask.ERROR_FILE)
            self.assertEqual(os.path.isfile(errfile), True)

            stderr = os.path.join(task.get_dir(), 'false.stderr')
            self.assertEqual(os.path.isfile(stderr), True)
            stdout = os.path.join(task.get_dir(), 'false.stdout')
            self.assertEqual(os.path.isfile(stdout), True)
        finally:
            shutil.rmtree(temp_dir)
Example #3
0
    def test_run_fails_cause_chimeraprep_is_not_found_rdkitpython_set(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.chimeraprep = '/bin/doesnotexist'
            params.pdbdb = '/foo'
            params.rdkitpython = '/data/miniconda2/bin'
            chall = ChallengeDataTask(temp_dir, params)
            chall.create_dir()

            challdir = os.path.join(chall.get_dir(),
                                    chall.get_celpp_challenge_data_dir_name())

            open(os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE),
                 'a').close()
            task = ChimeraProteinLigPrepTask(temp_dir, params)

            task.run()
            self.assertEqual(
                task.get_error(), 'Caught Exception trying to run ' +
                '/bin/doesnotexist --candidatedir ' + challdir +
                ' --rdkitpython \'/data/miniconda2/bin\' ' + '--pdbdb ' +
                '/foo --outdir ' + task.get_dir() +
                ' : [Errno 2] No such file or directory')

            # test files get created
            errfile = os.path.join(task.get_dir(), D3RTask.ERROR_FILE)
            self.assertEqual(os.path.isfile(errfile), True)
        finally:
            shutil.rmtree(temp_dir)
Example #4
0
    def test_upload_challenge_file_uploader_successful(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            yeardir = os.path.join(temp_dir, '2017')
            os.mkdir(yeardir)
            weekdir = os.path.join(yeardir, 'dataset.week.1')
            os.mkdir(weekdir)
            chall = ChallengeDataTask(weekdir, params)
            chall.create_dir()

            mockftp = D3RParameters()
            mockftp.put = Mock(side_effect=[3, 5])
            ftp = FtpFileTransfer(None)
            ftp.set_remote_challenge_dir('/challenge')
            ftp.set_connection(mockftp)
            ftp.connect()
            chall.set_file_transfer(ftp)
            tarball = os.path.join(chall.get_dir(), 'celppweek1_2017.tar.gz')
            f = open(tarball, 'w')
            f.write('hi')
            f.flush()
            f.close()
            latest_file = os.path.join(chall.get_dir(),
                                       ChallengeDataTask.LATEST_TXT)
            chall._upload_challenge_file(tarball)

            f = open(latest_file, 'r')
            line = f.readline()
            self.assertEqual(line, 'celppweek1_2017.tar.gz')
            f.close()
            ftp.disconnect()
        finally:
            shutil.rmtree(temp_dir)
Example #5
0
    def test_upload_challenge_file_uploader_upload_fails(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            yeardir = os.path.join(temp_dir, '2016')
            os.mkdir(yeardir)
            weekdir = os.path.join(yeardir, 'dataset.week.50')
            os.mkdir(weekdir)
            chall = ChallengeDataTask(weekdir, params)
            chall.create_dir()

            mockftp = D3RParameters()
            mockftp.put = Mock(side_effect=IOError('hi'))
            ftp = FtpFileTransfer(None)
            ftp.set_remote_challenge_dir('/challenge')
            ftp.set_connection(mockftp)
            ftp.connect()
            chall.set_file_transfer(ftp)
            tarball = os.path.join(chall.get_dir(), 'celppweek50_2016.tar.gz')
            f = open(tarball, 'w')
            f.write('hi')
            f.flush()
            f.close()
            try:
                chall._upload_challenge_file(tarball)
                self.fail('Expected exception')
            except Exception as e:
                self.assertEqual(str(e),
                                 'Unable to upload ' + tarball +
                                 ' to /challenge/celppweek50_2016.tar.gz : ' +
                                 'hi')
            ftp.disconnect()
        finally:
            shutil.rmtree(temp_dir)
Example #6
0
 def test_get_celpp_challenge_data_dir_name_not_standard_dir(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         task = ChallengeDataTask(temp_dir, params)
         task.create_dir()
         self.assertEqual(task.get_celpp_challenge_data_dir_name(),
                          'celpp_week0_0')
     finally:
         shutil.rmtree(temp_dir)
Example #7
0
    def test_can_run(self):
        temp_dir = tempfile.mkdtemp()
        try:
            # no blast task found so it cannot run
            params = D3RParameters()
            task = ChallengeDataTask(temp_dir, params)
            self.assertEqual(task.can_run(), False)
            self.assertEqual(task.get_error(),
                             'blastnfilter task has notfound status')

            # blastn filter running
            blastnfilter = BlastNFilterTask(temp_dir, params)
            blastnfilter.create_dir()
            open(os.path.join(blastnfilter.get_dir(), D3RTask.START_FILE),
                 'a').close()
            task = ChallengeDataTask(temp_dir, params)
            self.assertEqual(task.can_run(), False)
            self.assertEqual(task.get_error(),
                             'blastnfilter task has start status')

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

            # blastnfilter success
            os.remove(error_file)
            open(os.path.join(blastnfilter.get_dir(),
                              D3RTask.COMPLETE_FILE), 'a').close()
            task = ChallengeDataTask(temp_dir, params)
            self.assertEqual(task.can_run(), True)
            self.assertEqual(task.get_error(), None)

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

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

        finally:
            shutil.rmtree(temp_dir)
Example #8
0
    def test_copy_over_tsv_files(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            dimport = DataImportTask(temp_dir, params)
            dimport.create_dir()

            ctsv = dimport.get_crystalph_tsv()
            f = open(ctsv, 'w')
            f.write('crystal')
            f.flush()
            f.close()

            nonpoly = dimport.get_nonpolymer_tsv()
            f = open(nonpoly, 'w')
            f.write('nonpoly')
            f.flush()
            f.close()

            seq = dimport.get_sequence_tsv()
            f = open(seq, 'w')
            f.write('seq')
            f.flush()
            f.close()

            task = ChallengeDataTask(temp_dir, params)
            task.create_dir()
            challenge_dir = task._create_challenge_dir()
            self.assertEqual(os.path.isdir(challenge_dir), True)
            task._copy_over_tsv_files(challenge_dir)

            cop_ctsv = os.path.join(challenge_dir,
                                    DataImportTask.CRYSTALPH_TSV)
            self.assertEqual(os.path.isfile(cop_ctsv), True)
            f = open(cop_ctsv)
            self.assertEqual(f.readline(), 'crystal')
            f.close()

            cop_nonpoly = os.path.join(challenge_dir,
                                       DataImportTask.NONPOLYMER_TSV)
            self.assertEqual(os.path.isfile(cop_nonpoly), True)
            f = open(cop_nonpoly)
            self.assertEqual(f.readline(), 'nonpoly')
            f.close()

            cop_seq = os.path.join(challenge_dir,
                                   DataImportTask.SEQUENCE_TSV)
            self.assertEqual(os.path.isfile(cop_seq), True)
            f = open(cop_seq)
            self.assertEqual(f.readline(), 'seq')
            f.close()

        finally:
            shutil.rmtree(temp_dir)
Example #9
0
    def test_copy_over_tsv_files_no_dataimport(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            task = ChallengeDataTask(temp_dir, params)
            task.create_dir()
            challenge_dir = task._create_challenge_dir()
            self.assertEqual(os.path.isdir(challenge_dir), True)
            task._copy_over_tsv_files(challenge_dir)

        finally:
            shutil.rmtree(temp_dir)
Example #10
0
    def test_get_celpp_challenge_data_dir_name(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            cyear = os.path.join(temp_dir, '2016')
            cweek = os.path.join(cyear, 'dataset.week.5')
            os.mkdir(cyear)
            os.mkdir(cweek)
            task = ChallengeDataTask(cweek, params)
            task.create_dir()
            self.assertEqual(task.get_celpp_challenge_data_dir_name(),
                             'celpp_week5_2016')

        finally:
            shutil.rmtree(temp_dir)
Example #11
0
 def test_run_fails_cause_chimeraprep_not_set(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         chall = ChallengeDataTask(temp_dir, params)
         chall.create_dir()
         open(os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE),
              'a').close()
         task = ChimeraProteinLigPrepTask(temp_dir, params)
         task.run()
         self.assertEqual(task.get_error(), 'chimeraprep not set')
         # test files get created
         self.assertEqual(os.path.isdir(task.get_dir()), True)
         errfile = os.path.join(task.get_dir(), D3RTask.ERROR_FILE)
         self.assertEqual(os.path.isfile(errfile), True)
     finally:
         shutil.rmtree(temp_dir)
Example #12
0
    def test_tar_challenge_dir(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            dimport = DataImportTask(temp_dir, params)
            dimport.create_dir()
            open(dimport.get_sequence_tsv(), 'a').close()
            open(dimport.get_nonpolymer_tsv(), 'a').close()
            open(dimport.get_crystalph_tsv(), 'a').close()

            task = ChallengeDataTask(temp_dir, params)
            task.create_dir()
            chall_dir = task._create_challenge_dir()

            final_log = os.path.join(chall_dir, 'final.log')
            open(final_log, 'a').close()

            task._create_readme(chall_dir)
            task._copy_over_tsv_files(chall_dir)

            # make a fake candidate
            file_list = self.make_fake_candidate_dir(chall_dir, '5hib',
                                                     '2eb2', 'CSX')

            self.assertEqual(os.path.isdir(chall_dir), True)
            name = task.get_celpp_challenge_data_dir_name()
            tfile = task._tar_challenge_dir(name)
            self.assertEqual(os.path.isfile(tfile), True)

            foodir = os.path.join(temp_dir, 'foo')
            tar = tarfile.open(tfile, 'r:*')
            tar.extractall(path=foodir)
            tar.close()
            cdir = os.path.join(foodir, name)
            readme = os.path.join(cdir, ChallengeDataTask.README_TXT_FILE)
            self.assertEqual(os.path.isfile(readme), True)

            final_log = os.path.join(foodir, 'final.log')
            self.assertEqual(os.path.isfile(final_log), False)

            for fname in file_list:
                chk = os.path.join(cdir, fname)
                self.assertEqual(os.path.isfile(chk), True, chk)

        finally:
            shutil.rmtree(temp_dir)
Example #13
0
    def test_get_uploadable_files(self):
        temp_dir = tempfile.mkdtemp()
        try:
            # test where directory doesn't even exist
            params = D3RParameters()
            task = ChallengeDataTask(temp_dir, params)
            self.assertEqual(task.get_uploadable_files(), [])

            # test on empty dir
            task.create_dir()
            self.assertEqual(task.get_uploadable_files(), [])

            # test with tarfile
            tarfile = task.get_celpp_challenge_data_tar_file()

            open(tarfile, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 1)
            flist.index(tarfile)

            # test with additional stderr/stdout files
            errfile = os.path.join(task.get_dir(),
                                   'genchallengedata.py.stderr')
            open(errfile, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 2)
            flist.index(errfile)

            outfile = os.path.join(task.get_dir(),
                                   'genchallengedata.py.stdout')
            open(outfile, 'a').close()
            flist = task.get_uploadable_files()
            self.assertEqual(len(flist), 3)
            flist.index(outfile)
            flist.index(errfile)
            flist.index(tarfile)

        finally:
            shutil.rmtree(temp_dir)
Example #14
0
    def test_create_challenge_dir_unable_to_make_dir(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            cyear = os.path.join(temp_dir, '2016')
            cweek = os.path.join(cyear, 'dataset.week.5')
            os.mkdir(cyear)
            os.mkdir(cweek)
            task = ChallengeDataTask(cweek, params)
            task.create_dir()
            cdir = os.path.join(task.get_dir(),
                                task.get_celpp_challenge_data_dir_name())
            open(cdir, 'a').close()

            try:
                task._create_challenge_dir()
                self.fail('Expected OSError')
            except OSError:
                pass

        finally:
            shutil.rmtree(temp_dir)
Example #15
0
    def test_tar_challenge_dir_nothing_but_readme(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            task = ChallengeDataTask(temp_dir, params)
            task.create_dir()
            chall_dir = task._create_challenge_dir()
            task._create_readme(chall_dir)

            self.assertEqual(os.path.isdir(chall_dir), True)
            name = task.get_celpp_challenge_data_dir_name()
            tfile = task._tar_challenge_dir(name)
            self.assertEqual(os.path.isfile(tfile), True)

            foodir = os.path.join(temp_dir, 'foo')
            tar = tarfile.open(tfile, 'r:*')
            tar.extractall(path=foodir)
            tar.close()
            cdir = os.path.join(foodir, name)
            readme = os.path.join(cdir, ChallengeDataTask.README_TXT_FILE)
            self.assertEqual(os.path.isfile(readme), True)

        finally:
            shutil.rmtree(temp_dir)
    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)