Skip to content

Commit a125f40

Browse files
authored
docs: Update documentation for descriptive methods (#472)
1 parent b23102f commit a125f40

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

src/cool_seq_tool/mappers/exon_genomic_coords.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ async def genomic_to_tx_segment(
541541
return _return_service_errors(end_tx_seg_data.errors)
542542

543543
if start_tx_seg_data:
544-
# Need to check that gene, genomic_ac, tx_ac all match
544+
# When both start and end segments are provided, they must have
545+
# matching gene, genomic accession, and transcript
545546
errors = []
546547
for attr in ["gene", "genomic_ac", "tx_ac"]:
547548
start_seg_attr = params[attr]
@@ -661,7 +662,7 @@ def _get_tx_segment(
661662
:param genomic_ac_data: Exon coordinate data for ``genomic_ac``
662663
:param is_seg_start: ``True`` if retrieving genomic data where the transcript
663664
segment starts, defaults to ``False``
664-
:return: Transcript segment data
665+
:return: Transcript segment data and error message if unsucessful
665666
"""
666667
if is_seg_start:
667668
if strand == Strand.POSITIVE:
@@ -770,7 +771,9 @@ async def _genomic_to_tx_segment(
770771
"""
771772
params = dict.fromkeys(GenomicTxSeg.model_fields)
772773

773-
# Validate inputs exist in UTA
774+
# Validate inputs exist in UTA. We cannot create a TranscriptSegmentElement
775+
# object if the inputs do not exist in UTA, so we begin with a validation
776+
# step here
774777
if gene:
775778
async with self.uta_db.repository() as uta:
776779
gene_validation = await uta.gene_exists(gene)
@@ -803,7 +806,8 @@ async def _genomic_to_tx_segment(
803806
)
804807
genomic_ac = genomic_acs[0]
805808

806-
# Liftover to GRCh38 if the provided assembly is GRCh37
809+
# Now that we have the GRCh38 genomic assembly, we need to liftover the
810+
# coordinates to GRCh38 (if the provided assembly is GRCh37).
807811
if starting_assembly == Assembly.GRCH37:
808812
genomic_pos = await self._get_grch38_pos(
809813
genomic_ac, genomic_pos, chromosome=chromosome if chromosome else None
@@ -815,7 +819,11 @@ async def _genomic_to_tx_segment(
815819
]
816820
)
817821

818-
# Select a transcript if not provided
822+
# Select a transcript if not provided. We prioritize the selection of a
823+
# transcript in the MANE collection as these are considered clinically
824+
# representative transcripts. If a MANE or longest compatible transcript
825+
# is not available, we then attempt to select a noncoding transcript
826+
# (e.g. NR_)
819827
if not transcript:
820828
mane_transcripts = self.mane_transcript_mappings.get_gene_mane_data(gene)
821829

@@ -835,7 +843,10 @@ async def _genomic_to_tx_segment(
835843
if results:
836844
transcript = results.refseq
837845
else:
838-
# Run if gene is for a noncoding transcript
846+
# Run if gene is for a noncoding transcript, NR (i.e. the
847+
# gene symbol does not map to an NM_ transcript accession).
848+
# The code block above specifically looks within the MANE
849+
# transcript set (NM_ accessions).
839850
query = """
840851
SELECT DISTINCT tx_ac
841852
FROM tx_exon_aln_mv
@@ -880,8 +891,9 @@ async def _genomic_to_tx_segment(
880891
if use_alt_start_i and coordinate_type == CoordinateType.RESIDUE:
881892
genomic_pos = genomic_pos - 1 # Convert residue coordinate to inter-residue
882893

883-
# Validate that the breakpoint occurs within 150 bp of the first and last exon for the selected transcript.
884-
# A breakpoint beyond this range is likely erroneous.
894+
# Validate that the breakpoint occurs within 150 bp of the first and last exon
895+
# for the selected transcript. A breakpoint beyond this range may represent
896+
# a regulatory event, so we would like to note this for the user.
885897
async with self.uta_db.repository() as uta:
886898
coordinate_check = await uta.validate_genomic_breakpoint(
887899
pos=genomic_pos, genomic_ac=genomic_ac, tx_ac=transcript
@@ -929,7 +941,7 @@ async def _genomic_to_tx_segment(
929941

930942
genomic_location, err_msg = self._get_vrs_seq_loc(
931943
genomic_ac, genomic_pos, is_seg_start, strand, is_exonic
932-
)
944+
) # Represent genomic breakpoint using VRS SequenceLocation class
933945
if err_msg:
934946
return GenomicTxSeg(errors=[err_msg])
935947

@@ -1019,7 +1031,10 @@ def _get_adjacent_exon(
10191031
if len(tx_exons_genomic_coords) == 1:
10201032
return 0
10211033

1022-
# Check if a breakpoint occurs before/after the transcript boundaries
1034+
# Check if a breakpoint occurs before/after the transcript boundaries.
1035+
# We return 0 if the breakpoint occurs before the transcript boundary
1036+
# and the last exon number if the breakpoint occurs after the transcript
1037+
# boundary.
10231038
bp = start if start else end
10241039
exon_list_len = len(tx_exons_genomic_coords) - 1
10251040

@@ -1034,6 +1049,9 @@ def _get_adjacent_exon(
10341049
if bp < tx_exons_genomic_coords[exon_list_len].alt_start_i:
10351050
return exon_list_len
10361051

1052+
# Having determined that the breakpoint occurs within the boundaries
1053+
# of the exon, we then iterate through all exon pairs and determine
1054+
# the appropriate exon number.
10371055
for i in range(exon_list_len):
10381056
exon = tx_exons_genomic_coords[i]
10391057
if start == exon.alt_start_i:
@@ -1047,7 +1065,9 @@ def _get_adjacent_exon(
10471065
else:
10481066
lte_exon = next_exon
10491067
gte_exon = exon
1050-
if bp >= lte_exon.alt_end_i and bp <= gte_exon.alt_start_i:
1068+
if (
1069+
bp >= lte_exon.alt_end_i and bp <= gte_exon.alt_start_i
1070+
): # Breakpoint occurs between the current and next exon
10511071
break
10521072

10531073
# Return current exon if end position is provided, next exon if start position

0 commit comments

Comments
 (0)