varcode 9.3.8__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.
Files changed (172) hide show
  1. {varcode-9.3.8/varcode.egg-info → varcode-9.4.0}/PKG-INFO +2 -2
  2. {varcode-9.3.8 → varcode-9.4.0}/pyproject.toml +1 -1
  3. varcode-9.4.0/tests/test_annotator_haplotypes.py +278 -0
  4. varcode-9.4.0/tests/test_osteosarc_dataset.py +127 -0
  5. {varcode-9.3.8 → varcode-9.4.0}/varcode/annotators/__init__.py +5 -0
  6. {varcode-9.3.8 → varcode-9.4.0}/varcode/annotators/fast.py +28 -0
  7. {varcode-9.3.8 → varcode-9.4.0}/varcode/annotators/protein_diff.py +7 -0
  8. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_classes.py +24 -0
  9. {varcode-9.3.8 → varcode-9.4.0}/varcode/phasing.py +42 -40
  10. {varcode-9.3.8 → varcode-9.4.0}/varcode/transcript_model.py +52 -15
  11. {varcode-9.3.8 → varcode-9.4.0}/varcode/variant_collection.py +3 -2
  12. varcode-9.4.0/varcode/version.py +1 -0
  13. {varcode-9.3.8 → varcode-9.4.0/varcode.egg-info}/PKG-INFO +2 -2
  14. {varcode-9.3.8 → varcode-9.4.0}/varcode.egg-info/SOURCES.txt +1 -0
  15. {varcode-9.3.8 → varcode-9.4.0}/varcode.egg-info/requires.txt +1 -1
  16. varcode-9.3.8/tests/test_osteosarc_dataset.py +0 -74
  17. varcode-9.3.8/varcode/version.py +0 -1
  18. {varcode-9.3.8 → varcode-9.4.0}/LICENSE +0 -0
  19. {varcode-9.3.8 → varcode-9.4.0}/MANIFEST.in +0 -0
  20. {varcode-9.3.8 → varcode-9.4.0}/README.md +0 -0
  21. {varcode-9.3.8 → varcode-9.4.0}/requirements.txt +0 -0
  22. {varcode-9.3.8 → varcode-9.4.0}/setup.cfg +0 -0
  23. {varcode-9.3.8 → varcode-9.4.0}/tests/test_annotator_divergence_scenarios.py +0 -0
  24. {varcode-9.3.8 → varcode-9.4.0}/tests/test_annotator_parity_adversarial.py +0 -0
  25. {varcode-9.3.8 → varcode-9.4.0}/tests/test_annotators.py +0 -0
  26. {varcode-9.3.8 → varcode-9.4.0}/tests/test_bnd_retained_segments.py +0 -0
  27. {varcode-9.3.8 → varcode-9.4.0}/tests/test_cli_effects.py +0 -0
  28. {varcode-9.3.8 → varcode-9.4.0}/tests/test_cli_genes.py +0 -0
  29. {varcode-9.3.8 → varcode-9.4.0}/tests/test_cli_without_pkg_resources.py +0 -0
  30. {varcode-9.3.8 → varcode-9.4.0}/tests/test_collection_filtering.py +0 -0
  31. {varcode-9.3.8 → varcode-9.4.0}/tests/test_collection_variants_attr_consistency.py +0 -0
  32. {varcode-9.3.8 → varcode-9.4.0}/tests/test_common.py +0 -0
  33. {varcode-9.3.8 → varcode-9.4.0}/tests/test_cosmic_mutations.py +0 -0
  34. {varcode-9.3.8 → varcode-9.4.0}/tests/test_cryptic_exons.py +0 -0
  35. {varcode-9.3.8 → varcode-9.4.0}/tests/test_csv_roundtrip.py +0 -0
  36. {varcode-9.3.8 → varcode-9.4.0}/tests/test_dbnsfp_validation.py +0 -0
  37. {varcode-9.3.8 → varcode-9.4.0}/tests/test_default_structural_helpers.py +0 -0
  38. {varcode-9.3.8 → varcode-9.4.0}/tests/test_documentation_examples.py +0 -0
  39. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effect_annotation_errors.py +0 -0
  40. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effect_candidates.py +0 -0
  41. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effect_classes.py +0 -0
  42. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effect_collection.py +0 -0
  43. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effect_collection_serialization.py +0 -0
  44. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effect_collection_sort_order.py +0 -0
  45. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effect_hypotheses.py +0 -0
  46. {varcode-9.3.8 → varcode-9.4.0}/tests/test_effects_from_mutagenix_variants.py +0 -0
  47. {varcode-9.3.8 → varcode-9.4.0}/tests/test_exacto_fusions.py +0 -0
  48. {varcode-9.3.8 → varcode-9.4.0}/tests/test_exonic_splice_site.py +0 -0
  49. {varcode-9.3.8 → varcode-9.4.0}/tests/test_fast_path.py +0 -0
  50. {varcode-9.3.8 → varcode-9.4.0}/tests/test_frameshift_cterminus_regression.py +0 -0
  51. {varcode-9.3.8 → varcode-9.4.0}/tests/test_frameshift_helpers.py +0 -0
  52. {varcode-9.3.8 → varcode-9.4.0}/tests/test_fusion_partner_candidates.py +0 -0
  53. {varcode-9.3.8 → varcode-9.4.0}/tests/test_genome_contig_validation.py +0 -0
  54. {varcode-9.3.8 → varcode-9.4.0}/tests/test_genome_sequence.py +0 -0
  55. {varcode-9.3.8 → varcode-9.4.0}/tests/test_genomic_layout.py +0 -0
  56. {varcode-9.3.8 → varcode-9.4.0}/tests/test_genotype.py +0 -0
  57. {varcode-9.3.8 → varcode-9.4.0}/tests/test_genotype_from_vcf.py +0 -0
  58. {varcode-9.3.8 → varcode-9.4.0}/tests/test_germline_context.py +0 -0
  59. {varcode-9.3.8 → varcode-9.4.0}/tests/test_germline_effects.py +0 -0
  60. {varcode-9.3.8 → varcode-9.4.0}/tests/test_haplotype_effect.py +0 -0
  61. {varcode-9.3.8 → varcode-9.4.0}/tests/test_maf.py +0 -0
  62. {varcode-9.3.8 → varcode-9.4.0}/tests/test_mitochondrial.py +0 -0
  63. {varcode-9.3.8 → varcode-9.4.0}/tests/test_mm10_klf6_frameshift.py +0 -0
  64. {varcode-9.3.8 → varcode-9.4.0}/tests/test_mouse.py +0 -0
  65. {varcode-9.3.8 → varcode-9.4.0}/tests/test_mutant_transcript.py +0 -0
  66. {varcode-9.3.8 → varcode-9.4.0}/tests/test_mutate.py +0 -0
  67. {varcode-9.3.8 → varcode-9.4.0}/tests/test_no_duplicate_variants.py +0 -0
  68. {varcode-9.3.8 → varcode-9.4.0}/tests/test_nonlocal_sv_transcripts.py +0 -0
  69. {varcode-9.3.8 → varcode-9.4.0}/tests/test_osteosarc_fusions.py +0 -0
  70. {varcode-9.3.8 → varcode-9.4.0}/tests/test_osteosarc_variants.py +0 -0
  71. {varcode-9.3.8 → varcode-9.4.0}/tests/test_partial_annotators.py +0 -0
  72. {varcode-9.3.8 → varcode-9.4.0}/tests/test_premature_stop_short_description.py +0 -0
  73. {varcode-9.3.8 → varcode-9.4.0}/tests/test_problematic_variants.py +0 -0
  74. {varcode-9.3.8 → varcode-9.4.0}/tests/test_protein_diff_parity.py +0 -0
  75. {varcode-9.3.8 → varcode-9.4.0}/tests/test_read_phase_resolver.py +0 -0
  76. {varcode-9.3.8 → varcode-9.4.0}/tests/test_real_world_callers.py +0 -0
  77. {varcode-9.3.8 → varcode-9.4.0}/tests/test_reference.py +0 -0
  78. {varcode-9.3.8 → varcode-9.4.0}/tests/test_reference_mismatch_error.py +0 -0
  79. {varcode-9.3.8 → varcode-9.4.0}/tests/test_reference_segments.py +0 -0
  80. {varcode-9.3.8 → varcode-9.4.0}/tests/test_rna_evidence.py +0 -0
  81. {varcode-9.3.8 → varcode-9.4.0}/tests/test_rna_haplotype_sequences.py +0 -0
  82. {varcode-9.3.8 → varcode-9.4.0}/tests/test_rna_read_phasing_source.py +0 -0
  83. {varcode-9.3.8 → varcode-9.4.0}/tests/test_selenocysteine.py +0 -0
  84. {varcode-9.3.8 → varcode-9.4.0}/tests/test_selenocysteine_proteins.py +0 -0
  85. {varcode-9.3.8 → varcode-9.4.0}/tests/test_silent_aa_pos.py +0 -0
  86. {varcode-9.3.8 → varcode-9.4.0}/tests/test_silent_hgvs_description.py +0 -0
  87. {varcode-9.3.8 → varcode-9.4.0}/tests/test_splice_graph.py +0 -0
  88. {varcode-9.3.8 → varcode-9.4.0}/tests/test_splice_outcomes.py +0 -0
  89. {varcode-9.3.8 → varcode-9.4.0}/tests/test_splice_site_effects.py +0 -0
  90. {varcode-9.3.8 → varcode-9.4.0}/tests/test_stop_codon_classification_bugs.py +0 -0
  91. {varcode-9.3.8 → varcode-9.4.0}/tests/test_string_helpers.py +0 -0
  92. {varcode-9.3.8 → varcode-9.4.0}/tests/test_structural_variant_annotator.py +0 -0
  93. {varcode-9.3.8 → varcode-9.4.0}/tests/test_structural_variants.py +0 -0
  94. {varcode-9.3.8 → varcode-9.4.0}/tests/test_sv_selenocysteine.py +0 -0
  95. {varcode-9.3.8 → varcode-9.4.0}/tests/test_sv_sequence_changes.py +0 -0
  96. {varcode-9.3.8 → varcode-9.4.0}/tests/test_sv_tabular_metadata.py +0 -0
  97. {varcode-9.3.8 → varcode-9.4.0}/tests/test_symbolic_alleles.py +0 -0
  98. {varcode-9.3.8 → varcode-9.4.0}/tests/test_symbolic_sv_padding.py +0 -0
  99. {varcode-9.3.8 → varcode-9.4.0}/tests/test_timings.py +0 -0
  100. {varcode-9.3.8 → varcode-9.4.0}/tests/test_transcript_layout.py +0 -0
  101. {varcode-9.3.8 → varcode-9.4.0}/tests/test_transcript_model.py +0 -0
  102. {varcode-9.3.8 → varcode-9.4.0}/tests/test_transcript_model_start_codons.py +0 -0
  103. {varcode-9.3.8 → varcode-9.4.0}/tests/test_transforms_left_align.py +0 -0
  104. {varcode-9.3.8 → varcode-9.4.0}/tests/test_transforms_pair_breakends.py +0 -0
  105. {varcode-9.3.8 → varcode-9.4.0}/tests/test_variant.py +0 -0
  106. {varcode-9.3.8 → varcode-9.4.0}/tests/test_variant_collection.py +0 -0
  107. {varcode-9.3.8 → varcode-9.4.0}/tests/test_vcf.py +0 -0
  108. {varcode-9.3.8 → varcode-9.4.0}/tests/test_vcf_output.py +0 -0
  109. {varcode-9.3.8 → varcode-9.4.0}/tests/test_vcf_parsing.py +0 -0
  110. {varcode-9.3.8 → varcode-9.4.0}/tests/test_vcf_phase_resolver.py +0 -0
  111. {varcode-9.3.8 → varcode-9.4.0}/tests/test_vcf_spec_examples.py +0 -0
  112. {varcode-9.3.8 → varcode-9.4.0}/varcode/__init__.py +0 -0
  113. {varcode-9.3.8 → varcode-9.4.0}/varcode/annotators/registry.py +0 -0
  114. {varcode-9.3.8 → varcode-9.4.0}/varcode/cli/__init__.py +0 -0
  115. {varcode-9.3.8 → varcode-9.4.0}/varcode/cli/effects_script.py +0 -0
  116. {varcode-9.3.8 → varcode-9.4.0}/varcode/cli/genes_script.py +0 -0
  117. {varcode-9.3.8 → varcode-9.4.0}/varcode/cli/logging.conf +0 -0
  118. {varcode-9.3.8 → varcode-9.4.0}/varcode/cli/variant_args.py +0 -0
  119. {varcode-9.3.8 → varcode-9.4.0}/varcode/cli/version_info.py +0 -0
  120. {varcode-9.3.8 → varcode-9.4.0}/varcode/common.py +0 -0
  121. {varcode-9.3.8 → varcode-9.4.0}/varcode/cryptic_exons.py +0 -0
  122. {varcode-9.3.8 → varcode-9.4.0}/varcode/csv_helpers.py +0 -0
  123. {varcode-9.3.8 → varcode-9.4.0}/varcode/effect_candidates.py +0 -0
  124. {varcode-9.3.8 → varcode-9.4.0}/varcode/effect_hypotheses.py +0 -0
  125. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/__init__.py +0 -0
  126. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/classify.py +0 -0
  127. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/codon_tables.py +0 -0
  128. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/common.py +0 -0
  129. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_collection.py +0 -0
  130. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_helpers.py +0 -0
  131. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_ordering.py +0 -0
  132. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_prediction.py +0 -0
  133. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_prediction_coding.py +0 -0
  134. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
  135. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
  136. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/fast_path.py +0 -0
  137. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/mutate.py +0 -0
  138. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/selenocysteine.py +0 -0
  139. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/sequence_change.py +0 -0
  140. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/structural.py +0 -0
  141. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/transcript_helpers.py +0 -0
  142. {varcode-9.3.8 → varcode-9.4.0}/varcode/effects/translate.py +0 -0
  143. {varcode-9.3.8 → varcode-9.4.0}/varcode/errors.py +0 -0
  144. {varcode-9.3.8 → varcode-9.4.0}/varcode/exacto.py +0 -0
  145. {varcode-9.3.8 → varcode-9.4.0}/varcode/genome.py +0 -0
  146. {varcode-9.3.8 → varcode-9.4.0}/varcode/genome_sequence.py +0 -0
  147. {varcode-9.3.8 → varcode-9.4.0}/varcode/genomic_layout.py +0 -0
  148. {varcode-9.3.8 → varcode-9.4.0}/varcode/genotype.py +0 -0
  149. {varcode-9.3.8 → varcode-9.4.0}/varcode/germline.py +0 -0
  150. {varcode-9.3.8 → varcode-9.4.0}/varcode/maf.py +0 -0
  151. {varcode-9.3.8 → varcode-9.4.0}/varcode/mutant_transcript.py +0 -0
  152. {varcode-9.3.8 → varcode-9.4.0}/varcode/nucleotides.py +0 -0
  153. {varcode-9.3.8 → varcode-9.4.0}/varcode/realized_effects.py +0 -0
  154. {varcode-9.3.8 → varcode-9.4.0}/varcode/reference.py +0 -0
  155. {varcode-9.3.8 → varcode-9.4.0}/varcode/rna_evidence.py +0 -0
  156. {varcode-9.3.8 → varcode-9.4.0}/varcode/rna_read_phasing.py +0 -0
  157. {varcode-9.3.8 → varcode-9.4.0}/varcode/splice_graph.py +0 -0
  158. {varcode-9.3.8 → varcode-9.4.0}/varcode/splice_outcomes.py +0 -0
  159. {varcode-9.3.8 → varcode-9.4.0}/varcode/string_helpers.py +0 -0
  160. {varcode-9.3.8 → varcode-9.4.0}/varcode/structural_variant.py +0 -0
  161. {varcode-9.3.8 → varcode-9.4.0}/varcode/sv_allele_parser.py +0 -0
  162. {varcode-9.3.8 → varcode-9.4.0}/varcode/transcript_layout.py +0 -0
  163. {varcode-9.3.8 → varcode-9.4.0}/varcode/transforms/__init__.py +0 -0
  164. {varcode-9.3.8 → varcode-9.4.0}/varcode/ucsc_reference_names.py +0 -0
  165. {varcode-9.3.8 → varcode-9.4.0}/varcode/util.py +0 -0
  166. {varcode-9.3.8 → varcode-9.4.0}/varcode/variant.py +0 -0
  167. {varcode-9.3.8 → varcode-9.4.0}/varcode/vcf.py +0 -0
  168. {varcode-9.3.8 → varcode-9.4.0}/varcode/vcf_output.py +0 -0
  169. {varcode-9.3.8 → varcode-9.4.0}/varcode/vcf_parsing.py +0 -0
  170. {varcode-9.3.8 → varcode-9.4.0}/varcode.egg-info/dependency_links.txt +0 -0
  171. {varcode-9.3.8 → varcode-9.4.0}/varcode.egg-info/entry_points.txt +0 -0
  172. {varcode-9.3.8 → 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.8
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.0; python_version >= "3.10" and extra == "test-data"
27
+ Requires-Dist: osteosarc==0.1.4; python_version >= "3.10" and extra == "test-data"
28
28
  Dynamic: license-file
29
29
 
30
30
  [![Tests](https://github.com/openvax/varcode/actions/workflows/tests.yml/badge.svg)](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.0; python_version >= '3.10'"]
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)
@@ -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
 
@@ -276,10 +276,34 @@ class Intragenic(MutationEffect):
276
276
 
277
277
 
278
278
  class TranscriptMutationEffect(Intragenic):
279
+ _haplotype_fields = (
280
+ "variants", "phase_source", "annotator", "annotator_version",
281
+ "observed_mutant_transcripts")
282
+
279
283
  def __init__(self, variant, transcript):
280
284
  Intragenic.__init__(self, variant, gene=transcript.gene)
281
285
  self.transcript = transcript
282
286
 
287
+ def to_dict(self):
288
+ state = super().to_dict()
289
+ # Annotators may return any ordinary effect class for a cis group.
290
+ # Preserve the group independently of that class's constructor fields.
291
+ if len(getattr(self, "variants", ())) > 1:
292
+ state["_haplotype_context"] = tuple(
293
+ (key, getattr(self, key)) for key in self._haplotype_fields
294
+ if hasattr(self, key))
295
+ return state
296
+
297
+ @classmethod
298
+ def from_dict(cls, state_dict):
299
+ state = dict(state_dict)
300
+ context = dict(state.pop("_haplotype_context", ()))
301
+ result = super().from_dict(state)
302
+ for key in cls._haplotype_fields:
303
+ if key in context:
304
+ setattr(result, key, context[key])
305
+ return result
306
+
283
307
  def __str__(self):
284
308
  return "%s(variant=%s, transcript_name=%s, transcript_id=%s)" % (
285
309
  self.__class__.__name__,
@@ -26,6 +26,7 @@ produces the evidence (Isovar, long-read callers, custom assemblers,
26
26
  test stubs).
27
27
  """
28
28
 
29
+ import logging
29
30
  from typing import Optional, Protocol, Sequence, runtime_checkable
30
31
 
31
32
 
@@ -340,29 +341,24 @@ def apply_phase_resolver_to_effects(effects, phase_resolver):
340
341
  return effects
341
342
 
342
343
 
343
- def build_haplotype_effects(variant_collection, effects, phase_resolver):
344
- """Enrich ``effects`` with :class:`HaplotypeEffect` entries when
345
- ``phase_resolver`` groups two or more cis variants on the same
346
- transcript (#269).
344
+ def build_haplotype_effects(
345
+ variant_collection, effects, phase_resolver, annotator=None,
346
+ germline=None, raise_on_error=True):
347
+ """Ask the selected annotator to predict each known-cis group.
347
348
 
348
- Additive — per-variant effects stay on the collection. Returns a
349
- flat list of new :class:`HaplotypeEffect` objects the caller can
350
- concatenate onto the existing :class:`EffectCollection`.
351
-
352
- Groups variants by transcript first, then uses
353
- ``phase_resolver.in_cis(v_i, v_j, transcript)`` to partition each
354
- transcript's variants into cis sets. Any cis set with ≥ 2
355
- resolvable edits becomes one HaplotypeEffect via
356
- :func:`apply_variants_to_transcript`.
357
-
358
- Edit conflicts (overlapping cDNA ranges) cause the joint build
359
- to return ``None`` — the group is skipped silently (the
360
- per-variant effects still describe each variant individually).
349
+ Return additive joint effects; individual effects stay in the collection.
350
+ The optional ``annotate_haplotype`` hook accepts the group's variants,
351
+ transcript, germline context and phase resolver. A missing hook or
352
+ ``NotImplemented`` produces an explicit :class:`Unresolved` group,
353
+ never a fallback prediction or a silently omitted group.
361
354
  """
362
355
  if phase_resolver is None or not hasattr(phase_resolver, "in_cis"):
363
356
  return []
364
- from .effects.effect_classes import HaplotypeEffect
365
- from .mutant_transcript import apply_variants_to_transcript
357
+ from .annotators.registry import resolve_annotator
358
+ from .effects.effect_classes import Failure, MutationEffect, Unresolved
359
+
360
+ annotator = resolve_annotator(annotator)
361
+ annotate = getattr(annotator, "annotate_haplotype", None)
366
362
 
367
363
  # Group variants by transcript via existing per-variant effects —
368
364
  # each effect already knows its transcript, which avoids
@@ -418,25 +414,31 @@ def build_haplotype_effects(variant_collection, effects, phase_resolver):
418
414
  for members in groups.values():
419
415
  if len(members) < 2:
420
416
  continue
421
- # Prefer a resolver-provided MutantTranscript (RNA assembly,
422
- # long-read, etc.) when available — it's the actual
423
- # observed molecule, not inferred from reference + edits.
424
- # Members of a cis group share a contig by definition, so
425
- # any member's contig covers the whole group.
426
- mt = None
427
- if hasattr(phase_resolver, "mutant_transcript"):
428
- for v in members:
429
- mt = phase_resolver.mutant_transcript(v, transcript)
430
- if mt is not None:
431
- break
432
- if mt is None:
433
- mt = apply_variants_to_transcript(members, transcript)
434
- if mt is None:
435
- continue
436
- haplotype_effects.append(HaplotypeEffect(
437
- variants=members,
438
- transcript=transcript,
439
- mutant_transcript=mt,
440
- phase_source=getattr(phase_resolver, "phase_source", None),
441
- ))
417
+ members = tuple(members)
418
+ try:
419
+ result = NotImplemented if annotate is None else annotate(
420
+ members, transcript, germline_ctx=germline,
421
+ phase_resolver=phase_resolver)
422
+ except (AssertionError, ValueError) as error:
423
+ if raise_on_error:
424
+ raise
425
+ logging.getLogger(__name__).warning(
426
+ "Encountered error annotating cis group %s for %s: %s",
427
+ members, transcript, error)
428
+ result = Failure(members[0], transcript)
429
+ if result is NotImplemented:
430
+ result = Unresolved(
431
+ members[0], transcript, mechanism="unsupported_haplotype",
432
+ reason="Annotator %r does not implement this cis group%s" % (
433
+ getattr(annotator, "name", type(annotator).__name__),
434
+ " with germline context" if germline else ""))
435
+ if not isinstance(result, MutationEffect):
436
+ raise TypeError(
437
+ "Annotators must return a MutationEffect or NotImplemented, got %r"
438
+ % (result,))
439
+ result.variants = members
440
+ result.phase_source = getattr(phase_resolver, "phase_source", None)
441
+ result.annotator = getattr(annotator, "name", None)
442
+ result.annotator_version = getattr(annotator, "version", None)
443
+ haplotype_effects.append(result)
442
444
  return haplotype_effects