Beispiel #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)
Beispiel #2
0
    def test_create_readme_version_empty_summary(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.version = '1.0'
            task = ChallengeDataTask(temp_dir, params)
            blast = BlastNFilterTask(temp_dir, params)
            blast.create_dir()
            sfile = blast.get_blastnfilter_summary_file()
            open(sfile, 'a').close()

            task._create_readme(temp_dir)
            readme = os.path.join(temp_dir,
                                  ChallengeDataTask.README_TXT_FILE)
            self.assertEqual(os.path.isfile(readme), True)
            f = open(readme, 'r')
            found = False
            for line in f:

                if re.match('^Celpprunner version: 1.0.*$', line):
                    found = True
                    break

            f.close()
            self.assertEqual(found, True)

        finally:
            shutil.rmtree(temp_dir)
Beispiel #3
0
    def test_create_readme(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            params.version = '1.0'
            task = ChallengeDataTask(temp_dir, params)
            blast = BlastNFilterTask(temp_dir, params)
            blast.create_dir()
            sfile = blast.get_blastnfilter_summary_file()
            f = open(sfile, 'w')
            f.write('hello there\n')
            f.flush()
            f.close()

            task._create_readme(temp_dir)
            readme = os.path.join(temp_dir,
                                  ChallengeDataTask.README_TXT_FILE)
            self.assertEqual(os.path.isfile(readme), True)
            f = open(readme, 'r')
            found = False
            for line in f:
                print line
                if re.match('^hello there.*$', line):
                    found = True
                    break

            f.close()
            self.assertEqual(found, True)

        finally:
            shutil.rmtree(temp_dir)
Beispiel #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)
Beispiel #5
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)
Beispiel #6
0
    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()
Beispiel #7
0
 def test_get_celpp_challenge_data_dir_name_path_not_found(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         task = ChallengeDataTask(temp_dir, params)
         self.assertEqual(task.get_celpp_challenge_data_dir_name(),
                          'celpp_week0_0')
     finally:
         shutil.rmtree(temp_dir)
Beispiel #8
0
    def __init__(self, path, args):
        super(ProteinLigPrepTask, self).__init__(path, args)
        self.set_name(ProteinLigPrepTask.TASK_NAME)

        # Make stage number one higher then BlastNFilter Stage
        chall = ChallengeDataTask(path, args)
        self.set_stage(chall.get_stage() + 1)

        self.set_status(D3RTask.UNKNOWN_STATUS)
Beispiel #9
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)
Beispiel #10
0
 def test_upload_challenge_file_uploader_is_none(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         chall = ChallengeDataTask(temp_dir, params)
         chall._upload_challenge_file('/foo')
         self.assertEqual(chall.get_email_log(), 'No uploader available '
                                                 'to upload challenge '
                                                 'data\n')
     finally:
         shutil.rmtree(temp_dir)
Beispiel #11
0
 def test_run_fails_cause_can_run_is_false(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         params.version = '1'
         # return immediately cause can_run is false
         chall = ChallengeDataTask(temp_dir, params)
         chall.run()
         self.assertEqual(chall.get_error(),
                          'blastnfilter task has notfound status')
     finally:
         shutil.rmtree(temp_dir)
Beispiel #12
0
    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)
Beispiel #13
0
 def __init__(self, path, args):
     """Constructor
     """
     try:
         logger.debug('ftpconfig set to ' + args.ftpconfig)
         self._file_transfer = FtpFileTransfer(args.ftpconfig)
     except Exception:
         logger.exception('Caught exception')
         self._file_transfer = None
     self._path = path
     self._args = args
     ctask = ChallengeDataTask(path, args)
     self._chall_dir_name = ctask.get_celpp_challenge_data_dir_name()
Beispiel #14
0
 def test_create_readme_unable_to_write_file(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         params.version = "1.0.0"
         task = ChallengeDataTask(temp_dir, params)
         try:
             task._create_readme(os.path.join(temp_dir, 'doesnotexist'))
             self.fail('Expected IOError')
         except IOError:
             pass
     finally:
         shutil.rmtree(temp_dir)
Beispiel #15
0
    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)
Beispiel #16
0
    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)
Beispiel #17
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)
Beispiel #18
0
    def test_tar_challenge_dir_unable_to_write_tarfile(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            task = ChallengeDataTask(temp_dir, params)

            chall_dir = task.get_celpp_challenge_data_dir_name()
            try:
                task._tar_challenge_dir(chall_dir)
                self.fail('Expected IOError')
            except IOError:
                pass

        finally:
            shutil.rmtree(temp_dir)
Beispiel #19
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)
Beispiel #20
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)
Beispiel #21
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)
Beispiel #22
0
    def test_create_readme_version_unset_and_no_summary_txt(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()
            task = ChallengeDataTask(temp_dir, params)
            task._create_readme(temp_dir)
            readme = os.path.join(temp_dir,
                                  ChallengeDataTask.README_TXT_FILE)
            self.assertEqual(os.path.isfile(readme), True)
            f = open(readme, 'r')
            found = False
            for line in f:

                if re.match('^Celpprunner version: Unknown.*$', line):
                    found = True
                    break

            f.close()
            self.assertEqual(found, True)

        finally:
            shutil.rmtree(temp_dir)
Beispiel #23
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)
Beispiel #24
0
    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)
