-
Notifications
You must be signed in to change notification settings - Fork 4
/
56_silent_to_nonsilent_ratio.py
executable file
·81 lines (67 loc) · 2.44 KB
/
56_silent_to_nonsilent_ratio.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
#! /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: [email protected]
#
from icgc_utils.common_queries import *
from config import Config
def main():
db = connect_to_mysql(Config.mysql_conf_file)
cursor = db.cursor()
# all protein coding genes
genes, chrom = protein_coding_genes(cursor)
switch_to_db(cursor,'icgc')
snvs = {}
silent_ratio = {}
#for gene in random.sample(genes,1000):
for gene in genes:
#silent
qry = "select count(*) from mutation2gene g, mutations_chrom_%s m where g.gene_symbol='%s' " % (chrom[gene], gene)
qry += "and m.icgc_mutation_id=g.icgc_mutation_id and m.consequence = 'synonymous' and m.reliability_estimate=1"
ret = search_db(cursor,qry, verbose=True)
if ret:
silent = ret[0][0]
else:
silent = 0
# other
qry = "select count(*) from mutation2gene g, mutations_chrom_%s m where g.gene_symbol='%s' " % (chrom[gene], gene)
qry += "and m.icgc_mutation_id=g.icgc_mutation_id and m.consequence in ('missense','stop_gained','stop_lost') "
qry += "and m.reliability_estimate=1"
ret = search_db(cursor,qry, verbose=True)
if ret:
other = ret[0][0]
else:
other = 0
if silent==0 and other==0: continue
#if silent+other<50: continue
if silent==0:
silent_ratio[gene] = 0.0
else:
silent_ratio[gene] = float(silent)/(silent+other)
snvs[gene] = silent+other
gene_ratio_list =[(gene,ratio) for gene,ratio in sorted(iter(silent_ratio.items()), key=lambda k_v: k_v[1])]
for gene,ratio in gene_ratio_list[:100]:
print("%15s %5.2f %4d " % (gene, ratio, snvs[gene]))
outf = open ("silent_ratio.tsv","w")
for gene,ratio in gene_ratio_list:
outf.write("\t".join([gene, "%.4f"%ratio, "%d"%snvs[gene]])+"\n")
outf.close()
cursor.close()
db.close()
#########################################
if __name__ == '__main__':
main()