def test_run_all_compinchi_fail(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.pdbfileurl = 'file://' + temp_dir params.compinchi = 'file://' + temp_dir make_blast = MakeBlastDBTask(temp_dir, params) make_blast.create_dir() open(os.path.join(make_blast.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() task = DataImportTask(temp_dir, params) task._retrysleep = 0 open(os.path.join(temp_dir, task.NONPOLYMER_TSV), 'a').close() open(os.path.join(temp_dir, task.SEQUENCE_TSV), 'a').close() open(os.path.join(temp_dir, task.OLDSEQUENCE_TSV), 'a').close() open(os.path.join(temp_dir, task.CRYSTALPH_TSV), 'a').close() task.run() self.assertEquals( task.get_error(), 'Unable to download file ' + 'from ' + params.compinchi + ' to ' + task.get_components_inchi_file()) finally: shutil.rmtree(temp_dir)
def test_get_uploadable_files(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() task = DataImportTask(temp_dir, params) self.assertEqual(task.get_uploadable_files(), []) task.create_dir() # test empty dir self.assertEqual(task.get_uploadable_files(), []) # test with only compinchi open(task.get_components_inchi_file(), 'a').close() flist = task.get_uploadable_files() self.assertEqual(len(flist), 1) flist.index(task.get_components_inchi_file()) # test with crystal file open(task.get_crystalph_tsv(), 'a').close() flist = task.get_uploadable_files() self.assertEqual(len(flist), 2) flist.index(task.get_components_inchi_file()) flist.index(task.get_crystalph_tsv()) # test with nonpolymer file open(task.get_nonpolymer_tsv(), 'a').close() flist = task.get_uploadable_files() self.assertEqual(len(flist), 3) flist.index(task.get_components_inchi_file()) flist.index(task.get_crystalph_tsv()) flist.index(task.get_nonpolymer_tsv()) # test with sequence file open(task.get_sequence_tsv(), 'a').close() flist = task.get_uploadable_files() self.assertEqual(len(flist), 4) flist.index(task.get_components_inchi_file()) flist.index(task.get_crystalph_tsv()) flist.index(task.get_nonpolymer_tsv()) flist.index(task.get_sequence_tsv()) finally: shutil.rmtree(temp_dir)
def test_download_files_fail(self): temp_dir = tempfile.mkdtemp() try: nonpoly = os.path.join(temp_dir, DataImportTask.NONPOLYMER_TSV) f = open(nonpoly, 'w') f.write('nonpoly\n') f.flush() f.close() seq = os.path.join(temp_dir, DataImportTask.SEQUENCE_TSV) f = open(seq, 'w') f.write('seq\n') f.flush() f.close() oldseq = os.path.join(temp_dir, DataImportTask.OLDSEQUENCE_TSV) f = open(oldseq, 'w') f.write('oldseq\n') f.flush() f.close() crystal = os.path.join(temp_dir, DataImportTask.CRYSTALPH_TSV) f = open(crystal, 'w') f.write('crystal\n') f.flush() f.close() params = D3RParameters() params.skipimportwait = True params.compinchi = 'file://' + temp_dir task = DataImportTask(temp_dir, params) task.create_dir() val = task._download_files('file://' + temp_dir) self.assertEqual( task.get_error(), 'Unable to download file from ' 'file://' + temp_dir + ' to ' + task.get_components_inchi_file()) self.assertFalse(val) finally: shutil.rmtree(temp_dir)
def run(self): """Runs blastnfilter task after verifying dataimport 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 and postanalysis script. Upon completion results are analyzed and success or error status is set appropriately and D3RTask.end is invoked """ super(BlastNFilterTask, self).run() if self._can_run is False: logger.debug(self.get_dir_name() + ' cannot run cause _can_run flag ' 'is False') return data_import = DataImportTask(self._path, self._args) make_blastdb = MakeBlastDBTask(self._path, self._args) try: loglevel = self.get_args().loglevel except AttributeError: logger.debug('No log level set in arguments using WARNING') loglevel = 'WARNING' # verify sequence.tsv file exists on filesystem. # if not fall back to oldsequence.tsv file sequencetsv = data_import.get_sequence_tsv() if not os.path.isfile(sequencetsv): logger.warning(sequencetsv + ' file not found. falling ' 'back to old file') self.append_to_email_log('\n ' + sequencetsv + ' file not found ' + 'falling back to ' + data_import.get_oldsequence_tsv() + '\n') sequencetsv = data_import.get_oldsequence_tsv() cmd_to_run = (self.get_args().blastnfilter + ' --nonpolymertsv ' + data_import.get_nonpolymer_tsv() + ' --sequencetsv ' + sequencetsv + ' --pdbblastdb ' + make_blastdb.get_dir() + ' --compinchi ' + data_import.get_components_inchi_file() + ' --crystalpH ' + data_import.get_crystalph_tsv() + ' --pdbdb ' + self.get_args().pdbdb + ' --log ' + loglevel + ' --outdir ' + self.get_dir()) blastnfilter_name = os.path.basename(self.get_args().blastnfilter) self.run_external_command( blastnfilter_name, cmd_to_run, False, ) self.set_status(D3RTask.COMPLETE_STATUS) cmd_to_run = (self.get_args().postanalysis + ' --compinchi ' + data_import.get_components_inchi_file() + ' ' + self.get_dir()) postanalysis_name = os.path.basename(self.get_args().postanalysis) self.run_external_command(postanalysis_name, cmd_to_run, False) try: # examine output to get candidate hit count DR-12 hit_stats = self._parse_blastnfilter_output_for_hit_stats() if hit_stats is not None: self.append_to_email_log(hit_stats) except Exception: logger.exception("Error caught exception") # assess the result self.end()