@@ -72,31 +72,118 @@ def ontology_dict_with_imports():
72
72
73
73
74
74
@pytest .fixture
75
- def mock_CXGSchema (ontology_dict , ontology_dict_with_imports , mock_load_supported_versions , mock_load_ontology_file ):
75
+ def ontology_dict_with_cross_ontology_terms ():
76
+ return {
77
+ # test cases: terms with exact matches + ancestors of terms without exact matches
78
+ "ZFA:0000000" : {
79
+ "ancestors" : {},
80
+ "cross_ontology_terms" : {
81
+ "CL" : "CL:0000000" ,
82
+ },
83
+ },
84
+ "ZFA:0000001" : {
85
+ "ancestors" : {
86
+ "ZFA:0000000" : 1 ,
87
+ },
88
+ "cross_ontology_terms" : {
89
+ "CL" : "CL:0000001" ,
90
+ },
91
+ },
92
+ "ZFA:0000002" : {
93
+ "ancestors" : {
94
+ "ZFA:0000000" : 1 ,
95
+ },
96
+ "cross_ontology_terms" : {
97
+ "CL" : "CL:0000002" ,
98
+ },
99
+ },
100
+ "ZFA:0000003" : {
101
+ "ancestors" : {
102
+ "ZFA:0000000" : 1 ,
103
+ },
104
+ "cross_ontology_terms" : {
105
+ "CL" : "CL:0000003" ,
106
+ },
107
+ },
108
+ # test case: term with no exact term and multiple closest terms 1 edge away
109
+ "ZFA:0000004" : {
110
+ "ancestors" : {
111
+ "ZFA:0000001" : 1 ,
112
+ "ZFA:0000002" : 1 ,
113
+ "ZFA:0000000" : 2 ,
114
+ },
115
+ },
116
+ # test case: term with no exact term and 1 closest term, 1 edge away
117
+ "ZFA:0000005" : {
118
+ "ancestors" : {
119
+ "ZFA:0000003" : 1 ,
120
+ "ZFA:0000000" : 2 ,
121
+ },
122
+ },
123
+ # test case: term with no exact term and multiple closest terms 2 edges away
124
+ "ZFA:0000006" : {
125
+ "ancestors" : {
126
+ "ZFA:0000004" : 1 ,
127
+ "ZFA:0000005" : 1 ,
128
+ "ZFA:0000001" : 2 ,
129
+ "ZFA:0000002" : 2 ,
130
+ "ZFA:0000003" : 2 ,
131
+ "ZFA:0000000" : 3 ,
132
+ },
133
+ },
134
+ # test case: term with no exact or closest term
135
+ "ZFA:0000007" : {
136
+ "ancestors" : {},
137
+ },
138
+ }
139
+
140
+
141
+ @pytest .fixture
142
+ def mock_CXGSchema (
143
+ ontology_dict ,
144
+ ontology_dict_with_imports ,
145
+ ontology_dict_with_cross_ontology_terms ,
146
+ mock_load_supported_versions ,
147
+ mock_load_ontology_file ,
148
+ ):
76
149
mock_load_supported_versions .return_value = {
77
150
"5.0.0" : {
78
151
"ontologies" : {
79
- "CL" : {"version" : "2024-01-01" , "source" : "http://example.com" , "filename" : "cl.owl" },
152
+ "CL" : {
153
+ "version" : "2024-01-01" ,
154
+ "source" : "http://example.com" ,
155
+ "filename" : "cl.owl" ,
156
+ "cross_ontology_mapping" : "cl.sssom" ,
157
+ },
80
158
"HANCESTRO" : {
81
159
"version" : "2024-01-01" ,
82
160
"source" : "http://example.com" ,
83
161
"filename" : "cl.owl" ,
84
162
"additional_ontologies" : ["AfPO" ],
85
163
},
164
+ "ZFA" : {
165
+ "version" : "2024-01-01" ,
166
+ "source" : "http://example.com" ,
167
+ "filename" : "zfa.owl" ,
168
+ "map_to" : ["CL" ],
169
+ },
86
170
}
87
171
}
88
172
}
89
173
cxg_schema = CXGSchema ()
90
174
cxg_schema .ontology_file_names = {
91
175
"CL" : "CL-ontology-2024-01-01.json.gz" ,
92
176
"HANCESTRO" : "HANCESTRO-ontology-2024-01-01.json.gz" ,
177
+ "ZFA" : "ZFA-ontology-2024-01-01.json.gz" ,
93
178
}
94
179
95
180
def get_mock_ontology_dict (file_name ):
96
181
if "CL" in file_name :
97
182
return ontology_dict
98
183
if "HANCESTRO" in file_name :
99
184
return ontology_dict_with_imports
185
+ if "ZFA" in file_name :
186
+ return ontology_dict_with_cross_ontology_terms
100
187
return None
101
188
102
189
mock_load_ontology_file .side_effect = get_mock_ontology_dict
@@ -584,3 +671,27 @@ def test_get_term_id_by_label(ontology_parser, label, ontology_name, expected):
584
671
def test_get_term_id_by_label__unsupported_ontology_name (ontology_parser ):
585
672
with pytest .raises (ValueError ):
586
673
ontology_parser .get_term_id_by_label ("gene A" , "GO" )
674
+
675
+
676
+ @pytest .mark .parametrize ("term_id,expected" , [("ZFA:0000000" , "CL:0000000" ), ("ZFA:0000004" , None )])
677
+ def test_get_bridge_term_id (ontology_parser , term_id , expected ):
678
+ assert ontology_parser .get_bridge_term_id (term_id , "CL" ) == expected
679
+
680
+
681
+ def test_get_bridge_term_id__unsupported_cross_ontology (ontology_parser ):
682
+ with pytest .raises (ValueError ):
683
+ ontology_parser .get_bridge_term_id ("ZFA:0000000" , "HANCESTRO" )
684
+
685
+
686
+ @pytest .mark .parametrize (
687
+ "term_id,expected" ,
688
+ [
689
+ ("ZFA:0000007" , []),
690
+ ("ZFA:0000006" , ["CL:0000001" , "CL:0000002" , "CL:0000003" ]),
691
+ ("ZFA:0000005" , ["CL:0000003" ]),
692
+ ("ZFA:0000004" , ["CL:0000001" , "CL:0000002" ]),
693
+ ("ZFA:0000000" , ["CL:0000000" ]),
694
+ ],
695
+ )
696
+ def test_get_closest_bridge_term_ids (ontology_parser , term_id , expected ):
697
+ assert ontology_parser .get_closest_bridge_term_ids (term_id , "CL" ) == expected
0 commit comments