# Path: gemBS/utils.py
# class CommandException(Exception):
#     """Exception thrown by gemtools commands"""
#     pass


import os
import sqlite3
import re
import fnmatch
import logging
import json
import threading as th
from .utils import CommandException
        # Don't bother if we are already in memory
        if not database._mem_db:
            # close existing connection
            self.close()
            # re-open connection to disk db
            oldname = database.db_name
            db = sqlite3.connect(oldname)
            # sswitch to in memory db
            database.db_name = 'file:gemBS?mode=memory&cache=shared'
            database._mem_db = True
            self.__init__()
            self.create_tables()
            c_old = db.cursor()
            c = self.cursor()
            for tab in ('indexing', 'mapping', 'calling', 'extract'):
                for ret in c_old.execute("SELECT * FROM {}".format(tab)):
                    c.execute("INSERT INTO {} VALUES {}".format(tab, ret))
            self.commit()
            db.close()
                    
    def check(self, sync = False):
        self.check_index()
        self.check_mapping(sync)
        self.check_contigs(sync)
        self.check_extract(sync)
    
    def check_index(self):
        config = database.json_data.config
        ref = config['DEFAULT']['reference']
        if not os.path.exists(ref):

# Path: gemBS/utils.py
# class CommandException(Exception):
#     """Exception thrown by gemtools commands"""
#     pass


# Path: gemBS/database.py
import os
import sqlite3
import re
import fnmatch
import logging
import json
import threading as th
from .utils import CommandException

        # Don't bother if we are already in memory
        if not database._mem_db:
            # close existing connection
            self.close()
            # re-open connection to disk db
            oldname = database.db_name
            db = sqlite3.connect(oldname)
            # sswitch to in memory db
            database.db_name = 'file:gemBS?mode=memory&cache=shared'
            database._mem_db = True
            self.__init__()
            self.create_tables()
            c_old = db.cursor()
            c = self.cursor()
            for tab in ('indexing', 'mapping', 'calling', 'extract'):
                for ret in c_old.execute("SELECT * FROM {}".format(tab)):
                    c.execute("INSERT INTO {} VALUES {}".format(tab, ret))
            self.commit()
            db.close()
                    
    def check(self, sync = False):
        self.check_index()
        self.check_mapping(sync)
        self.check_contigs(sync)
        self.check_extract(sync)
    
    def check_index(self):
        config = database.json_data.config
        ref = config['DEFAULT']['reference']
        if not os.path.exists(ref):

            raise CommandException("Reference file '{}' does not exist".format(ref))