Beispiel #25
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)
Beispiel #26
0
    def test_upload_challenge_file_challenge_file_is_none(self):
        temp_dir = tempfile.mkdtemp()
        try:
            params = D3RParameters()

            chall = ChallengeDataTask(temp_dir, params)
            chall._upload_challenge_file(None)
            chall.set_file_transfer(params)
            self.assertEqual(chall.get_email_log(), 'challenge_file is None in'
                                                    ' _upload_challenge_file'
                                                    '\n')
        finally:
            shutil.rmtree(temp_dir)
Beispiel #27
0
 def test_upload_challenge_file_no_remote_challenge_dir(self):
     temp_dir = tempfile.mkdtemp()
     try:
         params = D3RParameters()
         chall = ChallengeDataTask(temp_dir, params)
         ftp = FtpFileTransfer(None)
         chall.set_file_transfer(ftp)
         chall._upload_challenge_file('/foo')
         self.assertEqual(chall.get_email_log(), 'No remote challenge'
                                                 ' directory set for '
                                                 'ftp upload\n')
     finally:
         shutil.rmtree(temp_dir)
Beispiel #28
0
    def can_run(self):
        """Determines if task can actually run

           This method first verifies the `BlastNFilterTask` task
           has `D3RTask.COMPLETE_STATUS` for
           status.  The method then verifies a `ProteinLigPrepTask` does
           not already exist.  If above is not true then self.set_error()
           is set with information about the issue
           :return: True if can run otherwise False
        """
        self._can_run = False
        self._error = None
        # check blast
        chall = ChallengeDataTask(self._path, self._args)
        chall.update_status_from_filesystem()
        if chall.get_status() != D3RTask.COMPLETE_STATUS:
            logger.info('Cannot run ' + self.get_name() + 'task ' +
                        'because ' + chall.get_name() + 'task' +
                        'has a status of ' + chall.get_status())
            self.set_error(chall.get_name() + ' task has ' +
                           chall.get_status() + ' status')
            return False

        # check this task is not complete and does not exist

        self.update_status_from_filesystem()
        if self.get_status() == D3RTask.COMPLETE_STATUS:
            logger.debug("No work needed for " + self.get_name() + " task")
            return False

        if self.get_status() != D3RTask.NOTFOUND_STATUS:
            logger.warning(self.get_name() + " task was already " +
                           "attempted, but there was a problem")
            self.set_error(self.get_dir_name() + ' already exists and ' +
                           'status is ' + self.get_status())
            return False
        self._can_run = True
        return True
Beispiel #29
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)
Beispiel #30
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)