varcode 9.3.2__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.
- {varcode-9.3.2/varcode.egg-info → varcode-9.3.4}/PKG-INFO +1 -1
- varcode-9.3.4/tests/test_selenocysteine_proteins.py +190 -0
- varcode-9.3.4/tests/test_sv_selenocysteine.py +224 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/codon_tables.py +9 -1
- varcode-9.3.4/varcode/effects/selenocysteine.py +127 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/sequence_change.py +103 -31
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/structural.py +15 -6
- {varcode-9.3.2 → varcode-9.3.4}/varcode/mutant_transcript.py +14 -7
- {varcode-9.3.2 → varcode-9.3.4}/varcode/splice_outcomes.py +14 -10
- {varcode-9.3.2 → varcode-9.3.4}/varcode/transcript_layout.py +7 -2
- varcode-9.3.4/varcode/version.py +1 -0
- {varcode-9.3.2 → varcode-9.3.4/varcode.egg-info}/PKG-INFO +1 -1
- {varcode-9.3.2 → varcode-9.3.4}/varcode.egg-info/SOURCES.txt +3 -0
- varcode-9.3.2/varcode/version.py +0 -1
- {varcode-9.3.2 → varcode-9.3.4}/LICENSE +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/MANIFEST.in +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/README.md +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/pyproject.toml +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/requirements.txt +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/setup.cfg +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_annotator_divergence_scenarios.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_annotator_parity_adversarial.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_annotators.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_bnd_retained_segments.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_cli_effects.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_cli_genes.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_cli_without_pkg_resources.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_collection_filtering.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_collection_variants_attr_consistency.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_common.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_cosmic_mutations.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_cryptic_exons.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_csv_roundtrip.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_dbnsfp_validation.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_default_structural_helpers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_documentation_examples.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effect_annotation_errors.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effect_candidates.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effect_classes.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effect_collection.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effect_collection_serialization.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effect_collection_sort_order.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effect_hypotheses.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_effects_from_mutagenix_variants.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_exacto_fusions.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_exonic_splice_site.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_fast_path.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_frameshift_cterminus_regression.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_frameshift_helpers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_fusion_partner_candidates.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_genome_contig_validation.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_genome_sequence.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_genomic_layout.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_genotype.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_genotype_from_vcf.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_germline_context.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_germline_effects.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_haplotype_effect.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_maf.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_mitochondrial.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_mm10_klf6_frameshift.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_mouse.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_mutant_transcript.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_mutate.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_no_duplicate_variants.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_nonlocal_sv_transcripts.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_osteosarc_fusions.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_partial_annotators.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_premature_stop_short_description.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_problematic_variants.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_protein_diff_parity.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_read_phase_resolver.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_real_world_callers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_reference.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_reference_mismatch_error.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_reference_segments.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_rna_evidence.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_rna_haplotype_sequences.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_rna_read_phasing_source.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_selenocysteine.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_silent_aa_pos.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_silent_hgvs_description.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_splice_graph.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_splice_outcomes.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_splice_site_effects.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_stop_codon_classification_bugs.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_string_helpers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_structural_variant_annotator.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_structural_variants.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_sv_sequence_changes.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_sv_tabular_metadata.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_symbolic_alleles.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_symbolic_sv_padding.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_timings.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_transcript_layout.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_transcript_model.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_transforms_left_align.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_transforms_pair_breakends.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_variant.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_variant_collection.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_vcf.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_vcf_output.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_vcf_parsing.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_vcf_phase_resolver.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/tests/test_vcf_spec_examples.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/__init__.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/annotators/__init__.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/annotators/fast.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/annotators/protein_diff.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/annotators/registry.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/cli/__init__.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/cli/effects_script.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/cli/genes_script.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/cli/logging.conf +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/cli/variant_args.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/cli/version_info.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/common.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/cryptic_exons.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/csv_helpers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effect_candidates.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effect_hypotheses.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/__init__.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/classify.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/common.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_classes.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_collection.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_helpers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_ordering.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_prediction.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_prediction_coding.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/fast_path.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/mutate.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/transcript_helpers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/effects/translate.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/errors.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/exacto.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/genome.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/genome_sequence.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/genomic_layout.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/genotype.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/germline.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/maf.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/nucleotides.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/phasing.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/realized_effects.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/reference.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/rna_evidence.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/rna_read_phasing.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/splice_graph.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/string_helpers.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/structural_variant.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/sv_allele_parser.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/transcript_model.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/transforms/__init__.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/ucsc_reference_names.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/util.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/variant.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/variant_collection.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/vcf.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/vcf_output.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode/vcf_parsing.py +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode.egg-info/dependency_links.txt +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode.egg-info/entry_points.txt +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode.egg-info/requires.txt +0 -0
- {varcode-9.3.2 → varcode-9.3.4}/varcode.egg-info/top_level.txt +0 -0
|
@@ -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
|
+
|
|
@@ -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
|
|
@@ -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()
|