From c8773135b57cb4f75dc75d12ff0a89901472e11a Mon Sep 17 00:00:00 2001 From: Sally Grindstaff Date: Wed, 27 Nov 2024 16:13:11 -0800 Subject: [PATCH] Check for post-map haplotype before accessing members --- src/dcd_mapping/annotate.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/dcd_mapping/annotate.py b/src/dcd_mapping/annotate.py index 47cf38c..b8f7342 100644 --- a/src/dcd_mapping/annotate.py +++ b/src/dcd_mapping/annotate.py @@ -306,22 +306,20 @@ def _annotate_haplotype_mapping( for allele in pre_mapped.members: allele.extensions = [_get_vrs_ref_allele_seq(allele, metadata, tx_results)] - # Determine reference sequence - if mapped_score.annotation_layer == AnnotationLayer.GENOMIC: - sequence_id = ( - f"ga4gh:{post_mapped.members[0].location.sequenceReference.refgetAccession}" - ) - accession = get_chromosome_identifier_from_vrs_id(sequence_id) - if accession is None: - raise ValueError - if accession.startswith("refseq:"): - accession = accession[7:] - else: - if tx_results is None: - raise ValueError # impossible by definition - accession = tx_results.np - if post_mapped: + # Determine reference sequence + if mapped_score.annotation_layer == AnnotationLayer.GENOMIC: + sequence_id = f"ga4gh:{post_mapped.members[0].location.sequenceReference.refgetAccession}" + accession = get_chromosome_identifier_from_vrs_id(sequence_id) + if accession is None: + raise ValueError + if accession.startswith("refseq:"): + accession = accession[7:] + else: + if tx_results is None: + raise ValueError # impossible by definition + accession = tx_results.np + sr = get_seqrepo() for allele in post_mapped.members: loc = allele.location