# Path: lib/db.py
# DB_VERSION = '2.0'


import os
from os.path import join
from .db import DB_VERSION

def get_sequence_count(cxn):
    """Get the number of sequences in the table."""
    result = cxn.execute('SELECT COUNT(*) FROM sequences')
    return result.fetchone()[0]


def get_shard_cut(cxn, offset):
    """Get the sequence name at the given offset."""
    sql = 'SELECT seq_name FROM sequences ORDER BY seq_name LIMIT 1 OFFSET {}'
    result = cxn.execute(sql.format(offset))
    cut = result.fetchone()[0]
    return cut


# ########################## sequence names ##################################

def create_seq_names_table(cxn):
    """Create the sequence names table and index."""
    cxn.executescript("""
        CREATE TABLE aux.seq_names AS SELECT DISTINCT seq_name FROM sequences;
        CREATE INDEX aux.name_index ON seq_names (seq_name);
        """)


def get_sequences_in_shard(cxn, start, end):
    """Get all sequences in a shard."""
    sql = """
        SELECT seq_name, seq_end, seq
          FROM sequences

# Path: lib/db.py
# DB_VERSION = '2.0'


# Path: lib/db_preprocessor.py
import os
from os.path import join
from .db import DB_VERSION


def get_sequence_count(cxn):
    """Get the number of sequences in the table."""
    result = cxn.execute('SELECT COUNT(*) FROM sequences')
    return result.fetchone()[0]


def get_shard_cut(cxn, offset):
    """Get the sequence name at the given offset."""
    sql = 'SELECT seq_name FROM sequences ORDER BY seq_name LIMIT 1 OFFSET {}'
    result = cxn.execute(sql.format(offset))
    cut = result.fetchone()[0]
    return cut


# ########################## sequence names ##################################

def create_seq_names_table(cxn):
    """Create the sequence names table and index."""
    cxn.executescript("""
        CREATE TABLE aux.seq_names AS SELECT DISTINCT seq_name FROM sequences;
        CREATE INDEX aux.name_index ON seq_names (seq_name);
        """)


def get_sequences_in_shard(cxn, start, end):
    """Get all sequences in a shard."""
    sql = """
        SELECT seq_name, seq_end, seq
          FROM sequences

         WHERE seq_name >= ?