varcode 9.3.2__tar.gz → 9.3.3__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 (165) hide show
  1. {varcode-9.3.2/varcode.egg-info → varcode-9.3.3}/PKG-INFO +1 -1
  2. varcode-9.3.3/tests/test_sv_selenocysteine.py +224 -0
  3. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/sequence_change.py +150 -31
  4. varcode-9.3.3/varcode/version.py +1 -0
  5. {varcode-9.3.2 → varcode-9.3.3/varcode.egg-info}/PKG-INFO +1 -1
  6. {varcode-9.3.2 → varcode-9.3.3}/varcode.egg-info/SOURCES.txt +1 -0
  7. varcode-9.3.2/varcode/version.py +0 -1
  8. {varcode-9.3.2 → varcode-9.3.3}/LICENSE +0 -0
  9. {varcode-9.3.2 → varcode-9.3.3}/MANIFEST.in +0 -0
  10. {varcode-9.3.2 → varcode-9.3.3}/README.md +0 -0
  11. {varcode-9.3.2 → varcode-9.3.3}/pyproject.toml +0 -0
  12. {varcode-9.3.2 → varcode-9.3.3}/requirements.txt +0 -0
  13. {varcode-9.3.2 → varcode-9.3.3}/setup.cfg +0 -0
  14. {varcode-9.3.2 → varcode-9.3.3}/tests/test_annotator_divergence_scenarios.py +0 -0
  15. {varcode-9.3.2 → varcode-9.3.3}/tests/test_annotator_parity_adversarial.py +0 -0
  16. {varcode-9.3.2 → varcode-9.3.3}/tests/test_annotators.py +0 -0
  17. {varcode-9.3.2 → varcode-9.3.3}/tests/test_bnd_retained_segments.py +0 -0
  18. {varcode-9.3.2 → varcode-9.3.3}/tests/test_cli_effects.py +0 -0
  19. {varcode-9.3.2 → varcode-9.3.3}/tests/test_cli_genes.py +0 -0
  20. {varcode-9.3.2 → varcode-9.3.3}/tests/test_cli_without_pkg_resources.py +0 -0
  21. {varcode-9.3.2 → varcode-9.3.3}/tests/test_collection_filtering.py +0 -0
  22. {varcode-9.3.2 → varcode-9.3.3}/tests/test_collection_variants_attr_consistency.py +0 -0
  23. {varcode-9.3.2 → varcode-9.3.3}/tests/test_common.py +0 -0
  24. {varcode-9.3.2 → varcode-9.3.3}/tests/test_cosmic_mutations.py +0 -0
  25. {varcode-9.3.2 → varcode-9.3.3}/tests/test_cryptic_exons.py +0 -0
  26. {varcode-9.3.2 → varcode-9.3.3}/tests/test_csv_roundtrip.py +0 -0
  27. {varcode-9.3.2 → varcode-9.3.3}/tests/test_dbnsfp_validation.py +0 -0
  28. {varcode-9.3.2 → varcode-9.3.3}/tests/test_default_structural_helpers.py +0 -0
  29. {varcode-9.3.2 → varcode-9.3.3}/tests/test_documentation_examples.py +0 -0
  30. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effect_annotation_errors.py +0 -0
  31. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effect_candidates.py +0 -0
  32. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effect_classes.py +0 -0
  33. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effect_collection.py +0 -0
  34. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effect_collection_serialization.py +0 -0
  35. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effect_collection_sort_order.py +0 -0
  36. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effect_hypotheses.py +0 -0
  37. {varcode-9.3.2 → varcode-9.3.3}/tests/test_effects_from_mutagenix_variants.py +0 -0
  38. {varcode-9.3.2 → varcode-9.3.3}/tests/test_exacto_fusions.py +0 -0
  39. {varcode-9.3.2 → varcode-9.3.3}/tests/test_exonic_splice_site.py +0 -0
  40. {varcode-9.3.2 → varcode-9.3.3}/tests/test_fast_path.py +0 -0
  41. {varcode-9.3.2 → varcode-9.3.3}/tests/test_frameshift_cterminus_regression.py +0 -0
  42. {varcode-9.3.2 → varcode-9.3.3}/tests/test_frameshift_helpers.py +0 -0
  43. {varcode-9.3.2 → varcode-9.3.3}/tests/test_fusion_partner_candidates.py +0 -0
  44. {varcode-9.3.2 → varcode-9.3.3}/tests/test_genome_contig_validation.py +0 -0
  45. {varcode-9.3.2 → varcode-9.3.3}/tests/test_genome_sequence.py +0 -0
  46. {varcode-9.3.2 → varcode-9.3.3}/tests/test_genomic_layout.py +0 -0
  47. {varcode-9.3.2 → varcode-9.3.3}/tests/test_genotype.py +0 -0
  48. {varcode-9.3.2 → varcode-9.3.3}/tests/test_genotype_from_vcf.py +0 -0
  49. {varcode-9.3.2 → varcode-9.3.3}/tests/test_germline_context.py +0 -0
  50. {varcode-9.3.2 → varcode-9.3.3}/tests/test_germline_effects.py +0 -0
  51. {varcode-9.3.2 → varcode-9.3.3}/tests/test_haplotype_effect.py +0 -0
  52. {varcode-9.3.2 → varcode-9.3.3}/tests/test_maf.py +0 -0
  53. {varcode-9.3.2 → varcode-9.3.3}/tests/test_mitochondrial.py +0 -0
  54. {varcode-9.3.2 → varcode-9.3.3}/tests/test_mm10_klf6_frameshift.py +0 -0
  55. {varcode-9.3.2 → varcode-9.3.3}/tests/test_mouse.py +0 -0
  56. {varcode-9.3.2 → varcode-9.3.3}/tests/test_mutant_transcript.py +0 -0
  57. {varcode-9.3.2 → varcode-9.3.3}/tests/test_mutate.py +0 -0
  58. {varcode-9.3.2 → varcode-9.3.3}/tests/test_no_duplicate_variants.py +0 -0
  59. {varcode-9.3.2 → varcode-9.3.3}/tests/test_nonlocal_sv_transcripts.py +0 -0
  60. {varcode-9.3.2 → varcode-9.3.3}/tests/test_osteosarc_fusions.py +0 -0
  61. {varcode-9.3.2 → varcode-9.3.3}/tests/test_partial_annotators.py +0 -0
  62. {varcode-9.3.2 → varcode-9.3.3}/tests/test_premature_stop_short_description.py +0 -0
  63. {varcode-9.3.2 → varcode-9.3.3}/tests/test_problematic_variants.py +0 -0
  64. {varcode-9.3.2 → varcode-9.3.3}/tests/test_protein_diff_parity.py +0 -0
  65. {varcode-9.3.2 → varcode-9.3.3}/tests/test_read_phase_resolver.py +0 -0
  66. {varcode-9.3.2 → varcode-9.3.3}/tests/test_real_world_callers.py +0 -0
  67. {varcode-9.3.2 → varcode-9.3.3}/tests/test_reference.py +0 -0
  68. {varcode-9.3.2 → varcode-9.3.3}/tests/test_reference_mismatch_error.py +0 -0
  69. {varcode-9.3.2 → varcode-9.3.3}/tests/test_reference_segments.py +0 -0
  70. {varcode-9.3.2 → varcode-9.3.3}/tests/test_rna_evidence.py +0 -0
  71. {varcode-9.3.2 → varcode-9.3.3}/tests/test_rna_haplotype_sequences.py +0 -0
  72. {varcode-9.3.2 → varcode-9.3.3}/tests/test_rna_read_phasing_source.py +0 -0
  73. {varcode-9.3.2 → varcode-9.3.3}/tests/test_selenocysteine.py +0 -0
  74. {varcode-9.3.2 → varcode-9.3.3}/tests/test_silent_aa_pos.py +0 -0
  75. {varcode-9.3.2 → varcode-9.3.3}/tests/test_silent_hgvs_description.py +0 -0
  76. {varcode-9.3.2 → varcode-9.3.3}/tests/test_splice_graph.py +0 -0
  77. {varcode-9.3.2 → varcode-9.3.3}/tests/test_splice_outcomes.py +0 -0
  78. {varcode-9.3.2 → varcode-9.3.3}/tests/test_splice_site_effects.py +0 -0
  79. {varcode-9.3.2 → varcode-9.3.3}/tests/test_stop_codon_classification_bugs.py +0 -0
  80. {varcode-9.3.2 → varcode-9.3.3}/tests/test_string_helpers.py +0 -0
  81. {varcode-9.3.2 → varcode-9.3.3}/tests/test_structural_variant_annotator.py +0 -0
  82. {varcode-9.3.2 → varcode-9.3.3}/tests/test_structural_variants.py +0 -0
  83. {varcode-9.3.2 → varcode-9.3.3}/tests/test_sv_sequence_changes.py +0 -0
  84. {varcode-9.3.2 → varcode-9.3.3}/tests/test_sv_tabular_metadata.py +0 -0
  85. {varcode-9.3.2 → varcode-9.3.3}/tests/test_symbolic_alleles.py +0 -0
  86. {varcode-9.3.2 → varcode-9.3.3}/tests/test_symbolic_sv_padding.py +0 -0
  87. {varcode-9.3.2 → varcode-9.3.3}/tests/test_timings.py +0 -0
  88. {varcode-9.3.2 → varcode-9.3.3}/tests/test_transcript_layout.py +0 -0
  89. {varcode-9.3.2 → varcode-9.3.3}/tests/test_transcript_model.py +0 -0
  90. {varcode-9.3.2 → varcode-9.3.3}/tests/test_transforms_left_align.py +0 -0
  91. {varcode-9.3.2 → varcode-9.3.3}/tests/test_transforms_pair_breakends.py +0 -0
  92. {varcode-9.3.2 → varcode-9.3.3}/tests/test_variant.py +0 -0
  93. {varcode-9.3.2 → varcode-9.3.3}/tests/test_variant_collection.py +0 -0
  94. {varcode-9.3.2 → varcode-9.3.3}/tests/test_vcf.py +0 -0
  95. {varcode-9.3.2 → varcode-9.3.3}/tests/test_vcf_output.py +0 -0
  96. {varcode-9.3.2 → varcode-9.3.3}/tests/test_vcf_parsing.py +0 -0
  97. {varcode-9.3.2 → varcode-9.3.3}/tests/test_vcf_phase_resolver.py +0 -0
  98. {varcode-9.3.2 → varcode-9.3.3}/tests/test_vcf_spec_examples.py +0 -0
  99. {varcode-9.3.2 → varcode-9.3.3}/varcode/__init__.py +0 -0
  100. {varcode-9.3.2 → varcode-9.3.3}/varcode/annotators/__init__.py +0 -0
  101. {varcode-9.3.2 → varcode-9.3.3}/varcode/annotators/fast.py +0 -0
  102. {varcode-9.3.2 → varcode-9.3.3}/varcode/annotators/protein_diff.py +0 -0
  103. {varcode-9.3.2 → varcode-9.3.3}/varcode/annotators/registry.py +0 -0
  104. {varcode-9.3.2 → varcode-9.3.3}/varcode/cli/__init__.py +0 -0
  105. {varcode-9.3.2 → varcode-9.3.3}/varcode/cli/effects_script.py +0 -0
  106. {varcode-9.3.2 → varcode-9.3.3}/varcode/cli/genes_script.py +0 -0
  107. {varcode-9.3.2 → varcode-9.3.3}/varcode/cli/logging.conf +0 -0
  108. {varcode-9.3.2 → varcode-9.3.3}/varcode/cli/variant_args.py +0 -0
  109. {varcode-9.3.2 → varcode-9.3.3}/varcode/cli/version_info.py +0 -0
  110. {varcode-9.3.2 → varcode-9.3.3}/varcode/common.py +0 -0
  111. {varcode-9.3.2 → varcode-9.3.3}/varcode/cryptic_exons.py +0 -0
  112. {varcode-9.3.2 → varcode-9.3.3}/varcode/csv_helpers.py +0 -0
  113. {varcode-9.3.2 → varcode-9.3.3}/varcode/effect_candidates.py +0 -0
  114. {varcode-9.3.2 → varcode-9.3.3}/varcode/effect_hypotheses.py +0 -0
  115. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/__init__.py +0 -0
  116. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/classify.py +0 -0
  117. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/codon_tables.py +0 -0
  118. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/common.py +0 -0
  119. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_classes.py +0 -0
  120. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_collection.py +0 -0
  121. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_helpers.py +0 -0
  122. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_ordering.py +0 -0
  123. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_prediction.py +0 -0
  124. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_prediction_coding.py +0 -0
  125. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
  126. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
  127. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/fast_path.py +0 -0
  128. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/mutate.py +0 -0
  129. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/structural.py +0 -0
  130. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/transcript_helpers.py +0 -0
  131. {varcode-9.3.2 → varcode-9.3.3}/varcode/effects/translate.py +0 -0
  132. {varcode-9.3.2 → varcode-9.3.3}/varcode/errors.py +0 -0
  133. {varcode-9.3.2 → varcode-9.3.3}/varcode/exacto.py +0 -0
  134. {varcode-9.3.2 → varcode-9.3.3}/varcode/genome.py +0 -0
  135. {varcode-9.3.2 → varcode-9.3.3}/varcode/genome_sequence.py +0 -0
  136. {varcode-9.3.2 → varcode-9.3.3}/varcode/genomic_layout.py +0 -0
  137. {varcode-9.3.2 → varcode-9.3.3}/varcode/genotype.py +0 -0
  138. {varcode-9.3.2 → varcode-9.3.3}/varcode/germline.py +0 -0
  139. {varcode-9.3.2 → varcode-9.3.3}/varcode/maf.py +0 -0
  140. {varcode-9.3.2 → varcode-9.3.3}/varcode/mutant_transcript.py +0 -0
  141. {varcode-9.3.2 → varcode-9.3.3}/varcode/nucleotides.py +0 -0
  142. {varcode-9.3.2 → varcode-9.3.3}/varcode/phasing.py +0 -0
  143. {varcode-9.3.2 → varcode-9.3.3}/varcode/realized_effects.py +0 -0
  144. {varcode-9.3.2 → varcode-9.3.3}/varcode/reference.py +0 -0
  145. {varcode-9.3.2 → varcode-9.3.3}/varcode/rna_evidence.py +0 -0
  146. {varcode-9.3.2 → varcode-9.3.3}/varcode/rna_read_phasing.py +0 -0
  147. {varcode-9.3.2 → varcode-9.3.3}/varcode/splice_graph.py +0 -0
  148. {varcode-9.3.2 → varcode-9.3.3}/varcode/splice_outcomes.py +0 -0
  149. {varcode-9.3.2 → varcode-9.3.3}/varcode/string_helpers.py +0 -0
  150. {varcode-9.3.2 → varcode-9.3.3}/varcode/structural_variant.py +0 -0
  151. {varcode-9.3.2 → varcode-9.3.3}/varcode/sv_allele_parser.py +0 -0
  152. {varcode-9.3.2 → varcode-9.3.3}/varcode/transcript_layout.py +0 -0
  153. {varcode-9.3.2 → varcode-9.3.3}/varcode/transcript_model.py +0 -0
  154. {varcode-9.3.2 → varcode-9.3.3}/varcode/transforms/__init__.py +0 -0
  155. {varcode-9.3.2 → varcode-9.3.3}/varcode/ucsc_reference_names.py +0 -0
  156. {varcode-9.3.2 → varcode-9.3.3}/varcode/util.py +0 -0
  157. {varcode-9.3.2 → varcode-9.3.3}/varcode/variant.py +0 -0
  158. {varcode-9.3.2 → varcode-9.3.3}/varcode/variant_collection.py +0 -0
  159. {varcode-9.3.2 → varcode-9.3.3}/varcode/vcf.py +0 -0
  160. {varcode-9.3.2 → varcode-9.3.3}/varcode/vcf_output.py +0 -0
  161. {varcode-9.3.2 → varcode-9.3.3}/varcode/vcf_parsing.py +0 -0
  162. {varcode-9.3.2 → varcode-9.3.3}/varcode.egg-info/dependency_links.txt +0 -0
  163. {varcode-9.3.2 → varcode-9.3.3}/varcode.egg-info/entry_points.txt +0 -0
  164. {varcode-9.3.2 → varcode-9.3.3}/varcode.egg-info/requires.txt +0 -0
  165. {varcode-9.3.2 → varcode-9.3.3}/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.2
