varcode 9.3.7__tar.gz → 9.4.0__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.7/varcode.egg-info → varcode-9.4.0}/PKG-INFO +2 -2
- {varcode-9.3.7 → varcode-9.4.0}/pyproject.toml +1 -1
- varcode-9.4.0/tests/test_annotator_haplotypes.py +278 -0
- varcode-9.4.0/tests/test_osteosarc_dataset.py +127 -0
- varcode-9.4.0/tests/test_transcript_model_start_codons.py +163 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/annotators/__init__.py +5 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/annotators/fast.py +28 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/annotators/protein_diff.py +7 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_classes.py +24 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/phasing.py +42 -40
- {varcode-9.3.7 → varcode-9.4.0}/varcode/transcript_layout.py +35 -27
- {varcode-9.3.7 → varcode-9.4.0}/varcode/transcript_model.py +52 -15
- {varcode-9.3.7 → varcode-9.4.0}/varcode/variant_collection.py +3 -2
- varcode-9.4.0/varcode/version.py +1 -0
- {varcode-9.3.7 → varcode-9.4.0/varcode.egg-info}/PKG-INFO +2 -2
- {varcode-9.3.7 → varcode-9.4.0}/varcode.egg-info/SOURCES.txt +2 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode.egg-info/requires.txt +1 -1
- varcode-9.3.7/tests/test_osteosarc_dataset.py +0 -74
- varcode-9.3.7/varcode/version.py +0 -1
- {varcode-9.3.7 → varcode-9.4.0}/LICENSE +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/MANIFEST.in +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/README.md +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/requirements.txt +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/setup.cfg +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_annotator_divergence_scenarios.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_annotator_parity_adversarial.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_annotators.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_bnd_retained_segments.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_cli_effects.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_cli_genes.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_cli_without_pkg_resources.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_collection_filtering.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_collection_variants_attr_consistency.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_common.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_cosmic_mutations.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_cryptic_exons.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_csv_roundtrip.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_dbnsfp_validation.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_default_structural_helpers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_documentation_examples.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effect_annotation_errors.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effect_candidates.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effect_classes.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effect_collection.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effect_collection_serialization.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effect_collection_sort_order.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effect_hypotheses.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_effects_from_mutagenix_variants.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_exacto_fusions.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_exonic_splice_site.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_fast_path.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_frameshift_cterminus_regression.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_frameshift_helpers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_fusion_partner_candidates.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_genome_contig_validation.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_genome_sequence.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_genomic_layout.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_genotype.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_genotype_from_vcf.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_germline_context.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_germline_effects.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_haplotype_effect.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_maf.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_mitochondrial.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_mm10_klf6_frameshift.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_mouse.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_mutant_transcript.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_mutate.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_no_duplicate_variants.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_nonlocal_sv_transcripts.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_osteosarc_fusions.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_osteosarc_variants.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_partial_annotators.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_premature_stop_short_description.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_problematic_variants.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_protein_diff_parity.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_read_phase_resolver.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_real_world_callers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_reference.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_reference_mismatch_error.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_reference_segments.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_rna_evidence.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_rna_haplotype_sequences.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_rna_read_phasing_source.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_selenocysteine.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_selenocysteine_proteins.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_silent_aa_pos.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_silent_hgvs_description.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_splice_graph.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_splice_outcomes.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_splice_site_effects.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_stop_codon_classification_bugs.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_string_helpers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_structural_variant_annotator.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_structural_variants.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_sv_selenocysteine.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_sv_sequence_changes.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_sv_tabular_metadata.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_symbolic_alleles.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_symbolic_sv_padding.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_timings.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_transcript_layout.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_transcript_model.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_transforms_left_align.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_transforms_pair_breakends.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_variant.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_variant_collection.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_vcf.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_vcf_output.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_vcf_parsing.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_vcf_phase_resolver.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/tests/test_vcf_spec_examples.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/__init__.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/annotators/registry.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/cli/__init__.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/cli/effects_script.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/cli/genes_script.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/cli/logging.conf +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/cli/variant_args.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/cli/version_info.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/common.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/cryptic_exons.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/csv_helpers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effect_candidates.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effect_hypotheses.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/__init__.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/classify.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/codon_tables.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/common.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_collection.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_helpers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_ordering.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_prediction.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_prediction_coding.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/fast_path.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/mutate.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/selenocysteine.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/sequence_change.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/structural.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/transcript_helpers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/effects/translate.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/errors.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/exacto.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/genome.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/genome_sequence.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/genomic_layout.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/genotype.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/germline.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/maf.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/mutant_transcript.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/nucleotides.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/realized_effects.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/reference.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/rna_evidence.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/rna_read_phasing.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/splice_graph.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/splice_outcomes.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/string_helpers.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/structural_variant.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/sv_allele_parser.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/transforms/__init__.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/ucsc_reference_names.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/util.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/variant.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/vcf.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/vcf_output.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode/vcf_parsing.py +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode.egg-info/dependency_links.txt +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/varcode.egg-info/entry_points.txt +0 -0
- {varcode-9.3.7 → varcode-9.4.0}/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
|
+
Version: 9.4.0
|
|
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
|
|
@@ -24,7 +24,7 @@ Requires-Dist: sercol>=0.1.4
|
|
|
24
24
|
Provides-Extra: rna
|
|
25
25
|
Requires-Dist: pysam>=0.21; extra == "rna"
|
|
26
26
|
Provides-Extra: test-data
|
|
27
|
-
Requires-Dist: osteosarc==0.1.
|
|
27
|
+
Requires-Dist: osteosarc==0.1.4; python_version >= "3.10" and extra == "test-data"
|
|
28
28
|
Dynamic: license-file
|
|
29
29
|
|
|
30
30
|
[](https://github.com/openvax/varcode/actions/workflows/tests.yml)
|
|
@@ -35,7 +35,7 @@ include = ["varcode", "varcode.*"]
|
|
|
35
35
|
|
|
36
36
|
[project.optional-dependencies]
|
|
37
37
|
rna = ["pysam>=0.21"]
|
|
38
|
-
test-data = ["osteosarc==0.1.
|
|
38
|
+
test-data = ["osteosarc==0.1.4; python_version >= '3.10'"]
|
|
39
39
|
|
|
40
40
|
[project.scripts]
|
|
41
41
|
varcode-genes = "varcode.cli.genes_script:main"
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"""The selected annotator owns joint predictions through the collection API."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from pyensembl import cached_release
|
|
5
|
+
|
|
6
|
+
from varcode import (
|
|
7
|
+
EffectCollection, GermlineContext, MutantTranscript, StructuralVariant, Variant,
|
|
8
|
+
VariantCollection, get_annotator, use_annotator,
|
|
9
|
+
)
|
|
10
|
+
from varcode.effects.effect_classes import (
|
|
11
|
+
ComplexSubstitution, Deletion, Failure, HaplotypeEffect, PrematureStop,
|
|
12
|
+
Silent, Unresolved,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.fixture
|
|
17
|
+
def transcript():
|
|
18
|
+
return cached_release(81).transcript_by_id("ENST00000003084")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.fixture
|
|
22
|
+
def variants():
|
|
23
|
+
genome = cached_release(81)
|
|
24
|
+
# Each allele alone is missense; together GTA becomes TAA.
|
|
25
|
+
return (
|
|
26
|
+
Variant("7", 117530914, "G", "T", genome),
|
|
27
|
+
Variant("7", 117530915, "T", "A", genome),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Phase:
|
|
32
|
+
phase_source = "test_phase"
|
|
33
|
+
|
|
34
|
+
def __init__(self, answer=True, observed=None):
|
|
35
|
+
self.answer = answer
|
|
36
|
+
self.observed = observed or {}
|
|
37
|
+
|
|
38
|
+
def in_cis(self, left, right, transcript=None):
|
|
39
|
+
return self.answer
|
|
40
|
+
|
|
41
|
+
def mutant_transcript(self, variant, transcript):
|
|
42
|
+
return self.observed.get((variant, transcript.id))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def joint_effects(effects, transcript):
|
|
46
|
+
return [e for e in effects if getattr(e, "transcript", None) == transcript
|
|
47
|
+
and len(getattr(e, "variants", ())) > 1]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.parametrize("name", ["fast", "protein_diff", "transcript_model"])
|
|
51
|
+
def test_selected_model_composes_cis_codons_and_keeps_individuals(name, variants, transcript):
|
|
52
|
+
with use_annotator(name):
|
|
53
|
+
effects = VariantCollection(variants).effects(phase_resolver=Phase())
|
|
54
|
+
joint, = joint_effects(effects, transcript)
|
|
55
|
+
expected_stop = (transcript.spliced_offset(variants[0].start)
|
|
56
|
+
- min(transcript.start_codon_spliced_offsets)) // 3
|
|
57
|
+
assert joint.mutant_protein_sequence == transcript.protein_sequence[:expected_stop]
|
|
58
|
+
assert type(joint) is (PrematureStop if name == "transcript_model" else HaplotypeEffect)
|
|
59
|
+
assert joint.variants == variants
|
|
60
|
+
assert joint.phase_source == "test_phase"
|
|
61
|
+
assert joint.annotator == effects.annotator == name
|
|
62
|
+
assert joint.annotator_version == effects.annotator_version
|
|
63
|
+
for variant in variants:
|
|
64
|
+
individual, = [e for e in effects if e.transcript == transcript
|
|
65
|
+
and e.variant == variant
|
|
66
|
+
and len(getattr(e, "variants", ())) < 2]
|
|
67
|
+
assert len(individual.mutant_protein_sequence) == len(transcript.protein_sequence)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@pytest.mark.parametrize("name", ["fast", "transcript_model"])
|
|
71
|
+
@pytest.mark.parametrize("phase", [False, None])
|
|
72
|
+
def test_trans_and_unknown_phase_do_not_form_a_joint_prediction(name, phase, variants, transcript):
|
|
73
|
+
effects = VariantCollection(variants).effects(
|
|
74
|
+
annotator=name, phase_resolver=Phase(phase))
|
|
75
|
+
assert not joint_effects(effects, transcript)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class Declining:
|
|
79
|
+
name = "declining"
|
|
80
|
+
version = "test-1"
|
|
81
|
+
|
|
82
|
+
def annotate_on_transcript(self, variant, transcript):
|
|
83
|
+
return NotImplemented
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@pytest.mark.parametrize("explicit_hook", [False, True])
|
|
87
|
+
def test_declining_plugin_keeps_unresolved_group_without_default_prediction(
|
|
88
|
+
explicit_hook, variants, transcript):
|
|
89
|
+
annotator = Declining()
|
|
90
|
+
if explicit_hook:
|
|
91
|
+
annotator.annotate_haplotype = lambda *args, **kwargs: NotImplemented
|
|
92
|
+
effects = VariantCollection(variants).effects(
|
|
93
|
+
annotator=annotator, phase_resolver=Phase())
|
|
94
|
+
joint, = joint_effects(effects, transcript)
|
|
95
|
+
assert isinstance(joint, Unresolved)
|
|
96
|
+
assert joint.mechanism == "unsupported_haplotype"
|
|
97
|
+
assert "declining" in joint.reason
|
|
98
|
+
assert joint.variants == variants
|
|
99
|
+
assert joint.phase_source == "test_phase"
|
|
100
|
+
assert joint.annotator == effects.annotator == "declining"
|
|
101
|
+
assert joint.annotator_version == "test-1"
|
|
102
|
+
assert not any(isinstance(e, HaplotypeEffect) for e in effects)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_plugin_receives_whole_group_and_original_context(variants, transcript):
|
|
106
|
+
context = GermlineContext.from_variants([variants[0]])
|
|
107
|
+
resolver = Phase()
|
|
108
|
+
calls = []
|
|
109
|
+
|
|
110
|
+
class Plugin(Declining):
|
|
111
|
+
def annotate_haplotype(self, members, target, germline_ctx=None, phase_resolver=None):
|
|
112
|
+
calls.append((members, target, germline_ctx, phase_resolver))
|
|
113
|
+
return Silent(members[0], target, aa_pos=0, aa_ref="M")
|
|
114
|
+
|
|
115
|
+
effects = VariantCollection(variants).effects(
|
|
116
|
+
annotator=Plugin(), phase_resolver=resolver, germline=context)
|
|
117
|
+
joint, = joint_effects(effects, transcript)
|
|
118
|
+
assert type(joint) is Silent
|
|
119
|
+
assert (variants, transcript, context, resolver) in calls
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@pytest.mark.parametrize("name", ["fast", "protein_diff"])
|
|
123
|
+
def test_default_does_not_discard_joint_patient_baseline(name, variants, transcript):
|
|
124
|
+
context = GermlineContext.from_variants([
|
|
125
|
+
Variant("7", 117531101, "T", "C", cached_release(81))])
|
|
126
|
+
effects = VariantCollection(variants).effects(
|
|
127
|
+
annotator=name, germline=context, phase_resolver=Phase())
|
|
128
|
+
joint, = joint_effects(effects, transcript)
|
|
129
|
+
assert isinstance(joint, Unresolved)
|
|
130
|
+
assert "germline context" in joint.reason
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_model_uses_germline_near_every_member(transcript):
|
|
134
|
+
genome = cached_release(81)
|
|
135
|
+
members = (Variant("7", 117531100, "T", "A", genome),
|
|
136
|
+
Variant("7", 117534280, "T", "G", genome))
|
|
137
|
+
position = 117534281
|
|
138
|
+
offset = transcript.spliced_offset(position)
|
|
139
|
+
ref = transcript.sequence[offset]
|
|
140
|
+
alt = "A" if ref != "A" else "C"
|
|
141
|
+
germline = Variant("7", position, ref, alt, genome)
|
|
142
|
+
effects = VariantCollection(members).effects(
|
|
143
|
+
annotator="transcript_model", phase_resolver=Phase(),
|
|
144
|
+
germline=GermlineContext.from_variants([germline]))
|
|
145
|
+
joint, = joint_effects(effects, transcript)
|
|
146
|
+
for candidate in joint.candidates:
|
|
147
|
+
for outcome in candidate.outcomes:
|
|
148
|
+
assert outcome.baseline.cdna_sequence[offset] == alt
|
|
149
|
+
assert (germline, "cis") in outcome.hypothesis.phase
|
|
150
|
+
for variant in members:
|
|
151
|
+
index = transcript.spliced_offset(variant.start)
|
|
152
|
+
assert outcome.baseline.cdna_sequence[index] == variant.ref
|
|
153
|
+
assert outcome.mutant.cdna_sequence[index] == variant.alt
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@pytest.mark.parametrize("name", ["fast", "protein_diff", "transcript_model"])
|
|
157
|
+
def test_rna_observation_is_preserved_with_its_provenance(name, variants, transcript):
|
|
158
|
+
observed = MutantTranscript(
|
|
159
|
+
reference_transcript=transcript, cdna_sequence="ATGGCTTAA",
|
|
160
|
+
mutant_protein_sequence="MA", annotator_name="rna_source")
|
|
161
|
+
resolver = Phase(observed={(variants[1], transcript.id): observed})
|
|
162
|
+
effects = VariantCollection(variants).effects(annotator=name, phase_resolver=resolver)
|
|
163
|
+
joint, = joint_effects(effects, transcript)
|
|
164
|
+
if name == "transcript_model":
|
|
165
|
+
assert joint.observed_mutant_transcripts == ((variants[1], observed),)
|
|
166
|
+
assert joint.mutant_protein_sequence != observed.mutant_protein_sequence
|
|
167
|
+
else:
|
|
168
|
+
assert joint.mutant_transcript is observed
|
|
169
|
+
assert joint.mutant_protein_sequence == "MA"
|
|
170
|
+
assert observed.annotator_name == "rna_source"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@pytest.mark.parametrize("name", ["fast", "protein_diff", "transcript_model"])
|
|
174
|
+
@pytest.mark.parametrize("kind", ["splice", "sv"])
|
|
175
|
+
def test_splice_and_sv_groups_are_delegated_and_never_silently_dropped(name, kind, transcript):
|
|
176
|
+
genome = cached_release(81)
|
|
177
|
+
coding = Variant("7", 117531100, "T", "A", genome)
|
|
178
|
+
if kind == "splice":
|
|
179
|
+
second = Variant("7", 117531115, "G", "A", genome)
|
|
180
|
+
else:
|
|
181
|
+
exon = transcript.exons[4]
|
|
182
|
+
second = StructuralVariant(
|
|
183
|
+
"7", exon.start - 300, "DEL", end=exon.end + 300, genome=genome)
|
|
184
|
+
effects = VariantCollection([coding, second]).effects(
|
|
185
|
+
annotator=name, phase_resolver=Phase())
|
|
186
|
+
joint, = joint_effects(effects, transcript)
|
|
187
|
+
assert joint.variants == (coding, second)
|
|
188
|
+
if name == "transcript_model":
|
|
189
|
+
assert type(joint) is (Deletion if kind == "splice" else ComplexSubstitution)
|
|
190
|
+
assert joint.candidates
|
|
191
|
+
assert len(joint.mutant_protein_sequence) < len(transcript.protein_sequence)
|
|
192
|
+
else:
|
|
193
|
+
assert isinstance(joint, Unresolved)
|
|
194
|
+
assert joint.mechanism == "unsupported_haplotype"
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@pytest.mark.parametrize("name", ["fast", "protein_diff"])
|
|
198
|
+
def test_conflicting_point_edits_remain_an_unresolved_group(name, variants, transcript):
|
|
199
|
+
conflict = Variant("7", variants[0].start, "G", "A", cached_release(81))
|
|
200
|
+
members = (variants[0], conflict)
|
|
201
|
+
effects = VariantCollection(members).effects(annotator=name, phase_resolver=Phase())
|
|
202
|
+
joint, = joint_effects(effects, transcript)
|
|
203
|
+
assert isinstance(joint, Unresolved)
|
|
204
|
+
assert joint.variants == members
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def test_joint_error_policy_and_invalid_return(variants, transcript):
|
|
208
|
+
class Broken(Declining):
|
|
209
|
+
def annotate_haplotype(self, *args, **kwargs):
|
|
210
|
+
raise ValueError("joint prediction failed")
|
|
211
|
+
|
|
212
|
+
collection = VariantCollection(variants)
|
|
213
|
+
with pytest.raises(ValueError, match="joint prediction failed"):
|
|
214
|
+
collection.effects(annotator=Broken(), phase_resolver=Phase(), raise_on_error=True)
|
|
215
|
+
effects = collection.effects(
|
|
216
|
+
annotator=Broken(), phase_resolver=Phase(), raise_on_error=False)
|
|
217
|
+
joint, = joint_effects(effects, transcript)
|
|
218
|
+
assert isinstance(joint, Failure)
|
|
219
|
+
assert joint.variants == variants
|
|
220
|
+
invalid = Declining()
|
|
221
|
+
invalid.annotate_haplotype = lambda *args, **kwargs: None
|
|
222
|
+
with pytest.raises(TypeError, match="MutationEffect or NotImplemented"):
|
|
223
|
+
collection.effects(annotator=invalid, phase_resolver=Phase(), raise_on_error=False)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def test_model_conflicting_edits_follow_error_policy(variants, transcript):
|
|
227
|
+
conflict = Variant("7", variants[0].start, "G", "A", cached_release(81))
|
|
228
|
+
collection = VariantCollection([variants[0], conflict])
|
|
229
|
+
with pytest.raises(ValueError, match="does not match realized layout"):
|
|
230
|
+
collection.effects(annotator="transcript_model", phase_resolver=Phase())
|
|
231
|
+
effects = collection.effects(
|
|
232
|
+
annotator="transcript_model", phase_resolver=Phase(), raise_on_error=False)
|
|
233
|
+
joint, = joint_effects(effects, transcript)
|
|
234
|
+
assert isinstance(joint, Failure)
|
|
235
|
+
assert set(joint.variants) == {variants[0], conflict}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@pytest.mark.parametrize("name", ["fast", "protein_diff", "transcript_model"])
|
|
239
|
+
def test_reverse_strand_group_keeps_both_edits(name):
|
|
240
|
+
genome = cached_release(81)
|
|
241
|
+
transcript = genome.transcript_by_id("ENST00000357654")
|
|
242
|
+
variants = (Variant("17", 43082563, "T", "A", genome),
|
|
243
|
+
Variant("17", 43082570, "C", "A", genome))
|
|
244
|
+
effects = VariantCollection(variants).effects(
|
|
245
|
+
annotator=name, phase_resolver=Phase(), germline=GermlineContext.empty())
|
|
246
|
+
joint, = joint_effects(effects, transcript)
|
|
247
|
+
cdna = (joint.candidates[0].outcomes[0].mutant.cdna_sequence
|
|
248
|
+
if name == "transcript_model" else joint.mutant_transcript.cdna_sequence)
|
|
249
|
+
assert [i for i, (ref, alt) in enumerate(zip(transcript.sequence, cdna))
|
|
250
|
+
if ref != alt] == [4309, 4316]
|
|
251
|
+
assert cdna[4309] == cdna[4316] == "T"
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@pytest.mark.parametrize("name", ["fast", "transcript_model", "declining"])
|
|
255
|
+
def test_joint_membership_and_provenance_survive_json(name, variants, transcript):
|
|
256
|
+
annotator = Declining() if name == "declining" else name
|
|
257
|
+
observed = MutantTranscript(
|
|
258
|
+
reference_transcript=transcript, cdna_sequence="ATGGCTTAA",
|
|
259
|
+
mutant_protein_sequence="MA", annotator_name="rna_source")
|
|
260
|
+
effects = VariantCollection(variants).effects(
|
|
261
|
+
annotator=annotator,
|
|
262
|
+
phase_resolver=Phase(observed={(variants[1], transcript.id): observed}))
|
|
263
|
+
original, = joint_effects(effects, transcript)
|
|
264
|
+
restored = EffectCollection.from_json(effects.to_json())
|
|
265
|
+
joint, = joint_effects(restored, transcript)
|
|
266
|
+
assert joint.variants == original.variants
|
|
267
|
+
assert joint.phase_source == original.phase_source
|
|
268
|
+
assert joint.annotator == restored.annotator == name
|
|
269
|
+
assert joint.annotator_version == original.annotator_version
|
|
270
|
+
if name == "declining":
|
|
271
|
+
assert joint.reason == original.reason
|
|
272
|
+
elif name == "transcript_model":
|
|
273
|
+
(variant, model), = joint.observed_mutant_transcripts
|
|
274
|
+
assert variant == variants[1]
|
|
275
|
+
assert model.mutant_protein_sequence == "MA"
|
|
276
|
+
assert model.annotator_name == "rna_source"
|
|
277
|
+
else:
|
|
278
|
+
assert joint.mutant_protein_sequence == "MA"
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Opt-in, offline checks against the pinned public osteosarc snapshot.
|
|
2
|
+
|
|
3
|
+
See tests/README.md for acquisition and invocation. Source annotations are
|
|
4
|
+
provenance, not an independent oracle for protein consequences.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
from dataclasses import replace
|
|
10
|
+
from importlib.metadata import version
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
from pyensembl import cached_release
|
|
14
|
+
|
|
15
|
+
from varcode import Variant
|
|
16
|
+
from varcode.mutant_transcript import apply_variant_to_transcript
|
|
17
|
+
|
|
18
|
+
from .osteosarc_variants import SNAPSHOT_ID, read_fixture
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture(scope="module")
|
|
23
|
+
def dataset():
|
|
24
|
+
snapshot = os.environ.get("OSTEOSARC_TEST_SNAPSHOT")
|
|
25
|
+
if not snapshot:
|
|
26
|
+
pytest.skip("set OSTEOSARC_TEST_SNAPSHOT to enable the offline corpus checks")
|
|
27
|
+
# Once explicitly requested, missing dependencies/cache entries must fail.
|
|
28
|
+
from osteosarc import Cache, Dataset
|
|
29
|
+
|
|
30
|
+
assert version("osteosarc") == "0.1.4"
|
|
31
|
+
cache = Cache(os.environ.get("OSTEOSARC_TEST_CACHE"), offline=True)
|
|
32
|
+
data = Dataset.open(snapshot, cache=cache, offline=True)
|
|
33
|
+
assert data.id == SNAPSHOT_ID
|
|
34
|
+
return data
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_osteosarc_native_variants_preserve_alleles_and_provenance(dataset):
|
|
38
|
+
entries = dataset.variants(status="ready")
|
|
39
|
+
assert len(dataset.variants()) == 182
|
|
40
|
+
assert len(entries) == 179
|
|
41
|
+
genome = cached_release(81)
|
|
42
|
+
native = entries.to_varcode(genome=genome)
|
|
43
|
+
expected_ids = {entry.id for entry in entries}
|
|
44
|
+
actual_ids = set()
|
|
45
|
+
for variant in native:
|
|
46
|
+
assert variant.genome is genome
|
|
47
|
+
metadata = native.metadata[variant]
|
|
48
|
+
assert metadata["source"]["snapshot_id"] == SNAPSHOT_ID
|
|
49
|
+
assert metadata["source"]["receipts"]
|
|
50
|
+
for entry in metadata["entries"]:
|
|
51
|
+
actual_ids.add(entry["id"])
|
|
52
|
+
contig, position, ref, alt = entries[entry["id"]].allele
|
|
53
|
+
assert variant == Variant(
|
|
54
|
+
contig, position, ref, alt, genome,
|
|
55
|
+
convert_ucsc_contig_names=True)
|
|
56
|
+
assert actual_ids == expected_ids
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_osteosarc_corrected_map2_is_a_distinct_complex_allele(dataset):
|
|
60
|
+
entry = dataset.variants()["MAP2-chr2-209694768"]
|
|
61
|
+
assert entry.allele == (
|
|
62
|
+
"chr2", 209694768, "CCTGGGCTACTGTGTGTTCAATAAGTACACAGT", "CAGGG")
|
|
63
|
+
assert "allele-MAP2-chr2-209694768" in entry.annotations["corrections"]
|
|
64
|
+
genome = cached_release(81)
|
|
65
|
+
selected = dataset.variants().select(ids=entry.id).to_varcode(genome=genome)
|
|
66
|
+
variant, = selected
|
|
67
|
+
old_deletion = Variant("2", 209694768, "CCTGGGCTACTGTGTGTTCAATA", "C", genome)
|
|
68
|
+
assert variant != old_deletion
|
|
69
|
+
t = genome.transcript_by_id("ENST00000360351")
|
|
70
|
+
model = apply_variant_to_transcript(variant, t)
|
|
71
|
+
assert model is not None
|
|
72
|
+
assert model.mutant_protein_sequence is not None
|
|
73
|
+
assert model.mutant_protein_sequence != t.protein_sequence
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_historical_fixture_alleles_survive_package_update(dataset):
|
|
77
|
+
# The checked-in corpus remains the 0.1.0 export. New curation can resolve
|
|
78
|
+
# additional entries or enrich provenance without rewriting that history.
|
|
79
|
+
fixture = read_fixture()
|
|
80
|
+
entries = dataset.variants()
|
|
81
|
+
assert {entry.id for entry in entries} == {entry["id"] for entry in fixture["entries"]}
|
|
82
|
+
for entry in fixture["entries"]:
|
|
83
|
+
if entry["status"] == "ready":
|
|
84
|
+
assert entries[entry["id"]].allele == tuple(entry["alleles"][0])
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_mitochondrial_native_conversion_can_be_annotated(dataset):
|
|
88
|
+
genome = cached_release(81)
|
|
89
|
+
entries = dataset.variants(status="ready")
|
|
90
|
+
entry, = [entry for entry in entries if entry.allele[0] == "chrM"]
|
|
91
|
+
variants = entries.select(ids=entry.id).to_varcode(genome=genome)
|
|
92
|
+
variant, = variants
|
|
93
|
+
assert variant.contig == "MT"
|
|
94
|
+
assert variant.original_contig == "chrM"
|
|
95
|
+
effects = variant.effects(raise_on_error=True)
|
|
96
|
+
assert any(effect.gene_name == "MT-ND5"
|
|
97
|
+
and effect.short_description == "p.A220T" for effect in effects)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_shared_cache_offline_reuse_and_integrity(dataset, tmp_path):
|
|
101
|
+
from osteosarc import Cache, Dataset, IntegrityError, OfflineError
|
|
102
|
+
from osteosarc.cache import Receipt
|
|
103
|
+
|
|
104
|
+
shared = Cache(os.environ.get("OSTEOSARC_TEST_CACHE"), offline=True)
|
|
105
|
+
reopened = Dataset.open(os.environ["OSTEOSARC_TEST_SNAPSHOT"],
|
|
106
|
+
cache=shared, offline=True)
|
|
107
|
+
assert reopened.id == dataset.id
|
|
108
|
+
receipt = Receipt(**dataset.variants().source["receipts"]["source_variants"])
|
|
109
|
+
source_path = shared.path(receipt)
|
|
110
|
+
assert Cache(shared.root, offline=True).path(receipt) == source_path
|
|
111
|
+
with pytest.raises(OfflineError):
|
|
112
|
+
Cache(tmp_path / "empty", offline=True).path(receipt)
|
|
113
|
+
|
|
114
|
+
# Modify a private copy, never the user's shared cache.
|
|
115
|
+
isolated = Cache(tmp_path / "tampered", offline=True)
|
|
116
|
+
isolated.objects.mkdir(parents=True)
|
|
117
|
+
target = isolated.objects / source_path.name
|
|
118
|
+
shutil.copyfile(source_path, target)
|
|
119
|
+
assert isolated.path(receipt) == target
|
|
120
|
+
with pytest.raises(IntegrityError):
|
|
121
|
+
isolated.path(replace(receipt, size=receipt.size + 1))
|
|
122
|
+
with target.open("r+b") as handle:
|
|
123
|
+
byte = handle.read(1)
|
|
124
|
+
handle.seek(0)
|
|
125
|
+
handle.write(bytes([byte[0] ^ 1]))
|
|
126
|
+
with pytest.raises(IntegrityError):
|
|
127
|
+
isolated.path(receipt)
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"""Initiation codons in realized products (openvax/varcode#476)."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from pyensembl import cached_release
|
|
5
|
+
|
|
6
|
+
from varcode import Variant
|
|
7
|
+
from varcode.effect_hypotheses import SplicePlan
|
|
8
|
+
from varcode.effects import AlternateStartCodon, StartLoss, Substitution
|
|
9
|
+
from varcode.genomic_layout import GenomicLayout
|
|
10
|
+
from varcode.nucleotides import reverse_complement
|
|
11
|
+
from varcode.transcript_layout import (
|
|
12
|
+
build_exon_runs,
|
|
13
|
+
classify_products,
|
|
14
|
+
realize_exon_path,
|
|
15
|
+
realize_splice_plan,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
from .test_splice_graph import point
|
|
19
|
+
from .test_transcript_layout import Transcript, provider, structural
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.parametrize("annotator", ["fast", "protein_diff", "transcript_model"])
|
|
23
|
+
@pytest.mark.parametrize("transcript_id,alt_codon", [
|
|
24
|
+
("ENST00000003084", "CTG"),
|
|
25
|
+
("ENST00000003084", "TTG"),
|
|
26
|
+
("ENST00000357654", "CTG"),
|
|
27
|
+
("ENST00000357654", "TTG"),
|
|
28
|
+
("ENST00000361624", "ATT"),
|
|
29
|
+
("ENST00000361624", "ATC"),
|
|
30
|
+
("ENST00000361624", "ATA"),
|
|
31
|
+
("ENST00000361624", "GTG"),
|
|
32
|
+
])
|
|
33
|
+
def test_recognized_alternate_start_preserves_protein(
|
|
34
|
+
annotator, transcript_id, alt_codon):
|
|
35
|
+
genome = cached_release(81)
|
|
36
|
+
transcript = genome.transcript_by_id(transcript_id)
|
|
37
|
+
ref, alt = "ATG", alt_codon
|
|
38
|
+
if transcript.on_backward_strand:
|
|
39
|
+
ref, alt = reverse_complement(ref), reverse_complement(alt)
|
|
40
|
+
variant = Variant(
|
|
41
|
+
transcript.contig, min(transcript.start_codon_positions), ref, alt,
|
|
42
|
+
genome=genome)
|
|
43
|
+
|
|
44
|
+
effect = variant.effect_on_transcript(transcript, annotator=annotator)
|
|
45
|
+
|
|
46
|
+
assert type(effect) is AlternateStartCodon
|
|
47
|
+
assert effect.ref_codon == "ATG"
|
|
48
|
+
assert effect.alt_codon == alt_codon
|
|
49
|
+
assert effect.modifies_coding_sequence is True
|
|
50
|
+
assert effect.modifies_protein_sequence is False
|
|
51
|
+
if annotator == "transcript_model":
|
|
52
|
+
outcome = effect.candidates[0].outcomes[0]
|
|
53
|
+
assert outcome.baseline.start_codon_present is True
|
|
54
|
+
assert outcome.mutant.start_codon_present is True
|
|
55
|
+
assert outcome.baseline.protein_sequence == str(transcript.protein_sequence)
|
|
56
|
+
assert outcome.mutant.protein_sequence == str(transcript.protein_sequence)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.mark.parametrize("transcript_id,alt_codon", [
|
|
60
|
+
("ENST00000003084", "GTG"),
|
|
61
|
+
("ENST00000357654", "GTG"),
|
|
62
|
+
("ENST00000361624", "CTG"),
|
|
63
|
+
("ENST00000361624", "TTG"),
|
|
64
|
+
])
|
|
65
|
+
def test_start_recognition_uses_the_transcripts_codon_table(
|
|
66
|
+
transcript_id, alt_codon):
|
|
67
|
+
genome = cached_release(81)
|
|
68
|
+
transcript = genome.transcript_by_id(transcript_id)
|
|
69
|
+
ref, alt = "ATG", alt_codon
|
|
70
|
+
if transcript.on_backward_strand:
|
|
71
|
+
ref, alt = reverse_complement(ref), reverse_complement(alt)
|
|
72
|
+
variant = Variant(
|
|
73
|
+
transcript.contig, min(transcript.start_codon_positions), ref, alt,
|
|
74
|
+
genome=genome)
|
|
75
|
+
|
|
76
|
+
effect = variant.effect_on_transcript(transcript, annotator="transcript_model")
|
|
77
|
+
|
|
78
|
+
assert type(effect) is StartLoss
|
|
79
|
+
assert effect.modifies_protein_sequence is True
|
|
80
|
+
assert effect.candidates[0].outcomes[0].mutant.start_codon_present is False
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@pytest.fixture(params=["exon_path", "splice_plan"])
|
|
84
|
+
def realize(request):
|
|
85
|
+
if request.param == "exon_path":
|
|
86
|
+
return realize_exon_path
|
|
87
|
+
|
|
88
|
+
def splice_plan(transcript, layout):
|
|
89
|
+
plan = SplicePlan(
|
|
90
|
+
choices=(),
|
|
91
|
+
kept_runs=tuple(run.key for run in build_exon_runs(transcript, layout)))
|
|
92
|
+
product, unresolved = realize_splice_plan(transcript, layout, plan, ())
|
|
93
|
+
assert unresolved == ()
|
|
94
|
+
return product
|
|
95
|
+
|
|
96
|
+
return splice_plan
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@pytest.mark.parametrize("reverse", [False, True])
|
|
100
|
+
def test_both_layout_paths_translate_alternate_start_as_methionine(realize, reverse):
|
|
101
|
+
transcript = Transcript(reverse)
|
|
102
|
+
layout = GenomicLayout.from_transcript(
|
|
103
|
+
transcript, flank=0, sequence_provider=provider(reverse))
|
|
104
|
+
variant = point(18, "T", "G") if reverse else point(1, "A", "C")
|
|
105
|
+
baseline = realize(transcript, layout)
|
|
106
|
+
mutant = realize(transcript, layout.apply_point_variant(variant))
|
|
107
|
+
|
|
108
|
+
effect = classify_products(variant, transcript, baseline, mutant)
|
|
109
|
+
|
|
110
|
+
assert type(effect) is AlternateStartCodon
|
|
111
|
+
assert (effect.ref_codon, effect.alt_codon) == ("ATG", "CTG")
|
|
112
|
+
assert mutant.cdna_sequence == "CTGCAAGCTTAG"
|
|
113
|
+
assert mutant.protein_sequence == "MQA"
|
|
114
|
+
assert mutant.start_codon_present is True
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@pytest.mark.parametrize("reverse", [False, True])
|
|
118
|
+
def test_deleted_start_is_still_start_loss(realize, reverse):
|
|
119
|
+
transcript = Transcript(reverse)
|
|
120
|
+
layout = GenomicLayout.from_transcript(
|
|
121
|
+
transcript, flank=0, sequence_provider=provider(reverse))
|
|
122
|
+
variant = structural("DEL", *(16, 18) if reverse else (1, 3))
|
|
123
|
+
baseline = realize(transcript, layout)
|
|
124
|
+
mutant = realize(transcript, layout.apply_structural_variant(variant))
|
|
125
|
+
|
|
126
|
+
effect = classify_products(variant, transcript, baseline, mutant)
|
|
127
|
+
|
|
128
|
+
assert type(effect) is StartLoss
|
|
129
|
+
assert mutant.start_codon_present is False
|
|
130
|
+
assert mutant.protein_sequence == ""
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_alternate_start_is_compared_to_patient_baseline(realize):
|
|
134
|
+
transcript = Transcript()
|
|
135
|
+
layout = GenomicLayout.from_transcript(
|
|
136
|
+
transcript, flank=0, sequence_provider=provider())
|
|
137
|
+
layout = layout.apply_point_variant(point(1, "A", "C"))
|
|
138
|
+
baseline = realize(transcript, layout)
|
|
139
|
+
variant = point(1, "C", "T")
|
|
140
|
+
mutant = realize(transcript, layout.apply_point_variant(variant))
|
|
141
|
+
|
|
142
|
+
effect = classify_products(variant, transcript, baseline, mutant)
|
|
143
|
+
|
|
144
|
+
assert type(effect) is AlternateStartCodon
|
|
145
|
+
assert (effect.ref_codon, effect.alt_codon) == ("CTG", "TTG")
|
|
146
|
+
assert baseline.protein_sequence == mutant.protein_sequence == "MQA"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_alternate_start_does_not_hide_downstream_protein_change(realize):
|
|
150
|
+
transcript = Transcript()
|
|
151
|
+
layout = GenomicLayout.from_transcript(
|
|
152
|
+
transcript, flank=0, sequence_provider=provider())
|
|
153
|
+
baseline = realize(transcript, layout)
|
|
154
|
+
variant = point(1, "A", "C")
|
|
155
|
+
mutant_layout = layout.apply_point_variant(variant).apply_point_variant(
|
|
156
|
+
point(6, "C", "A"))
|
|
157
|
+
mutant = realize(transcript, mutant_layout)
|
|
158
|
+
|
|
159
|
+
effect = classify_products(variant, transcript, baseline, mutant)
|
|
160
|
+
|
|
161
|
+
assert type(effect) is Substitution
|
|
162
|
+
assert (effect.aa_ref, effect.aa_alt) == ("Q", "K")
|
|
163
|
+
assert mutant.protein_sequence == "MKA"
|
|
@@ -61,6 +61,11 @@ class EffectAnnotator(Protocol):
|
|
|
61
61
|
Without it, nonempty germline context is unsupported. Empty context
|
|
62
62
|
calls ``annotate_on_transcript`` as usual.
|
|
63
63
|
|
|
64
|
+
Optionally implement ``annotate_haplotype(variants, transcript,
|
|
65
|
+
germline_ctx=None, phase_resolver=None)`` with the same return contract.
|
|
66
|
+
Collections delegate each known-cis group to this method. A missing hook
|
|
67
|
+
or refusal leaves an explicit unresolved group alongside individual effects.
|
|
68
|
+
|
|
64
69
|
The contract is duck-typed (``@runtime_checkable``) so third-party annotators
|
|
65
70
|
don't need to inherit from varcode just to register.
|
|
66
71
|
"""
|
|
@@ -62,3 +62,31 @@ class FastEffectAnnotator:
|
|
|
62
62
|
return predict_germline_aware_effect(
|
|
63
63
|
variant, transcript, germline_ctx, annotator=self,
|
|
64
64
|
phase_resolver=phase_resolver)
|
|
65
|
+
|
|
66
|
+
def annotate_haplotype(
|
|
67
|
+
self, variants, transcript, germline_ctx=None, phase_resolver=None):
|
|
68
|
+
"""Build the established point-edit or observed joint transcript.
|
|
69
|
+
|
|
70
|
+
Patient-baseline and structural composition require the experimental
|
|
71
|
+
transcript model. Decline them rather than silently ignoring context.
|
|
72
|
+
"""
|
|
73
|
+
from ..effects.effect_classes import HaplotypeEffect
|
|
74
|
+
from ..mutant_transcript import apply_variants_to_transcript
|
|
75
|
+
|
|
76
|
+
if germline_ctx:
|
|
77
|
+
return NotImplemented
|
|
78
|
+
mt = None
|
|
79
|
+
if hasattr(phase_resolver, "mutant_transcript"):
|
|
80
|
+
for variant in variants:
|
|
81
|
+
mt = phase_resolver.mutant_transcript(variant, transcript)
|
|
82
|
+
if mt is not None:
|
|
83
|
+
break
|
|
84
|
+
if mt is None:
|
|
85
|
+
if any(getattr(v, "is_structural", False) for v in variants):
|
|
86
|
+
return NotImplemented
|
|
87
|
+
mt = apply_variants_to_transcript(variants, transcript)
|
|
88
|
+
if mt is None:
|
|
89
|
+
return NotImplemented
|
|
90
|
+
return HaplotypeEffect(
|
|
91
|
+
variants=variants, transcript=transcript, mutant_transcript=mt,
|
|
92
|
+
phase_source=getattr(phase_resolver, "phase_source", None))
|
|
@@ -85,6 +85,13 @@ class ProteinDiffEffectAnnotator:
|
|
|
85
85
|
self, variant, transcript, germline_ctx,
|
|
86
86
|
phase_resolver=phase_resolver)
|
|
87
87
|
|
|
88
|
+
def annotate_haplotype(
|
|
89
|
+
self, variants, transcript, germline_ctx=None, phase_resolver=None):
|
|
90
|
+
"""Use the shared point-edit builder for joint predictions."""
|
|
91
|
+
return FastEffectAnnotator.annotate_haplotype(
|
|
92
|
+
self, variants, transcript, germline_ctx=germline_ctx,
|
|
93
|
+
phase_resolver=phase_resolver)
|
|
94
|
+
|
|
88
95
|
def annotate_on_transcript(self, variant, transcript):
|
|
89
96
|
"""Classify the effect of ``variant`` on ``transcript``.
|
|
90
97
|
|