def run(self): _LOG.debug('launching %s.' % " ".join(self._invocation)) k = self._k proc_cwd = k.get('cwd', os.curdir) stdout_file_path = k.get('stdout', None) stderr_file_path = k.get('stderr', None) if stdout_file_path: _stdout_fo = open_with_intermediates(stdout_file_path, 'w') else: _stdout_fo = open_with_intermediates( os.path.join(proc_cwd, '.Job.stdout.txt'), 'w') k['stdout'] = _stdout_fo if stderr_file_path: _stderr_fo = open_with_intermediates(stderr_file_path, 'w') else: _stderr_fo = open_with_intermediates( os.path.join(proc_cwd, '.Job.stderr.txt'), 'w') k['stderr'] = _stderr_fo for key, v in self.environ.items(): os.environ[key] = v process = Popen(self._invocation, stdin=PIPE, **k) err_msg = [] err_msg.append( "PASTA failed because one of the programs it tried to run failed.") err_msg.append('The invocation that failed was: \n "%s"\n' % '" "'.join(self._invocation)) try: self.return_code = process.wait() _stdout_fo.close() _stderr_fo.close() process.stdin.close() if self.return_code: errorFromFile = self.read_stderr(_stderr_fo) if errorFromFile: err_msg.append(errorFromFile) self.error = "\n".join(err_msg) raise Exception("") _LOG.debug( 'Finished %s.\n Return code: %s; %s' % (" ".join(self._invocation), self.return_code, self.error)) except Exception as e: err_msg.append(str(e)) self.error = "\n".join(err_msg) _LOG.error(self.error)
def save_to_filepath(self, filepath): if filepath is None: filepath = os.path.expanduser(os.path.join( '~', '.pasta', 'pasta.cfg')) f = open_with_intermediates(filepath, 'w') for g in self.get_categories(): g.set_config_parser_fields(self._config_parser) self._config_parser.write(f) f.close()
def create_input_files(self, job_subdir, input_subdir=None): src_paths = [] seq_dir = os.path.join(self.top_dir, job_subdir) if input_subdir is not None: seq_dir = os.path.join(seq_dir, input_subdir) for i in range(5): fp = os.path.join(seq_dir, "data%d.fasta" % (i + 1)) src_paths.append(fp) f = filemgr.open_with_intermediates(fp, "w") f.close() return src_paths
def run(self): _LOG.debug('launching %s.' % " ".join(self._invocation)) k = self._k proc_cwd = k.get('cwd', os.curdir) stdout_file_path = k.get('stdout', None) stderr_file_path = k.get('stderr', None) if stdout_file_path: _stdout_fo = open_with_intermediates(stdout_file_path, 'w') else: _stdout_fo = open_with_intermediates(os.path.join(proc_cwd, '.Job.stdout.txt'), 'w') k['stdout'] = _stdout_fo if stderr_file_path: _stderr_fo = open_with_intermediates(stderr_file_path, 'w') else: _stderr_fo = open_with_intermediates(os.path.join(proc_cwd, '.Job.stderr.txt'), 'w') k['stderr'] = _stderr_fo for key,v in self.environ.items(): os.environ[key] = v process = Popen(self._invocation, stdin = PIPE, **k) err_msg = [] err_msg.append("PASTA failed because one of the programs it tried to run failed.") err_msg.append('The invocation that failed was: \n "%s"\n' % '" "'.join(self._invocation)) try: self.return_code = process.wait() _stdout_fo.close() _stderr_fo.close() process.stdin.close() if self.return_code: errorFromFile = self.read_stderr(_stderr_fo) if errorFromFile: err_msg.append(errorFromFile) self.error = "\n".join(err_msg) raise Exception("") _LOG.debug('Finished %s.\n Return code: %s; %s' % (" ".join(self._invocation), self.return_code, self.error)) except Exception as e: err_msg.append(str(e)) self.error = "\n".join(err_msg) _LOG.error(self.error)
def create_input_files(self, job_subdir, input_subdir=None): src_paths = [] seq_dir = os.path.join(self.top_dir, job_subdir) if input_subdir is not None: seq_dir = os.path.join(seq_dir, input_subdir) for i in range(5): fp = os.path.join(seq_dir, "data%d.fasta" % (i+1)) src_paths.append(fp) f = filemgr.open_with_intermediates(fp, "w") f.close() return src_paths
def _write_partition_filepath(self, parfn, partitions, model): # partition --- list of tuples, [("DNA", 1, 30), ("DNA", 31, 60), ("PROTEIN", 61, 100)] file_obj = open_with_intermediates(parfn,'w') count = 0 for item in partitions: key = "" count += 1 if item[0] == "DNA": key = "DNA" elif item[0] == "PROTEIN": if model.startswith("PROTGAMMA"): key = model[len("PROTGAMMAI"):] if model.startswith("PROTGAMMAI") else model[len("PROTGAMMA"):] if model.startswith("PROTCAT"): key = model[len("PROTCATI"):] if model.startswith("PROTCATI") else model[len("PROTCAT"):] file_obj.write("%s, p%s=%s-%s\n" % (key, count, item[1], item[2]) ) file_obj.close()
def _write_partition_filepath(self, parfn, partitions, model): # partition --- list of tuples, [("DNA", 1, 30), ("DNA", 31, 60), ("PROTEIN", 61, 100)] file_obj = open_with_intermediates(parfn, 'w') count = 0 for item in partitions: key = "" count += 1 if item[0] == "DNA": key = "DNA" elif item[0] == "PROTEIN": if model.startswith("PROTGAMMA"): key = model[len("PROTGAMMAI"):] if model.startswith( "PROTGAMMAI") else model[len("PROTGAMMA"):] if model.startswith("PROTCAT"): key = model[len("PROTCATI"):] if model.startswith( "PROTCATI") else model[len("PROTCAT"):] file_obj.write("%s, p%s=%s-%s\n" % (key, count, item[1], item[2])) file_obj.close()
def run(self): _LOG.debug('launching %s.' % " ".join(self._invocation)) k = self._k proc_cwd = k.get('cwd', os.curdir) stdout_file_path = k.get('stdout', None) stderr_file_path = k.get('stderr', None) if stdout_file_path: _stdout_fo = open_with_intermediates(stdout_file_path, 'w') else: _stdout_fo = open_with_intermediates(os.path.join(proc_cwd, '.Job.stdout.txt'), 'w') k['stdout'] = _stdout_fo if stderr_file_path: _stderr_fo = open_with_intermediates(stderr_file_path, 'w') else: _stderr_fo = open_with_intermediates(os.path.join(proc_cwd, '.Job.stderr.txt'), 'w') k['stderr'] = _stderr_fo for key, v in self.environ.items(): os.environ[key] = v err_msg = [] err_msg.append("PASTA failed because one of the programs it tried to run failed.") err_msg.append('The invocation that failed was: \n "%s"\n' % '" "'.join(self._invocation)) self.return_code = 0 # Initialization of return code try: command = "" for item in self._invocation: command = command + " "+item # MESSENGER.send_info("[JMAbuin] Initial command "+command) if configure_spark.isSpark(): fileIndex = 0 if(self._invocation[fileIndex] == "java"): # Case of opal # MESSENGER.send_info("[JMAbuin] We are launching OPAL") fileIndex = 3 # Check if Java is in our path # MESSENGER.send_info("[JMAbuin] JAVA_HOME is " + os.getenv('JAVA_HOME')) # MESSENGER.send_info("[JMAbuin] PATH is " + os.getenv('PATH')) newJava = os.getenv('JAVA_HOME')+"/bin/java" if newJava is not None: self._invocation[0] = newJava ''' current_dir = os.getcwd() current_theoretical_dir = "" currentItem = 0 totalItems = len(self._invocation[5].split("/")) for item in self._invocation[5].split("/"): if(currentItem > 0) and (totalItems - currentItem > 7): current_theoretical_dir = current_theoretical_dir + "/" + item currentItem += 1 if(current_dir != current_theoretical_dir): self._invocation[5] = self._invocation[5].replace(current_theoretical_dir, current_dir) self._invocation[7] = self._invocation[5].replace(current_theoretical_dir, current_dir) self._invocation[9] = self._invocation[5].replace(current_theoretical_dir, current_dir) ''' # Example: tempAHc28U/step0/centroid/pw/r5d2_r5d1/tempopal_waXAP/out.fasta # First file: self.changePermissions(self._invocation[5], 7) self.changePermissions(self._invocation[7], 7) self.changePermissions(self._invocation[9], 7) execname = os.path.basename(self._invocation[fileIndex]) if (not os.path.isfile(self._invocation[fileIndex])): MESSENGER.send_warning("[JMAbuin] " + self._invocation[fileIndex] + " does not exists! Finding it.") if(os.path.isfile(os.getcwd() + "/pasta.zip/bin/" + execname)): MESSENGER.send_info("[JMAbuin] Found " + execname + "!! => " + os.getcwd() + "/pasta.zip/bin/" + execname) self._invocation[fileIndex] = os.getcwd() + "/pasta.zip/bin/" + execname else: newInvocationPath = self.findFile("../", execname) if (os.path.isfile(newInvocationPath)): MESSENGER.send_info("[JMAbuin] new " + execname + " path is " + newInvocationPath) self._invocation[fileIndex] = newInvocationPath else: MESSENGER.send_error("[JMAbuin] Could not find " + execname + "!!") # MESSENGER.send_info("[JMAbuin] Final " + execname + " => " + self._invocation[fileIndex]) command = "" for item in self._invocation: command = command + " " + item #number_of_cpus = os.environ["OMP_NUM_THREADS"] #MESSENGER.send_info("[JMAbuin] Final command " + command + "with " + number_of_cpus + " CPUS") startTime = time.time() process = Popen(self._invocation, stdin=PIPE, **k) self.return_code = process.wait() # Chema aqui endTime = time.time() # process = Popen(self._invocation, stdin=PIPE, **k) # (output, output_err) = process.communicate() # self.return_code = process.returncode MESSENGER.send_info("[JMAbuin] :: run :: return code from " + self._invocation[0] + " is: " + str(self.return_code) + " and execution time is: " + str(endTime - startTime) + " seconds.") if "fasttreeMP" in self._invocation[0]: MESSENGER.send_info("[JMAbuin] running fastree in parallel") command = "" for item in self._invocation: command = command + " " + item number_of_cpus = os.environ["OMP_NUM_THREADS"] MESSENGER.send_info("[JMAbuin] Final command " + command + " with " + number_of_cpus+" CPUS") _stdout_fo.close() _stderr_fo.close() process.stdin.close() if self.return_code < 0: errorFromFile = self.read_stderr(_stderr_fo) if errorFromFile: err_msg.append(errorFromFile) # err_msg.append(output_err) self.error = "\n".join(err_msg) raise Exception("") _LOG.debug('Finished %s.\n Return code: %s; %s' % (" ".join(self._invocation), self.return_code, self.error)) except OSError as ose: err_msg.append(str(ose)) self.error = "\n".join(err_msg) MESSENGER.send_error("[JMAbuin] " + ose.message) MESSENGER.send_error("[JMAbuin] " + ose.child_traceback) _LOG.error(self.error) sys.exit(ose.message + " :: "+ose.child_traceback) except Exception as e: err_msg.append(str(e.message)) self.error = "\n".join(err_msg) MESSENGER.send_error("[JMAbuin] " + self.error) _LOG.error(self.error) sys.exit(e.message)