allelix 2.6.2__tar.gz → 2.6.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. {allelix-2.6.2/allelix.egg-info → allelix-2.6.3}/PKG-INFO +1 -1
  2. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/utility.py +21 -12
  3. {allelix-2.6.2 → allelix-2.6.3}/allelix/compare.py +4 -2
  4. {allelix-2.6.2 → allelix-2.6.3}/allelix/exporters/plink.py +31 -8
  5. {allelix-2.6.2 → allelix-2.6.3}/allelix/models.py +9 -0
  6. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/_helpers.py +42 -0
  7. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/ancestrydna.py +1 -0
  8. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/decodeme.py +4 -0
  9. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/ftdna_famfinder.py +4 -0
  10. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/ftdna_illumina.py +4 -0
  11. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/vcf.py +13 -1
  12. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/html.py +4 -1
  13. {allelix-2.6.2 → allelix-2.6.3}/allelix/utils/build_detect.py +9 -3
  14. {allelix-2.6.2 → allelix-2.6.3/allelix.egg-info}/PKG-INFO +1 -1
  15. {allelix-2.6.2 → allelix-2.6.3}/pyproject.toml +1 -1
  16. {allelix-2.6.2 → allelix-2.6.3}/LICENSE +0 -0
  17. {allelix-2.6.2 → allelix-2.6.3}/MANIFEST.in +0 -0
  18. {allelix-2.6.2 → allelix-2.6.3}/README.md +0 -0
  19. {allelix-2.6.2 → allelix-2.6.3}/allelix/__init__.py +0 -0
  20. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/__init__.py +0 -0
  21. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/_placement.py +0 -0
  22. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/_resolution.py +0 -0
  23. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/alphamissense.py +0 -0
  24. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/base.py +0 -0
  25. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/cadd.py +0 -0
  26. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/clinvar.py +0 -0
  27. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/gnomad.py +0 -0
  28. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/gwas.py +0 -0
  29. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/pharmgkb.py +0 -0
  30. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/reference_fallback.py +0 -0
  31. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/rsid_identity.py +0 -0
  32. {allelix-2.6.2 → allelix-2.6.3}/allelix/annotators/snpedia.py +0 -0
  33. {allelix-2.6.2 → allelix-2.6.3}/allelix/attribution.py +0 -0
  34. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/__init__.py +0 -0
  35. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/_helpers.py +0 -0
  36. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/_options.py +0 -0
  37. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/analyze.py +0 -0
  38. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/config.py +0 -0
  39. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/db.py +0 -0
  40. {allelix-2.6.2 → allelix-2.6.3}/allelix/cli/focused.py +0 -0
  41. {allelix-2.6.2 → allelix-2.6.3}/allelix/config.py +0 -0
  42. {allelix-2.6.2 → allelix-2.6.3}/allelix/data/__init__.py +0 -0
  43. {allelix-2.6.2 → allelix-2.6.3}/allelix/data/clinvar_clnsig_snapshot.yaml +0 -0
  44. {allelix-2.6.2 → allelix-2.6.3}/allelix/data/high_value_snps.yaml +0 -0
  45. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/__init__.py +0 -0
  46. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/_versions.py +0 -0
  47. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/alphamissense_loader.py +0 -0
  48. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/cache_state.py +0 -0
  49. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/cadd_loader.py +0 -0
  50. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/cpic_loader.py +0 -0
  51. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/gnomad_loader.py +0 -0
  52. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/gwas_loader.py +0 -0
  53. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/loader_utils.py +0 -0
  54. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/manager.py +0 -0
  55. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/pharmgkb_loader.py +0 -0
  56. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/rsid_identity_loader.py +0 -0
  57. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/schema.py +0 -0
  58. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/snpedia_loader.py +0 -0
  59. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/snpedia_parser.py +0 -0
  60. {allelix-2.6.2 → allelix-2.6.3}/allelix/databases/staging.py +0 -0
  61. {allelix-2.6.2 → allelix-2.6.3}/allelix/exporters/__init__.py +0 -0
  62. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/__init__.py +0 -0
  63. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/base.py +0 -0
  64. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/ftdna.py +0 -0
  65. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/genesforgood.py +0 -0
  66. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/livingdna.py +0 -0
  67. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/myhappygenes.py +0 -0
  68. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/myheritage.py +0 -0
  69. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/rsidlist.py +0 -0
  70. {allelix-2.6.2 → allelix-2.6.3}/allelix/parsers/twentythreeandme.py +0 -0
  71. {allelix-2.6.2 → allelix-2.6.3}/allelix/py.typed +0 -0
  72. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/__init__.py +0 -0
  73. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/_pipeline.py +0 -0
  74. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/_sources.py +0 -0
  75. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/association_text.py +0 -0
  76. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/build_text.py +0 -0
  77. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/clinvar_text.py +0 -0
  78. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/diff.py +0 -0
  79. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/high_value.py +0 -0
  80. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/json_report.py +0 -0
  81. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/methylation.py +0 -0
  82. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/terminal.py +0 -0
  83. {allelix-2.6.2 → allelix-2.6.3}/allelix/reports/vcf.py +0 -0
  84. {allelix-2.6.2 → allelix-2.6.3}/allelix/utils/__init__.py +0 -0
  85. {allelix-2.6.2 → allelix-2.6.3}/allelix/utils/allele.py +0 -0
  86. {allelix-2.6.2 → allelix-2.6.3}/allelix/utils/markup.py +0 -0
  87. {allelix-2.6.2 → allelix-2.6.3}/allelix/utils/plausibility.py +0 -0
  88. {allelix-2.6.2 → allelix-2.6.3}/allelix.egg-info/SOURCES.txt +0 -0
  89. {allelix-2.6.2 → allelix-2.6.3}/allelix.egg-info/dependency_links.txt +0 -0
  90. {allelix-2.6.2 → allelix-2.6.3}/allelix.egg-info/entry_points.txt +0 -0
  91. {allelix-2.6.2 → allelix-2.6.3}/allelix.egg-info/requires.txt +0 -0
  92. {allelix-2.6.2 → allelix-2.6.3}/allelix.egg-info/top_level.txt +0 -0
  93. {allelix-2.6.2 → allelix-2.6.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: allelix
3
- Version: 2.6.2
3
+ Version: 2.6.3
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>
@@ -24,7 +24,7 @@ from allelix.cli._options import (
24
24
  )
25
25
  from allelix.databases import resolve_data_dir
26
26
  from allelix.models import NO_CALL_MARKER
27
- from allelix.parsers._helpers import normalize_chromosome
27
+ from allelix.parsers._helpers import normalize_chromosome, summary_chromosome
28
28
  from allelix.reports._pipeline import BuildDiagnostics, UnusableInputError
29
29
  from allelix.reports.build_text import short_source
30
30
  from allelix.utils.build_detect import (
@@ -98,7 +98,10 @@ def stats(
98
98
  het += 1
99
99
  else:
100
100
  hom += 1
101
- chrom_counts[variant.chromosome] = chrom_counts.get(variant.chromosome, 0) + 1
101
+ # A standard chromosome under its lookup name (23 and X are one
102
+ # row); any other contig as the reader gave it.
103
+ chrom = summary_chromosome(variant.chromosome)
104
+ chrom_counts[chrom] = chrom_counts.get(chrom, 0) + 1
102
105
  finally:
103
106
  _helpers._unwire_parser_logging(counter, stderr_handler, snapshot)
104
107
 
@@ -396,7 +399,9 @@ def _settled(
396
399
  best = min(places, key=lambda locus: (rank.get(locus[0], len(rank)), locus[1]))
397
400
  # A later call standing at ``best`` ties on position and loses on line.
398
401
  return any(
399
- best[1] in _stands_at(v) and v.chromosome == best[0] and not v.is_no_call
402
+ best[1] in _stands_at(v)
403
+ and normalize_chromosome(v.chromosome) == best[0]
404
+ and not v.is_no_call
400
405
  for v in candidates
401
406
  )
402
407
 
@@ -429,12 +434,14 @@ def _extract_choice(
429
434
  # A call stands at its POS and, padded, at its trimmed site (ADR-0061);
430
435
  # at a placement it ranks by that placement, so a padded call and the
431
436
  # same call written trimmed tie and the earlier record wins.
432
- standing = [(v.chromosome, at) for at in _stands_at(v) if (v.chromosome, at) in places]
437
+ # Placements and the contig rank use the lookup name (23 is X).
438
+ name = normalize_chromosome(v.chromosome)
439
+ standing = [(name, at) for at in _stands_at(v) if (name, at) in places]
433
440
  mapped = bool(standing)
434
441
  chrom, pos = (
435
442
  min(standing, key=lambda locus: (rank.get(locus[0], len(rank)), locus[1]))
436
443
  if mapped
437
- else (v.chromosome, v.position)
444
+ else (name, v.position)
438
445
  )
439
446
  line = v.record_index if v.record_index is not None else 0
440
447
  if not rank:
@@ -1156,6 +1163,7 @@ def export_plink_cmd(
1156
1163
  coded_against,
1157
1164
  default_plink_prefix,
1158
1165
  export_plink,
1166
+ plink_chromosome,
1159
1167
  plink_paths,
1160
1168
  plink_record_key,
1161
1169
  plink_writable,
@@ -1206,13 +1214,14 @@ def export_plink_cmd(
1206
1214
  diagnostics = resolved_stream.build_diagnostics()
1207
1215
  _helpers._emit_build_notices(diagnostics)
1208
1216
 
1209
- # Sort by chromosome then position so the .bim has contiguous
1210
- # chromosome blocks — PLINK1.9 rejects split chromosomes.
1211
- chrom_order = {str(i): i for i in range(1, 23)}
1212
- chrom_order.update({"X": 23, "Y": 24, "XY": 25, "MT": 26})
1213
- variants.sort(
1214
- key=lambda v: (chrom_order.get(v.chromosome, 99), v.chromosome, v.position),
1215
- )
1217
+ # Sort by the chromosome code the .bim gets, then position, so the .bim
1218
+ # has contiguous chromosome blocks — PLINK1.9 rejects split chromosomes.
1219
+ def bim_order(v: Variant) -> tuple[int, str, int]:
1220
+ code = plink_chromosome(v)
1221
+ rank = int(code) if code.isdigit() and 1 <= int(code) <= 26 else 99
1222
+ return rank, code, v.position
1223
+
1224
+ variants.sort(key=bim_order)
1216
1225
 
1217
1226
  # Coordinates, REF/ALT and genotype coding all come from one build.
1218
1227
  grch38 = effective_build == "GRCh38"
@@ -15,7 +15,7 @@ from collections import Counter
15
15
  from dataclasses import dataclass, field
16
16
  from typing import TYPE_CHECKING
17
17
 
18
- from allelix.parsers._helpers import normalize_chromosome
18
+ from allelix.parsers._helpers import normalize_chromosome, summary_chromosome
19
19
  from allelix.parsers.vcf import _REFERENCE_BLOCK_ALTS
20
20
  from allelix.utils.allele import complement, is_strand_ambiguous
21
21
  from allelix.utils.build_detect import SUPPORTED_OVERRIDES
@@ -279,7 +279,9 @@ def compare_variants(
279
279
  o1 = map1[key1]
280
280
  o2 = map2[key2]
281
281
 
282
- chrom = o1.variant.chromosome
282
+ # A standard chromosome under its lookup name, so 23 in one file and X
283
+ # in the other count together; any other contig as the reader gave it.
284
+ chrom = summary_chromosome(o1.variant.chromosome)
283
285
  if chrom not in chrom_counts:
284
286
  chrom_counts[chrom] = Counter()
285
287
 
@@ -7,6 +7,8 @@ from __future__ import annotations
7
7
  import contextlib
8
8
  from typing import TYPE_CHECKING, NamedTuple
9
9
 
10
+ from allelix.annotators.base import variant_locus
11
+ from allelix.parsers._helpers import is_par_code, normalize_chromosome
10
12
  from allelix.utils.allele import (
11
13
  STRAND_COMPLEMENT,
12
14
  STRAND_DIRECT,
@@ -58,6 +60,10 @@ class EmptyPlinkSetError(ValueError):
58
60
  # PLINK1 .bim alleles: single nucleotides only.
59
61
  _NUCLEOTIDES = frozenset("ACGT")
60
62
 
63
+ PLINK_PAR_CODE = "25"
64
+
65
+ _AUTOSOMES = frozenset(str(n) for n in range(1, 23))
66
+
61
67
  _CHROM_CODES = {
62
68
  "X": "23",
63
69
  "Y": "24",
@@ -65,6 +71,21 @@ _CHROM_CODES = {
65
71
  }
66
72
 
67
73
 
74
+ def plink_chromosome(v: Variant) -> str:
75
+ """The call's PLINK chromosome code: 23, 24 and 26 for X, Y and MT.
76
+
77
+ A call the file names ``25`` or ``XY`` (the pseudo-autosomal region) is
78
+ 25, as PLINK names it, although every lookup reads it as X (2.6.3).
79
+ """
80
+ if v.par or is_par_code(v.chromosome):
81
+ return PLINK_PAR_CODE
82
+ chrom = normalize_chromosome(v.chromosome)
83
+ if chrom in _CHROM_CODES:
84
+ return _CHROM_CODES[chrom]
85
+ # An autosome by its number; any other contig as the reader gave it.
86
+ return chrom if chrom in _AUTOSOMES else v.chromosome
87
+
88
+
68
89
  # PLINK1 .bed genotype code for a missing call.
69
90
  _BED_MISSING = 0b01
70
91
 
@@ -164,8 +185,12 @@ def plink_record_key(v: Variant) -> RecordKey:
164
185
 
165
186
 
166
187
  def _generated_id(v: Variant, emitted: set[str]) -> str:
167
- """``chr:pos:ref:alt`` for a variant without an ID; ``:2``, ``:3``… if already written."""
168
- base = f"{v.chromosome}:{v.position}:{v.ref or '.'}:{v.input_alt or '.'}"
188
+ """``chr:pos:ref:alt`` for a variant without an ID; ``:2``, ``:3``… if already written.
189
+
190
+ ``chr`` is a numeric code as the file wrote it (``23:…``), as in 2.6.2.
191
+ """
192
+ chrom = v.chromosome_as_read or v.chromosome
193
+ base = f"{chrom}:{v.position}:{v.ref or '.'}:{v.input_alt or '.'}"
169
194
  candidate, n = base, 1
170
195
  while candidate in emitted:
171
196
  n += 1
@@ -292,7 +317,7 @@ def _write_plink(
292
317
  indels += 1
293
318
  continue
294
319
 
295
- chrom_code = _CHROM_CODES.get(v.chromosome, v.chromosome)
320
+ chrom_code = plink_chromosome(v)
296
321
  a1: str
297
322
  a2: str
298
323
  bed_code: int
@@ -425,9 +450,7 @@ def resolve_ref_alt_via_gnomad_records(
425
450
  pairs = [
426
451
  (ref, alt)
427
452
  for chrom, pos, ref, alt in coords.get(v.rsid, [])
428
- if (chrom, pos) == (v.chromosome, v.position)
429
- and ref in _NUCLEOTIDES
430
- and alt in _NUCLEOTIDES
453
+ if (chrom, pos) == variant_locus(v) and ref in _NUCLEOTIDES and alt in _NUCLEOTIDES
431
454
  ]
432
455
  if not pairs:
433
456
  continue
@@ -464,12 +487,12 @@ def resolve_ref_alt_via_identity(
464
487
  if not identity.is_ready():
465
488
  return None
466
489
  named = [v for v in variants if v.rsid and plink_writable(v)]
467
- rows = identity.alleles_at_loci("GRCh37", {(v.chromosome, v.position) for v in named})
490
+ rows = identity.alleles_at_loci("GRCh37", {variant_locus(v) for v in named})
468
491
  result: dict[RecordKey, tuple[str, str]] = {}
469
492
  for v in named:
470
493
  pairs = {
471
494
  (ref, alt)
472
- for ref, alt, rsid in rows.get((v.chromosome, v.position), [])
495
+ for ref, alt, rsid in rows.get(variant_locus(v), [])
473
496
  if rsid == v.rsid and ref in _NUCLEOTIDES and alt in _NUCLEOTIDES
474
497
  }
475
498
  if len(pairs) > 1:
@@ -99,6 +99,15 @@ class Variant:
99
99
  # call. The parsers still give both alleles (the called one twice), so
100
100
  # matching is unchanged; reports show the call as hemizygous.
101
101
  haploid: bool = False
102
+ # The file names the chromosome ``25`` or ``XY`` (the pseudo-autosomal
103
+ # region, on X coordinates). ``chromosome`` is ``X`` for every lookup;
104
+ # only PLINK output keeps the file's 25 (2.6.3).
105
+ par: bool = field(default=False, compare=False, repr=False)
106
+ # A numeric or XY chromosome code as the file wrote it (``chr`` dropped,
107
+ # case kept), set only by the readers that map it at parse time (VCF,
108
+ # deCODEme, FTDNA Illumina, FamFinder): the generated PLINK ID of a call
109
+ # without an rsID keeps it, as 2.6.2 wrote it (2.6.3).
110
+ chromosome_as_read: str | None = field(default=None, compare=False, repr=False)
102
111
  # Complete literal input ALT field, independent of GT and quality masking.
103
112
  # Internal comparison identity; existing model equality remains unchanged.
104
113
  input_alt: str | None = field(default=None, compare=False)
@@ -638,6 +638,40 @@ def is_haploid_call(genotype: str) -> bool:
638
638
  return len(genotype) == 1 and genotype.upper() not in NO_CALL_CODES
639
639
 
640
640
 
641
+ # PLINK's and Illumina's codes for X, Y, the pseudo-autosomal region (on X
642
+ # coordinates) and MT; AncestryDNA writes the same numbers.
643
+ _NUMERIC_CHROMOSOMES = {"23": "X", "24": "Y", "25": "X", "XY": "X", "26": "MT"}
644
+
645
+
646
+ _STANDARD_CHROMOSOMES = frozenset([*(str(n) for n in range(1, 23)), "X", "Y", "MT"])
647
+
648
+
649
+ def summary_chromosome(chrom: str) -> str:
650
+ """The name a per-chromosome count lists for a call's chromosome.
651
+
652
+ A standard chromosome (1-22, X, Y, MT, under any spelling or numeric
653
+ code) by its lookup name; any other contig exactly as the reader gave it.
654
+ """
655
+ name = normalize_chromosome(chrom)
656
+ return name if name in _STANDARD_CHROMOSOMES else chrom
657
+
658
+
659
+ def numeric_chromosome_code(chrom: str) -> str | None:
660
+ """A numeric or XY chromosome code as written, ``chr`` dropped; None for any other name."""
661
+ stripped = chrom[3:] if chrom[:3].lower() == "chr" else chrom
662
+ return stripped if stripped.upper() in _NUMERIC_CHROMOSOMES else None
663
+
664
+
665
+ def is_par_code(chrom: str) -> bool:
666
+ """Whether the file names the call's chromosome ``25`` or ``XY``: the pseudo-autosomal region.
667
+
668
+ Lookups read it as X (:func:`normalize_chromosome`); PLINK output keeps
669
+ the file's own designation.
670
+ """
671
+ stripped = chrom[3:] if chrom[:3].lower() == "chr" else chrom
672
+ return stripped.upper() in ("25", "XY")
673
+
674
+
641
675
  def normalize_chromosome(chrom: str) -> str:
642
676
  """Normalize a chromosome identifier to Allelix's canonical bare form.
643
677
 
@@ -650,6 +684,10 @@ def normalize_chromosome(chrom: str) -> str:
650
684
  - ``chrX`` / ``chrx`` / ``X`` / ``x`` -> ``X`` (same for Y)
651
685
  - ``chrM`` / ``chrm`` / ``chrMT`` / ``chrmt`` / ``M`` / ``MT`` /
652
686
  ``m`` / ``mt`` -> ``MT``
687
+ - Numeric sex and mitochondrial codes (PLINK, Illumina GenomeStudio,
688
+ AncestryDNA): ``23`` -> ``X``, ``24`` -> ``Y``, ``25`` / ``XY`` (the
689
+ pseudo-autosomal region, on X coordinates) -> ``X``, ``26`` -> ``MT``.
690
+ ``0`` (unplaced) is an unknown contig.
653
691
  - Unknown contigs (``chrUn_*``, ``GL00*``, etc.) pass through unchanged
654
692
  after the optional ``chr`` strip — downstream code decides whether
655
693
  to skip them. Case is preserved for unknown contigs.
@@ -674,6 +712,10 @@ def normalize_chromosome(chrom: str) -> str:
674
712
  # Standard sex chromosomes normalize to uppercase
675
713
  if upper in ("X", "Y"):
676
714
  return upper
715
+ # Numeric and PAR codes name the same chromosomes
716
+ numeric = _NUMERIC_CHROMOSOMES.get(upper)
717
+ if numeric is not None:
718
+ return numeric
677
719
  # Autosomes (digits) are unchanged by upper(); return as-is
678
720
  if stripped.isdigit():
679
721
  return stripped
@@ -119,6 +119,7 @@ class AncestryDNAParser(GenotypeParser):
119
119
  yield Variant(
120
120
  rsid=rsid,
121
121
  chromosome=chrom,
122
+ par=chrom_raw == "25",
122
123
  position=position,
123
124
  allele1=allele1,
124
125
  allele2=allele2,
@@ -36,7 +36,9 @@ from allelix.parsers._helpers import (
36
36
  DamagedFileError,
37
37
  first_nonblank_line,
38
38
  is_haploid_call,
39
+ is_par_code,
39
40
  normalize_chromosome,
41
+ numeric_chromosome_code,
40
42
  open_genotype_text,
41
43
  split_genotype,
42
44
  )
@@ -104,6 +106,8 @@ class DeCODEmeParser(GenotypeParser):
104
106
  yield Variant(
105
107
  rsid=rsid,
106
108
  chromosome=normalize_chromosome(chrom),
109
+ par=is_par_code(chrom),
110
+ chromosome_as_read=numeric_chromosome_code(chrom),
107
111
  position=position,
108
112
  allele1=allele1,
109
113
  allele2=allele2,
@@ -65,7 +65,9 @@ from allelix.models import DEFAULT_BUILD, NO_CALL_MARKER, Variant
65
65
  from allelix.parsers._helpers import (
66
66
  NO_CALL_CODES,
67
67
  DamagedFileError,
68
+ is_par_code,
68
69
  normalize_chromosome,
70
+ numeric_chromosome_code,
69
71
  open_genotype_text,
70
72
  )
71
73
  from allelix.parsers.base import GenotypeMetadata, GenotypeParser, read_header_build
@@ -239,6 +241,8 @@ class FTDNAFamFinderParser(GenotypeParser):
239
241
  yield Variant(
240
242
  rsid=rsid,
241
243
  chromosome=normalized_chrom,
244
+ par=is_par_code(chrom),
245
+ chromosome_as_read=numeric_chromosome_code(chrom),
242
246
  position=position,
243
247
  allele1=allele1,
244
248
  allele2=allele2,
@@ -40,7 +40,9 @@ from allelix.models import DEFAULT_BUILD, Variant
40
40
  from allelix.parsers._helpers import (
41
41
  DamagedFileError,
42
42
  is_haploid_call,
43
+ is_par_code,
43
44
  normalize_chromosome,
45
+ numeric_chromosome_code,
44
46
  open_genotype_text,
45
47
  split_genotype,
46
48
  )
@@ -142,6 +144,8 @@ class FTDNAIlluminaParser(GenotypeParser):
142
144
  yield Variant(
143
145
  rsid=rsid,
144
146
  chromosome=normalize_chromosome(chrom),
147
+ par=is_par_code(chrom),
148
+ chromosome_as_read=numeric_chromosome_code(chrom),
145
149
  position=position,
146
150
  allele1=allele1,
147
151
  allele2=allele2,
@@ -55,7 +55,13 @@ from typing import TYPE_CHECKING, ClassVar, TextIO
55
55
 
56
56
  from allelix.attribution import Placements, attributed_rsids, placement_index
57
57
  from allelix.models import NO_CALL_MARKER, Variant
58
- from allelix.parsers._helpers import DamagedFileError, normalize_chromosome, open_genotype_text
58
+ from allelix.parsers._helpers import (
59
+ DamagedFileError,
60
+ is_par_code,
61
+ normalize_chromosome,
62
+ numeric_chromosome_code,
63
+ open_genotype_text,
64
+ )
59
65
  from allelix.parsers.base import GenotypeMetadata, GenotypeParser
60
66
  from allelix.parsers.genesforgood import METHOD_ARRAY_IMPUTED
61
67
  from allelix.utils.allele import trim_allele_pair
@@ -378,6 +384,8 @@ def extract_reference_candidates(
378
384
  return []
379
385
  record_id = _canonical_rsid(cols[2])
380
386
  chrom = normalize_chromosome(cols[0])
387
+ par = is_par_code(cols[0])
388
+ as_read = numeric_chromosome_code(cols[0])
381
389
  end = _info_end(cols) if _reference_block_alts(cols[4]) else None
382
390
  other_rsid = record_id.startswith("rs") and record_id not in rsids
383
391
  stands_at = record_positions(pos, cols[3], cols[4]) if end is None else {}
@@ -392,6 +400,8 @@ def extract_reference_candidates(
392
400
  allele2=a2,
393
401
  ref=base,
394
402
  ref_from_input=True,
403
+ par=par,
404
+ chromosome_as_read=as_read,
395
405
  input_alt=cols[4],
396
406
  )
397
407
  variant.record_index = index
@@ -1657,6 +1667,8 @@ def _parse_record(
1657
1667
  ref=ref,
1658
1668
  ref_from_input=True,
1659
1669
  haploid=haploid,
1670
+ par=is_par_code(chrom),
1671
+ chromosome_as_read=numeric_chromosome_code(chrom),
1660
1672
  input_alt=alt,
1661
1673
  )
1662
1674
  return variant, state
@@ -1078,8 +1078,11 @@ def _build_variant_data(sorted_groups: list[list[Annotation]]) -> str:
1078
1078
  entry["annotations"].append(a)
1079
1079
  variant_data.append(entry)
1080
1080
 
1081
+ # Every "<" is written as \u003c: in a script element, "<!--" and
1082
+ # "<script" change how the browser finds the closing tag, not only "</".
1083
+ # JSON.parse reads it back as "<".
1081
1084
  json_str = json.dumps(variant_data, ensure_ascii=False)
1082
- return json_str.replace("</", "<\\/")
1085
+ return json_str.replace("<", "\\u003c")
1083
1086
 
1084
1087
 
1085
1088
  # ---------------------------------------------------------------------------
@@ -377,9 +377,11 @@ class LengthVerdict(NamedTuple):
377
377
 
378
378
 
379
379
  def _bare_contig(name: str) -> str:
380
- """``chr1`` -> ``1``, ``chrX`` -> ``X``, ``chrM`` / ``M`` -> ``MT``."""
381
- bare = (name[3:] if name.lower().startswith("chr") else name).upper()
382
- return "MT" if bare in ("M", "MT") else bare
380
+ """``chr1`` -> ``1``, ``chrX`` / ``23`` -> ``X``, ``chrM`` / ``26`` -> ``MT``."""
381
+ # Imported here: allelix.parsers imports this module.
382
+ from allelix.parsers._helpers import normalize_chromosome
383
+
384
+ return normalize_chromosome(name)
383
385
 
384
386
 
385
387
  def contig_length_verdict(lengths: dict[str, int]) -> LengthVerdict:
@@ -387,7 +389,11 @@ def contig_length_verdict(lengths: dict[str, int]) -> LengthVerdict:
387
389
  seen: dict[str, set[str]] = {}
388
390
  unsupported: list[str] = []
389
391
  skip_mt = False
392
+ from allelix.parsers._helpers import is_par_code
393
+
390
394
  for name, length in lengths.items():
395
+ if is_par_code(name):
396
+ continue # a PAR contig (25, XY) is part of X, not its full length
391
397
  bare = _bare_contig(name)
392
398
  if bare == "MT":
393
399
  skip_mt = skip_mt or length == HG19_CHRM_LENGTH
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: allelix
3
- Version: 2.6.2
3
+ Version: 2.6.3
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.6.2"
7
+ version = "2.6.3"
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"
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