varcode 9.3.3__tar.gz → 9.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. {varcode-9.3.3/varcode.egg-info → varcode-9.3.4}/PKG-INFO +1 -1
  2. varcode-9.3.4/tests/test_selenocysteine_proteins.py +190 -0
  3. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/codon_tables.py +9 -1
  4. varcode-9.3.4/varcode/effects/selenocysteine.py +127 -0
  5. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/sequence_change.py +12 -59
  6. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/structural.py +15 -6
  7. {varcode-9.3.3 → varcode-9.3.4}/varcode/mutant_transcript.py +14 -7
  8. {varcode-9.3.3 → varcode-9.3.4}/varcode/splice_outcomes.py +14 -10
  9. {varcode-9.3.3 → varcode-9.3.4}/varcode/transcript_layout.py +7 -2
  10. varcode-9.3.4/varcode/version.py +1 -0
  11. {varcode-9.3.3 → varcode-9.3.4/varcode.egg-info}/PKG-INFO +1 -1
  12. {varcode-9.3.3 → varcode-9.3.4}/varcode.egg-info/SOURCES.txt +2 -0
  13. varcode-9.3.3/varcode/version.py +0 -1
  14. {varcode-9.3.3 → varcode-9.3.4}/LICENSE +0 -0
  15. {varcode-9.3.3 → varcode-9.3.4}/MANIFEST.in +0 -0
  16. {varcode-9.3.3 → varcode-9.3.4}/README.md +0 -0
  17. {varcode-9.3.3 → varcode-9.3.4}/pyproject.toml +0 -0
  18. {varcode-9.3.3 → varcode-9.3.4}/requirements.txt +0 -0
  19. {varcode-9.3.3 → varcode-9.3.4}/setup.cfg +0 -0
  20. {varcode-9.3.3 → varcode-9.3.4}/tests/test_annotator_divergence_scenarios.py +0 -0
  21. {varcode-9.3.3 → varcode-9.3.4}/tests/test_annotator_parity_adversarial.py +0 -0
  22. {varcode-9.3.3 → varcode-9.3.4}/tests/test_annotators.py +0 -0
  23. {varcode-9.3.3 → varcode-9.3.4}/tests/test_bnd_retained_segments.py +0 -0
  24. {varcode-9.3.3 → varcode-9.3.4}/tests/test_cli_effects.py +0 -0
  25. {varcode-9.3.3 → varcode-9.3.4}/tests/test_cli_genes.py +0 -0
  26. {varcode-9.3.3 → varcode-9.3.4}/tests/test_cli_without_pkg_resources.py +0 -0
  27. {varcode-9.3.3 → varcode-9.3.4}/tests/test_collection_filtering.py +0 -0
  28. {varcode-9.3.3 → varcode-9.3.4}/tests/test_collection_variants_attr_consistency.py +0 -0
  29. {varcode-9.3.3 → varcode-9.3.4}/tests/test_common.py +0 -0
  30. {varcode-9.3.3 → varcode-9.3.4}/tests/test_cosmic_mutations.py +0 -0
  31. {varcode-9.3.3 → varcode-9.3.4}/tests/test_cryptic_exons.py +0 -0
  32. {varcode-9.3.3 → varcode-9.3.4}/tests/test_csv_roundtrip.py +0 -0
  33. {varcode-9.3.3 → varcode-9.3.4}/tests/test_dbnsfp_validation.py +0 -0
  34. {varcode-9.3.3 → varcode-9.3.4}/tests/test_default_structural_helpers.py +0 -0
  35. {varcode-9.3.3 → varcode-9.3.4}/tests/test_documentation_examples.py +0 -0
  36. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effect_annotation_errors.py +0 -0
  37. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effect_candidates.py +0 -0
  38. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effect_classes.py +0 -0
  39. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effect_collection.py +0 -0
  40. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effect_collection_serialization.py +0 -0
  41. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effect_collection_sort_order.py +0 -0
  42. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effect_hypotheses.py +0 -0
  43. {varcode-9.3.3 → varcode-9.3.4}/tests/test_effects_from_mutagenix_variants.py +0 -0
  44. {varcode-9.3.3 → varcode-9.3.4}/tests/test_exacto_fusions.py +0 -0
  45. {varcode-9.3.3 → varcode-9.3.4}/tests/test_exonic_splice_site.py +0 -0
  46. {varcode-9.3.3 → varcode-9.3.4}/tests/test_fast_path.py +0 -0
  47. {varcode-9.3.3 → varcode-9.3.4}/tests/test_frameshift_cterminus_regression.py +0 -0
  48. {varcode-9.3.3 → varcode-9.3.4}/tests/test_frameshift_helpers.py +0 -0
  49. {varcode-9.3.3 → varcode-9.3.4}/tests/test_fusion_partner_candidates.py +0 -0
  50. {varcode-9.3.3 → varcode-9.3.4}/tests/test_genome_contig_validation.py +0 -0
  51. {varcode-9.3.3 → varcode-9.3.4}/tests/test_genome_sequence.py +0 -0
  52. {varcode-9.3.3 → varcode-9.3.4}/tests/test_genomic_layout.py +0 -0
  53. {varcode-9.3.3 → varcode-9.3.4}/tests/test_genotype.py +0 -0
  54. {varcode-9.3.3 → varcode-9.3.4}/tests/test_genotype_from_vcf.py +0 -0
  55. {varcode-9.3.3 → varcode-9.3.4}/tests/test_germline_context.py +0 -0
  56. {varcode-9.3.3 → varcode-9.3.4}/tests/test_germline_effects.py +0 -0
  57. {varcode-9.3.3 → varcode-9.3.4}/tests/test_haplotype_effect.py +0 -0
  58. {varcode-9.3.3 → varcode-9.3.4}/tests/test_maf.py +0 -0
  59. {varcode-9.3.3 → varcode-9.3.4}/tests/test_mitochondrial.py +0 -0
  60. {varcode-9.3.3 → varcode-9.3.4}/tests/test_mm10_klf6_frameshift.py +0 -0
  61. {varcode-9.3.3 → varcode-9.3.4}/tests/test_mouse.py +0 -0
  62. {varcode-9.3.3 → varcode-9.3.4}/tests/test_mutant_transcript.py +0 -0
  63. {varcode-9.3.3 → varcode-9.3.4}/tests/test_mutate.py +0 -0
  64. {varcode-9.3.3 → varcode-9.3.4}/tests/test_no_duplicate_variants.py +0 -0
  65. {varcode-9.3.3 → varcode-9.3.4}/tests/test_nonlocal_sv_transcripts.py +0 -0
  66. {varcode-9.3.3 → varcode-9.3.4}/tests/test_osteosarc_fusions.py +0 -0
  67. {varcode-9.3.3 → varcode-9.3.4}/tests/test_partial_annotators.py +0 -0
  68. {varcode-9.3.3 → varcode-9.3.4}/tests/test_premature_stop_short_description.py +0 -0
  69. {varcode-9.3.3 → varcode-9.3.4}/tests/test_problematic_variants.py +0 -0
  70. {varcode-9.3.3 → varcode-9.3.4}/tests/test_protein_diff_parity.py +0 -0
  71. {varcode-9.3.3 → varcode-9.3.4}/tests/test_read_phase_resolver.py +0 -0
  72. {varcode-9.3.3 → varcode-9.3.4}/tests/test_real_world_callers.py +0 -0
  73. {varcode-9.3.3 → varcode-9.3.4}/tests/test_reference.py +0 -0
  74. {varcode-9.3.3 → varcode-9.3.4}/tests/test_reference_mismatch_error.py +0 -0
  75. {varcode-9.3.3 → varcode-9.3.4}/tests/test_reference_segments.py +0 -0
  76. {varcode-9.3.3 → varcode-9.3.4}/tests/test_rna_evidence.py +0 -0
  77. {varcode-9.3.3 → varcode-9.3.4}/tests/test_rna_haplotype_sequences.py +0 -0
  78. {varcode-9.3.3 → varcode-9.3.4}/tests/test_rna_read_phasing_source.py +0 -0
  79. {varcode-9.3.3 → varcode-9.3.4}/tests/test_selenocysteine.py +0 -0
  80. {varcode-9.3.3 → varcode-9.3.4}/tests/test_silent_aa_pos.py +0 -0
  81. {varcode-9.3.3 → varcode-9.3.4}/tests/test_silent_hgvs_description.py +0 -0
  82. {varcode-9.3.3 → varcode-9.3.4}/tests/test_splice_graph.py +0 -0
  83. {varcode-9.3.3 → varcode-9.3.4}/tests/test_splice_outcomes.py +0 -0
  84. {varcode-9.3.3 → varcode-9.3.4}/tests/test_splice_site_effects.py +0 -0
  85. {varcode-9.3.3 → varcode-9.3.4}/tests/test_stop_codon_classification_bugs.py +0 -0
  86. {varcode-9.3.3 → varcode-9.3.4}/tests/test_string_helpers.py +0 -0
  87. {varcode-9.3.3 → varcode-9.3.4}/tests/test_structural_variant_annotator.py +0 -0
  88. {varcode-9.3.3 → varcode-9.3.4}/tests/test_structural_variants.py +0 -0
  89. {varcode-9.3.3 → varcode-9.3.4}/tests/test_sv_selenocysteine.py +0 -0
  90. {varcode-9.3.3 → varcode-9.3.4}/tests/test_sv_sequence_changes.py +0 -0
  91. {varcode-9.3.3 → varcode-9.3.4}/tests/test_sv_tabular_metadata.py +0 -0
  92. {varcode-9.3.3 → varcode-9.3.4}/tests/test_symbolic_alleles.py +0 -0
  93. {varcode-9.3.3 → varcode-9.3.4}/tests/test_symbolic_sv_padding.py +0 -0
  94. {varcode-9.3.3 → varcode-9.3.4}/tests/test_timings.py +0 -0
  95. {varcode-9.3.3 → varcode-9.3.4}/tests/test_transcript_layout.py +0 -0
  96. {varcode-9.3.3 → varcode-9.3.4}/tests/test_transcript_model.py +0 -0
  97. {varcode-9.3.3 → varcode-9.3.4}/tests/test_transforms_left_align.py +0 -0
  98. {varcode-9.3.3 → varcode-9.3.4}/tests/test_transforms_pair_breakends.py +0 -0
  99. {varcode-9.3.3 → varcode-9.3.4}/tests/test_variant.py +0 -0
  100. {varcode-9.3.3 → varcode-9.3.4}/tests/test_variant_collection.py +0 -0
  101. {varcode-9.3.3 → varcode-9.3.4}/tests/test_vcf.py +0 -0
  102. {varcode-9.3.3 → varcode-9.3.4}/tests/test_vcf_output.py +0 -0
  103. {varcode-9.3.3 → varcode-9.3.4}/tests/test_vcf_parsing.py +0 -0
  104. {varcode-9.3.3 → varcode-9.3.4}/tests/test_vcf_phase_resolver.py +0 -0
  105. {varcode-9.3.3 → varcode-9.3.4}/tests/test_vcf_spec_examples.py +0 -0
  106. {varcode-9.3.3 → varcode-9.3.4}/varcode/__init__.py +0 -0
  107. {varcode-9.3.3 → varcode-9.3.4}/varcode/annotators/__init__.py +0 -0
  108. {varcode-9.3.3 → varcode-9.3.4}/varcode/annotators/fast.py +0 -0
  109. {varcode-9.3.3 → varcode-9.3.4}/varcode/annotators/protein_diff.py +0 -0
  110. {varcode-9.3.3 → varcode-9.3.4}/varcode/annotators/registry.py +0 -0
  111. {varcode-9.3.3 → varcode-9.3.4}/varcode/cli/__init__.py +0 -0
  112. {varcode-9.3.3 → varcode-9.3.4}/varcode/cli/effects_script.py +0 -0
  113. {varcode-9.3.3 → varcode-9.3.4}/varcode/cli/genes_script.py +0 -0
  114. {varcode-9.3.3 → varcode-9.3.4}/varcode/cli/logging.conf +0 -0
  115. {varcode-9.3.3 → varcode-9.3.4}/varcode/cli/variant_args.py +0 -0
  116. {varcode-9.3.3 → varcode-9.3.4}/varcode/cli/version_info.py +0 -0
  117. {varcode-9.3.3 → varcode-9.3.4}/varcode/common.py +0 -0
  118. {varcode-9.3.3 → varcode-9.3.4}/varcode/cryptic_exons.py +0 -0
  119. {varcode-9.3.3 → varcode-9.3.4}/varcode/csv_helpers.py +0 -0
  120. {varcode-9.3.3 → varcode-9.3.4}/varcode/effect_candidates.py +0 -0
  121. {varcode-9.3.3 → varcode-9.3.4}/varcode/effect_hypotheses.py +0 -0
  122. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/__init__.py +0 -0
  123. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/classify.py +0 -0
  124. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/common.py +0 -0
  125. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_classes.py +0 -0
  126. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_collection.py +0 -0
  127. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_helpers.py +0 -0
  128. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_ordering.py +0 -0
  129. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_prediction.py +0 -0
  130. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_prediction_coding.py +0 -0
  131. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
  132. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
  133. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/fast_path.py +0 -0
  134. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/mutate.py +0 -0
  135. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/transcript_helpers.py +0 -0
  136. {varcode-9.3.3 → varcode-9.3.4}/varcode/effects/translate.py +0 -0
  137. {varcode-9.3.3 → varcode-9.3.4}/varcode/errors.py +0 -0
  138. {varcode-9.3.3 → varcode-9.3.4}/varcode/exacto.py +0 -0
  139. {varcode-9.3.3 → varcode-9.3.4}/varcode/genome.py +0 -0
  140. {varcode-9.3.3 → varcode-9.3.4}/varcode/genome_sequence.py +0 -0
  141. {varcode-9.3.3 → varcode-9.3.4}/varcode/genomic_layout.py +0 -0
  142. {varcode-9.3.3 → varcode-9.3.4}/varcode/genotype.py +0 -0
  143. {varcode-9.3.3 → varcode-9.3.4}/varcode/germline.py +0 -0
  144. {varcode-9.3.3 → varcode-9.3.4}/varcode/maf.py +0 -0
  145. {varcode-9.3.3 → varcode-9.3.4}/varcode/nucleotides.py +0 -0
  146. {varcode-9.3.3 → varcode-9.3.4}/varcode/phasing.py +0 -0
  147. {varcode-9.3.3 → varcode-9.3.4}/varcode/realized_effects.py +0 -0
  148. {varcode-9.3.3 → varcode-9.3.4}/varcode/reference.py +0 -0
  149. {varcode-9.3.3 → varcode-9.3.4}/varcode/rna_evidence.py +0 -0
  150. {varcode-9.3.3 → varcode-9.3.4}/varcode/rna_read_phasing.py +0 -0
  151. {varcode-9.3.3 → varcode-9.3.4}/varcode/splice_graph.py +0 -0
  152. {varcode-9.3.3 → varcode-9.3.4}/varcode/string_helpers.py +0 -0
  153. {varcode-9.3.3 → varcode-9.3.4}/varcode/structural_variant.py +0 -0
  154. {varcode-9.3.3 → varcode-9.3.4}/varcode/sv_allele_parser.py +0 -0
  155. {varcode-9.3.3 → varcode-9.3.4}/varcode/transcript_model.py +0 -0
  156. {varcode-9.3.3 → varcode-9.3.4}/varcode/transforms/__init__.py +0 -0
  157. {varcode-9.3.3 → varcode-9.3.4}/varcode/ucsc_reference_names.py +0 -0
  158. {varcode-9.3.3 → varcode-9.3.4}/varcode/util.py +0 -0
  159. {varcode-9.3.3 → varcode-9.3.4}/varcode/variant.py +0 -0
  160. {varcode-9.3.3 → varcode-9.3.4}/varcode/variant_collection.py +0 -0
  161. {varcode-9.3.3 → varcode-9.3.4}/varcode/vcf.py +0 -0
  162. {varcode-9.3.3 → varcode-9.3.4}/varcode/vcf_output.py +0 -0
  163. {varcode-9.3.3 → varcode-9.3.4}/varcode/vcf_parsing.py +0 -0
  164. {varcode-9.3.3 → varcode-9.3.4}/varcode.egg-info/dependency_links.txt +0 -0
  165. {varcode-9.3.3 → varcode-9.3.4}/varcode.egg-info/entry_points.txt +0 -0
  166. {varcode-9.3.3 → varcode-9.3.4}/varcode.egg-info/requires.txt +0 -0
  167. {varcode-9.3.3 → varcode-9.3.4}/varcode.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: varcode
