def ensure_database_pressed(filepath: str, return_not_raise: bool = False) -> List[str]: """ Ensures that the given HMMer database exists and that the hmmpress generated files aren't out of date. Arguments: filepath: the path to the HMMer database return_not_raise: whether to catch errors and return their messages as strings Returns: any encountered error messages, will never be populated without return_not_raise == True """ components = [ "{}{}".format(filepath, ext) for ext in ['.h3f', '.h3i', '.h3m', '.h3p'] ] if path.is_outdated(components, filepath): logging.info("%s components missing or obsolete, re-pressing database", filepath) result = subprocessing.run_hmmpress(filepath) if not result.successful(): msg = "Failed to hmmpress {!r}: {}".format(filepath, result.stderr) if not return_not_raise: raise RuntimeError(msg) return [msg] return []
def check_diamond_files(definition_file: str, fasta_file: str, db_file: str, logging_only: bool = False) -> List[str]: """ Check if the database files exist in the right version. Arguments: definition_file: the path to a database metadata file fasta_file: the path to a proteins fasta file db_file: the path to the diamond databse file logging_only: return a list of errors messages instead of raising errors Returns: a list of error strings """ failure_messages: List[str] = [] if path.locate_file(definition_file) is None: failure_messages.append( "Failed to locate cluster definition file: {!r}".format( definition_file)) regen_message = "" if path.locate_file(fasta_file) is None: failure_messages.append( "Failed to locate cluster proteins: {!r}".format(fasta_file)) if not logging_only: raise FileNotFoundError(failure_messages[-1]) elif path.locate_file(db_file) is None: regen_message = f"could not find diamond database: {db_file}" elif not check_diamond_db_compatible(db_file): regen_message = f"incompatible diamond database version: {db_file}" elif path.is_outdated(db_file, fasta_file): regen_message = f"diamond database outdated: {db_file}" if regen_message: try: logging.debug("%s, regenerating", regen_message) run_diamond_makedb(db_file, fasta_file) except RuntimeError: if not logging_only: raise failure_messages.append( "Failed to regenerate diamond database %r" % db_file) if failure_messages: failure_messages.append( f"with diamond executable: {get_config().executables.diamond}") return failure_messages
def check_clusterblast_files(definition_file: str, fasta_file: str, db_file: str, logging_only: bool = False) -> List[str]: """ Check if the clusterblast files exist in the right version. Arguments: definition_file: the path to the cluster definition TSV file fasta_file: the path to the cluster proteins fasta file db_file: the path to the diamond databse file Returns: A list of error strings the way `check_prereqs` does """ failure_messages: List[str] = [] if path.locate_file(definition_file) is None: failure_messages.append( "Failed to locate cluster definition file: {!r}".format( definition_file)) regen_message = "" if path.locate_file(fasta_file) is None: failure_messages.append( "Failed to locate cluster proteins: {!r}".format(fasta_file)) elif path.locate_file(db_file) is None: regen_message = "could not find diamond database: %s" % db_file elif not check_diamond_db_compatible(db_file): regen_message = "incompatible diamond database version: %s" % db_file elif path.is_outdated(db_file, fasta_file): regen_message = "diamond database outdated: %s" % db_file if regen_message: try: logging.debug("%s, regenerating", regen_message) subprocessing.run_diamond_makedb(db_file, fasta_file) except RuntimeError: if not logging_only: raise failure_messages.append( "Failed to regenerate diamond database %r" % db_file) if failure_messages: failure_messages.append("with diamond executable: %s" % get_config().executables.diamond) return failure_messages
def prepare_data(_logging_only: bool = False) -> List[str]: """ Rebuild any dynamically buildable data """ flavours = ["bacteria", "fungi", "plants"] with path.changed_directory(path.get_full_path(__file__, "css")): built_files = [os.path.abspath("%s.css" % flavour) for flavour in flavours] if path.is_outdated(built_files, glob.glob("*.scss")): logging.info("CSS files out of date, rebuilding") for flavour in flavours: target = "%s.css" % flavour assert os.path.exists(flavour + ".scss"), flavour result = scss.Compiler(output_style="expanded").compile(flavour + ".scss") assert result with open(target, "w") as out: out.write(result) return []