-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_knowledge_graph.py
133 lines (117 loc) · 3.86 KB
/
create_knowledge_graph.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from biocypher import BioCypher
from decider_genetics.adapters.all_variants_adapter import (
AllVariantsAdapter,
AllVariantsAdapterNodeType,
AllVariantsAdapterEdgeType,
AllVariantsAdapterPatientField,
AllVariantsAdapterSampleField,
AllVariantsAdapterVariantField,
)
from decider_genetics.adapters.cn_genes_adapter import (
CnGenesAdapter,
CnGenesAdapterNodeType,
CnGenesAdapterEdgeType,
CnGenesAdapterSampleField,
CnGenesAdapterGeneField,
CnGenesAdapterEdgeField,
)
from decider_genetics.adapters.pandas_adapter import PandasAdapter
from decider_genetics.adapters.oncokb_adapter import OncoKBAdapter
from decider_genetics.adapters.clinical_adapter import ClinicalAdapter
bc = BioCypher(
biocypher_config_path="config/biocypher_config.yaml",
)
# VARIANTS from all_variants.csv
variant_node_types = [
AllVariantsAdapterNodeType.PATIENT,
AllVariantsAdapterNodeType.SAMPLE,
AllVariantsAdapterNodeType.VARIANT,
]
variant_node_fields = [
# Patients
AllVariantsAdapterPatientField.ID,
AllVariantsAdapterPatientField.SAMPLES,
# Samples
AllVariantsAdapterSampleField.ID,
AllVariantsAdapterSampleField.READ_COUNTS,
# Variants
AllVariantsAdapterVariantField.ID,
AllVariantsAdapterVariantField.CHROMOSOME,
AllVariantsAdapterVariantField.POSITION,
AllVariantsAdapterVariantField.REF,
AllVariantsAdapterVariantField.ALT,
AllVariantsAdapterVariantField.GENE,
AllVariantsAdapterVariantField.CADD_PHRED,
AllVariantsAdapterVariantField.FUNCTION,
AllVariantsAdapterVariantField.EXONIC_FUNCTION,
AllVariantsAdapterVariantField.AA_CHANGE,
AllVariantsAdapterVariantField.COSMIC_TOTAL_OCCURENCE,
AllVariantsAdapterVariantField.CLNSIG,
AllVariantsAdapterVariantField.CLNREVSTAT,
AllVariantsAdapterVariantField.GNOMAD_GENOME_MAX,
]
variant_edge_types = [
AllVariantsAdapterEdgeType.PATIENT_SAMPLE_ASSOCIATION,
AllVariantsAdapterEdgeType.SAMPLE_VARIANT_ASSOCIATION,
AllVariantsAdapterEdgeType.VARIANT_GENE_ASSOCIATION,
]
variant_adapter = AllVariantsAdapter(
node_types=variant_node_types,
node_fields=variant_node_fields,
edge_types=variant_edge_types,
)
# COPY NUMBERS from CnCombinedGenes.csv
cn_node_types = [
CnGenesAdapterNodeType.SAMPLE,
CnGenesAdapterNodeType.GENE,
]
cn_node_fields = [
# Samples
CnGenesAdapterSampleField.ID,
# Genes
CnGenesAdapterGeneField.ENSEMBL_ID,
CnGenesAdapterGeneField.NAME,
CnGenesAdapterGeneField.CHR,
CnGenesAdapterGeneField.START,
CnGenesAdapterGeneField.END,
CnGenesAdapterGeneField.STRAND,
CnGenesAdapterGeneField.BAND,
CnGenesAdapterGeneField.TYPE,
]
cn_edge_types = [
CnGenesAdapterEdgeType.SAMPLE_GENE_ASSOCIATION,
]
cn_edge_fields = [
CnGenesAdapterEdgeField.BREAKS_IN_GENE,
CnGenesAdapterEdgeField.N_MAJOR,
CnGenesAdapterEdgeField.N_MINOR,
CnGenesAdapterEdgeField.PURIFIED_LOG_R,
CnGenesAdapterEdgeField.MIN_PURIFIED_LOG_R,
CnGenesAdapterEdgeField.MAX_PURIFIED_LOG_R,
CnGenesAdapterEdgeField.PURIFIED_BAF,
CnGenesAdapterEdgeField.PURIFIED_LOH,
]
cn_adapter = CnGenesAdapter(
node_types=cn_node_types,
node_fields=cn_node_fields,
edge_types=cn_edge_types,
edge_fields=cn_edge_fields,
)
pandas_adapter = PandasAdapter()
oncokb_adapter = OncoKBAdapter()
clinical_adapter = ClinicalAdapter()
# Create a knowledge graph from the adapters
bc.write_nodes(variant_adapter.get_nodes())
bc.write_nodes(cn_adapter.get_nodes())
bc.write_nodes(pandas_adapter.get_nodes())
bc.write_nodes(oncokb_adapter.get_nodes())
bc.write_nodes(clinical_adapter.get_nodes())
bc.write_edges(variant_adapter.get_edges())
bc.write_edges(cn_adapter.get_edges())
bc.write_edges(pandas_adapter.get_edges())
bc.write_edges(oncokb_adapter.get_edges())
bc.write_schema_info(as_node=True)
# Write admin import statement
data = bc.write_import_call()
# Print summary
bc.summary()