3
- Version: 9.3.3
3
+ Version: 9.3.4
4
4
  Summary: Variant annotation in Python
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  Project-URL: Homepage, https://github.com/openvax/varcode
@@ -0,0 +1,190 @@
1
+ """Stored mutant proteins read annotated selenocysteine UGA codons (#470).
2
+
3
+ Ensembl marks Sec as U in the reference protein. Translators read those codons
4
+ as Sec unless the mutant keeps no selenoprotein 3' UTR, where the SECIS element
5
+ lies. Also covers the CDS start shifted by upstream 5' UTR edits (#471).
6
+ """
7
+
8
+ import pytest
9
+ from pyensembl import cached_release
10
+
11
+ from varcode import StructuralVariant, TranscriptEdit, Variant
12
+ from varcode.effects import GeneFusion
13
+ from varcode.effects import structural
14
+ from varcode.effects.codon_tables import translate_sequence
15
+ from varcode.effects.selenocysteine import edited_selenocysteine, reference_selenocysteine
16
+ from varcode.effects.sequence_change import structural_sequence_changes
17
+ from varcode.mutant_transcript import apply_variant_to_transcript, apply_variants_to_transcript
18
+ from varcode.splice_outcomes import _build_exon_skip_mutant_transcript
19
+
20
+ # GPX1 (-), GPX4 (+), SEPP1 (-, ten Sec), TXNRD1 (+, Sec is the penultimate residue).
21
+ SELENOPROTEINS = ["ENST00000419783", "ENST00000354171", "ENST00000514985", "ENST00000525566"]
22
+ COMPLEMENT = dict(zip("ACGT", "TGCA"))
23
+
24
+
25
+ def _transcript(transcript_id):
26
+ return cached_release(81).transcript_by_id(transcript_id)
27
+
28
+
29
+ def _genomic(transcript, offset):
30
+ for exon in transcript.exons:
31
+ length = exon.end - exon.start + 1
32
+ if offset < length:
33
+ return exon.end - offset if transcript.strand == "-" else exon.start + offset
34
+ offset -= length
35
+
36
+
37
+ def _variant(transcript, offset, ref, alt):
38
+ """A variant given in transcript orientation at a cDNA offset."""
39
+ if transcript.strand == "-":
40
+ ref = "".join(COMPLEMENT[b] for b in reversed(ref))
41
+ alt = "".join(COMPLEMENT[b] for b in reversed(alt))
42
+ position = _genomic(transcript, offset + len(ref) - 1)
43
+ else:
44
+ position = _genomic(transcript, offset)
45
+ return Variant(transcript.contig, position, ref, alt, transcript.genome)
46
+
47
+
48
+ def _snv(transcript, residue, base, alt):
49
+ offset = min(transcript.start_codon_spliced_offsets) + 3 * residue + base
50
+ return _variant(transcript, offset, transcript.sequence[offset], alt)
51
+
52
+
53
+ def _cases(transcript):
54
+ """Point variants at, before, and after the first Sec codon."""
55
+ u = transcript.protein_sequence.index("U")
56
+ start = min(transcript.start_codon_spliced_offsets)
57
+
58
+ def codon(i):
59
+ return transcript.sequence[start + 3 * i:start + 3 * i + 3]
60
+
61
+ def other(base):
62
+ return "A" if base != "A" else "C"
63
+
64
+ silent = next(i for i in range(u + 1, len(transcript.protein_sequence))
65
+ if codon(i)[:2] in ("CT", "GT", "TC", "CC", "AC", "GC", "CG", "GG"))
66
+ return {
67
+ "sec_to_trp": _snv(transcript, u, 2, "G"),
68
+ "before_sec": _snv(transcript, 10, 1, other(codon(10)[1])),
69
+ "after_sec": _snv(transcript, u + 1, 1, other(codon(u + 1)[1])),
70
+ "silent_after_sec": _snv(transcript, silent, 2, other(codon(silent)[2])),
71
+ }
72
+
73
+
74
+ def test_translate_sequence_reads_listed_tga_as_selenocysteine():
75
+ assert translate_sequence("ATGTGAGGCTAA") == "M"
76
+ assert translate_sequence("ATGTGAGGCTAA", selenocysteine={3}) == "MUG"
77
+ # Only a TGA at a listed codon offset is read as Sec.
78
+ assert translate_sequence("ATGTAAGGC", selenocysteine={3}) == "M"
79
+
80
+
81
+ @pytest.mark.parametrize("transcript_id", SELENOPROTEINS)
82
+ @pytest.mark.parametrize("case", ["sec_to_trp", "before_sec", "after_sec", "silent_after_sec"])
83
+ @pytest.mark.parametrize("annotator", ["protein_diff", "transcript_model"])
84
+ def test_annotators_agree_with_fast_on_selenoproteins(transcript_id, case, annotator):
85
+ t = _transcript(transcript_id)
86
+ variant = _cases(t)[case]
87
+ expected = variant.effect_on_transcript(t, annotator="fast")
88
+ effect = variant.effect_on_transcript(t, annotator=annotator)
89
+ assert (type(effect), effect.short_description) == (type(expected), expected.short_description)
90
+
91
+
92
+ def test_gpx1_calls_are_pinned():
93
+ t = _transcript("ENST00000419783")
94
+ for annotator in ("fast", "protein_diff", "transcript_model"):
95
+ assert _snv(t, 48, 2, "G").effect_on_transcript(
96
+ t, annotator=annotator).short_description == "p.U49W"
97
+ assert _snv(t, 53, 0, "T").effect_on_transcript(
98
+ t, annotator=annotator).short_description == "p.R54W"
99
+
100
+
101
+ @pytest.mark.parametrize("transcript_id", SELENOPROTEINS)
102
+ def test_stored_protein_continues_past_selenocysteine(transcript_id):
103
+ t = _transcript(transcript_id)
104
+ mt = apply_variant_to_transcript(_cases(t)["after_sec"], t)
105
+ protein = mt.mutant_protein_sequence
106
+ assert len(protein) == len(t.protein_sequence)
107
+ assert [i for i, aa in enumerate(protein) if aa == "U"] == [
108
+ i for i, aa in enumerate(t.protein_sequence) if aa == "U"]
109
+ assert sum(a != b for a, b in zip(protein, t.protein_sequence)) == 1
110
+
111
+
112
+ def test_edited_selenocysteine_codon_is_translated_literally():
113
+ t = _transcript("ENST00000354171")
114
+ sec, = reference_selenocysteine(t)
115
+ assert edited_selenocysteine(t, ()) == {sec}
116
+ assert edited_selenocysteine(t, (TranscriptEdit(sec + 2, sec + 3, "G"),)) == set()
117
+ assert edited_selenocysteine(t, (TranscriptEdit(sec + 1, sec + 1, "A"),)) == set()
118
+ # A 5' UTR deletion shifts the codon; an insertion at its first base precedes it.
119
+ assert edited_selenocysteine(t, (TranscriptEdit(10, 12, ""),)) == {sec - 2}
120
+ assert edited_selenocysteine(t, (TranscriptEdit(sec, sec, "AAA"),)) == {sec + 3}
121
+
122
+
123
+ def test_deleting_the_whole_three_prime_utr_leaves_uga_a_stop():
124
+ t = _transcript("ENST00000354171")
125
+ utr = max(t.stop_codon_spliced_offsets) + 1
126
+ assert edited_selenocysteine(t, (TranscriptEdit(utr, len(t.sequence), ""),)) == set()
127
+ assert edited_selenocysteine(t, (TranscriptEdit(utr, len(t.sequence) - 1, ""),))
128
+
129
+
130
+ @pytest.mark.parametrize("transcript_id", ["ENST00000003084", "ENST00000354171"])
131
+ def test_joint_translation_follows_a_five_prime_utr_indel(transcript_id):
132
+ # #471: a 5' UTR deletion shifts the CDS start in the mutant cDNA.
133
+ t = _transcript(transcript_id)
134
+ start = min(t.start_codon_spliced_offsets)
135
+ utr = start // 2
136
+ deletion = _variant(t, utr, t.sequence[utr:utr + 2], t.sequence[utr])
137
+ missense = _snv(t, 1, 1, "A" if t.sequence[start + 4] != "A" else "C")
138
+ alone = apply_variant_to_transcript(missense, t).mutant_protein_sequence
139
+ joint = apply_variants_to_transcript([deletion, missense], t)
140
+ assert joint.mutant_protein_sequence == alone
141
+ assert len(alone) == len(t.protein_sequence)
142
+
143
+
144
+ @pytest.mark.parametrize("transcript_id,index", [
145
+ ("ENST00000514985", 2), # SEPP1 (-): between its first and second Sec
146
+ ("ENST00000525566", 15), # TXNRD1 (+): just upstream of its Sec
147
+ ])
148
+ def test_exon_skipping_keeps_selenocysteine(transcript_id, index):
149
+ t = _transcript(transcript_id)
150
+ exon = t.exons[index]
151
+ variant = StructuralVariant(t.contig, exon.start, "DEL", end=exon.end, genome=t.genome)
152
+ mt = _build_exon_skip_mutant_transcript(variant, t, exon)
153
+ skipped = (exon.end - exon.start + 1) // 3
154
+ assert mt.mutant_protein_sequence.count("U") == t.protein_sequence.count("U")
155
+ assert len(mt.mutant_protein_sequence) == len(t.protein_sequence) - skipped
156
+
157
+
158
+ def _fusion(five_prime, five_prime_position, three_prime, three_prime_position):
159
+ model = structural._build_fusion_mutant_transcript(
160
+ five_prime, five_prime, five_prime_position, three_prime, three_prime_position)
161
+ variant = StructuralVariant(five_prime.contig, five_prime_position, "BND",
162
+ genome=five_prime.genome)
163
+ return model, GeneFusion(variant, five_prime, three_prime, mutant_transcript=model)
164
+
165
+
166
+ def test_fused_selenoprotein_three_prime_partner_keeps_selenocysteine():
167
+ # The 3' partner brings its own 3' UTR, and so its SECIS.
168
+ cftr, gpx4 = _transcript("ENST00000003084"), _transcript("ENST00000354171")
169
+ model, _ = _fusion(cftr, cftr.exons[4].end, gpx4, gpx4.exons[1].start)
170
+ protein = model.mutant_protein_sequence
171
+ assert "U" in protein
172
+ assert protein.endswith(gpx4.protein_sequence[-20:])
173
+
174
+
175
+ def test_fusion_in_five_prime_partner_utr_keeps_reference_protein_but_flags_unknown():
176
+ gpx4, cftr = _transcript("ENST00000354171"), _transcript("ENST00000003084")
177
+ model, effect = _fusion(gpx4, gpx4.end - 10, cftr, cftr.end - 10)
178
+ assert model.mutant_protein_sequence == gpx4.protein_sequence
179
+ # Whether the kept part of the 3' UTR still holds the SECIS is unknown.
180
+ assert structural_sequence_changes(effect) == (False, None)
181
+
182
+
183
+ def test_fusion_that_drops_the_selenoprotein_utr_stops_at_selenocysteine():
184
+ gpx4, cftr = _transcript("ENST00000354171"), _transcript("ENST00000003084")
185
+ sec, = reference_selenocysteine(gpx4)
186
+ breakpoint = _genomic(gpx4, sec + 30)
187
+ model, effect = _fusion(gpx4, breakpoint, cftr, cftr.end - 10)
188
+ assert model.mutant_protein_sequence == gpx4.protein_sequence[:gpx4.protein_sequence.index("U")]
189
+ assert effect.modifies_protein_sequence is True
190
+
@@ -117,7 +117,8 @@ def codon_table_for_transcript(transcript):
117
117
  def translate_sequence(
118
118
  nucleotide_sequence,
119
119
  codon_table=STANDARD,
120
- to_stop=True):
120
+ to_stop=True,
121
+ selenocysteine=()):
121
122
  """Translate a cDNA string to amino acids using ``codon_table``.
122
123
 
123
124
  Parameters
@@ -130,6 +131,10 @@ def translate_sequence(
130
131
  If True (default), stop translation at the first stop codon and
131
132
  return the protein up to (but not including) the stop. If False,
132
133
  include ``'*'`` characters for in-sequence stops.
134
+ selenocysteine : collection of int
135
+ Offsets into ``nucleotide_sequence`` of TGA codons to read as
136
+ selenocysteine (``'U'``), e.g. annotated Sec codons whose SECIS
137
+ element is retained. See :mod:`varcode.effects.selenocysteine`.
133
138
  """