3
+ Version: 9.3.3
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,224 @@
1
+ """SV change flags read annotated selenocysteine UGA codons as the reference does.
2
+
3
+ Ensembl marks Sec as U in the reference protein. UGA encodes Sec only with a
4
+ SECIS element in the same mRNA's 3' UTR, which isn't annotated, so decoding
5
+ is known only where a model keeps the transcript through its 3' end.
6
+ """
7
+
8
+ from dataclasses import replace
9
+
10
+ import pytest
11
+ from pyensembl import cached_release
12
+
13
+ from varcode import (
14
+ MutantTranscript, ReferenceSegment, StructuralVariant, make_fusion_outcome,
15
+ )
16
+ from varcode.effects import (
17
+ EffectCollection, GeneFusion, LargeDeletion, StructuralVariantEffect,
18
+ )
19
+ from varcode.effects import structural
20
+
21
+ # GPX1 (-), GPX4 (+), SEPP1 (-, ten Sec), TXNRD1 (+, Sec is the penultimate residue).
22
+ SELENOPROTEINS = ["ENST00000419783", "ENST00000354171", "ENST00000514985", "ENST00000525566"]
23
+
24
+
25
+ @pytest.fixture
26
+ def isolate_span(monkeypatch):
27
+ monkeypatch.setattr(structural, "_fusion_partners", lambda *args: ())
28
+ monkeypatch.setattr(structural, "_enumerate_and_attach_cryptics", lambda *args: None)
29
+ monkeypatch.setattr(structural, "_enumerate_and_attach_splice_outcomes", lambda *args: None)
30
+
31
+
32
+ def _transcript(transcript_id):
33
+ return cached_release(81).transcript_by_id(transcript_id)
34
+
35
+
36
+ def _effect(transcript, cdna, segments=None, protein=None, evidence=None):
37
+ variant = StructuralVariant(transcript.contig, transcript.start, "BND",
38
+ genome=transcript.genome)
39
+ model = MutantTranscript(
40
+ reference_transcript=transcript, reference_segments=segments,
41
+ cdna_sequence=cdna, mutant_protein_sequence=protein, evidence=evidence)
42
+ return StructuralVariantEffect(variant, transcript, mutant_transcript=model)
43
+
44
+
45
+ def _sec_offset(transcript, nth=0):
46
+ start = min(transcript.start_codon_spliced_offsets)
47
+ return start + 3 * [i for i, aa in enumerate(transcript.protein_sequence) if aa == "U"][nth]
48
+
49
+
50
+ def _with_codon(sequence, pos, codon):
51
+ return sequence[:pos] + codon + sequence[pos + 3:]
52
+
53
+
54
+ @pytest.mark.parametrize("transcript_id", SELENOPROTEINS)
55
+ def test_unchanged_selenoprotein_is_unchanged(transcript_id):
56
+ t = _transcript(transcript_id)
57
+ effect = _effect(t, t.sequence, (ReferenceSegment(t, 0, len(t.sequence)),))
58
+ assert effect.modifies_coding_sequence is False
59
+ assert effect.modifies_protein_sequence is False
60
+ assert len(EffectCollection([effect]).drop_silent_and_noncoding()) == 0
61
+
62
+
63
+ @pytest.mark.parametrize("transcript_id", SELENOPROTEINS)
64
+ @pytest.mark.parametrize("change,coding,protein", [
65
+ ("sec_to_trp", True, True), ("sec_to_stop", True, True),
66
+ ("missense_before", True, True), ("synonymous_before", True, False),
67
+ ])
68
+ def test_changes_at_and_around_selenocysteine(transcript_id, change, coding, protein):
69
+ t = _transcript(transcript_id)
70
+ sec = _sec_offset(t)
71
+ start = min(t.start_codon_spliced_offsets)
72
+ cdna = t.sequence
73
+ if change == "sec_to_trp":
74
+ cdna = _with_codon(cdna, sec, "TGG")
75
+ elif change == "sec_to_stop":
76
+ cdna = _with_codon(cdna, sec, "TAA")
77
+ elif change == "missense_before":
78
+ cdna = _with_codon(cdna, start + 3, "TGG" if cdna[start + 3:start + 6] != "TGG" else "GCT")
79
+ else:
80
+ # Leucine CTN codons are four-fold degenerate at the third base.
81
+ pos = next(i for i in range(start + 3, sec, 3) if cdna[i:i + 2] == "CT")
82
+ cdna = _with_codon(cdna, pos, "CT" + ("A" if cdna[pos + 2] != "A" else "G"))
83
+ effect = _effect(t, cdna, (ReferenceSegment(t, 0, len(t.sequence)),))
84
+ assert effect.modifies_coding_sequence is coding
85
+ assert effect.modifies_protein_sequence is protein
86
+
87
+
88
+ def test_change_after_a_decoded_selenocysteine_is_found():
89
+ t = _transcript("ENST00000354171")
90
+ pos = _sec_offset(t) + 6
91
+ codon = "TGG" if t.sequence[pos:pos + 3] != "TGG" else "GCT"
92
+ effect = _effect(t, _with_codon(t.sequence, pos, codon),
93
+ (ReferenceSegment(t, 0, len(t.sequence)),))
94
+ assert effect.modifies_coding_sequence is True
95
+ assert effect.modifies_protein_sequence is True
96
+
97
+
98
+ def test_split_segments_still_retain_the_three_prime_end():
99
+ t = _transcript("ENST00000354171")
100
+ cut = _sec_offset(t) + 1
101
+ segments = (ReferenceSegment(t, 0, cut), ReferenceSegment(t, cut, len(t.sequence)))
102
+ effect = _effect(t, t.sequence, segments)
103
+ assert effect.modifies_protein_sequence is False
104
+
105
+
106
+ @pytest.mark.parametrize("transcript_id", SELENOPROTEINS)
107
+ @pytest.mark.parametrize("region,coding,protein", [
108
+ ("5utr", False, False), ("3utr", False, None)])
109
+ def test_utr_deletions_respect_secis_uncertainty(transcript_id, region, coding, protein,
110
+ isolate_span):
111
+ # A 3' UTR deletion may remove the SECIS element, so Sec decoding is unknown.
112
+ t = _transcript(transcript_id)
113
+ exon = t.exons[0] if region == "5utr" else t.exons[-1]
114
+ at_low_end = (region == "5utr") == (t.strand == "+")
115
+ start, end = (exon.start, exon.start + 9) if at_low_end else (exon.end - 9, exon.end)
116
+ variant = StructuralVariant(t.contig, start, "DEL", end=end, genome=t.genome)
117
+ effect = variant.effect_on_transcript(t)
118
+ assert isinstance(effect, LargeDeletion)
119
+ assert effect.modifies_coding_sequence is coding
120
+ assert effect.modifies_protein_sequence is protein
121
+ assert len(EffectCollection([effect]).drop_silent_and_noncoding()) == int(protein is None)
122
+
123
+
124
+ @pytest.mark.parametrize("breakpoint,coding,protein", [
125
+ ("three_prime_utr", False, None), ("after_sec", True, True)])
126
+ def test_fusion_of_a_selenoprotein_five_prime_partner(breakpoint, coding, protein):
127
+ t = _transcript("ENST00000354171")
128
+ partner = _transcript("ENST00000003084")
129
+ if breakpoint == "three_prime_utr":
130
+ position = t.end - 10
131
+ else:
132
+ # GPX4 is on the forward strand: walk exons to a CDS base past the Sec codon.
133
+ offset = _sec_offset(t) + 30
134
+ for exon in t.exons:
135
+ if offset < exon.end - exon.start + 1:
136
+ position = exon.start + offset
137
+ break
138
+ offset -= exon.end - exon.start + 1
139
+ model = structural._build_fusion_mutant_transcript(t, t, position, partner, partner.end - 10)
140
+ variant = StructuralVariant(t.contig, position, "BND", genome=t.genome)
141
+ effect = GeneFusion(variant, t, partner, mutant_transcript=model)
142
+ assert effect.modifies_coding_sequence is coding
143
+ assert effect.modifies_protein_sequence is protein
144
+
145
+
146
+ def test_three_prime_utr_duplication_leaves_cds_unchanged(isolate_span):
147
+ t = _transcript("ENST00000354171")
148
+ start = t.exons[-1].end - 20
149
+ effect = StructuralVariant(t.contig, start, "DUP", end=start + 5,
150
+ genome=t.genome).effect_on_transcript(t)
151
+ assert effect.modifies_coding_sequence is False
152
+ assert effect.modifies_protein_sequence is None
153
+
154
+
155
+ def test_losing_the_whole_three_prime_utr_truncates_at_selenocysteine(isolate_span):
156
+ # No 3' UTR, so no SECIS: the CDS is intact, but UGA now terminates.
157
+ t = _transcript("ENST00000354171")
158
+ variant = StructuralVariant(t.contig, max(t.stop_codon_positions) + 1, "DEL",
159
+ end=t.end, genome=t.genome)
160
+ effect = variant.effect_on_transcript(t)
161
+ assert effect.modifies_coding_sequence is False
162
+ assert effect.modifies_protein_sequence is True
163
+
164
+
165
+ @pytest.mark.parametrize("transcript_id", SELENOPROTEINS)
166
+ def test_unmapped_import_of_selenoprotein_is_unknown_not_changed(transcript_id):
167
+ # Without coordinates, only the reference Sec index marks a possible Sec UGA.
168
+ t = _transcript(transcript_id)
169
+ variant = StructuralVariant(t.contig, t.start, "BND", genome=t.genome)
170
+ candidate = make_fusion_outcome(variant, t, sequence=t.sequence,
171
+ cds_start=min(t.start_codon_spliced_offsets),
172
+ transcript_model_id="observed-model")
173
+ assert candidate.effect.modifies_coding_sequence is False
174
+ assert candidate.effect.modifies_protein_sequence is None
175
+ start = min(t.start_codon_spliced_offsets)
176
+ missense = _with_codon(t.sequence, start + 3,
177
+ "TGG" if t.sequence[start + 3:start + 6] != "TGG" else "GCT")
178
+ changed = make_fusion_outcome(variant, t, sequence=missense, cds_start=start,
179
+ transcript_model_id="observed-model")
180
+ assert changed.effect.modifies_protein_sequence is True
181
+
182
+
183
+ def test_peptide_ending_at_selenocysteine_is_not_a_truncation():
184
+ # Exacto translates UGA as a stop, so its peptide ends at the Sec residue.
185
+ t = _transcript("ENST00000354171")
186
+ start, sec = min(t.start_codon_spliced_offsets), _sec_offset(t)
187
+ effect = _effect(t, t.sequence, protein=t.protein_sequence[:(sec - start) // 3],
188
+ evidence={"protein_completeness": "start_to_stop",
189
+ "cds_start": start, "cds_end": sec + 3})
190
+ assert effect.modifies_coding_sequence is False
191
+ assert effect.modifies_protein_sequence is None
192
+
193
+
194
+ @pytest.mark.parametrize("reaches_three_prime_end", [True, False])
195
+ def test_partial_observation_reads_through_only_decoded_selenocysteine(reaches_three_prime_end):
196
+ t = _transcript("ENST00000354171")
197
+ sec = _sec_offset(t)
198
+ left = sec - 30
199
+ right = len(t.sequence) if reaches_three_prime_end else max(t.stop_codon_spliced_offsets) + 1
200
+ cdna = t.sequence[left:right]
201
+ pos = sec - left + 6
202
+ cdna = _with_codon(cdna, pos, "TGG" if cdna[pos:pos + 3] != "TGG" else "GCT")
203
+ effect = _effect(t, cdna, (ReferenceSegment(t, left, right),), evidence={
204
+ "protein_completeness": "partial_start", "cds_start": 0,
205
+ "cds_end": max(t.stop_codon_spliced_offsets) + 1 - left})
206
+ assert effect.modifies_coding_sequence is (True if reaches_three_prime_end else None)
207
+ assert effect.modifies_protein_sequence is (True if reaches_three_prime_end else None)
208
+ sec_to_stop = _with_codon(effect.mutant_transcript.cdna_sequence, sec - left, "TAA")
209
+ effect.mutant_transcript = replace(effect.mutant_transcript, cdna_sequence=sec_to_stop)
210
+ assert effect.modifies_coding_sequence is True
211
+ assert effect.modifies_protein_sequence is True
212
+
213
+
214
+ # TXNRD3 (CTG start, Sec) and FGF2 (CTG start): Ensembl writes the initiator as L.
215
+ @pytest.mark.parametrize("transcript_id", ["ENST00000523403", "ENST00000264498"])
216
+ def test_non_atg_initiator_is_not_a_protein_change(transcript_id):
217
+ t = _transcript(transcript_id)
218
+ assert t.coding_sequence[:3] == "CTG" and t.protein_sequence[0] == "L"
219
+ effect = _effect(t, t.sequence, (ReferenceSegment(t, 0, len(t.sequence)),))
220
+ assert effect.modifies_coding_sequence is False
221
+ assert effect.modifies_protein_sequence is False
222
+ effect.mutant_transcript = replace(
223
+ effect.mutant_transcript, mutant_protein_sequence="M" + t.protein_sequence[1:])
224
+ assert effect.modifies_protein_sequence is False
@@ -56,11 +56,12 @@ def _retained_start(model, transcript):
56
56
  if p + 1 in positions[1] and p + 2 in positions[2]), None)
