4242 ScoresetMetadata ,
4343 TargetSequenceType ,
4444 TxSelectResult ,
45+ VrsVersion ,
4546)
4647
4748_logger = logging .getLogger (__name__ )
@@ -243,8 +244,9 @@ def _annotate_allele_mapping(
243244 mapped_score : MappedScore ,
244245 tx_results : TxSelectResult | None ,
245246 metadata : ScoresetMetadata ,
247+ vrs_version : VrsVersion = VrsVersion .V_2 ,
246248) -> ScoreAnnotationWithLayer :
247- """Perform annotations and create VRS 1.3 equivalents for allele mappings."""
249+ """Perform annotations and, if necessary, create VRS 1.3 equivalents for allele mappings."""
248250 pre_mapped : Allele = mapped_score .pre_mapped
249251 post_mapped : Allele = mapped_score .post_mapped
250252
@@ -274,24 +276,27 @@ def _annotate_allele_mapping(
274276 hgvs_string , syntax = _get_hgvs_string (post_mapped , accession )
275277 post_mapped .expressions = [Expression (syntax = syntax , value = hgvs_string )]
276278
277- pre_mapped_vod = _allele_to_vod (pre_mapped )
278- post_mapped_vod = _allele_to_vod (post_mapped )
279+ if vrs_version == VrsVersion .V_1_3 :
280+ pre_mapped = _allele_to_vod (pre_mapped )
281+ post_mapped = _allele_to_vod (post_mapped )
279282
280283 return ScoreAnnotationWithLayer (
281- pre_mapped = pre_mapped_vod ,
282- post_mapped = post_mapped_vod ,
283- pre_mapped_2_0 = pre_mapped ,
284- post_mapped_2_0 = post_mapped ,
284+ pre_mapped = pre_mapped ,
285+ post_mapped = post_mapped ,
286+ vrs_version = vrs_version ,
285287 mavedb_id = mapped_score .accession_id ,
286288 score = float (mapped_score .score ) if mapped_score .score else None ,
287289 annotation_layer = mapped_score .annotation_layer ,
288290 )
289291
290292
291293def _annotate_haplotype_mapping (
292- mapping : MappedScore , tx_results : TxSelectResult | None , metadata : ScoresetMetadata
294+ mapping : MappedScore ,
295+ tx_results : TxSelectResult | None ,
296+ metadata : ScoresetMetadata ,
297+ vrs_version : VrsVersion = VrsVersion .V_2 ,
293298) -> ScoreAnnotationWithLayer :
294- """Perform annotations and create VRS 1.3 equivalents for haplotype mappings."""
299+ """Perform annotations and, if necessary, create VRS 1.3 equivalents for haplotype mappings."""
295300 pre_mapped : Haplotype = mapping .pre_mapped # type: ignore
296301 post_mapped : Haplotype = mapping .post_mapped # type: ignore
297302 # get vrs_ref_allele_seq for pre-mapped variants
@@ -324,14 +329,14 @@ def _annotate_haplotype_mapping(
324329 hgvs , syntax = _get_hgvs_string (allele , accession )
325330 allele .expressions = [Expression (syntax = syntax , value = hgvs )]
326331
327- pre_mapped_converted = _haplotype_to_haplotype_1_3 (pre_mapped )
328- post_mapped_converted = _haplotype_to_haplotype_1_3 (post_mapped )
332+ if vrs_version == VrsVersion .V_1_3 :
333+ pre_mapped = _haplotype_to_haplotype_1_3 (pre_mapped )
334+ post_mapped = _haplotype_to_haplotype_1_3 (post_mapped )
329335
330336 return ScoreAnnotationWithLayer (
331- pre_mapped = pre_mapped_converted ,
332- post_mapped = post_mapped_converted ,
333- pre_mapped_2_0 = pre_mapped ,
334- post_mapped_2_0 = post_mapped ,
337+ pre_mapped = pre_mapped ,
338+ post_mapped = post_mapped ,
339+ vrs_version = vrs_version ,
335340 mavedb_id = mapping .accession_id ,
336341 score = float (mapping .score ) if mapping .score is not None else None ,
337342 annotation_layer = mapping .annotation_layer ,
@@ -342,6 +347,7 @@ def annotate(
342347 mapped_scores : list [MappedScore ],
343348 tx_results : TxSelectResult | None ,
344349 metadata : ScoresetMetadata ,
350+ vrs_version : VrsVersion = VrsVersion .V_2 ,
345351) -> list [ScoreAnnotationWithLayer ]:
346352 """Given a list of mappings, add additional contextual data:
347353
@@ -365,13 +371,17 @@ def annotate(
365371 mapped_score .post_mapped , Haplotype
366372 ):
367373 score_annotations .append (
368- _annotate_haplotype_mapping (mapped_score , tx_results , metadata )
374+ _annotate_haplotype_mapping (
375+ mapped_score , tx_results , metadata , vrs_version
376+ )
369377 )
370378 elif isinstance (mapped_score .pre_mapped , Allele ) and isinstance (
371379 mapped_score .post_mapped , Allele
372380 ):
373381 score_annotations .append (
374- _annotate_allele_mapping (mapped_score , tx_results , metadata )
382+ _annotate_allele_mapping (
383+ mapped_score , tx_results , metadata , vrs_version
384+ )
375385 )
376386 else :
377387 ValueError ("inconsistent variant structure" )
@@ -464,7 +474,6 @@ def save_mapped_output_json(
464474 mappings : list [ScoreAnnotationWithLayer ],
465475 align_result : AlignmentResult ,
466476 tx_output : TxSelectResult | None ,
467- include_vrs_2 : bool = False ,
468477 preferred_layer_only : bool = False ,
469478 output_path : Path | None = None ,
470479) -> Path :
@@ -474,7 +483,6 @@ def save_mapped_output_json(
474483 :param mave_vrs_mappings: A dictionary of VrsObject1_x objects
475484 :param align_result: Alignment information for a score set
476485 :param tx_output: Transcript output for a score set
477- :param include_vrs_2: if true, also include VRS 2.0 mappings
478486 :param output_path: specific location to save output to. Default to
479487 <dcd_mapping_data_dir>/urn:mavedb:00000XXX-X-X_mapping_<ISO8601 datetime>.json
480488 :return: output location
@@ -523,19 +531,14 @@ def save_mapped_output_json(
523531 mapped_scores = mapped_scores ,
524532 )
525533
526- if not include_vrs_2 :
527- for m in output .mapped_scores :
528- m .pre_mapped_2_0 = None
529- m .post_mapped_2_0 = None
530-
531534 if not output_path :
532535 now = datetime .datetime .now (tz = datetime .UTC ).isoformat ()
533536 output_path = LOCAL_STORE_PATH / f"{ urn } _mapping_{ now } .json"
534537
535538 _logger .info ("Saving mapping output to %s" , output_path )
536539 with output_path .open ("w" ) as file :
537540 json .dump (
538- json . loads ( output .model_dump_json (exclude_unset = True , exclude_none = True ) ),
541+ output .model_dump (exclude_unset = True , exclude_none = True ),
539542 file ,
540543 indent = 4 ,
541544 )
0 commit comments