3
3
"""PyOBO's Gilda utilities."""
4
4
5
5
import logging
6
+ from subprocess import CalledProcessError
6
7
from typing import Iterable , List , Optional , Tuple , Type , Union
7
8
8
9
import bioregistry
@@ -96,6 +97,7 @@ def get_grounder(
96
97
versions : Union [None , str , Iterable [Union [str , None ]]] = None ,
97
98
strict : bool = True ,
98
99
skip_obsolete : bool = False ,
100
+ progress : bool = True ,
99
101
) -> Grounder :
100
102
"""Get a Gilda grounder for the given prefix(es)."""
101
103
unnamed = set () if unnamed is None else set (unnamed )
@@ -113,7 +115,7 @@ def get_grounder(
113
115
raise ValueError
114
116
115
117
terms : List [gilda .term .Term ] = []
116
- for prefix , version in zip (prefixes , versions ):
118
+ for prefix , version in zip (tqdm ( prefixes , leave = False , disable = not progress ) , versions ):
117
119
try :
118
120
p_terms = list (
119
121
get_gilda_terms (
@@ -122,9 +124,10 @@ def get_grounder(
122
124
version = version ,
123
125
strict = strict ,
124
126
skip_obsolete = skip_obsolete ,
127
+ progress = progress ,
125
128
)
126
129
)
127
- except NoBuild :
130
+ except ( NoBuild , CalledProcessError ) :
128
131
continue
129
132
else :
130
133
terms .extend (p_terms )
@@ -164,13 +167,20 @@ def get_gilda_terms(
164
167
version : Optional [str ] = None ,
165
168
strict : bool = True ,
166
169
skip_obsolete : bool = False ,
170
+ progress : bool = True ,
167
171
) -> Iterable [gilda .term .Term ]:
168
172
"""Get gilda terms for the given namespace."""
169
173
id_to_name = get_id_name_mapping (prefix , version = version , strict = strict )
170
174
id_to_species = get_id_species_mapping (prefix , version = version , strict = strict )
171
175
obsoletes = get_obsolete (prefix , version = version , strict = strict ) if skip_obsolete else set ()
172
176
173
- it = tqdm (id_to_name .items (), desc = f"[{ prefix } ] mapping" , unit_scale = True , unit = "name" )
177
+ it = tqdm (
178
+ id_to_name .items (),
179
+ desc = f"[{ prefix } ] mapping" ,
180
+ unit_scale = True ,
181
+ unit = "name" ,
182
+ disable = not progress ,
183
+ )
174
184
for identifier , name in it :
175
185
if identifier in obsoletes :
176
186
continue
@@ -186,7 +196,11 @@ def get_gilda_terms(
186
196
id_to_synonyms = get_id_synonyms_mapping (prefix , version = version )
187
197
if id_to_synonyms :
188
198
it = tqdm (
189
- id_to_synonyms .items (), desc = f"[{ prefix } ] mapping" , unit_scale = True , unit = "synonym"
199
+ id_to_synonyms .items (),
200
+ desc = f"[{ prefix } ] mapping" ,
201
+ unit_scale = True ,
202
+ unit = "synonym" ,
203
+ disable = not progress ,
190
204
)
191
205
for identifier , synonyms in it :
192
206
if identifier in obsoletes :
@@ -205,7 +219,13 @@ def get_gilda_terms(
205
219
)
206
220
207
221
if identifiers_are_names :
208
- it = tqdm (get_ids (prefix ), desc = f"[{ prefix } ] mapping" , unit_scale = True , unit = "id" )
222
+ it = tqdm (
223
+ get_ids (prefix ),
224
+ desc = f"[{ prefix } ] mapping" ,
225
+ unit_scale = True ,
226
+ unit = "id" ,
227
+ disable = not progress ,
228
+ )
209
229
for identifier in it :
210
230
if identifier in obsoletes :
211
231
continue
0 commit comments