11import hashlib
22import logging
3- import requests
43import os
54import time
65from datetime import datetime
7- from typing import Optional
6+ from typing import Optional , Union
87from urllib import parse
98
10-
9+ import requests
1110from jose import jwt
1211
13- from mavedb .lib .logging .context import logging_context , save_to_logging_context , format_raised_exception_info_as_dict
1412from mavedb .lib .clingen .constants import GENBOREE_ACCOUNT_NAME , GENBOREE_ACCOUNT_PASSWORD , LDH_MAVE_ACCESS_ENDPOINT
15-
16- from mavedb .lib .types .clingen import LdhSubmission , ClinGenAllele
13+ from mavedb . lib . logging . context import format_raised_exception_info_as_dict , logging_context , save_to_logging_context
14+ from mavedb .lib .types .clingen import ClinGenAllele , ClinGenSubmissionError , LdhSubmission
1715from mavedb .lib .utils import batched
1816
1917logger = logging .getLogger (__name__ )
@@ -71,7 +69,9 @@ def construct_auth_url(self, url: str) -> str:
7169 token = hashlib .sha1 ((url + identity + gbTime ).encode ("utf-8" )).hexdigest ()
7270 return url + "&gbLogin=" + GENBOREE_ACCOUNT_NAME + "&gbTime=" + gbTime + "&gbToken=" + token
7371
74- def dispatch_submissions (self , content_submissions : list [str ]) -> list [ClinGenAllele ]:
72+ def dispatch_submissions (
73+ self , content_submissions : list [str ]
74+ ) -> list [Union [ClinGenAllele , ClinGenSubmissionError ]]:
7575 save_to_logging_context ({"car_submission_count" : len (content_submissions )})
7676
7777 try :
@@ -89,7 +89,7 @@ def dispatch_submissions(self, content_submissions: list[str]) -> list[ClinGenAl
8989 logger .error (msg = "Failed to dispatch CAR submission." , exc_info = exc , extra = logging_context ())
9090 return []
9191
92- response_data : list [ClinGenAllele ] = response .json ()
92+ response_data : list [Union [ ClinGenAllele , ClinGenSubmissionError ] ] = response .json ()
9393 save_to_logging_context ({"car_submission_response_count" : len (response_data )})
9494 logger .info (msg = "Successfully dispatched CAR submission." , extra = logging_context ())
9595
@@ -324,7 +324,7 @@ def clingen_allele_id_from_ldh_variation(variation: Optional[dict]) -> Optional[
324324
325325
326326def get_allele_registry_associations (
327- content_submissions : list [str ], submission_response : list [ClinGenAllele ]
327+ content_submissions : list [str ], submission_response : list [Union [ ClinGenAllele , ClinGenSubmissionError ] ]
328328) -> dict [str , str ]:
329329 """
330330 Links HGVS strings and ClinGen Canonoical Allele IDs (CAIDs) given a list of both.
@@ -360,6 +360,13 @@ def get_allele_registry_associations(
360360
361361 allele_registry_associations : dict [str , str ] = {}
362362 for registration in submission_response :
363+ if "errorType" in registration :
364+ logger .warning (
365+ msg = f"Skipping errored ClinGen Allele Registry HGVS { registration .get ('hgvs' , 'unknown' )} ({ registration .get ('errorType' , 'unknown' )} ): { registration .get ('message' , 'unknown error message' )} " ,
366+ extra = logging_context (),
367+ )
368+ continue
369+
363370 # Extract the CAID from the URL (e.g., "http://reg.test.genome.network/allele/CA2513066" -> "CA2513066")
364371 caid = registration ["@id" ].split ("/" )[- 1 ]
365372 alleles = registration .get ("genomicAlleles" , []) + registration .get ("transcriptAlleles" , [])
0 commit comments