57
57
 
58
58
 
59
- def _coding_sequence(model, initiator):
60
- """Read a known ORF, or the retained reference ORF; never search for one.
59
+ def _orf_bounds(model, initiator):
60
+ """A known ORF, or the retained reference start; never search for one.
61
61
 
62
- Return None for unmapped assemblies, partial fragments, missing sequence,
63
- overlaid edits whose coordinates haven't been mapped, or an incomplete ORF.
62
+ Return ``(start, end)`` with ``end`` None when unbounded, or None for
63
+ unmapped assemblies, partial fragments, missing sequence, or overlaid
64
+ edits whose coordinates haven't been mapped.
64
65
  """
65
66
  if model.cdna_sequence is None:
66
67
  return None
@@ -69,21 +70,146 @@ def _coding_sequence(model, initiator):
69
70
  if start is None or end is None:
70
71
  if not initiator.complete or model.edits:
71
72
  return None
72
- start = _retained_start(model, initiator)
73
- end = None
74
- if start is None:
75
- return None
76
- sequence = model.cdna_sequence[start:end].upper()
77
- table = codon_table_for_transcript(initiator)
73
+ start, end = _retained_start(model, initiator), None
74
+ return None if start is None else (start, end)
75
+
76
+
77
+ def _read_orf(sequence, start, end, table, selenocysteine):
78
+ """The ORF from ``start`` through its stop codon, or None if incomplete.
79
+
80
+ TGA codons at the offsets in ``selenocysteine`` are read as Sec. A
81
+ producer's ``end`` assumed they terminate, so reading through lifts it.
82
+ """
83
+ sequence = sequence[start:].upper()
84
+ limit = len(sequence) if end is None else end - start
78
85
  if sequence[:3] not in table.start_codons:
79
86
  return None
80
87
  for i in range(3, len(sequence) - 2, 3):
81
- if sequence[i:i + 3] in table.stop_codons:
88
+ if start + i in selenocysteine:
89
+ limit = len(sequence)
90
+ elif i + 3 > limit:
91
+ return None
92
+ elif sequence[i:i + 3] in table.stop_codons:
82
93
  coding = sequence[:i + 3]
83
94
  return coding if not set(coding) - set("ACGT") else None
84
95
  return None
85
96
 
86
97
 
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
+ def _initiated(protein):
150
+ # Any start codon initiates as Met; Ensembl writes CTG/TTG initiators literally.
151
+ return "M" + protein[1:] if protein else protein
152
+
153
+
154
+ def _orf_changes(model, transcript, reference_protein, table, start, end, selenocysteine):
155
+ """Compare the ORF read with one Sec decoding against the reference."""
156
+ coding = _read_orf(model.cdna_sequence, start, end, table, selenocysteine)
157
+ if coding is None:
158
+ return None, None
159
+ reference_coding = transcript.coding_sequence
160
+ coding_status = None if reference_coding is None else coding != reference_coding.upper()
161
+ if reference_protein is None or "X" in reference_protein:
162
+ return coding_status, None
163
+ residues = translate_sequence(coding, codon_table=table, to_stop=False)
164
+ # 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]
167
+ return coding_status, protein != reference_protein
168
+
169
+
170
+ def _complete_sequence_changes(model, transcript, initiator):
171
+ """Compare a start-to-stop prediction with the whole reference.
172
+
173
+ CDS bases are compared with every Sec codon read through; how Sec is
174
+ decoded affects only the protein. Where that is unknown, evaluate both
175
+ readings and keep the protein flag only when they agree.
176
+ """
177
+ supplied = None
178
+ protein = _initiated(model.mutant_protein_sequence)
179
+ reference_protein = _initiated(transcript.protein_sequence)
180
+ if (protein is not None and reference_protein is not None
181
+ and "X" not in protein and "X" not in reference_protein
182
+ # Ending exactly at a Sec residue is a decoding choice, not a change.
183
+ and not (reference_protein.startswith(protein)
184
+ and reference_protein[len(protein):len(protein) + 1] == "U")):
185
+ # An empty protein is a known absence, not missing data.
186
+ supplied = protein != reference_protein
187
+ bounds = _orf_bounds(model, initiator)
188
+ if bounds is None:
189
+ return None, supplied
190
+ start, end = bounds
191
+ mapped = _mapped_selenocysteine(model)
192
+ if mapped is not None and any(s.source == transcript for s in model.reference_segments or ()):
193
+ decoded, uncertain, terminating = mapped
194
+ else:
195
+ # Without coordinates, a TGA at a reference Sec index of an ORF read
196
+ # from this transcript's own start may be Sec.
197
+ decoded, uncertain, terminating = set(), set(), set()
198
+ if initiator == transcript and reference_protein:
199
+ sequence = model.cdna_sequence
200
+ uncertain = {pos for pos in (start + 3 * i for i, aa in enumerate(reference_protein)
201
+ if aa == "U")
202
+ if sequence[pos:pos + 3].upper() == "TGA"}
203
+ table = codon_table_for_transcript(initiator)
204
+ coding_status, _ = _orf_changes(model, transcript, reference_protein, table, start, end,
205
+ decoded | uncertain | terminating)
206
+ proteins = {_orf_changes(model, transcript, reference_protein, table, start, end,
207
+ selenocysteine)[1]
208
+ for selenocysteine in {frozenset(decoded), frozenset(decoded | uncertain)}}
209
+ protein_status = proteins.pop() if len(proteins) == 1 else None
210
+ return coding_status, supplied if supplied is not None else protein_status
211
+
212
+
87
213
  def _residue(codon, table, initiator):
88
214
  # As for a complete ORF, any start codon at the initiator reads as Met.
89
215
  if initiator and codon in table.start_codons:
@@ -125,6 +251,8 @@ def _partial_sequence_changes(model, transcript, table):
125
251
  offset += segment.length
126
252
  reference_start = min(transcript.start_codon_spliced_offsets)
127
253
  reference_coding = transcript.coding_sequence.upper()
254
+ reference_selenocysteine = _selenocysteine_offsets(transcript)
255
+ decoded = _mapped_selenocysteine(model)[0]
128
256
  coding_status = None
129
257
  for pos in range(start, end - 2, 3):
130
258
  codon = sequence[pos:pos + 3].upper()
@@ -138,9 +266,11 @@ def _partial_sequence_changes(model, transcript, table):
138
266
  coding_status = True
139
267
  # Only an observed ORF that begins here can initiate here.
140
268
  observed = _residue(codon, table, k == 0 and pos == start)
141
- if observed != _residue(reference_codon, table, k == 0):
269
+ reference = ("U" if ref in reference_selenocysteine
270
+ else _residue(reference_codon, table, k == 0))
271
+ if observed != reference:
142
272
  return True, True
143
- if codon in table.stop_codons:
273
+ if codon in table.stop_codons and pos not in decoded:
144
274
  break # Later bases are not translated in this frame.
145
275
  return coding_status, None
146
276
 
@@ -164,23 +294,8 @@ def structural_sequence_changes(effect):
164
294
  coding_status, protein_status = _partial_sequence_changes(
165
295
  model, transcript, codon_table_for_transcript(initiator))
166
296
  elif model is not None:
167
- protein = model.mutant_protein_sequence
168
- reference_protein = transcript.protein_sequence
169
- if protein is not None and reference_protein is not None:
170
- # An empty protein is a known absence, not missing data.
171
- if "X" not in protein and "X" not in reference_protein:
172
- protein_status = protein != reference_protein
173
- coding = _coding_sequence(model, initiator)
174
- if coding is not None:
175
- reference_coding = transcript.coding_sequence
176
- if reference_coding is not None:
177
- coding_status = coding != reference_coding.upper()
178
- if protein_status is None and reference_protein is not None:
179
- # Initiator methionine also applies to alternative start codons.
180
- protein = "M" + translate_sequence(
181
- coding[3:], codon_table=codon_table_for_transcript(initiator))
182
- if "X" not in reference_protein:
183
- protein_status = protein != reference_protein
297
+ coding_status, protein_status = _complete_sequence_changes(
298
+ model, transcript, initiator)
184
299
 
185
300
  # A pure deletion can establish CDS/start loss without a translated model.
186
301
  # Do not apply DNA-span inference to a supplied assembly or an RNA outcome.
@@ -200,7 +315,11 @@ def structural_sequence_changes(effect):
200
315
  coding_status = coding_overlap
201
316
  if protein_status is None:
202
317
  if not coding_overlap:
203
- protein_status = False
318
+ # Deleting a selenoprotein's 3' UTR may remove its SECIS element.
319
+ stops = _selenocysteine_offsets(transcript) and transcript.stop_codon_positions
320
+ if not stops or (end < min(stops) if transcript.strand == "+"
321
+ else start > max(stops)):
322
+ protein_status = False
204
323
  elif (transcript.contains_start_codon
205
324
  and any(start <= pos <= end for pos in transcript.start_codon_positions)):
206
325
  protein_status = True
@@ -0,0 +1 @@
1
+ __version__ = "9.3.3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: varcode
3
- Version: 9.3.2
3
+ Version: 9.3.3
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
@@ -72,6 +72,7 @@ tests/test_stop_codon_classification_bugs.py
72
72
  tests/test_string_helpers.py
73
73
  tests/test_structural_variant_annotator.py
74
74
  tests/test_structural_variants.py
75
+ tests/test_sv_selenocysteine.py
75
76
  tests/test_sv_sequence_changes.py
76
77
  tests/test_sv_tabular_metadata.py
77
78
  tests/test_symbolic_alleles.py
@@ -1 +0,0 @@
1
- __version__ = "9.3.2"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes