-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconstants.py
164 lines (122 loc) · 6.2 KB
/
constants.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
# -*- coding: utf-8 -*-
"""Tests constants."""
import logging
import os
import tempfile
from bio2bel.testing import TemporaryConnectionMixin
from bio2bel_chebi import Manager as ChebiManager
from bio2bel_hgnc import Manager as HgncManager
from bio2bel_kegg.manager import Manager
from pathme.kegg.convert_to_bel import kegg_to_bel
from pathme.kegg.kegg_xml_parser import import_xml_etree
from pybel import BELGraph
logger = logging.getLogger(__name__)
TEST_FOLDER = os.path.dirname(os.path.realpath(__file__))
KEGG_TEST_RESOURCES = os.path.join(TEST_FOLDER, 'resources', 'kegg')
WP_TEST_RESOURCES = os.path.join(TEST_FOLDER, 'resources', 'wp')
REACTOME_TEST_RESOURCES = os.path.join(TEST_FOLDER, 'resources', 'reactome')
GLYCOLYSIS_XML = os.path.join(KEGG_TEST_RESOURCES, 'hsa00010.xml')
NOTCH_XML = os.path.join(KEGG_TEST_RESOURCES, 'hsa04330.xml')
PPAR_XML = os.path.join(KEGG_TEST_RESOURCES, '03320_cpd_test.xml')
WP22 = os.path.join(WP_TEST_RESOURCES, 'WP22.ttl')
WP706 = os.path.join(WP_TEST_RESOURCES, 'WP706.ttl')
WP1871 = os.path.join(WP_TEST_RESOURCES, 'WP1871.ttl')
WP2799 = os.path.join(WP_TEST_RESOURCES, 'WP2799.ttl')
WP2359 = os.path.join(WP_TEST_RESOURCES, 'WP2359_mod.ttl')
dir_path = os.path.dirname(os.path.realpath(__file__))
resources_path = os.path.join(dir_path, 'resources')
pathways = os.path.join(resources_path, 'hsa.txt')
protein_pathway_url = os.path.join(resources_path, 'pathway_gene.txt')
hgnc_test_path = os.path.join(resources_path, 'hgnc_test.json')
chebi_test_path = os.path.join(resources_path, 'chebi_test.tsv.gz')
class KeggTest(TemporaryConnectionMixin):
"""A test case with a populated HGNC/CheBI databases for KEGG parser."""
@classmethod
def setUpClass(cls):
"""Create temporary file."""
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s")
logger.setLevel(logging.INFO)
"""Create temporary file"""
cls.fd, cls.path = tempfile.mkstemp()
cls.connection = 'sqlite:///' + cls.path
# create temporary database
cls.manager = Manager(cls.connection)
"""HGNC Manager"""
cls.hgnc_manager = HgncManager(engine=cls.manager.engine, session=cls.manager.session)
cls.hgnc_manager.populate(hgnc_file_path=hgnc_test_path, use_hcop=False)
logger.info('HGNC database loaded')
"""CHEBI Manager"""
cls.chebi_manager = ChebiManager(engine=cls.manager.engine, session=cls.manager.session)
cls.chebi_manager._populate_compounds(url=chebi_test_path)
logger.info('ChEBI database loaded')
cls.notch_tree = import_xml_etree(NOTCH_XML)
cls.glycolysis_tree = import_xml_etree(GLYCOLYSIS_XML)
cls.ppar_tree = import_xml_etree(PPAR_XML)
logger.info('Loading notch unflatten')
cls.notch_bel_unflatten = kegg_to_bel(NOTCH_XML, cls.hgnc_manager, cls.chebi_manager)
logger.info('Loading notch flatten')
cls.notch_bel_flatten = kegg_to_bel(NOTCH_XML, cls.hgnc_manager, cls.chebi_manager, flatten=True)
logger.info('Loading glycolysis unflatten')
cls.glycolysis_bel_unflatten = kegg_to_bel(GLYCOLYSIS_XML, cls.hgnc_manager, cls.chebi_manager)
logger.info('Loading glycolysis flatten')
cls.glycolysis_bel_flatten = kegg_to_bel(GLYCOLYSIS_XML, cls.hgnc_manager, cls.chebi_manager, flatten=True)
logger.info('Loading PPAR unflatten')
cls.ppar_bel_unflatten = kegg_to_bel(PPAR_XML, cls.hgnc_manager, cls.chebi_manager)
logger.info('Loading PPAR flatten')
cls.ppar_bel_flatten = kegg_to_bel(PPAR_XML, cls.hgnc_manager, cls.chebi_manager, flatten=True)
cls.glycolysis_empty_graph = BELGraph(
name='Glycolysis',
version='1.0.0',
description='Glycolysis',
authors="Daniel Domingo-Fernández, Josep Marín-Llaó and Sarah Mubeen",
contact='[email protected]',
)
cls.glycolysis_empty_graph.graph['pathway_id'] = 'path:hsa00010'
cls.glycolysis_empty_flatten_graph = BELGraph(
name='Glycolysis flatten',
version='1.0.0',
description='Glycolysis',
authors="Daniel Domingo-Fernández, Josep Marín-Llaó and Sarah Mubeen",
contact='[email protected]',
)
cls.glycolysis_empty_graph.graph['pathway_id'] = 'path:hsa00010'
cls.notch_empty_graph = BELGraph(
name='Notch',
version='1.0.0',
description='Notch signaling pathway',
authors="Daniel Domingo-Fernández, Josep Marín-Llaó and Sarah Mubeen",
contact='[email protected]',
)
cls.notch_empty_graph.graph['pathway_id'] = 'path:hsa04330'
cls.notch_empty_flatten_graph = BELGraph(
name='Notch flatten',
version='1.0.0',
description='Notch signaling pathway',
authors="Daniel Domingo-Fernández, Josep Marín-Llaó and Sarah Mubeen",
contact='[email protected]',
)
cls.notch_empty_flatten_graph.graph['pathway_id'] = 'path:hsa04330'
cls.ppar_empty_graph = BELGraph(
name='PPAR',
version='1.0.0',
description='PPAR signaling pathway',
authors="Daniel Domingo-Fernández, Josep Marín-Llaó and Sarah Mubeen",
contact='[email protected]',
)
cls.ppar_empty_graph.graph['pathway_id'] = 'path:hsa03320'
cls.ppar_empty_flatten_graph = BELGraph(
name='PPAR flatten',
version='1.0.0',
description='PPAR signaling pathway',
authors="Daniel Domingo-Fernández, Josep Marín-Llaó and Sarah Mubeen",
contact='[email protected]',
)
cls.ppar_empty_flatten_graph.graph['pathway_id'] = 'path:hsa03320'
@classmethod
def tearDownClass(cls):
"""Close the connection in the manager and deletes the temporary database."""
cls.manager.drop_all()
cls.hgnc_manager.drop_all()
cls.manager.session.close()
cls.hgnc_manager.session.close()
super().tearDownClass()