@@ -770,7 +770,9 @@ async def _genomic_to_tx_segment(
770770 """
771771 params = dict .fromkeys (GenomicTxSeg .model_fields )
772772
773- # Validate inputs exist in UTA
773+ # Validate inputs exist in UTA. We cannot create a TranscriptSegmentElement
774+ # object if the inputs do not exist in UTA, so we begin with a validation
775+ # step here
774776 if gene :
775777 async with self .uta_db .repository () as uta :
776778 gene_validation = await uta .gene_exists (gene )
@@ -803,7 +805,7 @@ async def _genomic_to_tx_segment(
803805 )
804806 genomic_ac = genomic_acs [0 ]
805807
806- # Liftover to GRCh38 if the provided assembly is GRCh37
808+ # Liftover to GRCh38 if the provided assembly is GRCh37.
807809 if starting_assembly == Assembly .GRCH37 :
808810 genomic_pos = await self ._get_grch38_pos (
809811 genomic_ac , genomic_pos , chromosome = chromosome if chromosome else None
@@ -815,7 +817,11 @@ async def _genomic_to_tx_segment(
815817 ]
816818 )
817819
818- # Select a transcript if not provided
820+ # Select a transcript if not provided. We prioritize the selection of a
821+ # transcript in the MANE collection as these are considered clinically
822+ # representative transcripts. If a MANE or longest compatible transcript
823+ # is not available, we then attempt to select a noncoding transcript
824+ # (e.g. NR_)
819825 if not transcript :
820826 mane_transcripts = self .mane_transcript_mappings .get_gene_mane_data (gene )
821827
@@ -929,7 +935,7 @@ async def _genomic_to_tx_segment(
929935
930936 genomic_location , err_msg = self ._get_vrs_seq_loc (
931937 genomic_ac , genomic_pos , is_seg_start , strand , is_exonic
932- )
938+ ) # Represent genomic breakpoint using VRS SequenceLocation class
933939 if err_msg :
934940 return GenomicTxSeg (errors = [err_msg ])
935941
@@ -1019,7 +1025,10 @@ def _get_adjacent_exon(
10191025 if len (tx_exons_genomic_coords ) == 1 :
10201026 return 0
10211027
1022- # Check if a breakpoint occurs before/after the transcript boundaries
1028+ # Check if a breakpoint occurs before/after the transcript boundaries.
1029+ # We return 0 if the breakpoint occurs before the transcript boundary
1030+ # and the last exon number if the breakpoint occurs after the transcript
1031+ # boundary.
10231032 bp = start if start else end
10241033 exon_list_len = len (tx_exons_genomic_coords ) - 1
10251034
@@ -1034,6 +1043,9 @@ def _get_adjacent_exon(
10341043 if bp < tx_exons_genomic_coords [exon_list_len ].alt_start_i :
10351044 return exon_list_len
10361045
1046+ # Having determined that the breakpoint occurs within the boundaries
1047+ # of the exon, we then iterate through all exon pairs and determine
1048+ # the appropriate exon number.
10371049 for i in range (exon_list_len ):
10381050 exon = tx_exons_genomic_coords [i ]
10391051 if start == exon .alt_start_i :
@@ -1047,7 +1059,9 @@ def _get_adjacent_exon(
10471059 else :
10481060 lte_exon = next_exon
10491061 gte_exon = exon
1050- if bp >= lte_exon .alt_end_i and bp <= gte_exon .alt_start_i :
1062+ if (
1063+ bp >= lte_exon .alt_end_i and bp <= gte_exon .alt_start_i
1064+ ): # Breakpoint occurs between the current and next exon
10511065 break
10521066
10531067 # Return current exon if end position is provided, next exon if start position
0 commit comments