示例#1
0
    def _check_database(self, database):
        #Database file does not exist
        if not os.path.isfile(database):
            raise BE(code = -5, value = database)

        #Database is not formated (if dbformatexe is added in the configuration path it will be autoformated)
        formatdb_files = []
        if self._search_type == 'nucl':     formatdb_sufix = ['.nhr','.nin','.nsq']
        elif self._search_type == 'prot':   formatdb_sufix = ['.phr','.pin','.psq']
        for sufix in formatdb_sufix:
            if not os.path.isfile(database + sufix):
                formatdb_files.append(database + sufix)

        if len(formatdb_files) > 0:
            try:
                dbexe  = Executable(executable    = self._configurator.get('blast','dbformatexe'),
                                    path          = self._configurator.get('blast','path'),
                                    variable_path = self._configurator.get('blast','variable_path'))

                SBIglobals.alert('debug', self, 'Trying to format de DB {0} to perform a blast search.\n'.format(database))

                dbexe.add_attribute(database, '-in')
                dbexe.add_attribute(self._search_type, '-dbtype')

                SBIglobals.alert('debug', self, 'Executing command {0}\n'.format(dbexe))

                dbexe.execute()

            except ConfigParser.NoOptionError, e:
                raise BE(code = -6, value = formatdb_files)
            except SystemError, e:
                raise BE(code = -11, value = e)
示例#2
0
class CDhitExe(object):
    def __init__(self, fasta, threshold, output_dir=None, execute=True):
        fasta = os.path.abspath(fasta)
        if output_dir is None:
            output_dir = os.path.split(fasta)[0]

        if threshold >= 0.7: word = 5
        elif threshold >= 0.6: word = 4
        elif threshold >= 0.5: word = 3
        elif threshold >= 0.4: word = 2
        else: word = 1

        #CDhit executable configuration
        self._configurator = ConfigParser.RawConfigParser(allow_no_value=True)
        self._configurator.read(
            os.getenv('SBI_CONFIG_FILE', default_configuration_file))
        self._exe = Executable(executable=self._configurator.get(
            'cd-hit', 'executable'),
                               path=self._configurator.get('cd-hit', 'path'))

        self._input = fasta
        output_file = os.path.split(fasta)[1] + '.' + str(threshold).replace(
            '.', '_')
        self._output = os.path.join(output_dir, output_file)
        self._threshold = str(threshold)
        self._word = word

        if execute:
            self._execute()

    @property
    def output_file(self):
        return self._output + '.clstr'

    def _execute(self):
        self._exe.add_attribute(self._input, '-i')
        self._exe.add_attribute(self._output, '-o')
        self._exe.add_attribute(self._threshold, '-c')
        self._exe.add_attribute('1', '-g')
        self._exe.add_attribute(self._word, '-n')

        try:
            self._exe.execute(silent=True)
        except SystemError, e:
            sys.stderr.write(
                'Some error occurred while executing cd-hit\n{0}\n'.format(e))