varcode 10.0.2__tar.gz → 10.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. {varcode-10.0.2/varcode.egg-info → varcode-10.0.3}/PKG-INFO +1 -1
  2. varcode-10.0.3/tests/test_structural_serialization.py +116 -0
  3. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_classes.py +20 -0
  4. varcode-10.0.3/varcode/effects/structural_serialization.py +110 -0
  5. varcode-10.0.3/varcode/version.py +1 -0
  6. {varcode-10.0.2 → varcode-10.0.3/varcode.egg-info}/PKG-INFO +1 -1
  7. {varcode-10.0.2 → varcode-10.0.3}/varcode.egg-info/SOURCES.txt +2 -0
  8. varcode-10.0.2/varcode/version.py +0 -1
  9. {varcode-10.0.2 → varcode-10.0.3}/LICENSE +0 -0
  10. {varcode-10.0.2 → varcode-10.0.3}/MANIFEST.in +0 -0
  11. {varcode-10.0.2 → varcode-10.0.3}/README.md +0 -0
  12. {varcode-10.0.2 → varcode-10.0.3}/pyproject.toml +0 -0
  13. {varcode-10.0.2 → varcode-10.0.3}/requirements.txt +0 -0
  14. {varcode-10.0.2 → varcode-10.0.3}/setup.cfg +0 -0
  15. {varcode-10.0.2 → varcode-10.0.3}/tests/test_annotator_divergence_scenarios.py +0 -0
  16. {varcode-10.0.2 → varcode-10.0.3}/tests/test_annotator_haplotypes.py +0 -0
  17. {varcode-10.0.2 → varcode-10.0.3}/tests/test_annotator_parity_adversarial.py +0 -0
  18. {varcode-10.0.2 → varcode-10.0.3}/tests/test_annotators.py +0 -0
  19. {varcode-10.0.2 → varcode-10.0.3}/tests/test_bnd_retained_segments.py +0 -0
  20. {varcode-10.0.2 → varcode-10.0.3}/tests/test_cli_effects.py +0 -0
  21. {varcode-10.0.2 → varcode-10.0.3}/tests/test_cli_genes.py +0 -0
  22. {varcode-10.0.2 → varcode-10.0.3}/tests/test_cli_records.py +0 -0
  23. {varcode-10.0.2 → varcode-10.0.3}/tests/test_cli_without_pkg_resources.py +0 -0
  24. {varcode-10.0.2 → varcode-10.0.3}/tests/test_collection_filtering.py +0 -0
  25. {varcode-10.0.2 → varcode-10.0.3}/tests/test_collection_variants_attr_consistency.py +0 -0
  26. {varcode-10.0.2 → varcode-10.0.3}/tests/test_common.py +0 -0
  27. {varcode-10.0.2 → varcode-10.0.3}/tests/test_cosmic_mutations.py +0 -0
  28. {varcode-10.0.2 → varcode-10.0.3}/tests/test_cryptic_exons.py +0 -0
  29. {varcode-10.0.2 → varcode-10.0.3}/tests/test_csv_roundtrip.py +0 -0
  30. {varcode-10.0.2 → varcode-10.0.3}/tests/test_dbnsfp_validation.py +0 -0
  31. {varcode-10.0.2 → varcode-10.0.3}/tests/test_default_structural_helpers.py +0 -0
  32. {varcode-10.0.2 → varcode-10.0.3}/tests/test_documentation_examples.py +0 -0
  33. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effect_annotation_errors.py +0 -0
  34. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effect_candidates.py +0 -0
  35. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effect_classes.py +0 -0
  36. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effect_collection.py +0 -0
  37. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effect_collection_serialization.py +0 -0
  38. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effect_collection_sort_order.py +0 -0
  39. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effect_hypotheses.py +0 -0
  40. {varcode-10.0.2 → varcode-10.0.3}/tests/test_effects_from_mutagenix_variants.py +0 -0
  41. {varcode-10.0.2 → varcode-10.0.3}/tests/test_exacto_fusions.py +0 -0
  42. {varcode-10.0.2 → varcode-10.0.3}/tests/test_exonic_splice_site.py +0 -0
  43. {varcode-10.0.2 → varcode-10.0.3}/tests/test_fast_path.py +0 -0
  44. {varcode-10.0.2 → varcode-10.0.3}/tests/test_frameshift_cterminus_regression.py +0 -0
  45. {varcode-10.0.2 → varcode-10.0.3}/tests/test_frameshift_helpers.py +0 -0
  46. {varcode-10.0.2 → varcode-10.0.3}/tests/test_fusion_insertions.py +0 -0
  47. {varcode-10.0.2 → varcode-10.0.3}/tests/test_fusion_partner_candidates.py +0 -0
  48. {varcode-10.0.2 → varcode-10.0.3}/tests/test_genome_contig_validation.py +0 -0
  49. {varcode-10.0.2 → varcode-10.0.3}/tests/test_genome_sequence.py +0 -0
  50. {varcode-10.0.2 → varcode-10.0.3}/tests/test_genomic_layout.py +0 -0
  51. {varcode-10.0.2 → varcode-10.0.3}/tests/test_genotype.py +0 -0
  52. {varcode-10.0.2 → varcode-10.0.3}/tests/test_genotype_from_vcf.py +0 -0
  53. {varcode-10.0.2 → varcode-10.0.3}/tests/test_germline_context.py +0 -0
  54. {varcode-10.0.2 → varcode-10.0.3}/tests/test_germline_effects.py +0 -0
  55. {varcode-10.0.2 → varcode-10.0.3}/tests/test_haplotype_effect.py +0 -0
  56. {varcode-10.0.2 → varcode-10.0.3}/tests/test_local_sv_insertions.py +0 -0
  57. {varcode-10.0.2 → varcode-10.0.3}/tests/test_maf.py +0 -0
  58. {varcode-10.0.2 → varcode-10.0.3}/tests/test_mitochondrial.py +0 -0
  59. {varcode-10.0.2 → varcode-10.0.3}/tests/test_mm10_klf6_frameshift.py +0 -0
  60. {varcode-10.0.2 → varcode-10.0.3}/tests/test_mouse.py +0 -0
  61. {varcode-10.0.2 → varcode-10.0.3}/tests/test_mutant_transcript.py +0 -0
  62. {varcode-10.0.2 → varcode-10.0.3}/tests/test_mutate.py +0 -0
  63. {varcode-10.0.2 → varcode-10.0.3}/tests/test_no_duplicate_variants.py +0 -0
  64. {varcode-10.0.2 → varcode-10.0.3}/tests/test_nonlocal_sv_transcripts.py +0 -0
  65. {varcode-10.0.2 → varcode-10.0.3}/tests/test_osteosarc_dataset.py +0 -0
  66. {varcode-10.0.2 → varcode-10.0.3}/tests/test_osteosarc_fusions.py +0 -0
  67. {varcode-10.0.2 → varcode-10.0.3}/tests/test_osteosarc_variants.py +0 -0
  68. {varcode-10.0.2 → varcode-10.0.3}/tests/test_partial_annotators.py +0 -0
  69. {varcode-10.0.2 → varcode-10.0.3}/tests/test_premature_stop_short_description.py +0 -0
  70. {varcode-10.0.2 → varcode-10.0.3}/tests/test_problematic_variants.py +0 -0
  71. {varcode-10.0.2 → varcode-10.0.3}/tests/test_protein_diff_parity.py +0 -0
  72. {varcode-10.0.2 → varcode-10.0.3}/tests/test_read_phase_resolver.py +0 -0
  73. {varcode-10.0.2 → varcode-10.0.3}/tests/test_real_world_callers.py +0 -0
  74. {varcode-10.0.2 → varcode-10.0.3}/tests/test_reference.py +0 -0
  75. {varcode-10.0.2 → varcode-10.0.3}/tests/test_reference_mismatch_error.py +0 -0
  76. {varcode-10.0.2 → varcode-10.0.3}/tests/test_reference_segments.py +0 -0
  77. {varcode-10.0.2 → varcode-10.0.3}/tests/test_rna_evidence.py +0 -0
  78. {varcode-10.0.2 → varcode-10.0.3}/tests/test_rna_haplotype_sequences.py +0 -0
  79. {varcode-10.0.2 → varcode-10.0.3}/tests/test_rna_read_phasing_source.py +0 -0
  80. {varcode-10.0.2 → varcode-10.0.3}/tests/test_selenocysteine.py +0 -0
  81. {varcode-10.0.2 → varcode-10.0.3}/tests/test_selenocysteine_proteins.py +0 -0
  82. {varcode-10.0.2 → varcode-10.0.3}/tests/test_silent_aa_pos.py +0 -0
  83. {varcode-10.0.2 → varcode-10.0.3}/tests/test_silent_hgvs_description.py +0 -0
  84. {varcode-10.0.2 → varcode-10.0.3}/tests/test_splice_graph.py +0 -0
  85. {varcode-10.0.2 → varcode-10.0.3}/tests/test_splice_outcomes.py +0 -0
  86. {varcode-10.0.2 → varcode-10.0.3}/tests/test_splice_site_effects.py +0 -0
  87. {varcode-10.0.2 → varcode-10.0.3}/tests/test_stop_codon_classification_bugs.py +0 -0
  88. {varcode-10.0.2 → varcode-10.0.3}/tests/test_string_helpers.py +0 -0
  89. {varcode-10.0.2 → varcode-10.0.3}/tests/test_structural_variant_annotator.py +0 -0
  90. {varcode-10.0.2 → varcode-10.0.3}/tests/test_structural_variants.py +0 -0
  91. {varcode-10.0.2 → varcode-10.0.3}/tests/test_sv_comparison.py +0 -0
  92. {varcode-10.0.2 → varcode-10.0.3}/tests/test_sv_consequences.py +0 -0
  93. {varcode-10.0.2 → varcode-10.0.3}/tests/test_sv_selenocysteine.py +0 -0
  94. {varcode-10.0.2 → varcode-10.0.3}/tests/test_sv_sequence_changes.py +0 -0
  95. {varcode-10.0.2 → varcode-10.0.3}/tests/test_sv_tabular_metadata.py +0 -0
  96. {varcode-10.0.2 → varcode-10.0.3}/tests/test_symbolic_alleles.py +0 -0
  97. {varcode-10.0.2 → varcode-10.0.3}/tests/test_symbolic_sv_padding.py +0 -0
  98. {varcode-10.0.2 → varcode-10.0.3}/tests/test_timings.py +0 -0
  99. {varcode-10.0.2 → varcode-10.0.3}/tests/test_transcript_layout.py +0 -0
  100. {varcode-10.0.2 → varcode-10.0.3}/tests/test_transcript_model.py +0 -0
  101. {varcode-10.0.2 → varcode-10.0.3}/tests/test_transcript_model_start_codons.py +0 -0
  102. {varcode-10.0.2 → varcode-10.0.3}/tests/test_transforms_left_align.py +0 -0
  103. {varcode-10.0.2 → varcode-10.0.3}/tests/test_transforms_pair_breakends.py +0 -0
  104. {varcode-10.0.2 → varcode-10.0.3}/tests/test_variant.py +0 -0
  105. {varcode-10.0.2 → varcode-10.0.3}/tests/test_variant_collection.py +0 -0
  106. {varcode-10.0.2 → varcode-10.0.3}/tests/test_vcf.py +0 -0
  107. {varcode-10.0.2 → varcode-10.0.3}/tests/test_vcf_output.py +0 -0
  108. {varcode-10.0.2 → varcode-10.0.3}/tests/test_vcf_parsing.py +0 -0
  109. {varcode-10.0.2 → varcode-10.0.3}/tests/test_vcf_phase_resolver.py +0 -0
  110. {varcode-10.0.2 → varcode-10.0.3}/tests/test_vcf_spec_examples.py +0 -0
  111. {varcode-10.0.2 → varcode-10.0.3}/varcode/__init__.py +0 -0
  112. {varcode-10.0.2 → varcode-10.0.3}/varcode/annotators/__init__.py +0 -0
  113. {varcode-10.0.2 → varcode-10.0.3}/varcode/annotators/fast.py +0 -0
  114. {varcode-10.0.2 → varcode-10.0.3}/varcode/annotators/protein_diff.py +0 -0
  115. {varcode-10.0.2 → varcode-10.0.3}/varcode/annotators/registry.py +0 -0
  116. {varcode-10.0.2 → varcode-10.0.3}/varcode/cli/__init__.py +0 -0
  117. {varcode-10.0.2 → varcode-10.0.3}/varcode/cli/effects_script.py +0 -0
  118. {varcode-10.0.2 → varcode-10.0.3}/varcode/cli/genes_script.py +0 -0
  119. {varcode-10.0.2 → varcode-10.0.3}/varcode/cli/logging.conf +0 -0
  120. {varcode-10.0.2 → varcode-10.0.3}/varcode/cli/variant_args.py +0 -0
  121. {varcode-10.0.2 → varcode-10.0.3}/varcode/cli/version_info.py +0 -0
  122. {varcode-10.0.2 → varcode-10.0.3}/varcode/common.py +0 -0
  123. {varcode-10.0.2 → varcode-10.0.3}/varcode/cryptic_exons.py +0 -0
  124. {varcode-10.0.2 → varcode-10.0.3}/varcode/csv_helpers.py +0 -0
  125. {varcode-10.0.2 → varcode-10.0.3}/varcode/effect_candidates.py +0 -0
  126. {varcode-10.0.2 → varcode-10.0.3}/varcode/effect_hypotheses.py +0 -0
  127. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/__init__.py +0 -0
  128. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/classify.py +0 -0
  129. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/codon_tables.py +0 -0
  130. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/common.py +0 -0
  131. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_collection.py +0 -0
  132. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_helpers.py +0 -0
  133. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_ordering.py +0 -0
  134. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_prediction.py +0 -0
  135. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_prediction_coding.py +0 -0
  136. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
  137. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
  138. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/fast_path.py +0 -0
  139. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/mutate.py +0 -0
  140. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/selenocysteine.py +0 -0
  141. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/sequence_change.py +0 -0
  142. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/structural.py +0 -0
  143. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/transcript_helpers.py +0 -0
  144. {varcode-10.0.2 → varcode-10.0.3}/varcode/effects/translate.py +0 -0
  145. {varcode-10.0.2 → varcode-10.0.3}/varcode/errors.py +0 -0
  146. {varcode-10.0.2 → varcode-10.0.3}/varcode/exacto.py +0 -0
  147. {varcode-10.0.2 → varcode-10.0.3}/varcode/genome.py +0 -0
  148. {varcode-10.0.2 → varcode-10.0.3}/varcode/genome_sequence.py +0 -0
  149. {varcode-10.0.2 → varcode-10.0.3}/varcode/genomic_layout.py +0 -0
  150. {varcode-10.0.2 → varcode-10.0.3}/varcode/genotype.py +0 -0
  151. {varcode-10.0.2 → varcode-10.0.3}/varcode/germline.py +0 -0
  152. {varcode-10.0.2 → varcode-10.0.3}/varcode/maf.py +0 -0
  153. {varcode-10.0.2 → varcode-10.0.3}/varcode/mutant_transcript.py +0 -0
  154. {varcode-10.0.2 → varcode-10.0.3}/varcode/nucleotides.py +0 -0
  155. {varcode-10.0.2 → varcode-10.0.3}/varcode/phasing.py +0 -0
  156. {varcode-10.0.2 → varcode-10.0.3}/varcode/realized_effects.py +0 -0
  157. {varcode-10.0.2 → varcode-10.0.3}/varcode/reference.py +0 -0
  158. {varcode-10.0.2 → varcode-10.0.3}/varcode/rna_evidence.py +0 -0
  159. {varcode-10.0.2 → varcode-10.0.3}/varcode/rna_read_phasing.py +0 -0
  160. {varcode-10.0.2 → varcode-10.0.3}/varcode/splice_graph.py +0 -0
  161. {varcode-10.0.2 → varcode-10.0.3}/varcode/splice_outcomes.py +0 -0
  162. {varcode-10.0.2 → varcode-10.0.3}/varcode/string_helpers.py +0 -0
  163. {varcode-10.0.2 → varcode-10.0.3}/varcode/structural_variant.py +0 -0
  164. {varcode-10.0.2 → varcode-10.0.3}/varcode/sv_allele_parser.py +0 -0
  165. {varcode-10.0.2 → varcode-10.0.3}/varcode/sv_comparison.py +0 -0
  166. {varcode-10.0.2 → varcode-10.0.3}/varcode/transcript_layout.py +0 -0
  167. {varcode-10.0.2 → varcode-10.0.3}/varcode/transcript_model.py +0 -0
  168. {varcode-10.0.2 → varcode-10.0.3}/varcode/transforms/__init__.py +0 -0
  169. {varcode-10.0.2 → varcode-10.0.3}/varcode/ucsc_reference_names.py +0 -0
  170. {varcode-10.0.2 → varcode-10.0.3}/varcode/util.py +0 -0
  171. {varcode-10.0.2 → varcode-10.0.3}/varcode/variant.py +0 -0
  172. {varcode-10.0.2 → varcode-10.0.3}/varcode/variant_collection.py +0 -0
  173. {varcode-10.0.2 → varcode-10.0.3}/varcode/vcf.py +0 -0
  174. {varcode-10.0.2 → varcode-10.0.3}/varcode/vcf_output.py +0 -0
  175. {varcode-10.0.2 → varcode-10.0.3}/varcode/vcf_parsing.py +0 -0
  176. {varcode-10.0.2 → varcode-10.0.3}/varcode.egg-info/dependency_links.txt +0 -0
  177. {varcode-10.0.2 → varcode-10.0.3}/varcode.egg-info/entry_points.txt +0 -0
  178. {varcode-10.0.2 → varcode-10.0.3}/varcode.egg-info/requires.txt +0 -0
  179. {varcode-10.0.2 → varcode-10.0.3}/varcode.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: varcode
