@@ -146,10 +146,6 @@ class DownloadError(Exception):
146
146
'Individual/Origin/Geographic' : 'String'
147
147
}
148
148
149
- # CONFIGURATIONS
150
- logging .basicConfig (level = logging .INFO , format = '%(asctime)s - %(levelname)s - %(message)s' )
151
-
152
-
153
149
def get_file_from_url (url , save_to , override = False ):
154
150
"""
155
151
Gets file from url and saves it into provided path. Overrides, if override is True.
@@ -289,20 +285,6 @@ def from_clinvar_name_to_dna(name):
289
285
290
286
return name [start :end ]
291
287
292
-
293
- def check_if_valid_response (text ):
294
- """
295
- Checks if gene symbol is valid
296
-
297
- :param str text: response's text
298
- """
299
-
300
- if 'Error' in text :
301
- return False
302
- return True
303
-
304
-
305
-
306
288
def download_gene_lovd (gene_list :list ,folder_path ,raise_exception = False ):
307
289
"""
308
290
Downloads data into txt files from gene_list.
@@ -315,11 +297,19 @@ def download_gene_lovd(gene_list:list,folder_path,raise_exception = False):
315
297
for gene in gene_list :
316
298
file_path = folder_path + '/' + gene + ".txt"
317
299
url = f"https://databases.lovd.nl/shared/download/all/gene/{ gene } "
318
- response = requests .get (url ,timeout = 10 )
319
- valid = check_if_valid_response (response .text [:6 ])
300
+ try :
301
+ response = requests .get (url , timeout = 10 )
302
+ except RequestException as e :
303
+ raise DownloadError (f"Error while downloading file from { url } " ) from e
304
+
305
+ if response .status_code != 200 :
306
+ raise BadResponseException (f"Bad response from { url } ."
307
+ f" Status code: { response .status_code } " )
308
+ #If gene does not exist, the first word of the file will be Error
309
+ valid = 'Error' not in response .text [:6 ]
320
310
if valid :
321
311
get_file_from_url (url ,file_path )
322
312
elif raise_exception :
323
313
raise ValueError (f"Symbol: { gene } does not exist in the LOVD database" )
324
314
else :
325
- logging .info ("Symbol: %s does not exist in the LOVD database" ,gene )
315
+ logging .error ("Symbol: %s does not exist in the LOVD database" ,gene )
0 commit comments