/
create_crossbar.py
202 lines (162 loc) · 5.28 KB
/
create_crossbar.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from bccb.uniprot_adapter import (
Uniprot,
UniprotNodeType,
UniprotNodeField,
UniprotEdgeType,
UniprotEdgeField,
)
from bccb.ppi_adapter import (
PPI
)
from bccb.interpro_adapter import (
InterPro
)
from bccb.go_adapter import (
GO
)
from bccb.drug_adapter import (
Drug
)
from bccb.compound_adapter import (
Compound
)
from bccb.orthology_adapter import (
Orthology
)
from bccb.disease_adapter import (
Disease
)
from bccb.phenotype_adapter import (
HPO
)
from bccb.pathway_adapter import (
Pathway
)
from biocypher import BioCypher
bc = BioCypher(biocypher_config_path= r"config/biocypher_config.yaml",
schema_config_path= r"config/schema_config.yaml",
)
# Whether to cache data by pypath for future usage
CACHE = True
# Flag for exporting node and edge files as csv format
export_as_csv = True
# dirs
output_dir_path = "YOUR_PATH"
# user and passwd
drugbank_user = "YOUR_DRUGBANK_USER"
drugbank_passwd = "YOUR_DRUGBANK_PASSWD"
# uniprot configuration
uniprot_node_types = [
UniprotNodeType.PROTEIN,
UniprotNodeType.GENE,
UniprotNodeType.ORGANISM,
]
uniprot_node_fields = [
UniprotNodeField.PRIMARY_GENE_NAME,
UniprotNodeField.LENGTH,
UniprotNodeField.MASS,
UniprotNodeField.ORGANISM,
UniprotNodeField.ORGANISM_ID,
UniprotNodeField.PROTEIN_NAMES,
UniprotNodeField.PROTEOME,
UniprotNodeField.PROTEIN_GENE_NAMES,
UniprotNodeField.ENSEMBL_TRANSCRIPT_IDS,
UniprotNodeField.ENSEMBL_GENE_IDS,
UniprotNodeField.ENTREZ_GENE_IDS,
UniprotNodeField.VIRUS_HOSTS,
UniprotNodeField.KEGG_IDS,
UniprotNodeField.SEQUENCE,
UniprotNodeField.PROTT5_EMBEDDING,
]
uniprot_edge_types = [
UniprotEdgeType.PROTEIN_TO_ORGANISM,
UniprotEdgeType.GENE_TO_PROTEIN,
]
uniprot_id_type = [
UniprotIDField.GENE_ENTREZ_ID,
]
uniprot_adapter = Uniprot(
organism="*",
node_types=uniprot_node_types,
node_fields=uniprot_node_fields,
edge_types=uniprot_edge_types,
id_fields=uniprot_id_type,
test_mode=False,
)
uniprot_adapter.download_uniprot_data(cache=CACHE, retries=6)
uniprot_nodes = uniprot_adapter.get_nodes()
uniprot_edges = uniprot_adapter.get_edges()
bc.write_nodes(uniprot_nodes)
bc.write_edges(uniprot_edges)
bc.write_import_call()
if export_as_csv:
uniprot_adapter.export_data_to_csv(path=output_dir_path,
node_data=uniprot_nodes,
edge_data=uniprot_edges)
# PPI
ppi_adapter = PPI(organism=None,
cache=CACHE,
output_dir=output_dir_path,
export_csv=export_as_csv)
ppi_adapter.download_intact_data()
ppi_adapter.download_biogrid_data()
ppi_adapter.download_string_data()
ppi_adapter.intact_process()
ppi_adapter.biogrid_process()
ppi_adapter.string_process()
bc.write_edges(ppi_adapter.get_ppi_edges())
# protein domain
interpro_adapter = InterPro(cache=CACHE)
interpro_adapter.download_domain_node_data()
interpro_adapter.download_domain_edge_data()
if export_as_csv:
interpro_adapter.export_as_csv(path=output_dir_path,
node_csv_name="domain",
edge_csv_name="protein_has_domain")
bc.write_nodes(interpro_adapter.get_interpro_nodes())
bc.write_edges(interpro_adapter.get_interpro_edges())
# gene ontology
go_adapter = GO(organism="*")
go_adapter.download_go_data(cache=CACHE)
bc.write_nodes(go_adapter.get_go_nodes())
bc.write_edges(go_adapter.get_go_edges())
if export_as_csv:
go_adapter.export_as_csv(path=output_dir_path)
# drug
drug_adapter = Drug(drugbank_user=drugbank_user, drugbank_passwd=drugbank_passwd,
export_csv=export_as_csv, output_dir=output_dir_path)
drug_adapter.download_drug_data(cache=CACHE)
drug_adapter.process_drug_data()
bc.write_nodes(drug_adapter.get_drug_nodes())
bc.write_edges(drug_adapter.get_dti_edges())
bc.write_edges(drug_adapter.get_ddi_edges())
bc.write_edges(drug_adapter.get_dgi_edges())
# compound
compound_adapter = Compound(export_csv=export_as_csv, output_dir=output_dir_path)
compound_adapter.download_compound_data(cache=CACHE)
compound_adapter.process_compound_data()
bc.write_nodes(compound_adapter.get_compound_nodes())
bc.write_edges(compound_adapter.get_cti_edges())
# orthology
orthology_adapter = Orthology(export_csv=export_as_csv, output_dir=output_dir_path)
orthology_adapter.download_orthology_data(cache=CACHE)
bc.write_edges(orthology_adapter.get_orthology_edges())
# disease
disease_adapter = Disease(drugbank_user=drugbank_user, drugbank_passwd=drugbank_passwd,
export_csv=export_as_csv, output_dir=output_dir_path)
disease_adapter.download_disease_data(cache=CACHE)
bc.write_nodes(disease_adapter.get_nodes())
bc.write_edges(disease_adapter.get_edges())
# phenotype
phenotype_adapter = HPO(export_csv=export_as_csv, output_dir=output_dir_path)
phenotype_adapter.download_hpo_data(cache=CACHE)
bc.write_nodes(phenotype_adapter.get_nodes())
bc.write_edges(phenotype_adapter.get_edges())
# pathway
pathway_adapter = Pathway(drugbank_user=drugbank_user, drugbank_passwd=drugbank_passwd)
pathway_adapter.download_pathway_data(cache=CACHE)
pathway_adapter.get_nodes()
pathway_adapter.get_edges()
# Write import call and other post-processing
bc.write_import_call()
bc.summary()