3
- Version: 10.0.2
3
+ Version: 10.0.3
4
4
  Summary: Variant annotation in Python
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  Project-URL: Homepage, https://github.com/openvax/varcode
@@ -0,0 +1,116 @@
1
+ """Reproducible SV object archives with self links and attached evidence."""
2
+
3
+ import pytest
4
+ from pathlib import Path
5
+ from pyensembl import cached_release
6
+
7
+ from varcode import EffectCandidate, EffectCollection, StructuralVariant, load_vcf
8
+ from varcode.effects import (
9
+ CrypticExonCandidate, GeneFusion, Inversion, LargeDeletion,
10
+ LargeDuplication, StructuralVariantEffect, TranslocationToIntergenic,
11
+ )
12
+ from .test_sv_consequences import local_model # isolate individual transcript models
13
+
14
+
15
+ @pytest.fixture
16
+ def transcript():
17
+ return cached_release(81).transcript_by_id("ENST00000003084")
18
+
19
+
20
+ def assert_round_trip(effect):
21
+ clone = type(effect).from_json(effect.to_json())
22
+ assert clone.to_dict() == effect.to_dict()
23
+ assert clone.variant == effect.variant
24
+ assert clone.transcript == effect.transcript
25
+ assert clone.mutant_protein_sequence == effect.mutant_protein_sequence
26
+ assert clone.modifies_coding_sequence == effect.modifies_coding_sequence
27
+ assert clone.modifies_protein_sequence == effect.modifies_protein_sequence
28
+ collection = EffectCollection(
29
+ [effect], distinct=True, annotator="fast", annotator_version="test",
30
+ annotated_at="2026-09-23T00:00:00Z")
31
+ restored = EffectCollection.from_json(collection.to_json())
32
+ assert restored[0].to_dict() == effect.to_dict()
33
+ assert restored.annotator == "fast"
34
+ assert restored.annotator_version == "test"
35
+ assert restored.annotated_at == collection.annotated_at
36
+ return clone
37
+
38
+
39
+ @pytest.mark.parametrize("kind", ["DEL", "DUP", "INV", "CNV", "INS"])
40
+ @pytest.mark.parametrize("assembly", [None, "ATGAAATAG"])
41
+ @pytest.mark.usefixtures("local_model")
42
+ def test_predicted_sv_round_trip(transcript, kind, assembly):
43
+ exon = transcript.exons[4]
44
+ variant = StructuralVariant(
45
+ "7", exon.start + 10, kind, end=exon.end - 10,
46
+ genome=transcript.genome, alt_assembly=assembly)
47
+ effect = variant.effect_on_transcript(transcript)
48
+ restored = assert_round_trip(effect)
49
+ assert restored.affected_exons == effect.affected_exons
50
+ assert restored.mutant_transcript == effect.mutant_transcript
51
+ assert [(c.source, c.evidence) for c in restored.candidates] == [
52
+ (c.source, c.evidence) for c in effect.candidates]
53
+
54
+
55
+ @pytest.mark.usefixtures("local_model")
56
+ def test_direct_consequence_preserves_attached_model(transcript):
57
+ exon = transcript.exons[4]
58
+ variant = StructuralVariant("7", exon.start - 20, "DEL", end=exon.end + 20,
59
+ genome=transcript.genome)
60
+ effect = variant.effect_on_transcript(transcript)
61
+ assert not isinstance(effect, StructuralVariantEffect)
62
+ restored = assert_round_trip(effect)
63
+ assert restored.mutant_transcript == effect.mutant_transcript
64
+ assert restored.affected_exons == effect.affected_exons
65
+
66
+
67
+ @pytest.mark.parametrize("cls", [StructuralVariantEffect, LargeDeletion,
68
+ LargeDuplication, Inversion, TranslocationToIntergenic])
69
+ def test_legacy_self_candidate_round_trip(transcript, cls):
70
+ variant = StructuralVariant("7", 117531100, "DEL", end=117531200, genome=transcript.genome)
71
+ kwargs = {"affected_exons": transcript.exons[:1]} if cls in (LargeDeletion, LargeDuplication) else {}
72
+ effect = cls(variant, transcript, **kwargs)
73
+ restored = assert_round_trip(effect)
74
+ assert restored.candidates[0].effect is restored
75
+
76
+
77
+ def test_fusion_all_candidate_sources_and_shared_self_links(transcript):
78
+ partner = transcript.genome.transcript_by_id("ENST00000357654")
79
+ variant = StructuralVariant("7", transcript.exons[4].end, "BND", genome=transcript.genome,
80
+ mate_contig="17", mate_start=partner.exons[4].start)
81
+ effect = GeneFusion(variant, transcript, partner)
82
+ other = TranslocationToIntergenic(variant, transcript)
83
+ effect._attach_primary_effects((other,))
84
+ effect._attach_cryptic_candidates((
85
+ CrypticExonCandidate(variant, "7", 123, 145, donor_score=0.8, acceptor_score=0.9),))
86
+ effect._attach_splice_outcomes((EffectCandidate(other, "varcode_splice", {"reads": 2}),))
87
+ effect._extra_candidates = (EffectCandidate(effect, "RNA", {"witnesses": ["read1"]}),)
88
+ effect.candidate_evidence = {"assumption": "reference_splicing"}
89
+ restored = assert_round_trip(effect)
90
+ assert restored.partner_transcript == partner
91
+ assert restored.five_prime_transcript == transcript
92
+ assert restored.three_prime_transcript == partner
93
+ assert restored.candidates[0].effect is restored
94
+ assert restored.candidates[-1].effect is restored
95
+ assert restored.candidates[1].effect is restored.candidates[-2].effect
96
+ assert [c.source for c in restored.candidates] == [
97
+ "varcode", "varcode", "varcode_motif", "varcode_splice", "RNA"]
98
+
99
+
100
+ def test_unknown_schema_rejected(transcript):
101
+ with pytest.raises(ValueError, match="Unsupported.*schema"):
102
+ StructuralVariantEffect.from_dict({"structural_effect_schema": 999})
103
+
104
+
105
+ def test_esvee_predicted_fusions_and_collection_round_trip():
106
+ variants = load_vcf(
107
+ str(Path(__file__).parent / "data/osteosarc_esvee_somatic.vcf"),
108
+ genome=81, parse_structural_variants=True)
109
+ effects = variants.effects()
110
+ assert any(isinstance(effect, GeneFusion) for effect in effects)
111
+ restored = EffectCollection.from_json(effects.to_json())
112
+ assert len(restored) == len(effects)
113
+ for before, after in zip(effects, restored):
114
+ assert type(before) is type(after)
115
+ assert before.to_dict() == after.to_dict()
116
+ assert before.mutant_protein_sequence == after.mutant_protein_sequence
@@ -34,6 +34,26 @@ class MutationEffect(Serializable):
34
34
  def __init__(self, variant):
