-
Notifications
You must be signed in to change notification settings - Fork 0
/
just_cardio.py
111 lines (92 loc) · 3.55 KB
/
just_cardio.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from oakvar import BasePostAggregator
from pathlib import Path
import sqlite3
class CravatPostAggregator (BasePostAggregator):
genes:set[str] = set()
significance_filter:list[str] = [
"Pathogenic",
"Pathogenic/Likely pathogenic"
]
def check(self):
return True
def setup (self):
with open(str(Path(__file__).parent)+"/data/genes.txt") as f:
self.genes = set(f.read().split("\n"))
self.result_path:str = Path(self.output_dir, self.run_name + "_longevity.sqlite")
self.longevity_conn:str = sqlite3.connect(self.result_path)
self.longevity_cursor:str = self.longevity_conn.cursor()
# Sequence ontology - base__so
sql_create:str = """ CREATE TABLE IF NOT EXISTS cardio (
id integer NOT NULL PRIMARY KEY,
gene text,
rsid text,
cdnachange text,
genotype text,
sequence_ontology text,
sift_pred text,
alelfreq text,
phenotype text,
significance text,
clinvarid text,
omimid text,
ncbi text
)"""
self.longevity_cursor.execute(sql_create)
self.longevity_cursor.execute("DELETE FROM cardio;")
self.longevity_conn.commit()
def cleanup(self):
if self.longevity_cursor is not None:
self.longevity_cursor.close()
if self.longevity_conn is not None:
self.longevity_conn.commit()
self.longevity_conn.close()
return
def get_nucleotides(self, ref:str, alt:str, zygocity:str) -> str:
if zygocity == 'hom':
return alt+"/"+alt
return alt+"/"+ref
def annotate(self, input_data):
gene:str = input_data['base__hugo']
if gene not in self.genes:
return
isOk:bool = False
significance:str = input_data['clinvar__sig']
if significance in self.significance_filter:
isOk = True
sift_prediction:str = input_data['sift__prediction']
if sift_prediction == "Damaging":
isOk = True
cardioboost_arrhythmias:str = input_data['cardioboost__arrhythmias']
if cardioboost_arrhythmias is not None and cardioboost_arrhythmias != '':
isOk = True
cardioboost_cardiomyopathy:str = input_data['cardioboost__cardiomyopathy']
if cardioboost_cardiomyopathy is not None and cardioboost_cardiomyopathy != '':
isOk = True
if not isOk:
return
sql:str = """ INSERT INTO cardio (
gene,
rsid,
cdnachange,
genotype,
sequence_ontology,
sift_pred,
alelfreq,
phenotype,
significance,
clinvarid,
omimid,
ncbi
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) """
zygot:str = input_data['vcfinfo__zygosity']
if zygot is None or zygot == "":
zygot = "het"
alt:str = input_data['base__alt_base']
ref:str = input_data['base__ref_base']
genotype:str = self.get_nucleotides(ref, alt, zygot)
task:tuple[str, ...] = (gene, input_data['dbsnp__rsid'], input_data['base__cchange'],
genotype, input_data['base__so'], sift_prediction,
input_data['gnomad__af'], input_data['clinvar__disease_names'],
significance, input_data['clinvar__id'], input_data['omim__omim_id'],
input_data['ncbigene__ncbi_desc'])
self.longevity_cursor.execute(sql, task)