134
139
  seq = str(nucleotide_sequence).upper()
135
140
  if len(seq) % 3 != 0:
@@ -141,6 +146,9 @@ def translate_sequence(
141
146
  result = []
142
147
  for i in range(0, len(seq), 3):
143
148
  codon = seq[i:i + 3]
149
+ if codon == "TGA" and i in selenocysteine:
150
+ result.append("U")
151
+ continue
144
152
  if codon in stops:
145
153
  if to_stop:
146
154
  break
@@ -0,0 +1,127 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ """Where annotated selenocysteine UGA codons survive in a mutant cDNA.
14
+
15
+ Ensembl marks selenocysteine (Sec) as U in the reference protein, on an
16
+ in-frame UGA. UGA encodes Sec only with a SECIS element in the same mRNA's
17
+ 3' UTR, and SECIS positions aren't annotated. Translators read these codons
18
+ as Sec unless the mutant keeps no selenoprotein 3' UTR at all. The SV change
19
+ flags also treat a partly kept 3' UTR as uncertain; one stored protein
20
+ follows the reference reading.
21
+ """
22
+
23
+
24
+ def reference_selenocysteine(transcript):
25
+ """cDNA offsets of the first base of each annotated Sec codon."""
26
+ protein = getattr(transcript, "protein_sequence", None)
27
+ if not protein or "U" not in protein or not getattr(transcript, "complete", False):
28
+ return ()
29
+ start = min(transcript.start_codon_spliced_offsets)
30
+ return tuple(start + 3 * i for i, aa in enumerate(protein) if aa == "U")
31
+
32
+
33
+ def _three_prime_utr_start(transcript):
34
+ return max(transcript.stop_codon_spliced_offsets) + 1
35
+
36
+
37
+ def edit_shift(offset, edits):
38
+ """Net length change from edits wholly upstream of reference ``offset``."""
39
+ return sum(len(e.alt_bases) - (e.cdna_end - e.cdna_start)
40
+ for e in edits if e.cdna_end <= offset)
41
+
42
+
43
+ def edited_selenocysteine(transcript, edits):
44
+ """Mutant cDNA offsets of annotated Sec codons that no edit touches.
45
+
46
+ For a reference cDNA with point-level edits. Empty when the edits delete
47
+ the transcript's whole 3' UTR, since no SECIS can remain.
48
+ """
49
+ offsets = reference_selenocysteine(transcript)
50
+ if not offsets:
51
+ return set()
52
+ utr_start, utr_end = _three_prime_utr_start(transcript), len(transcript.sequence)
53
+ deleted = sum(max(0, min(e.cdna_end, utr_end) - max(e.cdna_start, utr_start))
54
+ for e in edits)
55
+ if utr_end > utr_start and deleted == utr_end - utr_start:
56
+ return set()
57
+ return {ref + edit_shift(ref, edits) for ref in offsets
58
+ if not any((e.cdna_start < ref + 3 and ref < e.cdna_end)
59
+ or ref < e.cdna_start == e.cdna_end < ref + 3 for e in edits)}
60
+
61
+
62
+ def segment_selenocysteine(model):
63
+ """Observed offsets of TGA codons mapped by segments onto annotated Sec codons.
64
+
65
+ Return ``(decoded, uncertain, terminating)``: a codon is decoded where the
66
+ model keeps its transcript contiguously from that codon through the 3'
67
+ end. With no selenoprotein 3' UTR sequence at all there is no SECIS, so
68
+ UGA terminates. Otherwise decoding is unknown. None when segments don't
69
+ render the cDNA or point edits are overlaid.
70
+ """
71
+ sequence = model.cdna_sequence
72
+ segments = model.reference_segments or ()
73
+ if (sequence is None or model.edits
74
+ or sum(s.length for s in segments) != len(sequence)):
75
+ return None
76
+ runs, offset = [], 0
77
+ for segment in segments:
78
+ if segment.strand == "+":
79
+ last = runs[-1] if runs else None
80
+ if (last and last[0] == segment.source and last[2] == segment.start
81
+ and last[3] + last[2] - last[1] == offset):
82
+ last[2] = segment.end # A split that continues the same reference.
83
+ else:
84
+ runs.append([segment.source, segment.start, segment.end, offset])
85
+ offset += segment.length
86
+ decoded, uncertain = set(), set()
87
+ secis_possible = False
88
+ for source, ref_start, ref_end, observed in runs:
89
+ selenocysteine = reference_selenocysteine(source)
90
+ if selenocysteine and ref_end > _three_prime_utr_start(source):
91
+ secis_possible = True
92
+ for ref in selenocysteine:
93
+ pos = observed + ref - ref_start
94
+ if (ref_start <= ref and ref + 3 <= ref_end
95
+ and sequence[pos:pos + 3].upper() == "TGA"):
96
+ (decoded if ref_end == len(source.sequence) else uncertain).add(pos)
97
+ if not secis_possible:
98
+ return decoded, set(), uncertain
99
+ return decoded, uncertain, set()
100
+
101
+
102
+ def layout_selenocysteine(transcript, layouts):
103
+ """cDNA offsets of annotated Sec codons in concatenated genomic layouts.
104
+
105
+ Each layout exposes ``origins()`` as ``(contig, position, kind)`` per base,
106
+ in transcript orientation. Empty when no base of an annotated 3' UTR
107
+ remains.
108
+ """
109
+ offsets = set(reference_selenocysteine(transcript))
110
+ if not offsets:
111
+ return set()
112
+ utr_start = _three_prime_utr_start(transcript)
113
+ found, index = set(), 0
114
+ utr_present = utr_start >= len(transcript.sequence)
115
+ for layout in layouts:
116
+ for contig, position, kind in layout.origins():
117
+ if contig == transcript.contig and kind != "inverted":
118
+ try:
119
+ reference = transcript.spliced_offset(position)
120
+ except ValueError:
121
+ reference = None
122
+ if reference in offsets:
123
+ found.add(index)
124
+ elif reference is not None and reference >= utr_start:
125
+ utr_present = True
126
+ index += 1
127
+ return found if utr_present else set()
@@ -3,6 +3,7 @@
3
3
  import operator
4
4
 
5
5
  from .codon_tables import codon_table_for_transcript, translate_sequence
6
+ from .selenocysteine import reference_selenocysteine, segment_selenocysteine
6
7
 
7
8
 
8
9
  def modification_status(effect, attribute):
@@ -95,57 +96,6 @@ def _read_orf(sequence, start, end, table, selenocysteine):
95
96
  return None
96
97
 
97
98
 
98
- def _selenocysteine_offsets(transcript):
99
- """cDNA offsets of annotated Sec codons: Ensembl marks them U in the protein."""
100
- protein = getattr(transcript, "protein_sequence", None)
101
- if not protein or "U" not in protein or not getattr(transcript, "complete", False):
102
- return ()
103
- start = min(transcript.start_codon_spliced_offsets)
104
- return tuple(start + 3 * i for i, aa in enumerate(protein) if aa == "U")
105
-
106
-
107
- def _mapped_selenocysteine(model):
108
- """Observed offsets of TGA codons mapped onto annotated Sec codons.
109
-
110
- UGA encodes Sec only with a SECIS element in the same mRNA's 3' UTR, and
111
- SECIS positions aren't annotated. Return ``(decoded, uncertain,
112
- terminating)``: a codon is decoded only where the model keeps its
113
- transcript contiguously from that codon through the 3' end. With no
114
- selenoprotein 3' UTR sequence at all there is no SECIS, so UGA
115
- terminates. Otherwise decoding is unknown. None when segments don't
116
- render the cDNA.
117
- """
118
- sequence = model.cdna_sequence
119
- segments = model.reference_segments or ()
120
- if (sequence is None or model.edits
121
- or sum(s.length for s in segments) != len(sequence)):
122
- return None
123
- runs, offset = [], 0
124
- for segment in segments:
125
- if segment.strand == "+":
126
- last = runs[-1] if runs else None
127
- if (last and last[0] == segment.source and last[2] == segment.start
128
- and last[3] + last[2] - last[1] == offset):
129
- last[2] = segment.end # A split that continues the same reference.
130
- else:
131
- runs.append([segment.source, segment.start, segment.end, offset])
132
- offset += segment.length
133
- decoded, uncertain = set(), set()
134
- secis_possible = False
135
- for source, ref_start, ref_end, observed in runs:
136
- selenocysteine = _selenocysteine_offsets(source)
137
- if selenocysteine and ref_end > max(source.stop_codon_spliced_offsets) + 1:
138
- secis_possible = True
139
- for ref in selenocysteine:
140
- pos = observed + ref - ref_start
141
- if (ref_start <= ref and ref + 3 <= ref_end
142
- and sequence[pos:pos + 3].upper() == "TGA"):
143
- (decoded if ref_end == len(source.sequence) else uncertain).add(pos)
144
- if not secis_possible:
145
- return decoded, set(), uncertain
146
- return decoded, uncertain, set()
147
-
148
-
149
99
  def _initiated(protein):
150
100
  # Any start codon initiates as Met; Ensembl writes CTG/TTG initiators literally.
151
101
  return "M" + protein[1:] if protein else protein
@@ -160,10 +110,10 @@ def _orf_changes(model, transcript, reference_protein, table, start, end, seleno
160
110
  coding_status = None if reference_coding is None else coding != reference_coding.upper()
161
111
  if reference_protein is None or "X" in reference_protein:
162
112
  return coding_status, None
163
- residues = translate_sequence(coding, codon_table=table, to_stop=False)
113
+ residues = translate_sequence(coding, codon_table=table, to_stop=False,
114
+ selenocysteine={pos - start for pos in selenocysteine})
164
115
  # Initiator methionine also applies to alternative start codons.
165
- protein = "M" + "".join("U" if start + 3 * i in selenocysteine else aa
166
- for i, aa in enumerate(residues))[1:-1]
116
+ protein = "M" + residues[1:-1]
167
117
  return coding_status, protein != reference_protein
168
118
 
169
119
 
@@ -188,7 +138,7 @@ def _complete_sequence_changes(model, transcript, initiator):
188
138
  if bounds is None:
189
139
  return None, supplied
190
140
  start, end = bounds
191
- mapped = _mapped_selenocysteine(model)
141
+ mapped = segment_selenocysteine(model)
192
142
  if mapped is not None and any(s.source == transcript for s in model.reference_segments or ()):
193
143
  decoded, uncertain, terminating = mapped
194
144
  else:
@@ -207,6 +157,9 @@ def _complete_sequence_changes(model, transcript, initiator):
207
157
  selenocysteine)[1]
208
158
  for selenocysteine in {frozenset(decoded), frozenset(decoded | uncertain)}}