35
35
  self.variant = variant
36
36
 
37
+ def to_dict(self):
38
+ if getattr(self.variant, "is_structural", False):
39
+ from .structural_serialization import structural_effect_to_dict
40
+ return structural_effect_to_dict(self)
41
+ return super().to_dict()
42
+
43
+ @classmethod
44
+ def from_dict(cls, state_dict):
45
+ if "structural_effect_schema" in state_dict:
46
+ from .structural_serialization import structural_effect_from_dict
47
+ return structural_effect_from_dict(cls, state_dict)
48
+ return super().from_dict(state_dict)
49
+
50
+ def __hash__(self):
51
+ if getattr(self.variant, "is_structural", False):
52
+ # Evidence contains dictionaries and candidates can point back
53
+ # to this effect. Equal effects have equal identity fields.
54
+ return hash((type(self), self.variant, self.transcript))
55
+ return super().__hash__()
56
+
37
57
  def __str__(self):
38
58
  return "%s(variant=%s)" % (self.__class__.__name__, self.variant)
39
59
 
@@ -0,0 +1,110 @@
1
+ """Versioned structural-effect graphs, including self-referential candidates.
2
+
3
+ Only effect/candidate links use graph references. Variants, transcripts, and
4
+ MutantTranscript models retain their existing Serializable representations.
5
+ This is an object archive, not a portable annotation database.
6
+ """
7
+
8
+ from dataclasses import dataclass, replace
9
+ from inspect import Parameter, signature
10
+
11
+ from serializable import DataclassSerializable
12
+
13
+ from ..effect_candidates import EffectCandidate
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class _EffectReference(DataclassSerializable):
18
+ index: int
19
+
20
+
21
+ # Explicit post-construction annotation state. Do not archive caches, logger
22
+ # handles, or arbitrary implementation attributes from __dict__.
23
+ _ATTACHED_FIELDS = (
24
+ "mutant_transcript", "affected_exons", "candidate_evidence", "_cryptic_candidates",
25
+ "_splice_candidates", "_extra_candidates", "_original_protein_sequence",
26
+ "_mutant_protein_sequence", "_modifies_coding_sequence",
27
+ "_modifies_protein_sequence", "modifies_coding_sequence",
28
+ "modifies_protein_sequence", "variants", "phase_source", "annotator",
29
+ "annotator_version", "observed_mutant_transcripts",
30
+ )
31
+
32
+
33
+ def structural_effect_to_dict(root):
34
+ from .effect_classes import MutationEffect, StructuralVariantEffect
35
+
36
+ indices = {}
37
+ nodes = []
38
+
39
+ def encode(value):
40
+ if isinstance(value, MutationEffect):
41
+ key = id(value)
42
+ if key not in indices:
43
+ indices[key] = len(nodes)
44
+ nodes.append(None) # reserve before following self links
45
+ fields = {}
46
+ for name, parameter in signature(type(value).__init__).parameters.items():
47
+ if name == "self" or parameter.kind in (
48
+ Parameter.VAR_POSITIONAL, Parameter.VAR_KEYWORD):
49
+ continue
50
+ if name == "primary_effects" and isinstance(value, StructuralVariantEffect):
51
+ fields[name] = value._primary_effects
52
+ elif name == "candidates" and hasattr(value, "_candidates"):
53
+ fields[name] = value._candidates
54
+ elif hasattr(value, name):
55
+ fields[name] = getattr(value, name)
56
+ elif parameter.default is Parameter.empty:
57
+ raise ValueError("Missing effect constructor field: %s" % name)
58
+ attached = {name: value.__dict__[name] for name in _ATTACHED_FIELDS
59
+ if name in value.__dict__ and name not in fields}
60
+ nodes[indices[key]] = (type(value), encode(fields), encode(attached))
61
+ return _EffectReference(indices[key])
62
+ if isinstance(value, EffectCandidate):
63
+ return replace(value, effect=encode(value.effect), evidence=encode(value.evidence))
64
+ if isinstance(value, dict):
65
+ return {key: encode(item) for key, item in value.items()}
66
+ if isinstance(value, (tuple, list)):
67
+ return type(value)(encode(item) for item in value)
68
+ return value
69
+
70
+ encode(root)
71
+ return {"structural_effect_schema": 1, "nodes": tuple(nodes)}
72
+
73
+
74
+ def structural_effect_from_dict(root_class, state):
75
+ from .effect_classes import MutationEffect
76
+
77
+ if state.get("structural_effect_schema") != 1:
78
+ raise ValueError("Unsupported structural effect serialization schema")
79
+ nodes = state["nodes"]
80
+ if not nodes or nodes[0][0] is not root_class:
81
+ raise ValueError("Structural effect root class does not match archive")
82
+ for cls, _, _ in nodes:
83
+ if not isinstance(cls, type) or not issubclass(cls, MutationEffect):
84
+ raise ValueError("Structural effect graph contains a non-effect class")
85
+ objects = [object.__new__(cls) for cls, _, _ in nodes]
86
+ started = set()
87
+
88
+ def decode(value):
89
+ if isinstance(value, _EffectReference):
90
+ index = value.index
91
+ if not isinstance(index, int) or not 0 <= index < len(nodes):
92
+ raise ValueError("Invalid structural effect graph reference")
93
+ if index not in started:
94
+ started.add(index)
95
+ cls, fields, attached = nodes[index]
96
+ cls.__init__(objects[index], **decode(fields))
97
+ for name, item in decode(attached).items():
98
+ if name not in _ATTACHED_FIELDS:
99
+ raise ValueError("Unknown structural effect attachment: %s" % name)
100
+ setattr(objects[index], name, item)
101
+ return objects[index]
102
+ if isinstance(value, EffectCandidate):
103
+ return replace(value, effect=decode(value.effect), evidence=decode(value.evidence))
104
+ if isinstance(value, dict):
105
+ return {key: decode(item) for key, item in value.items()}
106
+ if isinstance(value, (tuple, list)):
107
+ return type(value)(decode(item) for item in value)
108
+ return value
109
+
110
+ return decode(_EffectReference(0))
@@ -0,0 +1 @@
1
+ __version__ = "10.0.3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: varcode
3
- Version: 10.0.2
3
+ Version: 10.0.3
4
4
  Summary: Variant annotation in Python
5
5
  Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
6
6
  Project-URL: Homepage, https://github.com/openvax/varcode
@@ -77,6 +77,7 @@ tests/test_splice_outcomes.py
77
77
  tests/test_splice_site_effects.py
78
78
  tests/test_stop_codon_classification_bugs.py
79
79
  tests/test_string_helpers.py
80
+ tests/test_structural_serialization.py
80
81
  tests/test_structural_variant_annotator.py
81
82
  tests/test_structural_variants.py
82
83
  tests/test_sv_comparison.py
@@ -169,6 +170,7 @@ varcode/effects/mutate.py
169
170
  varcode/effects/selenocysteine.py
170
171
  varcode/effects/sequence_change.py
171
172
  varcode/effects/structural.py
173
+ varcode/effects/structural_serialization.py
172
174
  varcode/effects/transcript_helpers.py
173
175
  varcode/effects/translate.py
174
176
  varcode/transforms/__init__.py
@@ -1 +0,0 @@
1
- __version__ = "10.0.2"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes