Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
    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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
    def _execute_tool(self, analysisResource, fileName=None, stdin_data=None):
        "Perform the external program execution"

        cmdlineList = []

        # Assemble commad line list

        # extract program name from XML
        executeObj = analysisResource.find('./Execute')
        cmdlineList.append(executeObj.attrib['program'])

        # Cycle through parameters in XML
        for parameter in list(analysisResource.findall('./Execute/parameters/parameter')):

            if 'prefix' in parameter.attrib:
                cmdlineList.append(parameter.attrib['prefix'])
            cmdlineList.append(parameter.text)

        # Get database name
        database = analysisResource.find('./Execute/database')
        if 'prefix' in database.attrib:
            cmdlineList.append(database.attrib['prefix'])
        # Add searchpath
        cmdlineList.append(utils.locate_file(path.join(self.options.activeSiteFinderHMMDir, database.text)))

        if fileName:
            # Get (optional) input file prefix (e.g. -query in blast)
            if 'inputfile_prefix' in executeObj.attrib:
                cmdlineList.append(executeObj.attrib['inputfile_prefix'])
            cmdlineList.append(fileName)

        if stdin_data:
            # Get (optional) prefix for stdin (e.g. "-" for hmmpfam / hmmscan
            if 'STDINprefix' in executeObj.attrib:
                cmdlineList.append(executeObj.attrib['STDINprefix'])

        logging.debug("ASF: %s; external program call:\n%s", analysisResource.attrib['name'], " ".join(cmdlineList))

        try:
            if fileName:
                logging.debug("Executing tool with file input")
                out, _, retcode = utils.execute(cmdlineList)
            else:
                logging.debug("Executing tools with STDIN input")
                out, _, retcode = utils.execute(cmdlineList, input=stdin_data)
        except OSError:
            logging.warn('OS error on execution of: %s', " ".join(cmdlineList))
            return []
        if retcode != 0:
            logging.warn('%s returned %s', cmdlineList[0], retcode)
            return []
        res_stream = StringIO(out)
        logging.debug('External program output: %s', res_stream)

        # Get Biopython parser information from XML
        biopython_parser = analysisResource.find('./Execute/BioPythonParser')
        try:
            results = list(SearchIO.parse(res_stream, biopython_parser.text))
        except Exception as e:
            logging.warn('Error parsing results for active site finder analysis: %s ; no hits will be reported', e)
            results = []

        return results
Beispiel #7
0
    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
Beispiel #8
0
 def test_locate_file(self):
     "Test utils.locate_file()"
     self.assertEqual(__file__, utils.locate_file(__file__))
     self.assertIsNone(utils.locate_file('totallymadeup'))