209
159
  protein_status = proteins.pop() if len(proteins) == 1 else None
160
+ if uncertain:
161
+ # A supplied protein assumed one decoding of these codons.
162
+ return coding_status, protein_status
210
163
  return coding_status, supplied if supplied is not None else protein_status
211
164
 
212
165
 
@@ -251,8 +204,8 @@ def _partial_sequence_changes(model, transcript, table):
251
204
  offset += segment.length
252
205
  reference_start = min(transcript.start_codon_spliced_offsets)
253
206
  reference_coding = transcript.coding_sequence.upper()
254
- reference_selenocysteine = _selenocysteine_offsets(transcript)
255
- decoded = _mapped_selenocysteine(model)[0]
207
+ reference_sec = reference_selenocysteine(transcript)
208
+ decoded = segment_selenocysteine(model)[0]
256
209
  coding_status = None
257
210
  for pos in range(start, end - 2, 3):
258
211
  codon = sequence[pos:pos + 3].upper()
@@ -266,7 +219,7 @@ def _partial_sequence_changes(model, transcript, table):
266
219
  coding_status = True
267
220
  # Only an observed ORF that begins here can initiate here.
268
221
  observed = _residue(codon, table, k == 0 and pos == start)
269
- reference = ("U" if ref in reference_selenocysteine
222
+ reference = ("U" if ref in reference_sec
270
223
  else _residue(reference_codon, table, k == 0))
271
224
  if observed != reference:
272
225
  return True, True
@@ -316,7 +269,7 @@ def structural_sequence_changes(effect):
316
269
  if protein_status is None:
317
270
  if not coding_overlap:
318
271
  # Deleting a selenoprotein's 3' UTR may remove its SECIS element.
319
- stops = _selenocysteine_offsets(transcript) and transcript.stop_codon_positions
272
+ stops = reference_selenocysteine(transcript) and transcript.stop_codon_positions
320
273
  if not stops or (end < min(stops) if transcript.strand == "+"
321
274
  else start > max(stops)):
322
275
  protein_status = False
@@ -20,6 +20,8 @@ Mutant transcripts retain the historical ``structural_variant`` builder
20
20
  provenance; their containing effect collection records the selected annotator.
21
21
  """
22
22
 
23
+ from dataclasses import replace
24
+
23
25
  from .effect_classes import (
24
26
  GeneFusion,
25
27
  Intergenic,
@@ -32,6 +34,7 @@ from .effect_classes import (
32
34
  TranslocationToIntergenic,
33
35
  )
34
36
  from .effect_helpers import exon_length
37
+ from .selenocysteine import segment_selenocysteine
35
38
  from ..mutant_transcript import MutantTranscript, ReferenceSegment
36
39
  # Existing assembled-SV pickles use this private module path.
37
40
  from ..mutant_transcript import _AssembledAllele # noqa: F401
@@ -423,13 +426,15 @@ def _build_inversion_mutant_transcript(variant, transcript):
423
426
  annotator_name="structural_variant")
424
427
 
425
428
 
426
- def _translate_fused_cdna(fused_cdna, five_prime_transcript, five_prime_len):
429
+ def _translate_fused_cdna(fused_cdna, five_prime_transcript, five_prime_len,
430
+ selenocysteine=()):
427
431
  """Translate ``fused_cdna`` from the 5' partner's CDS start when
428
432
  that start codon lies in the retained 5' portion (#336).
429
433
 
430
434
  Returns the translated protein (stopping at the first stop
431
435
  codon) or ``None`` when the CDS start is past the breakpoint or
432
- translation otherwise fails.
436
+ translation otherwise fails. TGA codons at the fused-cDNA offsets
437
+ in ``selenocysteine`` are read as Sec.
433
438
  """
434
439
  from .codon_tables import (
435
440
  codon_table_for_transcript,
@@ -449,7 +454,8 @@ def _translate_fused_cdna(fused_cdna, five_prime_transcript, five_prime_len):
449
454
  truncated = coding[:(len(coding) // 3) * 3]
450
455
  try:
451
456
  return translate_sequence(
452
- truncated, codon_table=codon_table, to_stop=True)
457
+ truncated, codon_table=codon_table, to_stop=True,
458
+ selenocysteine={pos - cds_start for pos in selenocysteine})
453
459
  except ValueError:
454
460
  return None
455
461
 
@@ -497,13 +503,16 @@ def _build_fusion_mutant_transcript(
497
503
  start=three_prime_start, end=len(three_prime_cdna),
498
504
  strand="+", label="3p_partner"),
499
505
  )
500
- return MutantTranscript(
506
+ model = MutantTranscript(
501
507
  reference_transcript=reference_transcript,
502
508
  reference_segments=segments,
503
509
  cdna_sequence=fused_cdna,
504
- mutant_protein_sequence=_translate_fused_cdna(
505
- fused_cdna, five_prime_transcript, five_prime_end),
506
510
  annotator_name="structural_variant")
511
+ # Read Sec where a SECIS may remain; the change flags report whether
512
+ # that reading is certain.
513
+ decoded, uncertain, _ = segment_selenocysteine(model) or (set(), set(), set())
514
+ return replace(model, mutant_protein_sequence=_translate_fused_cdna(
515
+ fused_cdna, five_prime_transcript, five_prime_end, decoded | uncertain))
507
516
 
508
517
 
509
518
  def _build_translocation_mutant_transcript(variant, transcript):
@@ -388,15 +388,19 @@ def _resolve_variant_edit(variant, transcript, full_sequence):
388
388
  return (edit, cdna_offset)
389
389
 
390
390
 
391
- def _translate_from_cds(mutant_cdna, transcript):
391
+ def _translate_from_cds(mutant_cdna, transcript, edits=()):
392
392
  """Translate ``mutant_cdna`` from the canonical CDS start to the
393
- first stop. Returns ``None`` if the CDS start is past the cDNA
394
- end or translation errors."""
393
+ first stop. ``edits`` (in reference coordinates) locate that start,
394
+ and the annotated selenocysteine codons they leave intact, in the
395
+ mutant. Returns ``None`` if the CDS start is past the cDNA end or
396
+ translation errors."""
395
397
  from .effects.codon_tables import (
396
398
  codon_table_for_transcript,
397
399
  translate_sequence,
398
400
  )
399
- cds_start = min(transcript.start_codon_spliced_offsets)
401
+ from .effects.selenocysteine import edit_shift, edited_selenocysteine
402
+ reference_start = min(transcript.start_codon_spliced_offsets)
403
+ cds_start = reference_start + edit_shift(reference_start, edits)
400
404
  if cds_start >= len(mutant_cdna):
401
405
  return None
402
406
  codon_table = codon_table_for_transcript(transcript)
@@ -404,7 +408,9 @@ def _translate_from_cds(mutant_cdna, transcript):
404
408
  truncated = coding[:(len(coding) // 3) * 3]
405
409
  try:
406
410
  return translate_sequence(
407
- truncated, codon_table=codon_table, to_stop=True)
411
+ truncated, codon_table=codon_table, to_stop=True,
412
+ selenocysteine={pos - cds_start for pos in
413
+ edited_selenocysteine(transcript, edits)})
408
414
  except ValueError:
409
415
  return None
410
416
 
@@ -453,7 +459,7 @@ def apply_variant_to_transcript(variant, transcript):
453
459
  mutant_protein = None
454
460
  cds_start = min(transcript.start_codon_spliced_offsets)
455
461
  if cdna_offset >= cds_start:
456
- mutant_protein = _translate_from_cds(mutant_cdna, transcript)
462
+ mutant_protein = _translate_from_cds(mutant_cdna, transcript, (edit,))
457
463
  return MutantTranscript(
458
464
  reference_transcript=transcript,
459
465
  edits=(edit,),
@@ -533,7 +539,8 @@ def apply_variants_to_transcript(variants, transcript):
533
539
  mutant_protein = None
534
540
  cds_start = min(transcript.start_codon_spliced_offsets)
535
541
  if any(anchor >= cds_start for _, anchor in resolved):
536
- mutant_protein = _translate_from_cds(mutant_cdna, transcript)
542
+ mutant_protein = _translate_from_cds(
543
+ mutant_cdna, transcript, [edit for edit, _ in resolved])
537
544
  return MutantTranscript(
538
545
  reference_transcript=transcript,
539
546
  edits=tuple(edit for edit, _ in resolved),
@@ -59,6 +59,7 @@ from serializable import DataclassSerializable
59
59
 
60
60
  from .effects.classify import classify_from_protein_diff
61
61
  from .effects.codon_tables import codon_table_for_transcript, translate_sequence
62
+ from .effects.selenocysteine import edited_selenocysteine
62
63
  from .effects.effect_helpers import exon_length
63
64
  from .effects.effect_classes import (
64
65
  CrypticAcceptor,
@@ -823,7 +824,7 @@ def _build_intron_retention_mutant_transcript(
823
824
  mutant_cdna, edits = composed
824
825
  # Translate from the canonical start codon; premature stop inside
825
826
  # the retained intron terminates the ORF.
826
- mut_protein = _translate_from_cds(mutant_cdna, transcript)
827
+ mut_protein = _translate_from_cds(mutant_cdna, transcript, edits)
827
828
  return MutantTranscript(
828
829
  reference_transcript=transcript,
829
830
  edits=edits,
@@ -1236,7 +1237,7 @@ def _build_cryptic_site_mutant_transcript(
1236
1237
  if composed is None:
1237
1238
  return None
1238
1239
  mutant_cdna, edits = composed
1239
- mut_protein = _translate_from_cds(mutant_cdna, transcript)
1240
+ mut_protein = _translate_from_cds(mutant_cdna, transcript, edits)
1240
1241
  mt = MutantTranscript(
1241
1242
  reference_transcript=transcript,
1242
1243
  edits=edits,
@@ -1357,24 +1358,27 @@ def _build_exon_skip_mutant_transcript(variant, transcript, exon):
1357
1358
  # Exon overlaps the CDS start → start codon lost.
1358
1359
  new_cds_start = None
1359
1360
 
1361
+ edit = TranscriptEdit(
1362
+ cdna_start=exon_start_in_tx,
1363
+ cdna_end=exon_start_in_tx + length,
1364
+ alt_bases="",
1365
+ source_variant=variant,
1366
+ )
1367
+
1360
1368
  mut_protein = ""
1361
1369
  if new_cds_start is not None and new_cds_start < len(post_skip_cdna):
1362
1370
  codon_table = codon_table_for_transcript(transcript)
1363
1371
  coding = post_skip_cdna[new_cds_start:]
1364
1372
  truncated = coding[:(len(coding) // 3) * 3]
1373
+ selenocysteine = {pos - new_cds_start
1374
+ for pos in edited_selenocysteine(transcript, (edit,))}
1365
1375
  try:
1366
1376
  mut_protein = translate_sequence(
1367
- truncated, codon_table=codon_table, to_stop=True)
1377
+ truncated, codon_table=codon_table, to_stop=True,
1378
+ selenocysteine=selenocysteine)
1368
1379
  except ValueError:
1369
1380
  mut_protein = ""
1370
1381
 
1371
- edit = TranscriptEdit(
1372
- cdna_start=exon_start_in_tx,
1373
- cdna_end=exon_start_in_tx + length,
1374
- alt_bases="",
1375
- source_variant=variant,
1376
- )
1377
-
1378
1382
  return MutantTranscript(
1379
1383
  reference_transcript=transcript,
1380
1384
  edits=(edit,),