forked from lumc-pgx/pharmvar-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
50 lines (39 loc) · 1.49 KB
/
config.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
import yaml
from api import get_alleles, get_variants
_GENES = None
def get_gene(gene):
global _GENES
if not _GENES:
with open("data/genes.yaml", encoding="utf-8") as file:
_GENES = yaml.safe_load(file)
return _GENES[gene]
_COLORS = None
def function_to_color(function):
global _COLORS
if not _COLORS:
with open("data/colors.yaml", encoding="utf-8") as file:
_COLORS = yaml.safe_load(file)
return _COLORS[function]
def impact_to_color(impact):
if impact is None:
return function_to_color("normal function")
if any(["del" in impact, "dup" in impact, "ins" in impact]):
return function_to_color("decreased function")
if any(["fs" in impact, "splice" in impact, "X" in impact]):
return function_to_color("no function")
if impact:
# FIXME: AA substitutions (BLOSOM?)
return function_to_color("unknown function")
# not assigned
return function_to_color("function not assigned")
def get_nodes(gene, version, cache):
nodes = {}
nodes.update({f"variant_{variant['id']}": {
"color": impact_to_color(variant["impact"]),
"label": variant["hgvs"],
} for variant in get_variants(gene, get_gene(gene)["nc_ref_seq_id"], version, cache)})
nodes.update({allele["name"]: {
"color": function_to_color(allele["function"]),
"label": allele["name"],
} for allele in get_alleles(gene, get_gene(gene)["nc_ref_seq_id"], version, cache)})
return nodes