Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ChIA-PET_network
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
ReGArDS
ChIA-PET_network
Commits
a00438bd
Commit
a00438bd
authored
Mar 3, 2020
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/db_utils/db_creation.py: database creation
parent
776ee351
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/db_utils/db_creation.py
+212
-138
212 additions, 138 deletions
src/db_utils/db_creation.py
with
212 additions
and
138 deletions
src/db_utils/db_creation.py
+
212
−
138
View file @
a00438bd
...
...
@@ -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
.
c
onnect
(
"
../../Results/Db_creation/chia_pet_database.db
"
)
c
=
conn
.
cursor
()
def
create_gin_gene_table
(
conn
:
sqlite3
.
C
onnect
ion
)
->
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
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment