def test_run_fails_cause_genchallenge_is_not_found(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.genchallenge = '/bin/doesnotexist' params.pdbdb = '/foo' params.version = '1' blastnfilter = BlastNFilterTask(temp_dir, params) blastnfilter.create_dir() open(os.path.join(blastnfilter.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() chall = ChallengeDataTask(temp_dir, params) chall.run() self.assertEqual(chall.get_error(), 'Caught Exception trying to run ' + '/bin/doesnotexist --candidatedir ' + blastnfilter.get_dir() + ' --pdbdb ' + '/foo --outdir ' + chall.get_dir() + '/' + chall.get_celpp_challenge_data_dir_name() + ' : [Errno 2] No such file or directory') # test files get created errfile = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), True) finally: shutil.rmtree(temp_dir)
def test_run_fails_cause_genchallenge_fails(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.genchallenge = 'false' params.pdbdb = '/foo' params.version = '1' blastnfilter = BlastNFilterTask(temp_dir, params) blastnfilter.create_dir() open(os.path.join(blastnfilter.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() chall = ChallengeDataTask(temp_dir, params) chall.run() self.assertEqual(chall.get_error(), 'Non zero exit code: 1 received. Standard out: ' + ' Standard error: ') # test file gets created errfile = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), True) stderr = os.path.join(chall.get_dir(), 'false.stderr') self.assertEqual(os.path.isfile(stderr), True) stdout = os.path.join(chall.get_dir(), 'false.stdout') self.assertEqual(os.path.isfile(stdout), True) finally: shutil.rmtree(temp_dir)
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)
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)
def test_run_success_with_ftp_upload(self): temp_dir = tempfile.mkdtemp() try: script = self.create_gen_challenge_script(temp_dir) params = D3RParameters() params.genchallenge = script params.pdbdb = '/foo' params.version = '1' blastnfilter = BlastNFilterTask(temp_dir, params) blastnfilter.create_dir() open(os.path.join(blastnfilter.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() chall = ChallengeDataTask(temp_dir, params) mockftp = D3RParameters() mockftp.put = Mock(side_effect=[3, 5]) ftp = FtpFileTransfer(None) ftp.set_remote_challenge_dir('/challenge') ftp.set_connection(mockftp) chall.set_file_transfer(ftp) 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() chall.run() self.assertEqual(chall.get_error(), None) # verify test files get created errfile = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), False) compfile = os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE) self.assertEqual(os.path.isfile(compfile), True) ftp.disconnect() finally: shutil.rmtree(temp_dir)
def test_can_run(self): temp_dir = tempfile.mkdtemp() try: # no blast task found so it cannot run params = D3RParameters() proteinligprep = ProteinLigPrepTask(temp_dir, params) self.assertEqual(proteinligprep.can_run(), False) self.assertEqual(proteinligprep.get_error(), 'challengedata task has notfound status') # challenge filter running chall = ChallengeDataTask(temp_dir, params) chall.create_dir() open(os.path.join(chall.get_dir(), D3RTask.START_FILE), 'a').close() proteinligprep = ProteinLigPrepTask(temp_dir, params) self.assertEqual(proteinligprep.can_run(), False) self.assertEqual(proteinligprep.get_error(), 'challengedata task has start status') # blastnfilter failed error_file = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) open(error_file, 'a').close() proteinligprep = ProteinLigPrepTask(temp_dir, params) self.assertEqual(proteinligprep.can_run(), False) self.assertEqual(proteinligprep.get_error(), 'challengedata task has error status') # blastnfilter success os.remove(error_file) open(os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() proteinligprep = ProteinLigPrepTask(temp_dir, params) self.assertEqual(proteinligprep.can_run(), True) self.assertEqual(proteinligprep.get_error(), None) # proteinligprep task exists already proteinligprep = ProteinLigPrepTask(temp_dir, params) proteinligprep.create_dir() self.assertEqual(proteinligprep.can_run(), False) self.assertEqual( proteinligprep.get_error(), proteinligprep.get_dir_name() + ' already exists and status is unknown') # proteinlibprep already complete proteinligprep = ProteinLigPrepTask(temp_dir, params) open(os.path.join(proteinligprep.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() self.assertEqual(proteinligprep.can_run(), False) self.assertEqual(proteinligprep.get_error(), None) finally: shutil.rmtree(temp_dir)
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)
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)
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)
def run(self): """Runs ChimeraProteinLigPrepTask after verifying BlastNFilterTask was good Method requires can_run() to be called before hand with successful outcome Otherwise method invokes D3RTask.start then this method creates a directory and invokes blastnfilter script. Upon completion results are analyzed and success or error status is set appropriately and D3RTask.end is invoked """ super(ChimeraProteinLigPrepTask, self).run() if self._can_run is False: logger.debug(self.get_dir_name() + ' cannot run cause _can_run flag ' 'is False') return try: logger.debug('chimeraprep set to ' + self.get_args().chimeraprep) except AttributeError: self.set_error('chimeraprep not set') self.end() return try: logger.debug('pdbdb set to ' + self.get_args().pdbdb) except AttributeError: self.set_error('pdbdb not set') self.end() return rdkitpython = '' try: logger.debug('rdkitpython set to ' + self.get_args().rdkitpython) rdkitpython = self.get_args().rdkitpython except AttributeError: logger.debug chall = ChallengeDataTask(self._path, self._args) # # chimeraprep.py --candidatedir <path to stage.3.challengedata> \ # --outdir <path to stage.4.chimeraligprep> challdir = os.path.join(chall.get_dir(), chall.get_celpp_challenge_data_dir_name()) cmd_to_run = (self.get_args().chimeraprep + ' --candidatedir ' + challdir + ' --rdkitpython \'' + rdkitpython + '\'' + ' --pdbdb ' + self.get_args().pdbdb + ' --outdir ' + self.get_dir()) chimeraprep_name = os.path.basename(self.get_args().chimeraprep) self.run_external_command(chimeraprep_name, cmd_to_run, True) # assess the result self.end()
def test_run_fails_cause_genchallenge_not_set(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.version = '1' blastnfilter = BlastNFilterTask(temp_dir, params) blastnfilter.create_dir() open(os.path.join(blastnfilter.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() chall = ChallengeDataTask(temp_dir, params) chall.run() self.assertEqual(chall.get_error(), 'genchallenge not set') # test files get created self.assertEqual(os.path.isdir(chall.get_dir()), True) errfile = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), True) finally: shutil.rmtree(temp_dir)
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)
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)
def test_create_challenge_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()) task._create_challenge_dir() self.assertEqual(os.path.isdir(cdir), True) task._create_challenge_dir() self.assertEqual(os.path.isdir(cdir), True) finally: shutil.rmtree(temp_dir)
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)
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)
def run(self): """Runs EvaluationTask after verifying dock was good Method requires can_run() to be called before hand with successful outcome Otherwise method invokes D3RTask.start then this method creates a directory and invokes evaluation script. Upon completion results are analyzed and success or error status is set appropriately and D3RTask.end is invoked """ super(EvaluationTask, self).run() if self._can_run is False: logger.debug(self.get_dir_name() + ' cannot run cause _can_run flag ' 'is False') return try: logger.debug('evaluation set to ' + self.get_args().evaluation) except AttributeError: self.set_error('evaluation not set') self.end() return try: logger.debug('pdbdb set to ' + self.get_args().pdbdb) except AttributeError: self.set_error('pdbdb not set') self.end() return try: evaltimeout = self.get_args().evaluationtimeout logger.debug('Setting evaluation timeout to ' + str(evaltimeout)) except AttributeError: evaltimeout = None try: killdelay = self.get_args().evaluationtimeoutkilldelay logger.debug('Setting evaluation kill delay to ' + str(killdelay)) except AttributeError: killdelay = 60 blastnfilter = BlastNFilterTask(self._path, self._args) challenge = ChallengeDataTask(self._path, self._args) challdir = os.path.join(challenge.get_dir(), challenge.get_celpp_challenge_data_dir_name()) # # --pdbdb <path to pdb.extracted> --dockdir <stage.4.glide> \ # --outdir <path to stage.5.glide.evaluation> # cmd_to_run = (self.get_args().evaluation + ' --pdbdb ' + self.get_args().pdbdb + ' --dockdir ' + self._docktask.get_dir() + ' --blastnfilterdir ' + blastnfilter.get_dir() + ' --challengedir ' + challdir + ' --outdir ' + self.get_dir()) eval_name = os.path.basename(self.get_args().evaluation) ecode = self.run_external_command(eval_name, cmd_to_run, False, timeout=evaltimeout, kill_delay=killdelay) # write out evaluate exit code file self._write_evaluate_exitcode_file(ecode) # attempt to send evaluation email try: self._emailer.send_evaluation_email(self) self.append_to_email_log(self._emailer.get_message_log()) except Exception as e: logger.exception('Caught exception trying to send evaluation ' 'email') self.append_to_email_log('Caught exception trying to send ' 'evaluation email ' + str(e) + '\n') # assess the result self.end()
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)
def run(self): """Runs PostEvaluationTask Method requires can_run() to be called before hand with successful outcome Otherwise method invokes D3RTask.start then this method creates a directory and invokes evaluation script. Upon completion results are analyzed and success or error status is set appropriately and D3RTask.end is invoked """ super(PostEvaluationTask, self).run() if self._can_run is False: logger.debug(self.get_dir_name() + ' cannot run cause _can_run flag ' 'is False') return try: logger.debug('postevaluation set to ' + self.get_args().postevaluation) except AttributeError: self.set_error('postevaluation not set') self.end() return # # --evaluationdir <path to stage.X.evaluation> # --evaluationdir <path to another etc...> # --challengedir <path to challenge dir ie # stage.4.challengedata/celpp_week10_2017> # chall = ChallengeDataTask(self.get_path(), self.get_args()) chall_dname = chall.get_celpp_challenge_data_dir_name() evaldir_args = self._get_evaluationdir_args() if evaldir_args is not '': cmd_to_run = (self.get_args().postevaluation + ' ' + self.get_dir() + ' ' + evaldir_args + ' --challengedir ' + os.path.join(chall.get_dir(), chall_dname) + ' --stageprefix ' + self._eval_task_prefix_str + ' --evaluationsuffix ' + self._eval_task_suffix_str) peval_name = os.path.basename(self.get_args().postevaluation) self.run_external_command(peval_name, cmd_to_run, True) else: self.set_error('Did not find any Evaluation tasks to summarize') # attempt to send postevaluation email try: self._emailer.send_postevaluation_email(self) self.append_to_email_log(self._emailer.get_message_log()) except Exception as e: logger.exception('Caught exception trying to send ' 'postevaluation email') self.append_to_email_log('Caught exception trying to send ' 'evaluation email ' + str(e) + '\n') # assess the result self.end()
def test_run_succeeds_no_ftp(self): temp_dir = tempfile.mkdtemp() try: script = self.create_gen_challenge_script(temp_dir) params = D3RParameters() params.genchallenge = script params.pdbdb = '/foo' params.version = '1' blastnfilter = BlastNFilterTask(temp_dir, params) blastnfilter.create_dir() open(os.path.join(blastnfilter.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() chall = ChallengeDataTask(temp_dir, params) 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() chall.run() self.assertEqual(chall.get_error(), None) # verify test files get created errfile = os.path.join(chall.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), False) compfile = os.path.join(chall.get_dir(), D3RTask.COMPLETE_FILE) self.assertEqual(os.path.isfile(compfile), True) stderr = os.path.join(chall.get_dir(), 'genchallenge.py.stderr') self.assertEqual(os.path.isfile(stderr), True) stdout = os.path.join(chall.get_dir(), 'genchallenge.py.stdout') self.assertEqual(os.path.isfile(stdout), True) # verify challenge directory is created and # filled with valid files chall_dir = os.path.join(chall.get_dir(), chall.get_celpp_challenge_data_dir_name()) self.assertEqual(os.path.isdir(chall_dir), True) readme = os.path.join(chall_dir, ChallengeDataTask.README_TXT_FILE) self.assertEqual(os.path.isfile(readme), True) crystal = os.path.join(chall_dir, DataImportTask.CRYSTALPH_TSV) self.assertEqual(os.path.isfile(crystal), True) seq = os.path.join(chall_dir, DataImportTask.SEQUENCE_TSV) self.assertEqual(os.path.isfile(seq), True) nonpoly = os.path.join(chall_dir, DataImportTask.NONPOLYMER_TSV) self.assertEqual(os.path.isfile(nonpoly), True) fivehibdir = os.path.join(chall_dir, '5hib') fivehibtxt = os.path.join(fivehibdir, '5hib.txt') self.assertEqual(os.path.isfile(fivehibtxt), True) fivehibfas = os.path.join(fivehibdir, '5hib.fasta') self.assertEqual(os.path.isfile(fivehibfas), True) fivehicdir = os.path.join(chall_dir, '5hic') fivehictxt = os.path.join(fivehicdir, '5hic.txt') self.assertEqual(os.path.isfile(fivehictxt), True) fivehicfas = os.path.join(fivehicdir, '5hic.fasta') self.assertEqual(os.path.isfile(fivehicfas), True) # verify tarball is created tfile = chall.get_celpp_challenge_data_tar_file() self.assertEqual(os.path.isfile(tfile), True) foodir = os.path.join(temp_dir, 'foo') os.mkdir(foodir) tar = tarfile.open(tfile, 'r:*') tar.extractall(path=foodir) tar.close() name = chall.get_celpp_challenge_data_dir_name() cdir = os.path.join(foodir, name) readme = os.path.join(cdir, ChallengeDataTask.README_TXT_FILE) self.assertEqual(os.path.isfile(readme), True) final = os.path.join(foodir, name, 'final.log') self.assertEqual(os.path.isfile(final), False) e_con = os.path.join(foodir, name, 'error_container') self.assertEqual(os.path.isdir(e_con), False) 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)