-
Notifications
You must be signed in to change notification settings - Fork 4
/
22_ensembl_id_tables.py
executable file
·94 lines (76 loc) · 2.84 KB
/
22_ensembl_id_tables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/python3
#
# This source code is part of icgc, an ICGC processing pipeline.
#
# Icgc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Icgc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see<http://www.gnu.org/licenses/>.
#
# Contact: ivana.mihalek@gmail.com
#
# from ensembl biomart: gene stable ID, transcript stable id
from icgc_utils.mysql import *
from config import Config
#########################################
# make one-on-one ENST to ENSG translation table
def make_ensembl_ids_table(cursor, db_name, ens_ids_table):
switch_to_db (cursor, db_name)
if check_table_exists (cursor, db_name, ens_ids_table):
qry = "drop table %s" % ens_ids_table
search_db(cursor, qry)
qry = ""
qry += " CREATE TABLE %s (" % ens_ids_table
charlen = 20
for name in ['transcript', 'gene', 'canonical_transcript']:
qry += " %s VARCHAR(%d) NOT NULL ," % (name, charlen)
qry += " PRIMARY KEY (transcript) "
qry += ") ENGINE=MyISAM"
rows = search_db(cursor, qry)
print(qry)
print(rows)
return
#########################################
# make table for deprecated ids mapping
def make_ensembl_deprecated_ids_table(cursor, db_name, ens_ids_table):
switch_to_db (cursor, db_name)
if check_table_exists (cursor, db_name, ens_ids_table):
qry = "drop table %s" % ens_ids_table
search_db(cursor, qry)
qry = "CREATE TABLE %s (" % ens_ids_table
qry += " id int NOT NULL, "
charlen = 20
for name in ['old_id', 'new_id']:
qry += " %s VARCHAR(%d) NOT NULL ," % (name, charlen)
qry += " PRIMARY KEY (id) "
qry += ") ENGINE=MyISAM"
rows = search_db(cursor, qry)
print(qry)
print(rows)
return
#########################################
#########################################
def main():
ens_id_file = "/storage/databases/ensembl-94/ensembl_gene2trans_stable.tsv"
ens_deprecated_id_file = "/storage/databases/ensembl-94/ensembl_deprecated2new_id.tsv"
db = connect_to_mysql(Config.mysql_conf_file)
cursor = db.cursor()
db_name = "icgc"
make_ensembl_ids_table(cursor, db_name, "ensembl_ids")
make_ensembl_deprecated_ids_table(cursor, db_name, "ensembl_deprecated_ids")
for file, table in [[ens_id_file, "ensembl_ids"], [ens_deprecated_id_file, "ensembl_deprecated_ids"]]:
qry = "load data local infile '%s' into table %s" % (file,table)
search_db(cursor, qry, verbose=True)
cursor.close()
db.close()
#########################################
if __name__ == '__main__':
main()