コード例 #1
0
ファイル: db.py プロジェクト: genomewalker/anvio
    def _exec_many(self, sql_query, values):
        """Execute many sql statements

        Notes
        =====
        - This is a private method, and so it is presumed whoever uses it knows what they are doing.
          For this reason, it is not decorated with _not_if_read_only. It is therefore possible to write
          to the DB using this method, even with self.read_only = True
        """

        chunk_counter = 0
        for chunk in get_list_in_chunks(values):
            if anvio.DISPLAY_DB_CALLS:
                header = f"MULTI SQL // {chunk_counter} of {len(values)} with {len(chunk)} {len(chunk)} entries"
                self.run.warning(None, header=header, progress=self.progress, lc='yellow')
                self.run.info_single(f"{sql_query}", nl_after=1, cut_after=None, level=0, mc='yellow')
                sql_exec_timer = terminal.Timer()

            self.cursor.executemany(sql_query, chunk)

            if anvio.DISPLAY_DB_CALLS:
                self.run.info("exec", f"{sql_exec_timer.time_elapsed()}", mc='yellow')

            chunk_counter += 1

        return True
コード例 #2
0
ファイル: db.py プロジェクト: genomewalker/anvio
    def _fetchall(self, response, table_name):
        """Wrapper for fetchall"""

        DISPLAY_DB_CALLS = False if table_name in self.tables_to_exclude_from_db_call_reports else anvio.DISPLAY_DB_CALLS

        if DISPLAY_DB_CALLS:
            sql_exec_timer = terminal.Timer()

        results = response.fetchall()

        if DISPLAY_DB_CALLS:
            self.run.info("fetchall", f"{sql_exec_timer.time_elapsed()}", mc='yellow', nl_after=1)

        return results
コード例 #3
0
ファイル: MODELLER.py プロジェクト: shiyi-pan/anvio
    def process(self):
        timer = terminal.Timer()

        try:
            self.load_pdb_db()
            timer.make_checkpoint('PDB DB loaded')

            self.run_fasta_to_pir()
            timer.make_checkpoint('Converted gene FASTA to PIR')

            self.check_database()
            timer.make_checkpoint('Checked databases')

            self.run_search_and_parse_results()
            timer.make_checkpoint('Ran DIAMOND search and parsed hits')

            self.get_structures()
            timer.make_checkpoint('Obtained template structures')

            self.run_align_to_templates(
                self.list_of_template_code_and_chain_ids)
            timer.make_checkpoint('Sequence aligned to templates')

            self.run_get_model(self.num_models, self.deviation, self.very_fast)
            timer.make_checkpoint('Ran structure predictions')

            self.tidyup()
            self.pick_best_model()
            self.run_add_chain_identifiers_to_best_model()
            timer.make_checkpoint('Picked best model and tidied up')

            self.out["structure_exists"] = True

        except self.EndModeller as e:
            pass

        except ModellerScriptError as e:
            print(e)

        finally:
            timer.gen_report(title='ID %s Time Report' %
                             str(self.corresponding_gene_call),
                             run=self.run)
            self.abort()

        return self.out
コード例 #4
0
ファイル: db.py プロジェクト: genomewalker/anvio
    def _exec(self, sql_query, value=None):
        """Execute an arbitrary sql statement

        Notes
        =====
        - This is a private method, and so it is presumed whoever uses it knows what they are doing.
          For this reason, it is not decorated with _not_if_read_only. It is therefore possible to write
          to the DB using this method, even with self.read_only = True
        """

        # this is an ugly workaround to not display DB calls if they involve talbes
        # such as `self` or `sqlite_master` (comlete list in self.tables_to_exclude_from_db_call_reports).
        # Otherwise when the user sets the `--display-db-calls` flag, the output is heavily
        # dominated by queries to `self`. Even though Meren is implementing this sadness,
        # Iva agreed to it as well. Just saying:
        if any(table_name for table_name in self.tables_to_exclude_from_db_call_reports if f' {table_name} ' in sql_query):
            DISPLAY_DB_CALLS = False
        else:
            DISPLAY_DB_CALLS = anvio.DISPLAY_DB_CALLS

        if DISPLAY_DB_CALLS:
            self.progress.reset()
            self.run.warning(None, header='EXECUTING SQL', lc='yellow', nl_before=1)

            self.run.info_single(f"{os.path.abspath(self.db_path)}", cut_after=None, level=0, mc='yellow', nl_after=1)
            self.run.info_single(f"{sql_query}", cut_after=None, level=0, mc='yellow', nl_after=1)
            sql_exec_timer = terminal.Timer()

        if value:
            ret_val = self.cursor.execute(sql_query, value)
        else:
            ret_val = self.cursor.execute(sql_query)

        if DISPLAY_DB_CALLS:
            self.run.info("exec", f"{sql_exec_timer.time_elapsed()}", mc='yellow')

        self.commit()
        return ret_val