def check_prereqs(options): "Check if all required applications are around" failure_messages = [] if options.genefinding == 'none': return failure_messages basedir = utils.get_genefinding_basedir(options) for binary_name, optional in _required_binaries: new_binary_name = path.join(basedir, binary_name) if locate_executable(new_binary_name) is None and not optional: if locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate executable for %r" % binary_name) return failure_messages
def check_prereqs(): failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate executable for %r" % binary_name) cfg = config.get_config() cfg.cdh_use_binary = True #Check if cd-hit binary exist if cfg.enable_cdhit: if utils.locate_executable("cd-hit") is None: cfg.cdh_use_binary = False logging.info( "Cannot locate cd-hit binary, using ps-cd-hit algorithm instead" ) for hmm_model in cfg.enabled_detection_models: #Check if hmmdetails.txt is readable and well-formatted dir_path = path.dirname(path.abspath(__file__)) model_name = "" if not hmm_model is "default": dir_path = path.join(dir_path, hmm_model) model_name = "(" + hmm_model + ")" #Check if hmmdetails.txt is readable and well-formatted lineno = 1 for line in open(path.join(dir_path, "hmmdetails.txt"), "r"): if line.count("\t") != 3: failure_messages.append( "Failed to use HMM profile %s from line %s due to misformatting:\n %r" % (model_name, lineno, line)) lineno += 1 #Check if cluster_rules.txt is readable and well-formatted lineno = 1 for line in open(path.join(dir_path, "cluster_rules.txt"), "r"): if line.count("\t") != 3: failure_messages.append( "Failed to use cluster rules %s from the line %s due to misformatting:\n %r" % (model_name, lineno, line)) lineno += 1 for sig in get_sig_profiles(): if not path.exists(sig.path): failure_messages.append("Failed to find HMM profile %r" % sig.path) return failure_messages
def check_prereqs(options): "Check if all required applications are around" failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate file: %r" % binary_name) for hmm in _markov_models: hmm = utils.get_full_path(__file__, hmm) if utils.locate_file(hmm) is None: failure_messages.append("Failed to locate file %r" % hmm) continue for ext in _binary_extensions: binary = "%s%s" % (hmm, ext) if utils.locate_file(binary) is None: command = ['hmmpress', hmm] try: out, err, retcode = utils.execute(command) except OSError as e: retcode = 1 err = str(e) if retcode != 0: failure_messages.append("Failed to hmmpress %r: %r" % (hmm, err)) break return failure_messages
def check_prereqs(): failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate executable for %r" % binary_name) return failure_messages
def check_prereqs(): "Check if all required files and applications are around" # Tuple is ( binary_name, optional) _required_binaries = [ ('blastp', False), ] failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate file: %r" % binary_name) try: import cobra logging.debug("Found cobra version %s", cobra.__version__) except (ImportError, ImportWarning) as err: failure_messages.append(str(err)) try: import libsbml logging.debug("Found libsmbl version %s", libsbml.getLibSBMLVersion()) except (ImportError, ImportWarning) as err: failure_messages.append(str(err)) if not libImport: failure_messages.append("Failed to import automodel") return failure_messages
def check_prereqs(self): "Check if all required files and applications are around" # Tuple is ( binary_name, optional) _required_binaries = [('blastp', False), ('hmmpfam2', False), ('hmmscan', False)] options = self.options failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate file: %r" % binary_name) # Get all HMM profile names from XML file for HMMProfile in self.HmmProfilesFilenameObj: if utils.locate_file( path.join(options.activeSiteFinderHMMDir, HMMProfile.text)) is None: failure_messages.append("Failed to locate file: %s" % HMMProfile.text) return failure_messages
def check_prereqs(options): "Check if all required applications are around" failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate file: %r" % binary_name) return failure_messages
def test_locate_executable(self): "Test utils.locate_executable()" test_executable = sys.argv[0] if not path.isfile(test_executable): self.skipTest("%r is not a file, skipping test" % test_executable) if not os.access(test_executable, os.X_OK): self.skipTest("%r is not executable, skipping test" % test_executable) self.assertEqual(utils.locate_executable(test_executable), test_executable) short_path = path.split(test_executable)[1] self.assertEqual(utils.locate_executable(short_path), test_executable) self.assertIsNone(utils.locate_executable("totallymaedup"))
def make_blastDB(query_fasta, options): db_dir = options.metabolicmodeldir + os.sep + 'targetBlastDB' DBprogramName = utils.locate_executable('makeblastdb') utils.execute( [DBprogramName, '-in', query_fasta, '-out', db_dir, '-dbtype', 'prot']) #Checks if DB is properly created; otherwise shutdown if os.path.isfile(options.metabolicmodeldir + os.sep + 'targetBlastDB.psq') == False: logging.exception("error in make_blastDB: blast DB not created") #FIXME: don't use sys.exit sys.exit(1)
def check_prereqs(): failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate executable for %r" % binary_name) hmm_files = [] # Check if hmmdetails.txt is readable and well-formatted lineno = 1 for line in open(utils.get_full_path(__file__, "hmmdetails.txt"), "r"): if line.count("\t") != 3: failure_messages.append( "Failed to use HMM profile from line %s due to misformatting:\n %r" % (lineno, line)) continue hmm_files.append(line.split('\t')[3].strip()) lineno += 1 #Check if cluster_rules.txt is readable and well-formatted lineno = 1 for line in open(utils.get_full_path(__file__, "cluster_rules.txt"), "r"): if line.count("\t") != 3: failure_messages.append( "Failed to use cluster rules from the line %s due to misformatting:\n %r" % (lineno, line)) lineno += 1 hmm = utils.get_full_path(__file__, _markov_model) if utils.locate_file(hmm) is None: # try to generate file from all specified profiles in hmmdetails try: with open(hmm, 'w') as all_hmms_handle: for hmm_file in hmm_files: with open(utils.get_full_path(__file__, hmm_file), 'r') as handle: all_hmms_handle.write(handle.read()) except OSError: failure_messages.append('Failed to generate file {!r}'.format(hmm)) for ext in _binary_extensions: binary = "{}{}".format(hmm, ext) if utils.locate_file(binary) is None: _, err, retcode = utils.run_hmmpress(hmm) if retcode != 0: failure_messages.append('Failed to hmmpress {!r}: {!r}'.format( hmm, err)) break return failure_messages
def check_prereqs(options): "Check if all required applications are around" failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate file: %r" % binary_name) for file_name, optional in _required_files: if utils.locate_file( path.join(utils.get_full_path(__file__, ''), file_name)) is None and not optional: failure_messages.append("Failed to locate file: %r" % file_name) return failure_messages
def check_prereqs(): "Check if all required files and applications are around" # Tuple is ( binary_name, optional) _required_binaries = [('eficaz2.5', False)] failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate executable: %r" % binary_name) return failure_messages
def run_blastp(target_fasta='', blastp_result='', db_dir='', evalue=1e-30): BLASTPprogramName = utils.locate_executable('blastp') # Execute blast if output file is not present if not os.path.isfile(blastp_result): args = [ BLASTPprogramName, '-query', target_fasta, '-out', blastp_result, '-db', db_dir, '-evalue', str(evalue), '-outfmt', "10 qseqid sseqid evalue score length pident" ] out, err, retcode = utils.execute(args) if retcode != 0: logging.debug("out: %r, err: %r, retcode: %s", out, err, retcode) else: logging.warn("Found blast file %s, skipping new caluclation", blastp_result)
def check_prereqs(): failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate executable for %r" % binary_name) for hmm in _markov_models: hmm = utils.get_full_path(__file__, hmm) if utils.locate_file(hmm) is None: failure_messages.append("Failed to locate file %r" % hmm) continue for ext in _binary_extensions: binary = "%s%s" % (hmm, ext) if utils.locate_file(binary) is None: _, err, retcode = utils.run_hmmpress(hmm) if retcode != 0: failure_messages.append("Failed to hmmpress %r: %r" % (hmm, err)) break else: binary_mtime = path.getmtime(binary) hmm_mtime = path.getmtime(hmm) if hmm_mtime > binary_mtime: try: from glob import glob for f in glob("%s.h3?" % hmm): logging.debug("removing outdated file %s", f) os.remove(f) except OSError as e: failure_messages.append("Failed to remove outdated binary file for %s: %s" % \ (hmm, e)) break _, err, retcode = utils.run_hmmpress(hmm) if retcode != 0: failure_messages.append("Failed to hmmpress %r: %r" % (hmm, err)) import datetime failure_messages.append("HMM binary files outdated. %s (changed: %s) vs %s (changed: %s)" % \ (hmm, datetime.datetime.fromtimestamp(hmm_mtime), binary, datetime.datetime.fromtimestamp(binary_mtime))) break return failure_messages
def _runEFICAz(self, chunkDir): cwd = os.getcwd() try: os.chdir(chunkDir) except OSError: logging.exception("Can't chdir to %s" % chunkDir) sys.exit(1) fastafile = os.path.basename(self.ChunkFilenames[chunkDir]) ecpredfile = fastafile + ".ecpred" # Only perform calculations if result file does not already exist (from previous run) if not os.path.isfile(os.path.join(self.basedirName, ecpredfile)): EFICAzExecutable = utils.locate_executable(EFICAzBinary) if not EFICAzExecutable: logging.exception( "EFICAz executable not found, bailing out, analysis not posible" ) sys.exit(1) cmdline = [EFICAzExecutable, fastafile] logging.debug("executing %s in directory %s" % (" ".join(cmdline), chunkDir)) try: utils.execute(cmdline) except: logging.exception('cannot execute EFICAz!') sys.exit(1) else: # As this method is executed in an own thread, it does not have the ability to change # the variables within th eobject; # As a workaround we just copy the "old" file to the tempdir... try: shutil.copy( os.path.abspath(os.path.join(self.basedirName, ecpredfile)), self.ChunkFilenames[chunkDir] + ".ecpred") except: logging.exception("Could not copy existing eficaz result file %s to tempfile %s", \ os.path.isfile(os.path.abspath(self.basedirName, ecpredfile)), \ self.ChunkFilenames[chunkDir]+".ecpred" ) sys.exit(1) os.chdir(cwd)
def check_prereqs(self): "Check if all required files and applications are around" # Tuple is ( binary_name, optional) _required_binaries = [ ('blastp', False), ('hmmpfam2', False), ('hmmscan', False), ('hmmpress', False), ] _binary_extensions = [ '.h3f', '.h3i', '.h3m', '.h3p' ] options = self.options failure_messages = [] for binary_name, optional in _required_binaries: if utils.locate_executable(binary_name) is None and not optional: failure_messages.append("Failed to locate file: %r" % binary_name) # Get all HMM profile names from XML file for HMMProfile in self.HmmProfilesFilenameObj: full_hmm_path = path.join(options.activeSiteFinderHMMDir, HMMProfile.text) if utils.locate_file(full_hmm_path) is None: failure_messages.append("Failed to locate file: %s" % HMMProfile.text) continue if HMMProfile.text.endswith(".hmm2"): continue for ext in _binary_extensions: binary = "{hmm}{ext}".format(hmm=full_hmm_path, ext=ext) if utils.locate_file(binary) is None: _, err, retcode = utils.run_hmmpress(full_hmm_path) if retcode != 0: failure_messages.append("Failed to hmmpress {!r}: {!r}".format(HMMProfile.text, err)) # hmmpress generates _all_ binary files in one go, so stop the loop break binary_mtime = path.getmtime(binary) hmm_mtime = path.getmtime(full_hmm_path) if hmm_mtime < binary_mtime: # generated file younger than hmm profile, do nothing continue try: from glob import glob for f in glob("{}.h3?".format(full_hmm_path)): logging.debug("removing outdated file %r", f) os.remove(f) except OSError as e: failure_messages.append("Failed to remove outdated binary file for %s: %s" % \ (HMMProfile.text, e)) break _, err, retcode = utils.run_hmmpress(full_hmm_path) if retcode != 0: failure_messages.append("Failed to hmmpress %r: %r" % (HMMProfile.text, err)) import datetime failure_messages.append("HMM binary files outdated. %s (changed: %s) vs %s (changed: %s)" % \ (HMMProfile.text, datetime.datetime.fromtimestamp(hmm_mtime), binary, datetime.datetime.fromtimestamp(binary_mtime))) # hmmpress generates _all_ binary files in one go, so stop the loop break return failure_messages