allelix 2.8.0__tar.gz → 2.8.1__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 (116) hide show
  1. {allelix-2.8.0/allelix.egg-info → allelix-2.8.1}/PKG-INFO +1 -1
  2. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/gwas.py +143 -8
  3. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/naming_chain.py +9 -8
  4. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/_helpers.py +4 -1
  5. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/focused.py +4 -4
  6. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/hgvs.py +5 -0
  7. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/__init__.py +51 -9
  8. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/_pipeline.py +11 -6
  9. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/diff.py +10 -0
  10. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/html.py +6 -2
  11. {allelix-2.8.0 → allelix-2.8.1}/allelix/utils/allele.py +35 -0
  12. {allelix-2.8.0 → allelix-2.8.1/allelix.egg-info}/PKG-INFO +1 -1
  13. {allelix-2.8.0 → allelix-2.8.1}/pyproject.toml +2 -2
  14. {allelix-2.8.0 → allelix-2.8.1}/LICENSE +0 -0
  15. {allelix-2.8.0 → allelix-2.8.1}/MANIFEST.in +0 -0
  16. {allelix-2.8.0 → allelix-2.8.1}/README.md +0 -0
  17. {allelix-2.8.0 → allelix-2.8.1}/allelix/__init__.py +0 -0
  18. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/__init__.py +0 -0
  19. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/_placement.py +0 -0
  20. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/_resolution.py +0 -0
  21. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/alphamissense.py +0 -0
  22. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/alt_naming.py +0 -0
  23. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/base.py +0 -0
  24. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/cadd.py +0 -0
  25. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/clinvar.py +0 -0
  26. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/gnomad.py +0 -0
  27. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/pharmgkb.py +0 -0
  28. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/rare_alleles.py +0 -0
  29. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/reference_fallback.py +0 -0
  30. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/rsid_identity.py +0 -0
  31. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/snpedia.py +0 -0
  32. {allelix-2.8.0 → allelix-2.8.1}/allelix/annotators/transcripts.py +0 -0
  33. {allelix-2.8.0 → allelix-2.8.1}/allelix/attribution.py +0 -0
  34. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/__init__.py +0 -0
  35. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/_options.py +0 -0
  36. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/analyze.py +0 -0
  37. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/config.py +0 -0
  38. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/db.py +0 -0
  39. {allelix-2.8.0 → allelix-2.8.1}/allelix/cli/utility.py +0 -0
  40. {allelix-2.8.0 → allelix-2.8.1}/allelix/compare.py +0 -0
  41. {allelix-2.8.0 → allelix-2.8.1}/allelix/config.py +0 -0
  42. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/__init__.py +0 -0
  43. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/cache.py +0 -0
  44. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/caller.py +0 -0
  45. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/coding.py +0 -0
  46. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/codons.py +0 -0
  47. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/csq.py +0 -0
  48. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/lift37_source.py +0 -0
  49. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/location.py +0 -0
  50. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/mane_source.py +0 -0
  51. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/model.py +0 -0
  52. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/mt_source.py +0 -0
  53. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/report.py +0 -0
  54. {allelix-2.8.0 → allelix-2.8.1}/allelix/consequence/terms.py +0 -0
  55. {allelix-2.8.0 → allelix-2.8.1}/allelix/data/__init__.py +0 -0
  56. {allelix-2.8.0 → allelix-2.8.1}/allelix/data/clinvar_clnsig_snapshot.yaml +0 -0
  57. {allelix-2.8.0 → allelix-2.8.1}/allelix/data/high_value_snps.yaml +0 -0
  58. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/__init__.py +0 -0
  59. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/_versions.py +0 -0
  60. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/alphamissense_loader.py +0 -0
  61. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/cache_state.py +0 -0
  62. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/cadd_loader.py +0 -0
  63. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/cpic_loader.py +0 -0
  64. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/gnomad_loader.py +0 -0
  65. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/gwas_loader.py +0 -0
  66. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/loader_utils.py +0 -0
  67. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/manager.py +0 -0
  68. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/pharmgkb_loader.py +0 -0
  69. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/rsid_identity_loader.py +0 -0
  70. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/schema.py +0 -0
  71. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/sidecar.py +0 -0
  72. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/snpedia_loader.py +0 -0
  73. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/snpedia_parser.py +0 -0
  74. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/staging.py +0 -0
  75. {allelix-2.8.0 → allelix-2.8.1}/allelix/databases/transcript_loader.py +0 -0
  76. {allelix-2.8.0 → allelix-2.8.1}/allelix/exporters/__init__.py +0 -0
  77. {allelix-2.8.0 → allelix-2.8.1}/allelix/exporters/plink.py +0 -0
  78. {allelix-2.8.0 → allelix-2.8.1}/allelix/models.py +0 -0
  79. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/__init__.py +0 -0
  80. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/_helpers.py +0 -0
  81. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/ancestrydna.py +0 -0
  82. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/base.py +0 -0
  83. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/decodeme.py +0 -0
  84. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/ftdna.py +0 -0
  85. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/ftdna_famfinder.py +0 -0
  86. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/ftdna_illumina.py +0 -0
  87. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/genesforgood.py +0 -0
  88. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/livingdna.py +0 -0
  89. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/myhappygenes.py +0 -0
  90. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/myheritage.py +0 -0
  91. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/rsidlist.py +0 -0
  92. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/split_site.py +0 -0
  93. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/twentythreeandme.py +0 -0
  94. {allelix-2.8.0 → allelix-2.8.1}/allelix/parsers/vcf.py +0 -0
  95. {allelix-2.8.0 → allelix-2.8.1}/allelix/py.typed +0 -0
  96. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/_sources.py +0 -0
  97. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/association_text.py +0 -0
  98. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/build_text.py +0 -0
  99. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/clinvar_text.py +0 -0
  100. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/high_value.py +0 -0
  101. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/json_report.py +0 -0
  102. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/methylation.py +0 -0
  103. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/terminal.py +0 -0
  104. {allelix-2.8.0 → allelix-2.8.1}/allelix/reports/vcf.py +0 -0
  105. {allelix-2.8.0 → allelix-2.8.1}/allelix/utils/__init__.py +0 -0
  106. {allelix-2.8.0 → allelix-2.8.1}/allelix/utils/build_detect.py +0 -0
  107. {allelix-2.8.0 → allelix-2.8.1}/allelix/utils/markup.py +0 -0
  108. {allelix-2.8.0 → allelix-2.8.1}/allelix/utils/numbers.py +0 -0
  109. {allelix-2.8.0 → allelix-2.8.1}/allelix/utils/plausibility.py +0 -0
  110. {allelix-2.8.0 → allelix-2.8.1}/allelix/utils/source_id.py +0 -0
  111. {allelix-2.8.0 → allelix-2.8.1}/allelix.egg-info/SOURCES.txt +0 -0
  112. {allelix-2.8.0 → allelix-2.8.1}/allelix.egg-info/dependency_links.txt +0 -0
  113. {allelix-2.8.0 → allelix-2.8.1}/allelix.egg-info/entry_points.txt +0 -0
  114. {allelix-2.8.0 → allelix-2.8.1}/allelix.egg-info/requires.txt +0 -0
  115. {allelix-2.8.0 → allelix-2.8.1}/allelix.egg-info/top_level.txt +0 -0
  116. {allelix-2.8.0 → allelix-2.8.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: allelix
3
- Version: 2.8.0
3
+ Version: 2.8.1
4
4
  Summary: Open-source genotype analysis toolkit. Format-agnostic ingestion, database-agnostic annotation, offline-first.
5
5
  Author: Allelix
6
6
  Maintainer-email: dial481 <dial481@users.noreply.github.com>
@@ -11,8 +11,9 @@ import re
11
11
  import shutil
12
12
  import sqlite3
13
13
  import zipfile
14
+ from dataclasses import replace
14
15
  from pathlib import Path
15
- from typing import TYPE_CHECKING, ClassVar
16
+ from typing import TYPE_CHECKING, ClassVar, NamedTuple
16
17
 
17
18
  from allelix.annotators.base import (
18
19
  Annotator,
@@ -45,15 +46,18 @@ from allelix.databases.manager import (
45
46
  parse_baked_version,
46
47
  )
47
48
  from allelix.databases.staging import owned_directory
48
- from allelix.models import Annotation, diploid_label
49
+ from allelix.models import NO_CALL_MARKER, Annotation, diploid_label
49
50
  from allelix.utils.allele import (
50
51
  STRAND_ABSTAIN_REASONS,
51
52
  STRAND_COMPLEMENT,
52
53
  STRAND_DIRECT,
53
54
  STRAND_FORWARD_CONFLICT,
54
55
  STRAND_NOT_IN_IDENTITY,
56
+ base_at_ref_offset,
55
57
  complement,
56
58
  forward_strand_reading,
59
+ is_single_base,
60
+ trim_allele_pair,
57
61
  )
58
62
 
59
63
  _EXCLUDED_TRAIT_CATEGORIES = frozenset(
@@ -548,8 +552,14 @@ class GWASCatalogAnnotator(Annotator):
548
552
  reading where the call does not carry them (`prune_rare_alleles`).
549
553
  """
550
554
  user_diploid = diploid_label(variant)
551
- forward = forward_alleles_at_call(variant, sites) if sites is not None else None
552
- forward = prune_rare_alleles(forward, rare.get(variant.rsid, frozenset()), variant)
555
+ proj = _project_padded_call(variant, sites)
556
+ if proj is not None:
557
+ forward = prune_rare_alleles(
558
+ proj.forward, rare.get(variant.rsid, frozenset()), proj.prune_variant
559
+ )
560
+ else:
561
+ forward = forward_alleles_at_call(variant, sites) if sites is not None else None
562
+ forward = prune_rare_alleles(forward, rare.get(variant.rsid, frozenset()), variant)
553
563
  conflicted = _forward_conflicts(rows, forward if sites is not None else None, sites)
554
564
  for row in rows:
555
565
  (
@@ -582,7 +592,12 @@ class GWASCatalogAnnotator(Annotator):
582
592
  risk_allele = self._forward_risk_allele(risk_allele, forward)
583
593
  if risk_allele is None:
584
594
  continue
585
- if variant.allele1 != risk_allele and variant.allele2 != risk_allele:
595
+ if proj is not None:
596
+ if risk_allele not in (proj.base1, proj.base2):
597
+ continue
598
+ elif (variant.ref_from_input and len(variant.ref or "") > 1) or (
599
+ variant.allele1 != risk_allele and variant.allele2 != risk_allele
600
+ ):
586
601
  continue
587
602
  mag = _magnitude(p_value, or_beta, ci_text)
588
603
  risk_note = ""
@@ -613,6 +628,16 @@ class GWASCatalogAnnotator(Annotator):
613
628
  references.append(f"gwas:{study_accession}")
614
629
 
615
630
  direction, measure = _effect_direction(risk_allele, or_beta, ci_text)
631
+ if proj is not None:
632
+ locus = (variant_locus(variant)[0], proj.snp_pos)
633
+ locus_ref: str | None = proj.ref_base
634
+ carried = tuple(b for b in (proj.base1, proj.base2) if b is not None)
635
+ record_key = _padded_record_key(variant, proj, risk_allele)
636
+ else:
637
+ locus = variant_locus(variant)
638
+ locus_ref = variant.ref
639
+ carried = (variant.allele1, variant.allele2)
640
+ record_key = None
616
641
  yield Annotation(
617
642
  source=self.name,
618
643
  rsid=variant.rsid,
@@ -626,9 +651,10 @@ class GWASCatalogAnnotator(Annotator):
626
651
  condition=clean_trait,
627
652
  gene=gene or "",
628
653
  alt=risk_allele or "",
629
- locus_ref=variant.ref,
630
- carried_alleles=(variant.allele1, variant.allele2),
631
- locus=variant_locus(variant),
654
+ locus_ref=locus_ref,
655
+ carried_alleles=carried,
656
+ locus=locus,
657
+ record_key=record_key,
632
658
  is_must_include=variant.rsid in _MUST_INCLUDE_RSIDS,
633
659
  trait=clean_trait,
634
660
  p_value=p_value,
@@ -638,6 +664,115 @@ class GWASCatalogAnnotator(Annotator):
638
664
  )
639
665
 
640
666
 
667
+ class _PaddedProjection(NamedTuple):
668
+ """A padded VCF call projected onto its rsID's single-base SNP position."""
669
+
670
+ snp_pos: int
671
+ ref_base: str
672
+ base1: str | None
673
+ base2: str | None
674
+ forward: frozenset[str] | None
675
+ prune_variant: Variant
676
+
677
+
678
+ def _project_padded_call(
679
+ variant: Variant, sites: dict[str, ForwardSite] | None
680
+ ) -> _PaddedProjection | None:
681
+ """Project a padded VCF call onto the rsID's single-base SNP position, or None.
682
+
683
+ Applies only to VCF calls (``ref_from_input=True``) whose REF or carried alleles
684
+ carry padding/indel bases (length > 1). Plain single-base calls, array calls, and
685
+ calls whose rsID is not placed inside the record's REF span return None so the
686
+ standard path handles them unchanged.
687
+ """
688
+ if (
689
+ not variant.ref_from_input
690
+ or not variant.ref
691
+ or variant.position <= 0
692
+ or (len(variant.ref) <= 1 and len(variant.allele1) <= 1 and len(variant.allele2) <= 1)
693
+ ):
694
+ return None
695
+ if sites is not None:
696
+ site = sites.get(variant.rsid)
697
+ if site is None:
698
+ return None
699
+ chrom, pos, alleles = site
700
+ if variant_locus(variant)[0] != chrom or not (
701
+ variant.position <= pos < variant.position + len(variant.ref)
702
+ ):
703
+ return None
704
+ snp_pos = pos
705
+ forward: frozenset[str] | None = alleles
706
+ else:
707
+ inferred = _infer_padded_snp_pos(variant)
708
+ if inferred is None:
709
+ return None
710
+ snp_pos = inferred
711
+ forward = None
712
+ offset = snp_pos - variant.position
713
+ ref_base = variant.ref[offset].upper()
714
+ base1 = base_at_ref_offset(variant.allele1, variant.ref, offset)
715
+ base2 = base_at_ref_offset(variant.allele2, variant.ref, offset)
716
+ prune_variant = replace(
717
+ variant,
718
+ position=snp_pos,
719
+ ref=ref_base,
720
+ allele1=base1 or NO_CALL_MARKER,
721
+ allele2=base2 or NO_CALL_MARKER,
722
+ )
723
+ return _PaddedProjection(
724
+ snp_pos=snp_pos,
725
+ ref_base=ref_base,
726
+ base1=base1,
727
+ base2=base2,
728
+ forward=forward,
729
+ prune_variant=prune_variant,
730
+ )
731
+
732
+
733
+ def _infer_padded_snp_pos(variant: Variant) -> int | None:
734
+ """Infer a single-base SNP position for a padded call when no identity table is wired.
735
+
736
+ For ``len(ref) == 1`` (an SNV beside an insertion), offset 0 is the only reference
737
+ base. For ``len(ref) > 1``, infer the unique single-base SNV position from carried
738
+ non-reference alleles via ``trim_allele_pair``; return None when no SNV is carried
739
+ or two carried SNVs sit at different offsets (avoiding false matches on a left
740
+ anchor base).
741
+ """
742
+ ref = variant.ref
743
+ if not ref:
744
+ return None
745
+ if len(ref) == 1:
746
+ return variant.position
747
+ snv_positions: set[int] = set()
748
+ for allele in (variant.allele1, variant.allele2):
749
+ if not allele or allele in (NO_CALL_MARKER, ref):
750
+ continue
751
+ pos, t_ref, t_alt = trim_allele_pair(variant.position, ref, allele)
752
+ if is_single_base(t_ref) and is_single_base(t_alt):
753
+ snv_positions.add(pos)
754
+ if len(snv_positions) != 1:
755
+ return None
756
+ return next(iter(snv_positions))
757
+
758
+
759
+ def _padded_record_key(
760
+ variant: Variant, proj: _PaddedProjection, risk_allele: str | None
761
+ ) -> tuple[str, int, str, str] | None:
762
+ """Record key linking a projected padded GWAS finding back to its input VCF record."""
763
+ if variant.ref is None:
764
+ return None
765
+ if risk_allele and risk_allele != proj.ref_base:
766
+ for raw, base in ((variant.allele1, proj.base1), (variant.allele2, proj.base2)):
767
+ if base == risk_allele and raw != variant.ref:
768
+ return (variant.chromosome, variant.position, variant.ref, raw)
769
+ if proj.snp_pos != variant.position:
770
+ # Keep the input record's position for ploidy/site attribution without
771
+ # matching an indel ALT in --vcf-out when the risk allele is REF or unknown.
772
+ return (variant.chromosome, variant.position, variant.ref, variant.ref)
773
+ return None
774
+
775
+
641
776
  def _trait_group(mapped_trait_uri: str | None, trait: str) -> tuple[str, str]:
642
777
  """One rsID's vote group (`gwas_loader._vote_group`): its exact URI, else its exact trait."""
643
778
  return ("uri", mapped_trait_uri) if mapped_trait_uri else ("trait", trait)
@@ -8,9 +8,10 @@ every genotype and FILTER. Its inputs are an ALT's facts (``AltFacts``) and
8
8
  the identity table's placements of the rsIDs involved.
9
9
 
10
10
  0. Rejection, per candidate and ALT: an rsID is rejected for an ALT when the
11
- identity table places it (on this build) on another locus, or on another
12
- ALT of the site, and not on this ALT. An rsID the table does not place is
13
- not rejected. A rejected written or listed rsID names nothing for that
11
+ identity table places it (on this build) only at other loci (at no
12
+ placement this locus), or on another ALT of the site, and not on this ALT.
13
+ An rsID the table does not place, or places here on an allele no record of
14
+ the site carries, is not rejected. A rejected written or listed rsID names nothing for that
14
15
  ALT, ClinVar's own row for it included. A ClinVar row's own rsID that the
15
16
  file did not write keeps naming its ALT only where the table places it on
16
17
  another ALT of the site; placed at another locus, it names nothing
@@ -93,18 +94,18 @@ def rsid_order(rsid: str) -> tuple[int, int, str]:
93
94
  def placed_elsewhere(
94
95
  places: frozenset[Allele] | None, allele: Allele, site_alleles: set[Allele]
95
96
  ) -> bool:
96
- """Step 0: an rsID placed on another locus or another ALT of the site, and not on this ALT.
97
+ """Step 0: an rsID placed only at other loci or on another ALT of the site, not on this ALT.
97
98
 
98
99
  Only a single-base change against single-base placements is judged (an
99
- indel's identity is unavailable, ADR-0061). A placement only on another
100
- allele at this locus, one no record of the site has, rejects nothing; nor
101
- does an rsID the table does not place.
100
+ indel's identity is unavailable, ADR-0061). An rsID placed at this locus on
101
+ another allele not present on the site (with or without an extra placement
102
+ at another locus) rejects nothing; nor does an rsID the table does not place.
102
103
  """
103
104
  if len(allele[2]) != 1 or len(allele[3]) != 1:
104
105
  return False
105
106
  if not places or allele in places:
106
107
  return False
107
- return any(p[:2] != allele[:2] or p in site_alleles for p in places)
108
+ return _foreign_to(places, allele) or any(p in site_alleles for p in places)
108
109
 
109
110
 
110
111
  def _foreign_to(places: frozenset[Allele] | None, allele: Allele) -> bool:
@@ -1352,7 +1352,10 @@ def _run_analysis_command(
1352
1352
  "(see warnings on stderr)."
1353
1353
  )
1354
1354
  for line in (
1355
- vcf_quality_lines(result.vcf_quality)
1355
+ vcf_quality_lines(
1356
+ result.vcf_quality,
1357
+ sources_ran={name for name, _ver in result.annotators_used},
1358
+ )
1356
1359
  + array_quality_lines(result.array_quality, result.probe_classes)
1357
1360
  + placement_lines(result.placement)
1358
1361
  ):
@@ -48,8 +48,8 @@ def _refuse_explicit(ctx: click.Context, param: click.Parameter, value: object)
48
48
  option = param.opts[0]
49
49
  raise click.UsageError(
50
50
  f"{option} never applies to pharmacogenomics: its report shows only ClinPGx "
51
- "findings, so no GWAS Catalog or SNPedia finding can reach it. Leave the "
52
- "option out, or use analyze for those sources.",
51
+ "findings, so ClinVar, GWAS Catalog, and SNPedia options cannot change it. "
52
+ "Leave the option out, or use analyze for those sources.",
53
53
  ctx,
54
54
  )
55
55
  return value
@@ -176,7 +176,7 @@ def methylation(
176
176
  @_OUTPUT_OPT
177
177
  @_REPORT_FORMAT_OPT
178
178
  @_BUILD_OPT
179
- @_INCLUDE_BENIGN_OPT
179
+ @_not_for_pharma("--include-benign", False)
180
180
  @_not_for_pharma("--gwas-min-magnitude", 9.0)
181
181
  @_not_for_pharma("--snpedia-min-magnitude", 2.0)
182
182
  @_not_for_pharma("--include-gwas", False)
@@ -213,7 +213,7 @@ def pharmacogenomics(
213
213
  ) -> None:
214
214
  """Pharmacogenomics-focused report (annotations from ClinPGx-style sources).
215
215
 
216
- The GWAS Catalog and SNPedia options of analyze and methylation are
216
+ ClinVar, GWAS Catalog, and SNPedia options of analyze and methylation are
217
217
  refused here: the report keeps ClinPGx findings only, so they never
218
218
  change it.
219
219
  """
@@ -792,6 +792,11 @@ def unchanged_protein_over_stop(codons: Codons, terms: set[str]) -> bool:
792
792
  s, e = codons.cds_start, codons.cds_end
793
793
  if s is None or e is None or codons.t.codon_table != 1:
794
794
  return False
795
+ # Same-length substitutions never trigger VEP's partial-codon/rebuilt-stop
796
+ # indel artifacts; guarding them out prevents downgrading VEP's stop_gained
797
+ # (selenocysteine) or start_lost (initial_met) to stop_retained_variant (LOW).
798
+ if not codons.insertion and len(codons.new) == e - s + 1:
799
+ return False
795
800
  t = codons.t
796
801
  reference = _to_stop(_translate(codons.cds, t), 1)
797
802
  edited = _to_stop(
@@ -14,7 +14,7 @@ from pathlib import Path
14
14
  from typing import TYPE_CHECKING
15
15
 
16
16
  if TYPE_CHECKING:
17
- from collections.abc import Iterator
17
+ from collections.abc import Collection, Iterator
18
18
  from typing import BinaryIO, TextIO
19
19
 
20
20
  from allelix.annotators._placement import PlacementStats
@@ -342,11 +342,17 @@ def atomic_write_text(
342
342
  staged.publish()
343
343
 
344
344
 
345
- def vcf_quality_lines(stats: VcfQualityStats | None) -> list[str]:
345
+ def vcf_quality_lines(
346
+ stats: VcfQualityStats | None,
347
+ *,
348
+ sources_ran: Collection[str] | None = None,
349
+ ) -> list[str]:
346
350
  """Plain-language lines describing what the VCF quality gate did.
347
351
 
348
352
  Shared by the terminal, HTML and CLI output so every surface says the
349
353
  same thing. Empty when the input was not a VCF or nothing was gated.
354
+ When ``sources_ran`` is provided, half-call notes name only the active
355
+ single-allele sources (ClinVar, GWAS Catalog) that actually ran.
350
356
  """
351
357
  if stats is None:
352
358
  return []
@@ -378,19 +384,55 @@ def vcf_quality_lines(stats: VcfQualityStats | None) -> list[str]:
378
384
  "allele is not assessed; a passing real ALT paired with it is assessed as a half "
379
385
  "call. The JSON report lists their positions."
380
386
  )
387
+ ran_single = (
388
+ ["ClinVar", "the GWAS Catalog"]
389
+ if sources_ran is None
390
+ else [
391
+ label
392
+ for key, label in (("clinvar", "ClinVar"), ("gwas", "the GWAS Catalog"))
393
+ if key in sources_ran
394
+ ]
395
+ )
381
396
  if stats.half_calls:
397
+ if len(ran_single) == 2:
398
+ detail = (
399
+ "ClinVar and the GWAS Catalog assessed the called allele; "
400
+ "ClinPGx and SNPedia, which need both alleles, did not."
401
+ )
402
+ elif len(ran_single) == 1:
403
+ detail = (
404
+ f"{ran_single[0]} assessed the called allele; "
405
+ "ClinPGx and SNPedia, which need both alleles, did not."
406
+ )
407
+ else:
408
+ detail = (
409
+ "no active source in this run assesses single-allele half calls; "
410
+ "ClinPGx and SNPedia need both alleles."
411
+ )
382
412
  lines.append(
383
- f"{stats.half_calls:,} half call(s) with one allele not called (such as ./1): "
384
- "ClinVar and the GWAS Catalog assessed the called allele; ClinPGx and "
385
- "SNPedia, which need both alleles, did not."
413
+ f"{stats.half_calls:,} half call(s) with one allele not called (such as ./1): {detail}"
386
414
  )
387
415
  if stats.split_site_half_calls:
416
+ if len(ran_single) == 2:
417
+ split_detail = (
418
+ "each is given only to the sources that read one allele, ClinVar and the GWAS "
419
+ "Catalog, to assess; ClinPGx and SNPedia, which need the genotype, are not "
420
+ "given it."
421
+ )
422
+ elif len(ran_single) == 1:
423
+ split_detail = (
424
+ f"each is given only to {ran_single[0]}, which reads one allele, to assess; "
425
+ "ClinPGx and SNPedia, which need the genotype, are not given it."
426
+ )
427
+ else:
428
+ split_detail = (
429
+ "no active source in this run assesses single-allele half calls; "
430
+ "ClinPGx and SNPedia need the full genotype."
431
+ )
388
432
  lines.append(
389
433
  f"{stats.split_site_half_calls:,} split-site half call(s), the called alleles of "
390
- "sites written over several VCF records that agree but are not one exact pair: "
391
- "each is given only to the sources that read one allele, ClinVar and the GWAS "
392
- "Catalog where they run, to assess; ClinPGx and SNPedia, which need the "
393
- "genotype, are not given it."
434
+ f"sites written over several VCF records that agree but are not one exact pair: "
435
+ f"{split_detail}"
394
436
  )
395
437
  if stats.trimmed_matches:
396
438
  lines.append(
@@ -2107,7 +2107,7 @@ def _identity_conflict_warning(
2107
2107
  A call whose name the identity table places at another locus reaches no source. An ALT of a
2108
2108
  joined or merged call whose own name it places at another locus is withheld alone; the
2109
2109
  call's other ALT keeps its findings. A written name dropped because the table places it on
2110
- another ALT or allele at the call's position leaves the call, and its findings, without it.
2110
+ another ALT at the call's position leaves the call, and its findings, without it.
2111
2111
  """
2112
2112
  if not withheld and not dropped and not partial:
2113
2113
  return None
@@ -2126,7 +2126,7 @@ def _identity_conflict_warning(
2126
2126
  if dropped:
2127
2127
  parts.append(
2128
2128
  f"{dropped} written rsID(s) were dropped because the rsID identity table places "
2129
- f"them on another ALT or allele at the same position on {build}; their calls were "
2129
+ f"them on another ALT at the same position on {build}; their calls were "
2130
2130
  "still annotated, without the rsID."
2131
2131
  )
2132
2132
  parts.append("A stale rsID, or coordinates converted from another build, usually causes this.")
@@ -2900,10 +2900,14 @@ def run_analysis(
2900
2900
  track_seeds = needs_late_seeds(decision)
2901
2901
  mt_skipped = 0
2902
2902
  # Coords for rsIDs the pipeline resolved on the fly (real-world VCFs from
2903
- # variant callers emit ID=.). Lets the enrichment phase fall
2904
- # back to position-keyed gnomAD / AlphaMissense lookups for resolved
2905
- # rsIDs that don't appear in those caches' rsid index.
2906
- resolved_coords: dict[str, tuple[str, int, str, str]] = {}
2903
+ # variant callers emit ID=.). Only needed to populate
2904
+ # ``VcfWriteInputs.recovered_rsids`` for the annotated-VCF writer
2905
+ # (enrichment uses ``_enrichment_keys`` per ADR-0040); omitting it on
2906
+ # HTML/JSON runs avoids retaining millions of resolved entries in memory
2907
+ # on 30x WGS inputs.
2908
+ resolved_coords: dict[str, tuple[str, int, str, str]] | None = (
2909
+ {} if collect_vcf_write_inputs else None
2910
+ )
2907
2911
  # annotation dict keyed by (chrom, pos, ref, alt) for the
2908
2912
  # annotated-VCF writer. Populated per batch inside ``_flush`` when
2909
2913
  # ``collect_vcf_write_inputs`` is True. Values are references to the
@@ -3505,6 +3509,7 @@ def run_analysis(
3505
3509
  # (which reaches into the annotator registry for attribution).
3506
3510
  from allelix.reports.vcf import VcfWriteInputs as _VcfWriteInputs
3507
3511
 
3512
+ assert resolved_coords is not None
3508
3513
  vcf_recovered_rsids = {
3509
3514
  (chrom, pos, ref, alt): rsid
3510
3515
  for rsid, (chrom, pos, ref, alt) in resolved_coords.items()
@@ -204,6 +204,16 @@ def load_previous_report(path: Path) -> dict:
204
204
  msg = f"{path.name} has no 'annotations' key."
205
205
  raise ValueError(msg)
206
206
 
207
+ input_meta = data.get("input")
208
+ if input_meta is not None:
209
+ if not isinstance(input_meta, dict):
210
+ msg = f"{path.name}: 'input' must be an object, got {type(input_meta).__name__}."
211
+ raise ValueError(msg)
212
+ input_file = input_meta.get("file")
213
+ if input_file is not None and not isinstance(input_file, str):
214
+ msg = f"{path.name}: 'input.file' must be a string, got {type(input_file).__name__}."
215
+ raise ValueError(msg)
216
+
207
217
  # validate per-annotation entries. `compute_diff` indexes
208
218
  # `d["source"]` / `d["rsid"]` unguarded; a baseline with the right
209
219
  # top-level shape but malformed entries (annotations as a dict,
@@ -232,6 +232,7 @@ a { color: var(--link); }
232
232
  background: var(--notice-warn-bg, #fff3e0);
233
233
  border-left: 4px solid var(--notice-warn-border, #e65100);
234
234
  padding: 1rem; margin: 1.5rem 0; border-radius: 4px; font-size: .95rem;
235
+ overflow-wrap: anywhere;
235
236
  }
236
237
  .notice table.panel-coverage {
237
238
  margin-top: .75rem; border-collapse: collapse; font-size: .85rem;
@@ -265,7 +266,7 @@ details.education[open] summary { margin-bottom: .5rem; }
265
266
  font-size: .75rem; color: var(--text-muted);
266
267
  text-transform: uppercase; letter-spacing: .05em;
267
268
  }
268
- .card .value { font-size: 1.2rem; font-weight: 600; }
269
+ .card .value { font-size: 1.2rem; font-weight: 600; overflow-wrap: anywhere; }
269
270
  .card .build-source { font-size: .75rem; font-weight: 400; color: var(--text-muted); }
270
271
  .card-bad .value { color: #c62828; }
271
272
  .card-good .value { color: #2e7d32; }
@@ -1817,7 +1818,10 @@ def render_html(
1817
1818
  )
1818
1819
 
1819
1820
  input_quality = (
1820
- vcf_quality_lines(result.vcf_quality)
1821
+ vcf_quality_lines(
1822
+ result.vcf_quality,
1823
+ sources_ran={name for name, _ver in result.annotators_used},
1824
+ )
1821
1825
  + array_quality_lines(result.array_quality, result.probe_classes)
1822
1826
  + placement_lines(result.placement)
1823
1827
  )
@@ -170,6 +170,41 @@ def trim_allele_pair(position: int, ref: str, alt: str) -> tuple[int, str, str]:
170
170
  return position, ref, alt
171
171
 
172
172
 
173
+ def base_at_ref_offset(allele: str, ref: str, offset: int) -> str | None:
174
+ """The single base ``allele`` carries at ``offset`` within ``ref``, or None.
175
+
176
+ ``allele`` and ``ref`` are written from the same VCF POS. Non-base alleles
177
+ (empty, ``-``, ``*``, symbolic tags) and out-of-range offsets return None.
178
+ Equal-length alleles (REF, padded SNVs, MNVs) carry ``allele[offset]``.
179
+ Unequal-length alleles (indels) are trimmed suffix-first, then prefix,
180
+ matching ``trim_allele_pair`` and VCF left-alignment: bases in the unchanged
181
+ prefix or suffix keep their base, while bases inside the deleted or
182
+ replaced span return None.
183
+ """
184
+ if not allele or not ref or not 0 <= offset < len(ref):
185
+ return None
186
+ allele_u, ref_u = allele.upper(), ref.upper()
187
+ if not (all(b in _BASES for b in allele_u) and all(b in _BASES for b in ref_u)):
188
+ return None
189
+ if len(allele_u) == len(ref_u):
190
+ return allele_u[offset]
191
+ # Trim common suffix first while keeping at least one anchor base on each
192
+ # side, matching trim_allele_pair (VCF left-alignment).
193
+ suffix = 0
194
+ max_suffix = min(len(allele_u), len(ref_u)) - 1
195
+ while suffix < max_suffix and allele_u[-1 - suffix] == ref_u[-1 - suffix]:
196
+ suffix += 1
197
+ prefix = 0
198
+ max_prefix = min(len(allele_u), len(ref_u)) - suffix
199
+ while prefix < max_prefix and allele_u[prefix] == ref_u[prefix]:
200
+ prefix += 1
201
+ if offset < prefix:
202
+ return allele_u[offset]
203
+ if offset >= len(ref_u) - suffix:
204
+ return allele_u[offset - len(ref_u) + len(allele_u)]
205
+ return None
206
+
207
+
173
208
  def resolve_rsid_at_locus(
174
209
  variant_ref: str | None,
175
210
  allele1: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: allelix
3
- Version: 2.8.0
3
+ Version: 2.8.1
4
4
  Summary: Open-source genotype analysis toolkit. Format-agnostic ingestion, database-agnostic annotation, offline-first.
5
5
  Author: Allelix
6
6
  Maintainer-email: dial481 <dial481@users.noreply.github.com>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "allelix"
7
- version = "2.8.0"
7
+ version = "2.8.1"
8
8
  description = "Open-source genotype analysis toolkit. Format-agnostic ingestion, database-agnostic annotation, offline-first."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -108,7 +108,7 @@ convention = "google"
108
108
 
109
109
  [tool.pytest.ini_options]
110
110
  testpaths = ["tests"]
111
- addopts = "-v --strict-markers --tb=short --cov=allelix --cov-branch --cov-report=term-missing --cov-fail-under=92.5"
111
+ addopts = "-v --strict-markers --tb=short -n auto -m 'not slow and not integration and not bundle'"
112
112
  markers = [
113
113
  "slow: marks tests that download databases or process large files",
114
114
  "integration: marks end-to-end pipeline tests",
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