varcode 10.0.2__tar.gz → 10.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. {varcode-10.0.2/varcode.egg-info → varcode-10.0.4}/PKG-INFO +1 -1
  2. varcode-10.0.4/tests/test_nonlocal_layout.py +70 -0
  3. varcode-10.0.4/tests/test_structural_serialization.py +116 -0
  4. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_classes.py +20 -0
  5. varcode-10.0.4/varcode/effects/structural_serialization.py +110 -0
  6. {varcode-10.0.2 → varcode-10.0.4}/varcode/genomic_layout.py +17 -0
  7. {varcode-10.0.2 → varcode-10.0.4}/varcode/transcript_model.py +18 -2
  8. varcode-10.0.4/varcode/version.py +1 -0
  9. {varcode-10.0.2 → varcode-10.0.4/varcode.egg-info}/PKG-INFO +1 -1
  10. {varcode-10.0.2 → varcode-10.0.4}/varcode.egg-info/SOURCES.txt +3 -0
  11. varcode-10.0.2/varcode/version.py +0 -1
  12. {varcode-10.0.2 → varcode-10.0.4}/LICENSE +0 -0
  13. {varcode-10.0.2 → varcode-10.0.4}/MANIFEST.in +0 -0
  14. {varcode-10.0.2 → varcode-10.0.4}/README.md +0 -0
  15. {varcode-10.0.2 → varcode-10.0.4}/pyproject.toml +0 -0
  16. {varcode-10.0.2 → varcode-10.0.4}/requirements.txt +0 -0
  17. {varcode-10.0.2 → varcode-10.0.4}/setup.cfg +0 -0
  18. {varcode-10.0.2 → varcode-10.0.4}/tests/test_annotator_divergence_scenarios.py +0 -0
  19. {varcode-10.0.2 → varcode-10.0.4}/tests/test_annotator_haplotypes.py +0 -0
  20. {varcode-10.0.2 → varcode-10.0.4}/tests/test_annotator_parity_adversarial.py +0 -0
  21. {varcode-10.0.2 → varcode-10.0.4}/tests/test_annotators.py +0 -0
  22. {varcode-10.0.2 → varcode-10.0.4}/tests/test_bnd_retained_segments.py +0 -0
  23. {varcode-10.0.2 → varcode-10.0.4}/tests/test_cli_effects.py +0 -0
  24. {varcode-10.0.2 → varcode-10.0.4}/tests/test_cli_genes.py +0 -0
  25. {varcode-10.0.2 → varcode-10.0.4}/tests/test_cli_records.py +0 -0
  26. {varcode-10.0.2 → varcode-10.0.4}/tests/test_cli_without_pkg_resources.py +0 -0
  27. {varcode-10.0.2 → varcode-10.0.4}/tests/test_collection_filtering.py +0 -0
  28. {varcode-10.0.2 → varcode-10.0.4}/tests/test_collection_variants_attr_consistency.py +0 -0
  29. {varcode-10.0.2 → varcode-10.0.4}/tests/test_common.py +0 -0
  30. {varcode-10.0.2 → varcode-10.0.4}/tests/test_cosmic_mutations.py +0 -0
  31. {varcode-10.0.2 → varcode-10.0.4}/tests/test_cryptic_exons.py +0 -0
  32. {varcode-10.0.2 → varcode-10.0.4}/tests/test_csv_roundtrip.py +0 -0
  33. {varcode-10.0.2 → varcode-10.0.4}/tests/test_dbnsfp_validation.py +0 -0
  34. {varcode-10.0.2 → varcode-10.0.4}/tests/test_default_structural_helpers.py +0 -0
  35. {varcode-10.0.2 → varcode-10.0.4}/tests/test_documentation_examples.py +0 -0
  36. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effect_annotation_errors.py +0 -0
  37. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effect_candidates.py +0 -0
  38. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effect_classes.py +0 -0
  39. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effect_collection.py +0 -0
  40. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effect_collection_serialization.py +0 -0
  41. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effect_collection_sort_order.py +0 -0
  42. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effect_hypotheses.py +0 -0
  43. {varcode-10.0.2 → varcode-10.0.4}/tests/test_effects_from_mutagenix_variants.py +0 -0
  44. {varcode-10.0.2 → varcode-10.0.4}/tests/test_exacto_fusions.py +0 -0
  45. {varcode-10.0.2 → varcode-10.0.4}/tests/test_exonic_splice_site.py +0 -0
  46. {varcode-10.0.2 → varcode-10.0.4}/tests/test_fast_path.py +0 -0
  47. {varcode-10.0.2 → varcode-10.0.4}/tests/test_frameshift_cterminus_regression.py +0 -0
  48. {varcode-10.0.2 → varcode-10.0.4}/tests/test_frameshift_helpers.py +0 -0
  49. {varcode-10.0.2 → varcode-10.0.4}/tests/test_fusion_insertions.py +0 -0
  50. {varcode-10.0.2 → varcode-10.0.4}/tests/test_fusion_partner_candidates.py +0 -0
  51. {varcode-10.0.2 → varcode-10.0.4}/tests/test_genome_contig_validation.py +0 -0
  52. {varcode-10.0.2 → varcode-10.0.4}/tests/test_genome_sequence.py +0 -0
  53. {varcode-10.0.2 → varcode-10.0.4}/tests/test_genomic_layout.py +0 -0
  54. {varcode-10.0.2 → varcode-10.0.4}/tests/test_genotype.py +0 -0
  55. {varcode-10.0.2 → varcode-10.0.4}/tests/test_genotype_from_vcf.py +0 -0
  56. {varcode-10.0.2 → varcode-10.0.4}/tests/test_germline_context.py +0 -0
  57. {varcode-10.0.2 → varcode-10.0.4}/tests/test_germline_effects.py +0 -0
  58. {varcode-10.0.2 → varcode-10.0.4}/tests/test_haplotype_effect.py +0 -0
  59. {varcode-10.0.2 → varcode-10.0.4}/tests/test_local_sv_insertions.py +0 -0
  60. {varcode-10.0.2 → varcode-10.0.4}/tests/test_maf.py +0 -0
  61. {varcode-10.0.2 → varcode-10.0.4}/tests/test_mitochondrial.py +0 -0
  62. {varcode-10.0.2 → varcode-10.0.4}/tests/test_mm10_klf6_frameshift.py +0 -0
  63. {varcode-10.0.2 → varcode-10.0.4}/tests/test_mouse.py +0 -0
  64. {varcode-10.0.2 → varcode-10.0.4}/tests/test_mutant_transcript.py +0 -0
  65. {varcode-10.0.2 → varcode-10.0.4}/tests/test_mutate.py +0 -0
  66. {varcode-10.0.2 → varcode-10.0.4}/tests/test_no_duplicate_variants.py +0 -0
  67. {varcode-10.0.2 → varcode-10.0.4}/tests/test_nonlocal_sv_transcripts.py +0 -0
  68. {varcode-10.0.2 → varcode-10.0.4}/tests/test_osteosarc_dataset.py +0 -0
  69. {varcode-10.0.2 → varcode-10.0.4}/tests/test_osteosarc_fusions.py +0 -0
  70. {varcode-10.0.2 → varcode-10.0.4}/tests/test_osteosarc_variants.py +0 -0
  71. {varcode-10.0.2 → varcode-10.0.4}/tests/test_partial_annotators.py +0 -0
  72. {varcode-10.0.2 → varcode-10.0.4}/tests/test_premature_stop_short_description.py +0 -0
  73. {varcode-10.0.2 → varcode-10.0.4}/tests/test_problematic_variants.py +0 -0
  74. {varcode-10.0.2 → varcode-10.0.4}/tests/test_protein_diff_parity.py +0 -0
  75. {varcode-10.0.2 → varcode-10.0.4}/tests/test_read_phase_resolver.py +0 -0
  76. {varcode-10.0.2 → varcode-10.0.4}/tests/test_real_world_callers.py +0 -0
  77. {varcode-10.0.2 → varcode-10.0.4}/tests/test_reference.py +0 -0
  78. {varcode-10.0.2 → varcode-10.0.4}/tests/test_reference_mismatch_error.py +0 -0
  79. {varcode-10.0.2 → varcode-10.0.4}/tests/test_reference_segments.py +0 -0
  80. {varcode-10.0.2 → varcode-10.0.4}/tests/test_rna_evidence.py +0 -0
  81. {varcode-10.0.2 → varcode-10.0.4}/tests/test_rna_haplotype_sequences.py +0 -0
  82. {varcode-10.0.2 → varcode-10.0.4}/tests/test_rna_read_phasing_source.py +0 -0
  83. {varcode-10.0.2 → varcode-10.0.4}/tests/test_selenocysteine.py +0 -0
  84. {varcode-10.0.2 → varcode-10.0.4}/tests/test_selenocysteine_proteins.py +0 -0
  85. {varcode-10.0.2 → varcode-10.0.4}/tests/test_silent_aa_pos.py +0 -0
  86. {varcode-10.0.2 → varcode-10.0.4}/tests/test_silent_hgvs_description.py +0 -0
  87. {varcode-10.0.2 → varcode-10.0.4}/tests/test_splice_graph.py +0 -0
  88. {varcode-10.0.2 → varcode-10.0.4}/tests/test_splice_outcomes.py +0 -0
  89. {varcode-10.0.2 → varcode-10.0.4}/tests/test_splice_site_effects.py +0 -0
  90. {varcode-10.0.2 → varcode-10.0.4}/tests/test_stop_codon_classification_bugs.py +0 -0
  91. {varcode-10.0.2 → varcode-10.0.4}/tests/test_string_helpers.py +0 -0
  92. {varcode-10.0.2 → varcode-10.0.4}/tests/test_structural_variant_annotator.py +0 -0
  93. {varcode-10.0.2 → varcode-10.0.4}/tests/test_structural_variants.py +0 -0
  94. {varcode-10.0.2 → varcode-10.0.4}/tests/test_sv_comparison.py +0 -0
  95. {varcode-10.0.2 → varcode-10.0.4}/tests/test_sv_consequences.py +0 -0
  96. {varcode-10.0.2 → varcode-10.0.4}/tests/test_sv_selenocysteine.py +0 -0
  97. {varcode-10.0.2 → varcode-10.0.4}/tests/test_sv_sequence_changes.py +0 -0
  98. {varcode-10.0.2 → varcode-10.0.4}/tests/test_sv_tabular_metadata.py +0 -0
  99. {varcode-10.0.2 → varcode-10.0.4}/tests/test_symbolic_alleles.py +0 -0
  100. {varcode-10.0.2 → varcode-10.0.4}/tests/test_symbolic_sv_padding.py +0 -0
  101. {varcode-10.0.2 → varcode-10.0.4}/tests/test_timings.py +0 -0
  102. {varcode-10.0.2 → varcode-10.0.4}/tests/test_transcript_layout.py +0 -0
  103. {varcode-10.0.2 → varcode-10.0.4}/tests/test_transcript_model.py +0 -0
  104. {varcode-10.0.2 → varcode-10.0.4}/tests/test_transcript_model_start_codons.py +0 -0
  105. {varcode-10.0.2 → varcode-10.0.4}/tests/test_transforms_left_align.py +0 -0
  106. {varcode-10.0.2 → varcode-10.0.4}/tests/test_transforms_pair_breakends.py +0 -0
  107. {varcode-10.0.2 → varcode-10.0.4}/tests/test_variant.py +0 -0
  108. {varcode-10.0.2 → varcode-10.0.4}/tests/test_variant_collection.py +0 -0
  109. {varcode-10.0.2 → varcode-10.0.4}/tests/test_vcf.py +0 -0
  110. {varcode-10.0.2 → varcode-10.0.4}/tests/test_vcf_output.py +0 -0
  111. {varcode-10.0.2 → varcode-10.0.4}/tests/test_vcf_parsing.py +0 -0
  112. {varcode-10.0.2 → varcode-10.0.4}/tests/test_vcf_phase_resolver.py +0 -0
  113. {varcode-10.0.2 → varcode-10.0.4}/tests/test_vcf_spec_examples.py +0 -0
  114. {varcode-10.0.2 → varcode-10.0.4}/varcode/__init__.py +0 -0
  115. {varcode-10.0.2 → varcode-10.0.4}/varcode/annotators/__init__.py +0 -0
  116. {varcode-10.0.2 → varcode-10.0.4}/varcode/annotators/fast.py +0 -0
  117. {varcode-10.0.2 → varcode-10.0.4}/varcode/annotators/protein_diff.py +0 -0
  118. {varcode-10.0.2 → varcode-10.0.4}/varcode/annotators/registry.py +0 -0
  119. {varcode-10.0.2 → varcode-10.0.4}/varcode/cli/__init__.py +0 -0
  120. {varcode-10.0.2 → varcode-10.0.4}/varcode/cli/effects_script.py +0 -0
  121. {varcode-10.0.2 → varcode-10.0.4}/varcode/cli/genes_script.py +0 -0
  122. {varcode-10.0.2 → varcode-10.0.4}/varcode/cli/logging.conf +0 -0
  123. {varcode-10.0.2 → varcode-10.0.4}/varcode/cli/variant_args.py +0 -0
  124. {varcode-10.0.2 → varcode-10.0.4}/varcode/cli/version_info.py +0 -0
  125. {varcode-10.0.2 → varcode-10.0.4}/varcode/common.py +0 -0
  126. {varcode-10.0.2 → varcode-10.0.4}/varcode/cryptic_exons.py +0 -0
  127. {varcode-10.0.2 → varcode-10.0.4}/varcode/csv_helpers.py +0 -0
  128. {varcode-10.0.2 → varcode-10.0.4}/varcode/effect_candidates.py +0 -0
  129. {varcode-10.0.2 → varcode-10.0.4}/varcode/effect_hypotheses.py +0 -0
  130. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/__init__.py +0 -0
  131. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/classify.py +0 -0
  132. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/codon_tables.py +0 -0
  133. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/common.py +0 -0
  134. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_collection.py +0 -0
  135. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_helpers.py +0 -0
  136. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_ordering.py +0 -0
  137. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_prediction.py +0 -0
  138. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_prediction_coding.py +0 -0
  139. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
  140. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
  141. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/fast_path.py +0 -0
  142. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/mutate.py +0 -0
  143. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/selenocysteine.py +0 -0
  144. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/sequence_change.py +0 -0
  145. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/structural.py +0 -0
  146. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/transcript_helpers.py +0 -0
  147. {varcode-10.0.2 → varcode-10.0.4}/varcode/effects/translate.py +0 -0
  148. {varcode-10.0.2 → varcode-10.0.4}/varcode/errors.py +0 -0
  149. {varcode-10.0.2 → varcode-10.0.4}/varcode/exacto.py +0 -0
  150. {varcode-10.0.2 → varcode-10.0.4}/varcode/genome.py +0 -0
  151. {varcode-10.0.2 → varcode-10.0.4}/varcode/genome_sequence.py +0 -0
  152. {varcode-10.0.2 → varcode-10.0.4}/varcode/genotype.py +0 -0
  153. {varcode-10.0.2 → varcode-10.0.4}/varcode/germline.py +0 -0
  154. {varcode-10.0.2 → varcode-10.0.4}/varcode/maf.py +0 -0
  155. {varcode-10.0.2 → varcode-10.0.4}/varcode/mutant_transcript.py +0 -0
  156. {varcode-10.0.2 → varcode-10.0.4}/varcode/nucleotides.py +0 -0
  157. {varcode-10.0.2 → varcode-10.0.4}/varcode/phasing.py +0 -0
  158. {varcode-10.0.2 → varcode-10.0.4}/varcode/realized_effects.py +0 -0
  159. {varcode-10.0.2 → varcode-10.0.4}/varcode/reference.py +0 -0
  160. {varcode-10.0.2 → varcode-10.0.4}/varcode/rna_evidence.py +0 -0
  161. {varcode-10.0.2 → varcode-10.0.4}/varcode/rna_read_phasing.py +0 -0
  162. {varcode-10.0.2 → varcode-10.0.4}/varcode/splice_graph.py +0 -0
  163. {varcode-10.0.2 → varcode-10.0.4}/varcode/splice_outcomes.py +0 -0
  164. {varcode-10.0.2 → varcode-10.0.4}/varcode/string_helpers.py +0 -0
  165. {varcode-10.0.2 → varcode-10.0.4}/varcode/structural_variant.py +0 -0
  166. {varcode-10.0.2 → varcode-10.0.4}/varcode/sv_allele_parser.py +0 -0
  167. {varcode-10.0.2 → varcode-10.0.4}/varcode/sv_comparison.py +0 -0
  168. {varcode-10.0.2 → varcode-10.0.4}/varcode/transcript_layout.py +0 -0
  169. {varcode-10.0.2 → varcode-10.0.4}/varcode/transforms/__init__.py +0 -0
  170. {varcode-10.0.2 → varcode-10.0.4}/varcode/ucsc_reference_names.py +0 -0
  171. {varcode-10.0.2 → varcode-10.0.4}/varcode/util.py +0 -0
  172. {varcode-10.0.2 → varcode-10.0.4}/varcode/variant.py +0 -0
  173. {varcode-10.0.2 → varcode-10.0.4}/varcode/variant_collection.py +0 -0
  174. {varcode-10.0.2 → varcode-10.0.4}/varcode/vcf.py +0 -0
  175. {varcode-10.0.2 → varcode-10.0.4}/varcode/vcf_output.py +0 -0
  176. {varcode-10.0.2 → varcode-10.0.4}/varcode/vcf_parsing.py +0 -0
  177. {varcode-10.0.2 → varcode-10.0.4}/varcode.egg-info/dependency_links.txt +0 -0
  178. {varcode-10.0.2 → varcode-10.0.4}/varcode.egg-info/entry_points.txt +0 -0
  179. {varcode-10.0.2 → varcode-10.0.4}/varcode.egg-info/requires.txt +0 -0
  180. {varcode-10.0.2 → varcode-10.0.4}/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.4
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,70 @@
1
+ """Nonlocal rearrangements must not be classified from clipped alleles."""
2
+
3
+ import pytest
4
+ from pyensembl import cached_release
5
+
6
+ from varcode import StructuralVariant
7
+ from varcode.effects import Unresolved
8
+ from varcode.genomic_layout import GenomicLayout, NonlocalStructuralEdit
9
+ from varcode.transcript_model import predict_transcript_model_effect
10
+ from .test_genomic_layout import structural, provider
11
+
12
+
13
+ @pytest.mark.parametrize("strand", ["+", "-"])
14
+ @pytest.mark.parametrize("kind", ["DUP", "INV"])
15
+ @pytest.mark.parametrize("start,end", [(1, 6), (6, 12), (1, 12)])
16
+ def test_layout_rejects_crossing_or_enclosing_event(strand, kind, start, end):
17
+ layout = GenomicLayout.from_interval("a", 3, 10, strand=strand, sequence_provider=provider)
18
+ with pytest.raises(NonlocalStructuralEdit, match="complete rearrangement junctions"):
19
+ layout.apply_structural_variant(structural(kind, start, end))
20
+ assert layout.length == 8
21
+
22
+
23
+ @pytest.mark.parametrize("strand", ["+", "-"])
24
+ @pytest.mark.parametrize("kind", ["DUP", "INV"])
25
+ def test_fully_represented_and_disjoint_events(strand, kind):
26
+ layout = GenomicLayout.from_interval("a", 3, 10, strand=strand, sequence_provider=provider)
27
+ local = layout.apply_structural_variant(structural(kind, 3, 10))
28
+ assert local.length == (16 if kind == "DUP" else 8)
29
+ assert layout.apply_structural_variant(structural(kind, 20, 30)) is layout
30
+
31
+
32
+ @pytest.mark.parametrize("tx_id", ["ENST00000003084", "ENST00000357654"])
33
+ @pytest.mark.parametrize("kind", ["DUP", "INV"])
34
+ @pytest.mark.parametrize("side", ["left", "right", "both"])
35
+ def test_transcript_model_nonlocal_events_are_unresolved(tx_id, kind, side):
36
+ tx = cached_release(81).transcript_by_id(tx_id)
37
+ start = tx.start - 100 if side in ("left", "both") else tx.start + 50
38
+ end = tx.end + 100 if side in ("right", "both") else tx.end - 50
39
+ variant = StructuralVariant(tx.contig, start, kind, end=end, genome=tx.genome)
40
+ for effect in (predict_transcript_model_effect((variant,), tx),
41
+ variant.effect_on_transcript(tx, annotator="transcript_model")):
42
+ assert isinstance(effect, Unresolved)
43
+ assert effect.mechanism == "nonlocal_structural_variant"
44
+ assert effect.modifies_coding_sequence is None
45
+ assert effect.modifies_protein_sequence is None
46
+ assert effect.mutant_protein_sequence is None
47
+
48
+
49
+ @pytest.mark.parametrize("kind", ["DUP", "INV"])
50
+ @pytest.mark.parametrize("tx_id", ["ENST00000003084", "ENST00000357654"])
51
+ def test_nonlocal_supplied_assembly_is_preserved(kind, tx_id):
52
+ tx = cached_release(81).transcript_by_id(tx_id)
53
+ variant = StructuralVariant(tx.contig, tx.start - 100, kind,
54
+ end=tx.end + 100, genome=tx.genome,
55
+ alt_assembly="ATGAAATAG")
56
+ effect = variant.effect_on_transcript(tx, annotator="transcript_model")
57
+ assert effect.mutant_transcript.cdna_sequence == "ATGAAATAG"
58
+ assert effect.modifies_protein_sequence is None
59
+
60
+
61
+ def test_each_isoform_checks_its_own_layout():
62
+ genome = cached_release(81)
63
+ gene = genome.transcript_by_id("ENST00000357654").gene
64
+ variant = StructuralVariant(gene.contig, gene.start - 100, "DUP", end=gene.end + 100, genome=genome)
65
+ effects = variant.effects(annotator="transcript_model")
66
+ coding = [e for e in effects if e.transcript and e.transcript.complete
67
+ and e.transcript.is_protein_coding and e.gene_name == "BRCA1"]
68
+ assert len(coding) > 1
69
+ assert all(isinstance(e, Unresolved) for e in coding)
70
+ assert all(e.modifies_protein_sequence is None for e in coding)
@@ -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))
@@ -39,6 +39,10 @@ class SequenceUnavailable(ValueError):
39
39
  """Raised when a lazy reference segment is materialized without FASTA."""
40
40
 
41
41
 
42
+ class NonlocalStructuralEdit(UnsupportedLayoutEdit):
43
+ """An overlapping DUP/INV needs junctions beyond this finite layout."""
44
+
45
+
42
46
  @dataclass(frozen=True)
43
47
  class LayoutSegment:
44
48
  """One contiguous piece of a rearranged genomic molecule.
@@ -443,6 +447,19 @@ class GenomicLayout:
443
447
  and segment.origin_kind in ("reference", "alternate")]
444
448
  if not covered:
445
449
  return self
450
+ layout_start = min(segment.start for segment in covered)
451
+ layout_end = max(segment.end for segment in covered)
452
+ if end < layout_start or start > layout_end:
453
+ return self
454
+ # A DUP or INV needs the whole affected body and its junctions.
455
+ # Clipping changes the allele into a different local rearrangement.
456
+ # A DEL can still remove just the intersecting reference sequence.
457
+ if kind in ("DUP", "INV") and (
458
+ start < layout_start or end > layout_end):
459
+ raise NonlocalStructuralEdit(
460
+ "%s %s:%d-%d extends beyond layout %d-%d; "
461
+ "the complete rearrangement junctions are unavailable" % (
462
+ kind, variant.contig, start, end, layout_start, layout_end))
446
463
  start = max(start, min(segment.start for segment in covered))
447
464
  end = min(end, max(segment.end for segment in covered))
448
465
  if start > end:
@@ -186,6 +186,16 @@ def predict_transcript_model_effect(
186
186
  raise ValueError("predict_transcript_model_effect requires a somatic variant")
187
187
  germline_variants = tuple(germline_variants)
188
188
  primary = variants[0]
189
+ if (getattr(primary, "sv_type", None) in ("DUP", "INV")
190
+ and primary.alt_assembly):
191
+ if len(variants) != 1 or germline_variants:
192
+ return Unresolved(
193
+ primary, transcript, mechanism="assembled_structural_haplotype",
194
+ reason="Composition with an assembled allele requires mapped variant coordinates")
195
+ # Preserve supplied full transcript assemblies using the same path as
196
+ # the structural annotator; never replace them with a clipped layout.
197
+ from .effects.structural import predict_structural_variant_effect
198
+ return predict_structural_variant_effect(primary, transcript)
189
199
  if getattr(primary, "sv_type", None) == "BND":
190
200
  if len(variants) != 1 or germline_variants:
191
201
  return Unresolved(
@@ -214,8 +224,14 @@ def predict_transcript_model_effect(
214
224
  for phase_hypothesis in phase_hypotheses:
215
225
  reference = GenomicLayout.from_transcript(
216
226
  transcript, flank=50, sequence_provider=sequence_provider)
217
- baseline_layout = reference.apply_variants(phase_hypothesis.cis)
218
- mutant_layout = baseline_layout.apply_variants(variants)
227
+ from .genomic_layout import NonlocalStructuralEdit
228
+ try:
229
+ baseline_layout = reference.apply_variants(phase_hypothesis.cis)
230
+ mutant_layout = baseline_layout.apply_variants(variants)
231
+ except NonlocalStructuralEdit as error:
232
+ return Unresolved(
233
+ primary, transcript, mechanism="nonlocal_structural_variant",
234
+ reason=str(error))
219
235
  baseline_runs, baseline_statuses = _status_map(
220
236
  transcript, baseline_layout)
221
237
  mutant_runs, mutant_statuses = _status_map(transcript, mutant_layout)
@@ -0,0 +1 @@
1
+ __version__ = "10.0.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: varcode
3
- Version: 10.0.2
3
+ Version: 10.0.4
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
@@ -52,6 +52,7 @@ tests/test_mouse.py
52
52
  tests/test_mutant_transcript.py
53
53
  tests/test_mutate.py
54
54
  tests/test_no_duplicate_variants.py
55
+ tests/test_nonlocal_layout.py
55
56
  tests/test_nonlocal_sv_transcripts.py
56
57
  tests/test_osteosarc_dataset.py
57
58
  tests/test_osteosarc_fusions.py
@@ -77,6 +78,7 @@ tests/test_splice_outcomes.py
77
78
  tests/test_splice_site_effects.py
78
79
  tests/test_stop_codon_classification_bugs.py
79
80
  tests/test_string_helpers.py
81
+ tests/test_structural_serialization.py
80
82
  tests/test_structural_variant_annotator.py
81
83
  tests/test_structural_variants.py
82
84
  tests/test_sv_comparison.py
@@ -169,6 +171,7 @@ varcode/effects/mutate.py
169
171
  varcode/effects/selenocysteine.py
170
172
  varcode/effects/sequence_change.py
171
173
  varcode/effects/structural.py
174
+ varcode/effects/structural_serialization.py
172
175
  varcode/effects/transcript_helpers.py
173
176
  varcode/effects/translate.py
174
177
  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