Skip to content
Snippets Groups Projects
Commit a00438bd authored by nfontrod's avatar nfontrod
Browse files

src/db_utils/db_creation.py: database creation

parent 776ee351
No related branches found
No related tags found
No related merge requests found
......@@ -3,20 +3,24 @@
# -*- coding: utf-8 -*-
#Creation of the database using Sqlite3 and SQL commands
"""
Creation of the database using Sqlite3 and SQL commands
"""
import sqlite3
from .config import Config
import logging
from ..logging_conf import logging_def
conn = sqlite3.connect("../../Results/Db_creation/chia_pet_database.db")
c = conn.cursor()
def create_gin_gene_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_gene.
###########################
# Create table - gin_gene #
###########################
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_gene
([name] VARCHAR(30) NOT NULL,
[id] INT NOT NULL,
......@@ -25,11 +29,16 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_gene
[stop] INT NOT NULL,
[strand] VARCHAR(1) NOT NULL,
PRIMARY KEY ([id]))''')
conn.commit()
def create_gin_exon_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_exon.
###########################
# Create table - gin_exon #
###########################
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_exon
([id] VARCHAR(30) NOT NULL,
[pos] INT NOT NULL,
......@@ -41,12 +50,17 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_exon
[strand] VARCHAR(1) NOT NULL,
PRIMARY KEY ([id])
FOREIGN KEY ([id_gene]) REFERENCES gin_gene([id]))''')
conn.commit()
##############################
# Create table - gin_project #
##############################
c.execute('''CREATE TABLE IF NOT EXISTS gin_project
def create_gin_projects_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_project.
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_projects
([id] INT NOT NULL,
[id_sample] VARCHAR(45) NOT NULL,
[id_project] VARCHAR(45) NOT NULL,
......@@ -58,11 +72,16 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_project
[institute] VARCHAR(45) NULL,
[citation] VARCHAR(20) NULL,
PRIMARY KEY ([id]))''')
conn.commit()
def create_gin_gene_frequency_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_gene_frequency.
#####################################
# Create table - gin_gene_frequency #
#####################################
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_gene_frequency
([id] INT NOT NULL,
[ft] VARCHAR(3) NOT NULL,
......@@ -70,11 +89,16 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_gene_frequency
[frequency] FLOAT NULL,
PRIMARY KEY ([id]),
FOREIGN KEY ([id_gene]) REFERENCES gin_gene([id]))''')
conn.commit()
#####################################
# Create table - gin_exon_frequency #
#####################################
def create_gin_exon_frequency_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_exon_frequency.
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_exon_frequency
([id] INT NOT NULL,
[ft] VARCHAR(3) NOT NULL,
......@@ -82,11 +106,16 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_exon_frequency
[frequency] FLOAT NULL,
PRIMARY KEY ([id]),
FOREIGN KEY ([id_exon]) REFERENCES gin_exon([id]))''')
conn.commit()
def create_gin_exon_interaction_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_exon_interaction.
#######################################
# Create table - gin_exon_interaction #
#######################################
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_exon_interaction
([id] INT NOT NULL,
[force] INT NOT NULL,
......@@ -98,11 +127,16 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_exon_interaction
FOREIGN KEY ([exon1]) REFERENCES gin_exon([id]),
FOREIGN KEY ([exon2]) REFERENCES gin_exon([id]),
FOREIGN KEY ([id_project]) REFERENCES gin_project([id]))''')
conn.commit()
#######################################
# Create table - gin_gene_interaction #
#######################################
def create_gin_gene_interaction_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_gene_interaction.
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_gene_interaction
([id] INT NOT NULL,
[force] INT NOT NULL,
......@@ -114,11 +148,16 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_gene_interaction
FOREIGN KEY ([gene1]) REFERENCES gin_gene([id]),
FOREIGN KEY ([gene2]) REFERENCES gin_gene([id]),
FOREIGN KEY ([id_project]) REFERENCES gin_project([id]))''')
conn.commit()
def create_gin_project_splicing_lore_table(conn: sqlite3.Connection) -> None:
"""
Create table gin_project_splicing_lore
############################################
# Create table - gin_project_splicing_lore #
############################################
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_project_splicing_lore
([id] INT NOT NULL,
[project_name] VARCHAR(45) NULL,
......@@ -127,12 +166,17 @@ c.execute('''CREATE TABLE IF NOT EXISTS gin_project_splicing_lore
[sf_name] VARCHAR(45) NOT NULL,
[cl_name] VARCHAR(45) NOT NULL,
PRIMARY KEY ([id]))''')
conn.commit()
############################
# Create table - ase_event #
############################
c.execute('''CREATE TABLE IF NOT EXISTS ase_event
def create_gin_ase_event_table(conn: sqlite3.Connection) -> None:
"""
Create table ase_event.
:param conn: Connection to chia-pet database.
"""
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS gin_ase_event
([id] INT NOT NULL,
[id_project] INT NOT NULL,
[gene_id] INT NOT NULL,
......@@ -144,6 +188,36 @@ c.execute('''CREATE TABLE IF NOT EXISTS ase_event
PRIMARY KEY ([id]),
FOREIGN KEY ([exon_id]) REFERENCES gin_exon([id]),
FOREIGN KEY ([gene_id]) REFERENCES gin_gene([id]),
FOREIGN KEY ([id_project]) REFERENCES gin_project_splicing_lore([id]))''')
FOREIGN KEY ([id_project])
REFERENCES gin_project_splicing_lore([id]))''')
conn.commit()
def main_create_db(logging_level: str = "DISABLE"):
"""
Create an empty chia-pet database.
"""
logging_def(Config.db_file.parent, __file__, logging_level)
conn = sqlite3.connect(Config.db_file)
logging.debug('Creation of gin_gene')
create_gin_gene_table(conn)
logging.debug('Creation of gin_exon')
create_gin_exon_table(conn)
logging.debug('Creation of gin_project_gene')
create_gin_projects_table(conn)
logging.debug('Creation of gin_gene_frequency_table')
create_gin_gene_frequency_table(conn)
logging.debug('Creation of gin_exon_frequency_table')
create_gin_exon_frequency_table(conn)
logging.debug('Creation of gin_exon_interaction_table')
create_gin_exon_interaction_table(conn)
logging.debug('Creation of gin_gene_interaction_table')
create_gin_gene_interaction_table(conn)
logging.debug('Creation of gin_project_splicing_lore_table')
create_gin_project_splicing_lore_table(conn)
logging.debug('Creation of gin_ase_event_table')
create_gin_ase_event_table(conn)
if __name__ == "__main__":
main_create_db("DEBUG")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment