varcode 9.4.2__tar.gz → 9.5.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 (174) hide show
  1. {varcode-9.4.2/varcode.egg-info → varcode-9.5.0}/PKG-INFO +1 -1
  2. varcode-9.5.0/tests/test_sv_comparison.py +113 -0
  3. varcode-9.5.0/varcode/sv_comparison.py +221 -0
  4. varcode-9.5.0/varcode/version.py +1 -0
  5. {varcode-9.4.2 → varcode-9.5.0/varcode.egg-info}/PKG-INFO +1 -1
  6. {varcode-9.4.2 → varcode-9.5.0}/varcode.egg-info/SOURCES.txt +2 -0
  7. varcode-9.4.2/varcode/version.py +0 -1
  8. {varcode-9.4.2 → varcode-9.5.0}/LICENSE +0 -0
  9. {varcode-9.4.2 → varcode-9.5.0}/MANIFEST.in +0 -0
  10. {varcode-9.4.2 → varcode-9.5.0}/README.md +0 -0
  11. {varcode-9.4.2 → varcode-9.5.0}/pyproject.toml +0 -0
  12. {varcode-9.4.2 → varcode-9.5.0}/requirements.txt +0 -0
  13. {varcode-9.4.2 → varcode-9.5.0}/setup.cfg +0 -0
  14. {varcode-9.4.2 → varcode-9.5.0}/tests/test_annotator_divergence_scenarios.py +0 -0
  15. {varcode-9.4.2 → varcode-9.5.0}/tests/test_annotator_haplotypes.py +0 -0
  16. {varcode-9.4.2 → varcode-9.5.0}/tests/test_annotator_parity_adversarial.py +0 -0
  17. {varcode-9.4.2 → varcode-9.5.0}/tests/test_annotators.py +0 -0
  18. {varcode-9.4.2 → varcode-9.5.0}/tests/test_bnd_retained_segments.py +0 -0
  19. {varcode-9.4.2 → varcode-9.5.0}/tests/test_cli_effects.py +0 -0
  20. {varcode-9.4.2 → varcode-9.5.0}/tests/test_cli_genes.py +0 -0
  21. {varcode-9.4.2 → varcode-9.5.0}/tests/test_cli_without_pkg_resources.py +0 -0
  22. {varcode-9.4.2 → varcode-9.5.0}/tests/test_collection_filtering.py +0 -0
  23. {varcode-9.4.2 → varcode-9.5.0}/tests/test_collection_variants_attr_consistency.py +0 -0
  24. {varcode-9.4.2 → varcode-9.5.0}/tests/test_common.py +0 -0
  25. {varcode-9.4.2 → varcode-9.5.0}/tests/test_cosmic_mutations.py +0 -0
  26. {varcode-9.4.2 → varcode-9.5.0}/tests/test_cryptic_exons.py +0 -0
  27. {varcode-9.4.2 → varcode-9.5.0}/tests/test_csv_roundtrip.py +0 -0
  28. {varcode-9.4.2 → varcode-9.5.0}/tests/test_dbnsfp_validation.py +0 -0
  29. {varcode-9.4.2 → varcode-9.5.0}/tests/test_default_structural_helpers.py +0 -0
  30. {varcode-9.4.2 → varcode-9.5.0}/tests/test_documentation_examples.py +0 -0
  31. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effect_annotation_errors.py +0 -0
  32. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effect_candidates.py +0 -0
  33. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effect_classes.py +0 -0
  34. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effect_collection.py +0 -0
  35. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effect_collection_serialization.py +0 -0
  36. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effect_collection_sort_order.py +0 -0
  37. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effect_hypotheses.py +0 -0
  38. {varcode-9.4.2 → varcode-9.5.0}/tests/test_effects_from_mutagenix_variants.py +0 -0
  39. {varcode-9.4.2 → varcode-9.5.0}/tests/test_exacto_fusions.py +0 -0
  40. {varcode-9.4.2 → varcode-9.5.0}/tests/test_exonic_splice_site.py +0 -0
  41. {varcode-9.4.2 → varcode-9.5.0}/tests/test_fast_path.py +0 -0
  42. {varcode-9.4.2 → varcode-9.5.0}/tests/test_frameshift_cterminus_regression.py +0 -0
  43. {varcode-9.4.2 → varcode-9.5.0}/tests/test_frameshift_helpers.py +0 -0
  44. {varcode-9.4.2 → varcode-9.5.0}/tests/test_fusion_insertions.py +0 -0
  45. {varcode-9.4.2 → varcode-9.5.0}/tests/test_fusion_partner_candidates.py +0 -0
  46. {varcode-9.4.2 → varcode-9.5.0}/tests/test_genome_contig_validation.py +0 -0
  47. {varcode-9.4.2 → varcode-9.5.0}/tests/test_genome_sequence.py +0 -0
  48. {varcode-9.4.2 → varcode-9.5.0}/tests/test_genomic_layout.py +0 -0
  49. {varcode-9.4.2 → varcode-9.5.0}/tests/test_genotype.py +0 -0
  50. {varcode-9.4.2 → varcode-9.5.0}/tests/test_genotype_from_vcf.py +0 -0
  51. {varcode-9.4.2 → varcode-9.5.0}/tests/test_germline_context.py +0 -0
  52. {varcode-9.4.2 → varcode-9.5.0}/tests/test_germline_effects.py +0 -0
  53. {varcode-9.4.2 → varcode-9.5.0}/tests/test_haplotype_effect.py +0 -0
  54. {varcode-9.4.2 → varcode-9.5.0}/tests/test_maf.py +0 -0
  55. {varcode-9.4.2 → varcode-9.5.0}/tests/test_mitochondrial.py +0 -0
  56. {varcode-9.4.2 → varcode-9.5.0}/tests/test_mm10_klf6_frameshift.py +0 -0
  57. {varcode-9.4.2 → varcode-9.5.0}/tests/test_mouse.py +0 -0
  58. {varcode-9.4.2 → varcode-9.5.0}/tests/test_mutant_transcript.py +0 -0
  59. {varcode-9.4.2 → varcode-9.5.0}/tests/test_mutate.py +0 -0
  60. {varcode-9.4.2 → varcode-9.5.0}/tests/test_no_duplicate_variants.py +0 -0
  61. {varcode-9.4.2 → varcode-9.5.0}/tests/test_nonlocal_sv_transcripts.py +0 -0
  62. {varcode-9.4.2 → varcode-9.5.0}/tests/test_osteosarc_dataset.py +0 -0
  63. {varcode-9.4.2 → varcode-9.5.0}/tests/test_osteosarc_fusions.py +0 -0
  64. {varcode-9.4.2 → varcode-9.5.0}/tests/test_osteosarc_variants.py +0 -0
  65. {varcode-9.4.2 → varcode-9.5.0}/tests/test_partial_annotators.py +0 -0
  66. {varcode-9.4.2 → varcode-9.5.0}/tests/test_premature_stop_short_description.py +0 -0
  67. {varcode-9.4.2 → varcode-9.5.0}/tests/test_problematic_variants.py +0 -0
  68. {varcode-9.4.2 → varcode-9.5.0}/tests/test_protein_diff_parity.py +0 -0
  69. {varcode-9.4.2 → varcode-9.5.0}/tests/test_read_phase_resolver.py +0 -0
  70. {varcode-9.4.2 → varcode-9.5.0}/tests/test_real_world_callers.py +0 -0
  71. {varcode-9.4.2 → varcode-9.5.0}/tests/test_reference.py +0 -0
  72. {varcode-9.4.2 → varcode-9.5.0}/tests/test_reference_mismatch_error.py +0 -0
  73. {varcode-9.4.2 → varcode-9.5.0}/tests/test_reference_segments.py +0 -0
  74. {varcode-9.4.2 → varcode-9.5.0}/tests/test_rna_evidence.py +0 -0
  75. {varcode-9.4.2 → varcode-9.5.0}/tests/test_rna_haplotype_sequences.py +0 -0
  76. {varcode-9.4.2 → varcode-9.5.0}/tests/test_rna_read_phasing_source.py +0 -0
  77. {varcode-9.4.2 → varcode-9.5.0}/tests/test_selenocysteine.py +0 -0
  78. {varcode-9.4.2 → varcode-9.5.0}/tests/test_selenocysteine_proteins.py +0 -0
  79. {varcode-9.4.2 → varcode-9.5.0}/tests/test_silent_aa_pos.py +0 -0
  80. {varcode-9.4.2 → varcode-9.5.0}/tests/test_silent_hgvs_description.py +0 -0
  81. {varcode-9.4.2 → varcode-9.5.0}/tests/test_splice_graph.py +0 -0
  82. {varcode-9.4.2 → varcode-9.5.0}/tests/test_splice_outcomes.py +0 -0
  83. {varcode-9.4.2 → varcode-9.5.0}/tests/test_splice_site_effects.py +0 -0
  84. {varcode-9.4.2 → varcode-9.5.0}/tests/test_stop_codon_classification_bugs.py +0 -0
  85. {varcode-9.4.2 → varcode-9.5.0}/tests/test_string_helpers.py +0 -0
  86. {varcode-9.4.2 → varcode-9.5.0}/tests/test_structural_variant_annotator.py +0 -0
  87. {varcode-9.4.2 → varcode-9.5.0}/tests/test_structural_variants.py +0 -0
  88. {varcode-9.4.2 → varcode-9.5.0}/tests/test_sv_selenocysteine.py +0 -0
  89. {varcode-9.4.2 → varcode-9.5.0}/tests/test_sv_sequence_changes.py +0 -0
  90. {varcode-9.4.2 → varcode-9.5.0}/tests/test_sv_tabular_metadata.py +0 -0
  91. {varcode-9.4.2 → varcode-9.5.0}/tests/test_symbolic_alleles.py +0 -0
  92. {varcode-9.4.2 → varcode-9.5.0}/tests/test_symbolic_sv_padding.py +0 -0
  93. {varcode-9.4.2 → varcode-9.5.0}/tests/test_timings.py +0 -0
  94. {varcode-9.4.2 → varcode-9.5.0}/tests/test_transcript_layout.py +0 -0
  95. {varcode-9.4.2 → varcode-9.5.0}/tests/test_transcript_model.py +0 -0
  96. {varcode-9.4.2 → varcode-9.5.0}/tests/test_transcript_model_start_codons.py +0 -0
  97. {varcode-9.4.2 → varcode-9.5.0}/tests/test_transforms_left_align.py +0 -0
  98. {varcode-9.4.2 → varcode-9.5.0}/tests/test_transforms_pair_breakends.py +0 -0
  99. {varcode-9.4.2 → varcode-9.5.0}/tests/test_variant.py +0 -0
  100. {varcode-9.4.2 → varcode-9.5.0}/tests/test_variant_collection.py +0 -0
  101. {varcode-9.4.2 → varcode-9.5.0}/tests/test_vcf.py +0 -0
  102. {varcode-9.4.2 → varcode-9.5.0}/tests/test_vcf_output.py +0 -0
  103. {varcode-9.4.2 → varcode-9.5.0}/tests/test_vcf_parsing.py +0 -0
  104. {varcode-9.4.2 → varcode-9.5.0}/tests/test_vcf_phase_resolver.py +0 -0
  105. {varcode-9.4.2 → varcode-9.5.0}/tests/test_vcf_spec_examples.py +0 -0
  106. {varcode-9.4.2 → varcode-9.5.0}/varcode/__init__.py +0 -0
  107. {varcode-9.4.2 → varcode-9.5.0}/varcode/annotators/__init__.py +0 -0
  108. {varcode-9.4.2 → varcode-9.5.0}/varcode/annotators/fast.py +0 -0
  109. {varcode-9.4.2 → varcode-9.5.0}/varcode/annotators/protein_diff.py +0 -0
  110. {varcode-9.4.2 → varcode-9.5.0}/varcode/annotators/registry.py +0 -0
  111. {varcode-9.4.2 → varcode-9.5.0}/varcode/cli/__init__.py +0 -0
  112. {varcode-9.4.2 → varcode-9.5.0}/varcode/cli/effects_script.py +0 -0
  113. {varcode-9.4.2 → varcode-9.5.0}/varcode/cli/genes_script.py +0 -0
  114. {varcode-9.4.2 → varcode-9.5.0}/varcode/cli/logging.conf +0 -0
  115. {varcode-9.4.2 → varcode-9.5.0}/varcode/cli/variant_args.py +0 -0
  116. {varcode-9.4.2 → varcode-9.5.0}/varcode/cli/version_info.py +0 -0
  117. {varcode-9.4.2 → varcode-9.5.0}/varcode/common.py +0 -0
  118. {varcode-9.4.2 → varcode-9.5.0}/varcode/cryptic_exons.py +0 -0
  119. {varcode-9.4.2 → varcode-9.5.0}/varcode/csv_helpers.py +0 -0
  120. {varcode-9.4.2 → varcode-9.5.0}/varcode/effect_candidates.py +0 -0
  121. {varcode-9.4.2 → varcode-9.5.0}/varcode/effect_hypotheses.py +0 -0
  122. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/__init__.py +0 -0
  123. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/classify.py +0 -0
  124. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/codon_tables.py +0 -0
  125. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/common.py +0 -0
  126. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_classes.py +0 -0
  127. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_collection.py +0 -0
  128. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_helpers.py +0 -0
  129. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_ordering.py +0 -0
  130. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_prediction.py +0 -0
  131. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_prediction_coding.py +0 -0
  132. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_prediction_coding_frameshift.py +0 -0
  133. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/effect_prediction_coding_in_frame.py +0 -0
  134. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/fast_path.py +0 -0
  135. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/mutate.py +0 -0
  136. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/selenocysteine.py +0 -0
  137. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/sequence_change.py +0 -0
  138. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/structural.py +0 -0
  139. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/transcript_helpers.py +0 -0
  140. {varcode-9.4.2 → varcode-9.5.0}/varcode/effects/translate.py +0 -0
  141. {varcode-9.4.2 → varcode-9.5.0}/varcode/errors.py +0 -0
  142. {varcode-9.4.2 → varcode-9.5.0}/varcode/exacto.py +0 -0
  143. {varcode-9.4.2 → varcode-9.5.0}/varcode/genome.py +0 -0
  144. {varcode-9.4.2 → varcode-9.5.0}/varcode/genome_sequence.py +0 -0
  145. {varcode-9.4.2 → varcode-9.5.0}/varcode/genomic_layout.py +0 -0
  146. {varcode-9.4.2 → varcode-9.5.0}/varcode/genotype.py +0 -0
  147. {varcode-9.4.2 → varcode-9.5.0}/varcode/germline.py +0 -0
  148. {varcode-9.4.2 → varcode-9.5.0}/varcode/maf.py +0 -0
  149. {varcode-9.4.2 → varcode-9.5.0}/varcode/mutant_transcript.py +0 -0
  150. {varcode-9.4.2 → varcode-9.5.0}/varcode/nucleotides.py +0 -0
  151. {varcode-9.4.2 → varcode-9.5.0}/varcode/phasing.py +0 -0
  152. {varcode-9.4.2 → varcode-9.5.0}/varcode/realized_effects.py +0 -0
  153. {varcode-9.4.2 → varcode-9.5.0}/varcode/reference.py +0 -0
  154. {varcode-9.4.2 → varcode-9.5.0}/varcode/rna_evidence.py +0 -0
  155. {varcode-9.4.2 → varcode-9.5.0}/varcode/rna_read_phasing.py +0 -0
  156. {varcode-9.4.2 → varcode-9.5.0}/varcode/splice_graph.py +0 -0
  157. {varcode-9.4.2 → varcode-9.5.0}/varcode/splice_outcomes.py +0 -0
  158. {varcode-9.4.2 → varcode-9.5.0}/varcode/string_helpers.py +0 -0
  159. {varcode-9.4.2 → varcode-9.5.0}/varcode/structural_variant.py +0 -0
  160. {varcode-9.4.2 → varcode-9.5.0}/varcode/sv_allele_parser.py +0 -0
  161. {varcode-9.4.2 → varcode-9.5.0}/varcode/transcript_layout.py +0 -0
  162. {varcode-9.4.2 → varcode-9.5.0}/varcode/transcript_model.py +0 -0
  163. {varcode-9.4.2 → varcode-9.5.0}/varcode/transforms/__init__.py +0 -0
  164. {varcode-9.4.2 → varcode-9.5.0}/varcode/ucsc_reference_names.py +0 -0
  165. {varcode-9.4.2 → varcode-9.5.0}/varcode/util.py +0 -0
  166. {varcode-9.4.2 → varcode-9.5.0}/varcode/variant.py +0 -0
  167. {varcode-9.4.2 → varcode-9.5.0}/varcode/variant_collection.py +0 -0
  168. {varcode-9.4.2 → varcode-9.5.0}/varcode/vcf.py +0 -0
  169. {varcode-9.4.2 → varcode-9.5.0}/varcode/vcf_output.py +0 -0
  170. {varcode-9.4.2 → varcode-9.5.0}/varcode/vcf_parsing.py +0 -0
  171. {varcode-9.4.2 → varcode-9.5.0}/varcode.egg-info/dependency_links.txt +0 -0
  172. {varcode-9.4.2 → varcode-9.5.0}/varcode.egg-info/entry_points.txt +0 -0
  173. {varcode-9.4.2 → varcode-9.5.0}/varcode.egg-info/requires.txt +0 -0
  174. {varcode-9.4.2 → varcode-9.5.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.4.2
3
+ Version: 9.5.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
@@ -0,0 +1,113 @@
1
+ """Small explicit VCF records are generated here; no external fixture cache."""
2
+ import json
3
+
4
+ import pytest
5
+
6
+ from varcode.sv_comparison import compare_sv_calls, main
7
+
8
+
9
+ def row(id, chrom="1", pos=100, ref="C", alt="C[2:200[", **kwargs):
10
+ return dict(call_id=id, caller="caller-" + id, sample="sample-" + id,
11
+ build="GRCh38", chrom=chrom, pos=str(pos), ref=ref, alt=alt, **kwargs)
12
+
13
+
14
+ def test_reciprocal_and_repeated_exports_preserve_all_evidence():
15
+ a = row("a", record_id="vcf-a", source_url="https://example.org/a.vcf")
16
+ b = row("b", chrom="2", pos=200, ref="G", alt="]1:100]G", record_id="vcf-b")
17
+ c = dict(a, call_id="c", duplicate_export_of="a")
18
+ result = compare_sv_calls([a, b, c])
19
+ group, = result["groups"]
20
+ assert group["status"] == "exact_reported_allele"
21
+ assert group["call_count"] == 3
22
+ assert len(group["exact_ids"]) == 1
23
+ assert [m["raw"] for m in result["members"]] == [a, b, c]
24
+ assert len(group["callers"]) == 2 # An exported copy is not another caller.
25
+
26
+
27
+ def test_inserted_sequence_disagreement_is_never_exact_equivalence():
28
+ result = compare_sv_calls([row("a", alt="CA[2:200["), row("b", alt="CT[2:200[")])
29
+ group, = result["groups"]
30
+ assert group["status"] == "nearby_candidate"
31
+ assert len(group["exact_ids"]) == 2
32
+ assert group["insertion_disagreement"] is True
33
+
34
+
35
+ def test_breakpoint_disagreement_and_no_transitive_chain():
36
+ rows = [row("a", pos=100), row("b", pos=180), row("c", pos=260)]
37
+ result = compare_sv_calls(rows, max_distance=100)
38
+ assert sorted(g["call_count"] for g in result["groups"]) == [1, 2]
39
+ assert all(max(g["breakpoint_spread"]) <= 100 for g in result["groups"])
40
+ assert result == compare_sv_calls(reversed(rows), max_distance=100)
41
+ assert len(compare_sv_calls(rows, max_distance=0)["groups"]) == 3
42
+
43
+
44
+ @pytest.mark.parametrize("change", [dict(build="GRCh37"), dict(alt="C]2:200]"), dict(alt="C[3:200["), dict(alt="C[2:301[")])
45
+ def test_assembly_orientation_contig_and_second_breakpoint_are_required(change):
46
+ assert len(compare_sv_calls([row("a"), dict(row("b"), **change)])["groups"]) == 2
47
+
48
+
49
+ @pytest.mark.parametrize("ref,alt,pos,bnd_alt,mate", [
50
+ ("C", "CA", 100, "CA[1:101[", 101),
51
+ ("CAAA", "C", 100, "C[1:104[", 104),
52
+ ("CAAA", "CTT", 100, "CTT[1:104[", 104),
53
+ ])
54
+ def test_explicit_indel_and_breakend_use_same_retained_base_coordinates(ref, alt, pos, bnd_alt, mate):
55
+ result = compare_sv_calls([row("a", pos=pos, ref=ref, alt=alt), row("b", pos=pos, alt=bnd_alt)])
56
+ group, = result["groups"]
57
+ assert group["status"] == "exact_reported_allele"
58
+ assert len(group["exact_ids"]) == 1
59
+ assert result["members"][0]["positions"] == (100, mate)
60
+
61
+
62
+ def test_symbolic_and_explicit_deletion_agree_but_inversion_has_two_junctions():
63
+ result = compare_sv_calls([row("a", alt="<DEL>", info="END=103"), row("b", ref="CAAA", alt="C")])
64
+ assert len(result["groups"][0]["exact_ids"]) == 1
65
+ inv = compare_sv_calls([row("a", alt="<INV>", info="END=103"), row("b", alt="C]1:103]")])
66
+ assert len(inv["groups"]) == 2 # One adjacency doesn't prove the whole inversion.
67
+
68
+
69
+ def test_unknown_sequence_imprecision_and_unplaced_calls_stay_explicit():
70
+ result = compare_sv_calls([row("a", alt="<INS>"), row("b", alt="CA[1:101["),
71
+ row("c", alt="C."), row("d", info="CIPOS=-5,5"),
72
+ dict(row("e"), build="unknown"), row("f", alt="bogus")])
73
+ members = {m["raw"]["call_id"]: m for m in result["members"]}
74
+ assert members["a"]["inserted_sequences"] == (None,)
75
+ assert members["d"]["imprecise"] is True
76
+ assert all(members[k]["status"] == "unresolved" for k in "cef")
77
+ assert len(result["members"]) == 6
78
+ assert all("reason" in members[k] for k in "cef")
79
+
80
+
81
+ def test_input_errors_and_empty_input():
82
+ assert compare_sv_calls([])["groups"] == []
83
+ with pytest.raises(ValueError, match="Duplicate"):
84
+ compare_sv_calls([row("a"), row("a")])
85
+ with pytest.raises(ValueError, match="required"):
86
+ compare_sv_calls([{}])
87
+ with pytest.raises(ValueError, match="non-negative"):
88
+ compare_sv_calls([], -1)
89
+
90
+
91
+ def test_portable_cli_exports_every_input_and_hash(tmp_path):
92
+ import csv
93
+ source = tmp_path / "calls.csv"
94
+ with source.open("w", newline="") as out:
95
+ writer = csv.DictWriter(out, fieldnames=row("a").keys())
96
+ writer.writeheader()
97
+ writer.writerows([row("a"), row("b", alt="C.")])
98
+ destination = tmp_path / "result"
99
+ main(["--calls", str(source), "--output", str(destination), "--max-distance", "10"])
100
+ result = json.loads((destination / "comparison.json").read_text())
101
+ assert result["provenance"]["call_count"] == 2
102
+ assert len(result["provenance"]["input_sha256"]) == 64
103
+ assert len(list(csv.DictReader((destination / "members.csv").open()))) == 2
104
+
105
+
106
+ def test_ucsc_and_ensembl_contig_names_match_at_both_ends():
107
+ result = compare_sv_calls([row("a", chrom="chr1", alt="C[chr2:200["),
108
+ row("b", chrom="2", pos=200, alt="]1:100]C")])
109
+ group, = result["groups"]
110
+ assert len(group["exact_ids"]) == 1
111
+ indels = compare_sv_calls([row("a", chrom="chr1", ref="CAAA", alt="C"),
112
+ row("b", chrom="1", alt="C[1:104[")])
113
+ assert len(indels["groups"][0]["exact_ids"]) == 1
@@ -0,0 +1,221 @@
1
+ """Compare reported SV alleles without erasing source or breakpoint disagreements.
2
+
3
+ Run ``python -m varcode.sv_comparison --help`` for the portable CSV interface.
4
+ Coordinates follow VCF (one-based); no reference liftover or repeat left-alignment
5
+ is performed. Nearby groups nominate comparisons, not proven identical alleles.
6
+ """
7
+
8
+ import argparse
9
+ import csv
10
+ import hashlib
11
+ import json
12
+ from collections import defaultdict
13
+ from pathlib import Path
14
+
15
+ from .nucleotides import reverse_complement
16
+ from .structural_variant import Breakend
17
+ from .sv_allele_parser import parse_symbolic_alt
18
+ from .variant import Variant
19
+
20
+ _REQUIRED = {"call_id", "caller", "sample", "build", "chrom", "pos", "ref", "alt"}
21
+
22
+
23
+ def _digest(value):
24
+ return hashlib.sha256(json.dumps(value, sort_keys=True).encode()).hexdigest()[:20]
25
+
26
+
27
+ def _info(text):
28
+ result = {}
29
+ for token in (text or "").split(";"):
30
+ key, _, value = token.partition("=")
31
+ if key in {"END", "SVLEN"} and value:
32
+ result[key] = int(value.split(",")[0])
33
+ elif key in {"CIPOS", "CIEND"} and value:
34
+ result[key] = tuple(int(v) for v in value.split(","))
35
+ elif key:
36
+ result[key] = value or True
37
+ return result
38
+
39
+
40
+ def _canonical(junction, inserted):
41
+ first, second = junction
42
+ if second < first:
43
+ first, second = second, first
44
+ if inserted is not None:
45
+ inserted = reverse_complement(inserted)
46
+ return (tuple(first), tuple(second)), inserted
47
+
48
+
49
+ def _normalize(row):
50
+ """Normalize representation only; retain every raw field in the result."""
51
+ assembly = row["build"].split(" (")[0]
52
+ if assembly not in {"GRCh37", "GRCh38"}:
53
+ raise ValueError("Unsupported/unknown assembly: %s" % row["build"])
54
+ info = _info(row.get("info"))
55
+ if row.get("end") and "END" not in info:
56
+ info["END"] = int(row["end"])
57
+ sv = parse_symbolic_alt(row["chrom"], int(row["pos"]), row["ref"], row["alt"],
58
+ info=info, genome=assembly, convert_ucsc_contig_names=True)
59
+ adjacencies = []
60
+ kind = "adjacency"
61
+ if sv is not None:
62
+ if sv.junctions:
63
+ for junction in sv.junctions:
64
+ if any(end.keeps is None for end in junction):
65
+ raise ValueError("Unknown breakend orientation")
66
+ adjacencies.append(_canonical(junction, sv.junction_inserted_sequence(junction)))
67
+ elif sv.sv_type == "INS":
68
+ adjacencies.append(_canonical((Breakend(sv.contig, sv.start, "left"),
69
+ Breakend(sv.contig, sv.start + 1, "right")),
70
+ sv.alt_assembly))
71
+ else:
72
+ raise ValueError("No complete adjacency in %s allele" % sv.sv_type)
73
+ imprecise = bool(info.get("IMPRECISE") or any(info.get(k) not in (None, (0, 0))
74
+ for k in ("CIPOS", "CIEND")))
75
+ else:
76
+ if not row["ref"] or not row["alt"] or set((row["ref"] + row["alt"]).upper()) - set("ACGTN"):
77
+ raise ValueError("Unsupported explicit allele")
78
+ v = Variant(row["chrom"], int(row["pos"]), row["ref"], row["alt"], genome=assembly,
79
+ convert_ucsc_contig_names=True)
80
+ if not v.ref and not v.alt:
81
+ raise ValueError("Reference-only allele")
82
+ if len(v.ref) == len(v.alt):
83
+ kind = "replacement"
84
+ adjacencies.append(_canonical((Breakend(v.contig, v.start - 1 if v.ref else v.start, "left"),
85
+ Breakend(v.contig, v.start + len(v.ref) if v.ref else v.start + 1, "right")), v.alt))
86
+ imprecise = False
87
+ adjacencies.sort(key=lambda item: item[0])
88
+ loci = tuple(end for junction, _ in adjacencies for end in junction)
89
+ inserts = tuple(insert for _, insert in adjacencies)
90
+ topology = (assembly, kind, tuple((chrom, side) for chrom, _, side in loci))
91
+ positions = tuple(pos for _, pos, _ in loci)
92
+ # Explicit replacements need the reference allele too; their two boundaries
93
+ # alone cannot establish the base identity on a nonstandard reference.
94
+ key = (topology, positions, inserts, row["ref"].upper() if kind == "replacement" else "")
95
+ return dict(exact_id=_digest(key), topology=topology, positions=positions,
96
+ inserted_sequences=inserts, imprecise=imprecise, assembly=assembly,
97
+ sequence_known=all(s is not None and "N" not in s.upper() for s in inserts),
98
+ breakends=loci, raw=dict(row), status="normalized")
99
+
100
+
101
+ def compare_sv_calls(rows, max_distance=100):
102
+ """Group complete reported adjacencies and retain all input records.
103
+
104
+ Parameters
105
+ ----------
106
+ rows : iterable of mappings
107
+ Fields ``call_id, caller, sample, build, chrom, pos, ref, alt`` are
108
+ required. Optional VCF ``info`` and ``end`` aid symbolic parsing.
109
+ Every input field is preserved. IDs must be unique within the input.
110
+ max_distance : int
111
+ Maximum separation at *every* corresponding breakpoint of *every*
112
+ pair in a nearby group. Deterministic greedy complete-link grouping
113
+ prevents chains from joining distant calls. Distinct inserted alleles
114
+ can share a nearby group but always have distinct exact IDs.
115
+
116
+ Returns
117
+ -------
118
+ dict
119
+ Groups and exhaustive members. Malformed, unsupported and unplaced
120
+ records remain singleton groups with an explicit reason. Counts are
121
+ reported calls, not independent molecules or independent callers.
122
+ """
123
+ if not isinstance(max_distance, int) or isinstance(max_distance, bool) or max_distance < 0:
124
+ raise ValueError("max_distance must be a non-negative integer")
125
+ normalized, seen = [], set()
126
+ for row in rows:
127
+ missing = sorted(_REQUIRED - row.keys())
128
+ if missing or not row.get("call_id"):
129
+ raise ValueError("Missing required fields: %s" % (missing or ["call_id"]))
130
+ if row["call_id"] in seen:
131
+ raise ValueError("Duplicate call_id: %s" % row["call_id"])
132
+ seen.add(row["call_id"])
133
+ try:
134
+ record = _normalize(row)
135
+ except (ValueError, TypeError, KeyError) as error:
136
+ record = dict(exact_id=_digest((row["call_id"], dict(row))), raw=dict(row),
137
+ status="unresolved", reason=str(error))
138
+ normalized.append(record)
139
+ buckets = defaultdict(list)
140
+ for record in normalized:
141
+ key = record.get("topology", ("unresolved", record["raw"]["call_id"]))
142
+ buckets[key].append(record)
143
+ groups = []
144
+ for key in sorted(buckets, key=repr):
145
+ clusters = []
146
+ for record in sorted(buckets[key], key=lambda r: (r.get("positions", ()), r["exact_id"], r["raw"]["call_id"])):
147
+ positions = record.get("positions", ())
148
+ match = None
149
+ # Earlier clusters cease to be eligible once the first breakpoint
150
+ # is too far away; keeping only active clusters bounds dense scans.
151
+ for cluster in reversed(clusters):
152
+ if positions and positions[0] - cluster["minimum"][0] > max_distance:
153
+ break
154
+ if positions and all(max(p, hi) - min(p, lo) <= max_distance
155
+ for p, lo, hi in zip(positions, cluster["minimum"], cluster["maximum"])):
156
+ match = cluster
157
+ break
158
+ if match is None:
159
+ match = dict(members=[], minimum=positions, maximum=positions)
160
+ clusters.append(match)
161
+ match["members"].append(record)
162
+ match["minimum"] = tuple(min(a, b) for a, b in zip(match["minimum"], positions))
163
+ match["maximum"] = tuple(max(a, b) for a, b in zip(match["maximum"], positions))
164
+ for cluster in clusters:
165
+ members = cluster["members"]
166
+ ids = sorted(r["raw"]["call_id"] for r in members)
167
+ group_id = _digest(ids)
168
+ exact = sorted({r["exact_id"] for r in members})
169
+ unresolved = any(r["status"] == "unresolved" for r in members)
170
+ sequence_known = all(r.get("sequence_known", False) for r in members)
171
+ imprecise = any(r.get("imprecise", False) for r in members)
172
+ status = ("unresolved" if unresolved else "nearby_candidate" if len(exact) > 1
173
+ else "same_reported_adjacency" if imprecise or not sequence_known
174
+ else "exact_reported_allele")
175
+ for member in members:
176
+ member["group_id"] = group_id
177
+ groups.append(dict(group_id=group_id, status=status, call_count=len(members),
178
+ call_ids=ids, exact_ids=exact,
179
+ callers=sorted({r["raw"]["caller"] for r in members}),
180
+ samples=sorted({r["raw"]["sample"] for r in members}),
181
+ breakpoint_min=cluster["minimum"], breakpoint_max=cluster["maximum"],
182
+ breakpoint_spread=tuple(b - a for a, b in zip(cluster["minimum"], cluster["maximum"])),
183
+ insertion_disagreement=len({r.get("inserted_sequences") for r in members}) > 1,
184
+ imprecise=imprecise, sequence_known=sequence_known))
185
+ return dict(schema_version=1, max_distance=max_distance,
186
+ groups=sorted(groups, key=lambda g: g["group_id"]),
187
+ members=sorted(normalized, key=lambda r: r["raw"]["call_id"]))
188
+
189
+
190
+ def _write_csv(path, rows):
191
+ rows = list(rows)
192
+ with path.open("w", newline="") as out:
193
+ fields = sorted({key for row in rows for key in row})
194
+ writer = csv.DictWriter(out, fieldnames=fields or ["group_id"])
195
+ writer.writeheader()
196
+ writer.writerows({key: json.dumps(value, sort_keys=True) if isinstance(value, (dict, tuple, list)) else value
197
+ for key, value in row.items()} for row in rows)
198
+
199
+
200
+ def main(argv=None):
201
+ parser = argparse.ArgumentParser(description=__doc__)
202
+ parser.add_argument("--calls", required=True, type=Path, help="CSV with the documented VCF allele/provenance columns")
203
+ parser.add_argument("--output", required=True, type=Path, help="New directory for exhaustive groups, members and manifest")
204
+ parser.add_argument("--max-distance", default=100, type=int, help="Maximum pairwise breakpoint separation in bp (default: 100)")
205
+ args = parser.parse_args(argv)
206
+ try:
207
+ with args.calls.open(newline="") as source:
208
+ result = compare_sv_calls(csv.DictReader(source), args.max_distance)
209
+ args.output.mkdir(parents=True, exist_ok=False)
210
+ _write_csv(args.output / "groups.csv", result["groups"])
211
+ _write_csv(args.output / "members.csv", result["members"])
212
+ from .version import __version__
213
+ result["provenance"] = dict(varcode_version=__version__, input_sha256=hashlib.sha256(args.calls.read_bytes()).hexdigest(),
214
+ input=str(args.calls), call_count=len(result["members"]), group_count=len(result["groups"]))
215
+ (args.output / "comparison.json").write_text(json.dumps(result, sort_keys=True) + "\n")
216
+ except (OSError, ValueError) as error:
217
+ parser.error(str(error))
218
+
219
+
220
+ if __name__ == "__main__":
221
+ main()
@@ -0,0 +1 @@
1
+ __version__ = "9.5.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: varcode
3
- Version: 9.4.2
3
+ Version: 9.5.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
@@ -77,6 +77,7 @@ tests/test_stop_codon_classification_bugs.py
77
77
  tests/test_string_helpers.py
78
78
  tests/test_structural_variant_annotator.py
79
79
  tests/test_structural_variants.py
80
+ tests/test_sv_comparison.py
80
81
  tests/test_sv_selenocysteine.py
81
82
  tests/test_sv_sequence_changes.py
82
83
  tests/test_sv_tabular_metadata.py
@@ -121,6 +122,7 @@ varcode/splice_outcomes.py
121
122
  varcode/string_helpers.py
122
123
  varcode/structural_variant.py
123
124
  varcode/sv_allele_parser.py
125
+ varcode/sv_comparison.py
124
126
  varcode/transcript_layout.py
125
127
  varcode/transcript_model.py
126
128
  varcode/ucsc_reference_names.py
@@ -1 +0,0 @@
1
- __version__ = "9.4.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
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