afquery 0.6.0__tar.gz → 0.7.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 (173) hide show
  1. {afquery-0.6.0 → afquery-0.7.0}/.github/workflows/ci.yml +4 -4
  2. {afquery-0.6.0 → afquery-0.7.0}/.github/workflows/docs.yml +2 -2
  3. {afquery-0.6.0 → afquery-0.7.0}/.github/workflows/release.yml +15 -15
  4. {afquery-0.6.0 → afquery-0.7.0}/PKG-INFO +8 -7
  5. {afquery-0.6.0 → afquery-0.7.0}/README.md +7 -6
  6. {afquery-0.6.0 → afquery-0.7.0}/docs/advanced/coverage-evidence.md +3 -3
  7. {afquery-0.6.0 → afquery-0.7.0}/docs/advanced/debugging-results.md +2 -1
  8. {afquery-0.6.0 → afquery-0.7.0}/docs/advanced/filter-pass-tracking.md +4 -4
  9. afquery-0.7.0/docs/advanced/ploidy-and-sex-chroms.md +204 -0
  10. {afquery-0.6.0 → afquery-0.7.0}/docs/faq.md +3 -1
  11. {afquery-0.6.0 → afquery-0.7.0}/docs/getting-started/concepts.md +8 -5
  12. {afquery-0.6.0 → afquery-0.7.0}/docs/getting-started/preprocessing.md +13 -3
  13. {afquery-0.6.0 → afquery-0.7.0}/docs/getting-started/quickstart.md +4 -3
  14. {afquery-0.6.0 → afquery-0.7.0}/docs/getting-started/tutorial.md +50 -33
  15. {afquery-0.6.0 → afquery-0.7.0}/docs/getting-started/understanding-output.md +15 -12
  16. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/annotate-vcf.md +5 -4
  17. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/dump-export.md +16 -5
  18. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/query.md +8 -7
  19. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/variant-info.md +10 -9
  20. {afquery-0.6.0 → afquery-0.7.0}/docs/index.md +2 -2
  21. {afquery-0.6.0 → afquery-0.7.0}/docs/reference/cli.md +10 -7
  22. {afquery-0.6.0 → afquery-0.7.0}/docs/reference/data-model.md +6 -5
  23. {afquery-0.6.0 → afquery-0.7.0}/docs/reference/glossary.md +17 -5
  24. {afquery-0.6.0 → afquery-0.7.0}/docs/reference/python-api.md +10 -7
  25. {afquery-0.6.0 → afquery-0.7.0}/docs/troubleshooting.md +1 -1
  26. {afquery-0.6.0 → afquery-0.7.0}/docs/use-cases/acmg-use-cases.md +4 -4
  27. {afquery-0.6.0 → afquery-0.7.0}/docs/use-cases/clinical-prioritization.md +1 -1
  28. {afquery-0.6.0 → afquery-0.7.0}/docs/use-cases/population-specific-af.md +1 -1
  29. {afquery-0.6.0 → afquery-0.7.0}/docs/use-cases/pseudo-controls.md +4 -4
  30. {afquery-0.6.0 → afquery-0.7.0}/docs/use-cases/sex-specific-af.md +6 -6
  31. {afquery-0.6.0 → afquery-0.7.0}/docs/use-cases/technology-integration.md +2 -2
  32. {afquery-0.6.0 → afquery-0.7.0}/examples/demo/README.md +1 -1
  33. {afquery-0.6.0 → afquery-0.7.0}/examples/demo/create_demo_data.py +15 -12
  34. {afquery-0.6.0 → afquery-0.7.0}/resources/normalize_vcf.sh +8 -27
  35. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/_version.py +2 -2
  36. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/annotate.py +35 -23
  37. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/cli.py +25 -14
  38. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/database.py +3 -2
  39. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/dump.py +9 -5
  40. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/models.py +6 -5
  41. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/ploidy.py +45 -6
  42. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/ingest.py +31 -8
  43. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/synth.py +4 -0
  44. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/query.py +59 -18
  45. {afquery-0.6.0 → afquery-0.7.0}/tests/conftest.py +20 -1
  46. {afquery-0.6.0 → afquery-0.7.0}/tests/data/expected_results.json +14 -5
  47. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S00.vcf +2 -2
  48. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S01.vcf +1 -1
  49. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S04.vcf +1 -1
  50. {afquery-0.6.0 → afquery-0.7.0}/tests/oracle.py +43 -19
  51. {afquery-0.6.0 → afquery-0.7.0}/tests/test_annotate.py +21 -0
  52. afquery-0.7.0/tests/test_chrY_par.py +79 -0
  53. {afquery-0.6.0 → afquery-0.7.0}/tests/test_cli_docs_consistency.py +56 -0
  54. {afquery-0.6.0 → afquery-0.7.0}/tests/test_dump.py +86 -0
  55. {afquery-0.6.0 → afquery-0.7.0}/tests/test_haploid_stats.py +58 -30
  56. {afquery-0.6.0 → afquery-0.7.0}/tests/test_invariants.py +6 -6
  57. {afquery-0.6.0 → afquery-0.7.0}/tests/test_no_coverage.py +7 -6
  58. afquery-0.7.0/tests/test_normalize_script.py +28 -0
  59. {afquery-0.6.0 → afquery-0.7.0}/tests/test_oracle_consistency.py +69 -1
  60. afquery-0.7.0/tests/test_ploidy.py +193 -0
  61. {afquery-0.6.0 → afquery-0.7.0}/tests/test_preprocess.py +44 -0
  62. {afquery-0.6.0 → afquery-0.7.0}/tests/test_query.py +3 -0
  63. {afquery-0.6.0 → afquery-0.7.0}/tests/test_synthetic_stats.py +64 -11
  64. {afquery-0.6.0 → afquery-0.7.0}/tests/test_variant_info.py +60 -3
  65. afquery-0.6.0/docs/advanced/ploidy-and-sex-chroms.md +0 -174
  66. afquery-0.6.0/src/afquery/cli.pyr +0 -369
  67. afquery-0.6.0/tests/test_ploidy.py +0 -117
  68. {afquery-0.6.0 → afquery-0.7.0}/.dockerignore +0 -0
  69. {afquery-0.6.0 → afquery-0.7.0}/.gitignore +0 -0
  70. {afquery-0.6.0 → afquery-0.7.0}/CONTRIBUTING.md +0 -0
  71. {afquery-0.6.0 → afquery-0.7.0}/Dockerfile +0 -0
  72. {afquery-0.6.0 → afquery-0.7.0}/LICENSE +0 -0
  73. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/.gitignore +0 -0
  74. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/INSTALL.md +0 -0
  75. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/README.md +0 -0
  76. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/Snakefile +0 -0
  77. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/.gitignore +0 -0
  78. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/01a_assign_samples.py +0 -0
  79. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/01b_write_manifests.py +0 -0
  80. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/02_build_databases.py +0 -0
  81. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/03_compute_metrics.py +0 -0
  82. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/04_classify_acmg.py +0 -0
  83. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/05_plot_figures.py +0 -0
  84. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/README.md +0 -0
  85. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/Snakefile +0 -0
  86. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/__init__.py +0 -0
  87. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/beds/SureSelect_v5.bed +0 -0
  88. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/beds/SureSelect_v6.bed +0 -0
  89. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/beds/SureSelect_v7.bed +0 -0
  90. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/capture_kit/config.py +0 -0
  91. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/config.yaml +0 -0
  92. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/envs/benchmark.yaml +0 -0
  93. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/.gitignore +0 -0
  94. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/01_prepare_data.py +0 -0
  95. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/02_query_scaling.py +0 -0
  96. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/03_build.py +0 -0
  97. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/04_annotate.py +0 -0
  98. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/05_vs_bcftools.py +0 -0
  99. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/06_plot.py +0 -0
  100. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/README.md +0 -0
  101. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/Snakefile +0 -0
  102. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/collect_annotate.py +0 -0
  103. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/collect_bcftools.py +0 -0
  104. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/collect_build_perf.py +0 -0
  105. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/collect_prepare.py +0 -0
  106. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/collect_query_scaling.py +0 -0
  107. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/config.py +0 -0
  108. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/performance/config_smoke.py +0 -0
  109. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/shared/__init__.py +0 -0
  110. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/shared/config.py +0 -0
  111. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/shared/rules/download_1kg.smk +0 -0
  112. {afquery-0.6.0 → afquery-0.7.0}/benchmarks/shared/utils.py +0 -0
  113. {afquery-0.6.0 → afquery-0.7.0}/docs/advanced/benchmarking.md +0 -0
  114. {afquery-0.6.0 → afquery-0.7.0}/docs/advanced/multi-cohort-strategies.md +0 -0
  115. {afquery-0.6.0 → afquery-0.7.0}/docs/advanced/performance.md +0 -0
  116. {afquery-0.6.0 → afquery-0.7.0}/docs/advanced/pipeline-integration.md +0 -0
  117. {afquery-0.6.0 → afquery-0.7.0}/docs/assets/img/gap2_mixed_technologies.png +0 -0
  118. {afquery-0.6.0 → afquery-0.7.0}/docs/getting-started/installation.md +0 -0
  119. {afquery-0.6.0 → afquery-0.7.0}/docs/getting-started/motivation.md +0 -0
  120. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/create-database.md +0 -0
  121. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/manifest-format.md +0 -0
  122. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/sample-filtering.md +0 -0
  123. {afquery-0.6.0 → afquery-0.7.0}/docs/guides/update-database.md +0 -0
  124. {afquery-0.6.0 → afquery-0.7.0}/docs/scripts/gen_gap2_figure.py +0 -0
  125. {afquery-0.6.0 → afquery-0.7.0}/docs/stylesheets/extra.css +0 -0
  126. {afquery-0.6.0 → afquery-0.7.0}/docs/use-cases/cohort-stratification.md +0 -0
  127. {afquery-0.6.0 → afquery-0.7.0}/mkdocs.yml +0 -0
  128. {afquery-0.6.0 → afquery-0.7.0}/pyproject.toml +0 -0
  129. {afquery-0.6.0 → afquery-0.7.0}/recipes/afquery/meta.yaml +0 -0
  130. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/__init__.py +0 -0
  131. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/benchmark.py +0 -0
  132. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/bitmaps.py +0 -0
  133. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/capture.py +0 -0
  134. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/constants.py +0 -0
  135. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/__init__.py +0 -0
  136. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/build.py +0 -0
  137. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/compact.py +0 -0
  138. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/manifest.py +0 -0
  139. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/regions.py +0 -0
  140. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/preprocess/update.py +0 -0
  141. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/storage.py +0 -0
  142. {afquery-0.6.0 → afquery-0.7.0}/src/afquery/variant_info.py +0 -0
  143. {afquery-0.6.0 → afquery-0.7.0}/tests/data/annotate_input.vcf +0 -0
  144. {afquery-0.6.0 → afquery-0.7.0}/tests/data/annotate_multi_bucket.vcf +0 -0
  145. {afquery-0.6.0 → afquery-0.7.0}/tests/data/annotate_multi_chrom.vcf +0 -0
  146. {afquery-0.6.0 → afquery-0.7.0}/tests/data/beds/wes_kit_a.bed +0 -0
  147. {afquery-0.6.0 → afquery-0.7.0}/tests/data/beds/wes_kit_b.bed +0 -0
  148. {afquery-0.6.0 → afquery-0.7.0}/tests/data/beds/wes_kit_nochr.bed +0 -0
  149. {afquery-0.6.0 → afquery-0.7.0}/tests/data/manifest.tsv +0 -0
  150. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S02.vcf +0 -0
  151. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S03.vcf +0 -0
  152. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S05.vcf +0 -0
  153. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S06.vcf +0 -0
  154. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S07.vcf +0 -0
  155. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S08.vcf +0 -0
  156. {afquery-0.6.0 → afquery-0.7.0}/tests/data/vcfs/S09.vcf +0 -0
  157. {afquery-0.6.0 → afquery-0.7.0}/tests/test_batch.py +0 -0
  158. {afquery-0.6.0 → afquery-0.7.0}/tests/test_benchmark.py +0 -0
  159. {afquery-0.6.0 → afquery-0.7.0}/tests/test_bitmaps.py +0 -0
  160. {afquery-0.6.0 → afquery-0.7.0}/tests/test_capture.py +0 -0
  161. {afquery-0.6.0 → afquery-0.7.0}/tests/test_cli.py +0 -0
  162. {afquery-0.6.0 → afquery-0.7.0}/tests/test_compact.py +0 -0
  163. {afquery-0.6.0 → afquery-0.7.0}/tests/test_constants.py +0 -0
  164. {afquery-0.6.0 → afquery-0.7.0}/tests/test_info.py +0 -0
  165. {afquery-0.6.0 → afquery-0.7.0}/tests/test_multiallelic.py +0 -0
  166. {afquery-0.6.0 → afquery-0.7.0}/tests/test_pass_filter.py +0 -0
  167. {afquery-0.6.0 → afquery-0.7.0}/tests/test_sample_filter.py +0 -0
  168. {afquery-0.6.0 → afquery-0.7.0}/tests/test_storage.py +0 -0
  169. {afquery-0.6.0 → afquery-0.7.0}/tests/test_synth.py +0 -0
  170. {afquery-0.6.0 → afquery-0.7.0}/tests/test_update.py +0 -0
  171. {afquery-0.6.0 → afquery-0.7.0}/tests/test_update_metadata.py +0 -0
  172. {afquery-0.6.0 → afquery-0.7.0}/tests/test_update_partitioned.py +0 -0
  173. {afquery-0.6.0 → afquery-0.7.0}/tests/test_warnings.py +0 -0
@@ -13,11 +13,11 @@ jobs:
13
13
  matrix:
14
14
  python-version: ["3.10", "3.11", "3.12"]
15
15
  steps:
16
- - uses: actions/checkout@v4
16
+ - uses: actions/checkout@v5
17
17
  with:
18
18
  fetch-depth: 0 # hatch-vcs needs full history to resolve version
19
19
 
20
- - uses: actions/setup-python@v5
20
+ - uses: actions/setup-python@v6
21
21
  with:
22
22
  python-version: ${{ matrix.python-version }}
23
23
 
@@ -29,9 +29,9 @@ jobs:
29
29
 
30
30
  - name: Upload coverage to Codecov
31
31
  if: matrix.python-version == '3.12'
32
- uses: codecov/codecov-action@v4
32
+ uses: codecov/codecov-action@v7
33
33
  with:
34
34
  token: ${{ secrets.CODECOV_TOKEN }}
35
35
  files: ./coverage.xml
36
36
  fail_ci_if_error: true
37
- disable-safe: true
37
+ disable_safe_directory: true
@@ -25,11 +25,11 @@ jobs:
25
25
  deploy:
26
26
  runs-on: ubuntu-latest
27
27
  steps:
28
- - uses: actions/checkout@v4
28
+ - uses: actions/checkout@v5
29
29
  with:
30
30
  fetch-depth: 0
31
31
 
32
- - uses: actions/setup-python@v5
32
+ - uses: actions/setup-python@v6
33
33
  with:
34
34
  python-version: '3.11'
35
35
 
@@ -14,10 +14,10 @@ jobs:
14
14
  matrix:
15
15
  python-version: ["3.10", "3.11", "3.12"]
16
16
  steps:
17
- - uses: actions/checkout@v4
17
+ - uses: actions/checkout@v5
18
18
  with:
19
19
  fetch-depth: 0
20
- - uses: actions/setup-python@v5
20
+ - uses: actions/setup-python@v6
21
21
  with:
22
22
  python-version: ${{ matrix.python-version }}
23
23
  - run: pip install -e ".[dev]"
@@ -28,15 +28,15 @@ jobs:
28
28
  needs: test
29
29
  runs-on: ubuntu-latest
30
30
  steps:
31
- - uses: actions/checkout@v4
31
+ - uses: actions/checkout@v5
32
32
  with:
33
33
  fetch-depth: 0 # required: hatch-vcs reads git tags for version
34
- - uses: actions/setup-python@v5
34
+ - uses: actions/setup-python@v6
35
35
  with:
36
36
  python-version: "3.11"
37
37
  - run: pip install build
38
38
  - run: python -m build
39
- - uses: actions/upload-artifact@v4
39
+ - uses: actions/upload-artifact@v7
40
40
  with:
41
41
  name: dist
42
42
  path: dist/
@@ -51,7 +51,7 @@ jobs:
51
51
  permissions:
52
52
  id-token: write # required for OIDC Trusted Publishing
53
53
  steps:
54
- - uses: actions/download-artifact@v4
54
+ - uses: actions/download-artifact@v8
55
55
  with:
56
56
  name: dist
57
57
  path: dist/
@@ -64,11 +64,11 @@ jobs:
64
64
  permissions:
65
65
  contents: write
66
66
  steps:
67
- - uses: actions/download-artifact@v4
67
+ - uses: actions/download-artifact@v8
68
68
  with:
69
69
  name: dist
70
70
  path: dist/
71
- - uses: softprops/action-gh-release@v2
71
+ - uses: softprops/action-gh-release@v3
72
72
  with:
73
73
  files: dist/*
74
74
  generate_release_notes: true
@@ -81,20 +81,20 @@ jobs:
81
81
  permissions:
82
82
  packages: write
83
83
  steps:
84
- - uses: actions/checkout@v4
84
+ - uses: actions/checkout@v5
85
85
 
86
86
  - name: Extract version
87
87
  id: version
88
88
  run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
89
89
 
90
90
  - name: Set up QEMU
91
- uses: docker/setup-qemu-action@v3
91
+ uses: docker/setup-qemu-action@v4
92
92
 
93
93
  - name: Set up Docker Buildx
94
- uses: docker/setup-buildx-action@v3
94
+ uses: docker/setup-buildx-action@v4
95
95
 
96
96
  - name: Login to GHCR
97
- uses: docker/login-action@v3
97
+ uses: docker/login-action@v4
98
98
  with:
99
99
  registry: ghcr.io
100
100
  username: ${{ github.actor }}
@@ -117,7 +117,7 @@ jobs:
117
117
  echo "Not available after 6 min, proceeding anyway."
118
118
 
119
119
  - name: Build and push
120
- uses: docker/build-push-action@v6
120
+ uses: docker/build-push-action@v7
121
121
  with:
122
122
  context: .
123
123
  push: true
@@ -135,11 +135,11 @@ jobs:
135
135
  permissions:
136
136
  contents: write
137
137
  steps:
138
- - uses: actions/checkout@v4
138
+ - uses: actions/checkout@v5
139
139
  with:
140
140
  fetch-depth: 0
141
141
 
142
- - uses: actions/setup-python@v5
142
+ - uses: actions/setup-python@v6
143
143
  with:
144
144
  python-version: "3.11"
145
145
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: afquery
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Genomic allele frequency query engine with bitmap-encoded genotypes
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -77,7 +77,7 @@ AFQuery solves this with per-position, per-technology capture-aware AN, ploidy-a
77
77
  - **Coverage evidence model** — `N_NO_COVERAGE` separates trusted hom-ref from samples lacking sufficient evidence; query-time gates (`--min-pass`, `--min-observed`, `--min-quality-evidence`) keep AF conservative.
78
78
  - **ACMG-compatible AC/AN/AF** — per-standard definitions, exposed as both query output and VCF INFO fields.
79
79
  - **Flexible metadata filtering** — arbitrary phenotype labels (ICD-10, HPO, OMIM, custom tags), inclusion or exclusion (`^` prefix), combined with sex and technology.
80
- - **Parallel VCF annotation** — multi-threaded; adds `AFQUERY_AC/AN/AF/N_HET/N_HOM_ALT/N_HOM_REF/N_FAIL/N_NO_COVERAGE` INFO fields.
80
+ - **Parallel VCF annotation** — multi-threaded; adds `AFQUERY_AC/AN/AF/N_HET/N_HOM_ALT/N_HEMI/N_HOM_REF/N_FAIL/N_NO_COVERAGE` INFO fields.
81
81
  - **Bulk CSV export** — per-variant frequencies with optional disaggregation by sex, technology, or phenotype.
82
82
  - **Incremental updates** — add or remove samples, edit phenotype/sex metadata, compact storage, without full rebuilds.
83
83
  - **Audit changelog** — every database operation is logged with timestamps and operator notes.
@@ -185,13 +185,14 @@ Every query and annotated VCF reports:
185
185
  | `AC` | Alt-allele count over eligible samples (FILTER=PASS) |
186
186
  | `AN` | Total alleles considered, ploidy- and capture-aware |
187
187
  | `AF` | `AC / AN` |
188
- | `N_HET` | Heterozygous PASS carriers |
189
- | `N_HOM_ALT` | Homozygous-alt PASS carriers |
190
- | `N_HOM_REF` | Samples trusted as homozygous reference |
191
- | `N_FAIL` | Samples with a failed call (FILTER ≠ PASS) at the position (excluded from AC/AN) |
188
+ | `N_HET` | Heterozygous PASS carriers (diploid) |
189
+ | `N_HOM_ALT` | Homozygous-alt PASS carriers (diploid); every carrier on chrM |
190
+ | `N_HEMI` | Hemizygous PASS carriers: males on chrX outside the PARs and on chrY |
191
+ | `N_HOM_REF` | Samples trusted as homozygous reference (hemizygous for REF where haploid) |
192
+ | `N_FAIL` | Samples with a failed call (FILTER ≠ PASS, or a genotype inconsistent with ploidy) at the position (excluded from AC/AN) |
192
193
  | `N_NO_COVERAGE` | Non-carriers on a partially-covered tech without sufficient evidence to call hom-ref |
193
194
 
194
- VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO_COVERAGE`).
195
+ VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO_COVERAGE`). `query` and `dump` also report `n_eligible`, the number of samples that can be genotyped at the position.
195
196
 
196
197
  ## CLI commands
197
198
 
@@ -47,7 +47,7 @@ AFQuery solves this with per-position, per-technology capture-aware AN, ploidy-a
47
47
  - **Coverage evidence model** — `N_NO_COVERAGE` separates trusted hom-ref from samples lacking sufficient evidence; query-time gates (`--min-pass`, `--min-observed`, `--min-quality-evidence`) keep AF conservative.
48
48
  - **ACMG-compatible AC/AN/AF** — per-standard definitions, exposed as both query output and VCF INFO fields.
49
49
  - **Flexible metadata filtering** — arbitrary phenotype labels (ICD-10, HPO, OMIM, custom tags), inclusion or exclusion (`^` prefix), combined with sex and technology.
50
- - **Parallel VCF annotation** — multi-threaded; adds `AFQUERY_AC/AN/AF/N_HET/N_HOM_ALT/N_HOM_REF/N_FAIL/N_NO_COVERAGE` INFO fields.
50
+ - **Parallel VCF annotation** — multi-threaded; adds `AFQUERY_AC/AN/AF/N_HET/N_HOM_ALT/N_HEMI/N_HOM_REF/N_FAIL/N_NO_COVERAGE` INFO fields.
51
51
  - **Bulk CSV export** — per-variant frequencies with optional disaggregation by sex, technology, or phenotype.
52
52
  - **Incremental updates** — add or remove samples, edit phenotype/sex metadata, compact storage, without full rebuilds.
53
53
  - **Audit changelog** — every database operation is logged with timestamps and operator notes.
@@ -155,13 +155,14 @@ Every query and annotated VCF reports:
155
155
  | `AC` | Alt-allele count over eligible samples (FILTER=PASS) |
156
156
  | `AN` | Total alleles considered, ploidy- and capture-aware |
157
157
  | `AF` | `AC / AN` |
158
- | `N_HET` | Heterozygous PASS carriers |
159
- | `N_HOM_ALT` | Homozygous-alt PASS carriers |
160
- | `N_HOM_REF` | Samples trusted as homozygous reference |
161
- | `N_FAIL` | Samples with a failed call (FILTER ≠ PASS) at the position (excluded from AC/AN) |
158
+ | `N_HET` | Heterozygous PASS carriers (diploid) |
159
+ | `N_HOM_ALT` | Homozygous-alt PASS carriers (diploid); every carrier on chrM |
160
+ | `N_HEMI` | Hemizygous PASS carriers: males on chrX outside the PARs and on chrY |
161
+ | `N_HOM_REF` | Samples trusted as homozygous reference (hemizygous for REF where haploid) |
162
+ | `N_FAIL` | Samples with a failed call (FILTER ≠ PASS, or a genotype inconsistent with ploidy) at the position (excluded from AC/AN) |
162
163
  | `N_NO_COVERAGE` | Non-carriers on a partially-covered tech without sufficient evidence to call hom-ref |
163
164
 
164
- VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO_COVERAGE`).
165
+ VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO_COVERAGE`). `query` and `dump` also report `n_eligible`, the number of samples that can be genotyped at the position.
165
166
 
166
167
  ## CLI commands
167
168
 
@@ -20,7 +20,7 @@ into `N_HOM_REF`. The flags below decide *which* samples land there.
20
20
  under the active criteria. At a biallelic site the genotype invariant becomes:
21
21
 
22
22
  ```
23
- N_HET + N_HOM_ALT + N_HOM_REF + N_FAIL + N_NO_COVERAGE = n_eligible
23
+ N_HET + N_HOM_ALT + N_HEMI + N_HOM_REF + N_FAIL + N_NO_COVERAGE = n_eligible
24
24
  ```
25
25
 
26
26
  At a multi-allelic site, eligible samples that carry only another ALT allele at
@@ -74,7 +74,7 @@ afquery query --db ./db/ --locus chr1:925952
74
74
  ```
75
75
 
76
76
  ```
77
- chr1:925952 G>A AC=142 AN=2742 AF=0.0518 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HOM_REF=1231 N_FAIL=0 N_NO_COVERAGE=0
77
+ chr1:925952 G>A AC=142 AN=2742 AF=0.0518 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HEMI=0 N_HOM_REF=1231 N_FAIL=0 N_NO_COVERAGE=0
78
78
  ```
79
79
 
80
80
  Now require at least one PASS carrier per partially-covered tech:
@@ -84,7 +84,7 @@ afquery query --db ./db/ --locus chr1:925952 --min-pass 1
84
84
  ```
85
85
 
86
86
  ```
87
- chr1:925952 G>A AC=142 AN=2742 AF=0.0518 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HOM_REF=1108 N_FAIL=0 N_NO_COVERAGE=123
87
+ chr1:925952 G>A AC=142 AN=2742 AF=0.0518 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HEMI=0 N_HOM_REF=1108 N_FAIL=0 N_NO_COVERAGE=123
88
88
  ```
89
89
 
90
90
  Samples on partially-covered techs that did not contribute a single PASS
@@ -19,6 +19,7 @@ AN=0 means no eligible samples at the queried position. Work through these check
19
19
  | WES samples missing from AN | `afquery query --db ./db/ --locus chr1:12345678 --tech WES_kit_A` | If this prints `No variants found for the given filters.` for a technology whose kit should cover the position, while the unfiltered query returns the variant, that technology's capture index is not matching the position. `afquery` warns on open when a capture BED is empty or matches no known chromosome, naming the offending contigs. |
20
20
  | AN=0 only on chrM | `afquery query --db ./db/ --locus chrM:3243` | Mitochondrial coverage is easy to lose on its own: a BED naming it `chrMT` still matches on the autosomes, so nothing else looks wrong. Names are normalized (`MT`, `M`, `chrMT` → `chrM`) since v0.4.0 — databases built before that may need the capture BED re-checked. |
21
21
  | Technology filter | Remove `--tech` filter | Check if any samples match the requested technology. |
22
+ | Position in a chrY PAR | `afquery query --db ./db/ --locus chrY:1500000` | A warning says the position lies in a pseudoautosomal region. PAR loci are counted at their chrX coordinates; query the chrX position instead. |
22
23
 
23
24
  ### 2. Unexpected AF Value
24
25
 
@@ -88,7 +89,7 @@ Validates: manifest consistency, Parquet file integrity, capture index presence.
88
89
  afquery query --db ./db/ --locus chr1:12345678 --format json
89
90
  ```
90
91
 
91
- JSON format shows all fields including N_HET, N_HOM_ALT, N_HOM_REF, and N_FAIL — useful for understanding the composition of the result.
92
+ JSON format shows all fields including N_HET, N_HOM_ALT, N_HEMI, N_HOM_REF, and N_FAIL — useful for understanding the composition of the result.
92
93
 
93
94
 
94
95
  ### Direct Metadata Inspection
@@ -10,7 +10,7 @@ A sample has a failed call at a position when its VCF holds, for any ALT allele
10
10
 
11
11
  - a call carrying the ALT allele with `FILTER` other than `PASS` or `.`;
12
12
  - a missing genotype (`./.`) at a site that failed a filter; or
13
- - calls that carry more alleles than the sample has at the position, such as two ALT alleles on chrX in a male. These are detected when the VCF is ingested, which logs a warning (see [Genotypes inconsistent with ploidy](ploidy-and-sex-chroms.md#genotypes-inconsistent-with-ploidy)).
13
+ - calls that carry more alleles than the sample has at the position, such as a heterozygous call (`0/1`) or two ALT alleles (`1/2`) on chrX non-PAR or chrY in a male. These are detected when the VCF is ingested, which logs a warning (see [Genotypes inconsistent with ploidy](ploidy-and-sex-chroms.md#genotypes-inconsistent-with-ploidy)).
14
14
 
15
15
  These samples are stored in the variant's `fail_bitmap` and reported as `N_FAIL`. A homozygous-reference call (`0/0`) is never stored, so at a failed site it would count as hom-ref; [`normalize_vcf.sh`](../getting-started/preprocessing.md) avoids this by masking every genotype at a failed site as missing.
16
16
 
@@ -23,7 +23,7 @@ A failed call is judged per **position**, not per allele: a sample with a failed
23
23
  - adds nothing to **AC**, even if another record at the position called it with `FILTER=PASS`;
24
24
  - is left out of **AN**, which counts only the alleles of samples with a usable call;
25
25
  - is counted in **N_FAIL**, which therefore has the same value on every line of a multi-allelic site;
26
- - stays in **n_eligible**, so `N_HET + N_HOM_ALT + N_HOM_REF + N_FAIL + N_NO_COVERAGE` still accounts for every eligible sample (see [Multi-allelic sites](../getting-started/understanding-output.md#multi-allelic-sites) for the one exception).
26
+ - stays in **n_eligible**, so `N_HET + N_HOM_ALT + N_HEMI + N_HOM_REF + N_FAIL + N_NO_COVERAGE` still accounts for every eligible sample (see [Multi-allelic sites](../getting-started/understanding-output.md#multi-allelic-sites) for the one exception).
27
27
 
28
28
  Leaving failed calls out of AN keeps AF an estimate over the genotypes that were actually observed. At every position, AN equals the reference alleles plus the AC of all its ALT alleles.
29
29
 
@@ -32,7 +32,7 @@ afquery query --db ./db/ --locus chr1:925952
32
32
  ```
33
33
 
34
34
  ```
35
- chr1:925952 G>A AC=142 AN=2728 AF=0.0521 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HOM_REF=1224 N_FAIL=7 N_NO_COVERAGE=0
35
+ chr1:925952 G>A AC=142 AN=2728 AF=0.0521 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HEMI=0 N_HOM_REF=1224 N_FAIL=7 N_NO_COVERAGE=0
36
36
  ```
37
37
 
38
38
  The 7 samples with a failed call are part of `n_eligible` (138 + 2 + 1224 + 7 = 1371) but not of AN: 2 × (1371 − 7) = 2728.
@@ -52,7 +52,7 @@ afquery query --db ./db/ --locus chr1:925952 --fail-as-ref
52
52
  ```
53
53
 
54
54
  ```
55
- chr1:925952 G>A AC=142 AN=2742 AF=0.0518 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HOM_REF=1224 N_FAIL=7 N_NO_COVERAGE=0
55
+ chr1:925952 G>A AC=142 AN=2742 AF=0.0518 n_eligible=1371 N_HET=138 N_HOM_ALT=2 N_HEMI=0 N_HOM_REF=1224 N_FAIL=7 N_NO_COVERAGE=0
56
56
  ```
57
57
 
58
58
  Because every failed sample is then treated as a non-carrier, the AF is never higher than the default one, which makes it a conservative lower estimate when a site has many failures. AN then no longer equals the reference alleles plus the AC of all ALT alleles.
@@ -0,0 +1,204 @@
1
+ # Ploidy & Special Chromosomes
2
+
3
+ AFQuery computes ploidy-aware AN for sex chromosomes (chrX, chrY) and the mitochondrial chromosome (chrM). This ensures that allele frequencies are correct when querying these chromosomes, where the number of alleles per sample differs from the diploid autosomes.
4
+
5
+ !!! note "Chromosome name normalization"
6
+ AFQuery accepts `MT`, `chrMT`, and `chrM` as input; output always uses `chrM`.
7
+
8
+ ---
9
+
10
+ ## Ploidy Rules
11
+
12
+ | Chromosome | Female AN contribution | Male AN contribution |
13
+ |------------|----------------------|---------------------|
14
+ | Autosomes (chr1–22) | 2 | 2 |
15
+ | chrX (non-PAR) | 2 | 1 |
16
+ | chrX (PAR1, PAR2) | 2 | 2 |
17
+ | chrY (non-PAR) | 0 | 1 |
18
+ | chrY (PAR1, PAR2) | 0 | 0 — counted on chrX |
19
+ | chrM | 1 | 1 |
20
+
21
+ For each eligible sample at a given position, AFQuery adds the appropriate ploidy count to AN based on the sample's sex and the chromosome/position.
22
+
23
+ A sample contributing ploidy 0 is not eligible at that position at all: a female has no chrY to genotype, so she is neither a carrier nor homozygous reference there. On chrY, `n_eligible`, `N_HOM_REF` and `AN` therefore count males only. In the chrY PARs nobody is eligible (see below).
24
+
25
+ !!! note "Karyotypes"
26
+ The manifest records each sample as `male` or `female`, read as XY or XX. Other sex-chromosome karyotypes (45,X; 47,XXY; mosaics) are not modelled: a sample is given the ploidy of the sex it is registered with.
27
+
28
+ ---
29
+
30
+ ## Pseudoautosomal Regions (PAR)
31
+
32
+ PAR1 and PAR2 are the same sequence at the two ends of chrX and chrY, and they recombine like an autosome: a male carries one copy on his X and one on his Y, so at a PAR locus every sample is diploid. The reference genome holds that sequence twice, once on each chromosome, so AFQuery counts every PAR locus once, at its chrX coordinates:
33
+
34
+ - **chrX PAR**: diploid for both sexes — males and females contribute AN=2.
35
+ - **chrY PAR**: not genotyped. Nobody is eligible there, so a query returns no results and AN is 0. This keeps a PAR variant from being counted twice, and keeps a male carrier from being taken for a hemizygote.
36
+
37
+ Most analysis references hard-mask the chrY PARs (the GRCh38 analysis sets do), so variant callers report PAR variants on chrX anyway. Calls at chrY PAR coordinates only appear when the reads were aligned to an unmasked reference; they are stored, but not counted. A point query (`query --locus`, `variant-info`) at such a position warns that it lies in a PAR; region and batch queries, `dump` and `annotate` skip it silently (`annotate` writes `AFQUERY_AN=0`).
38
+
39
+ PAR coordinates by genome build:
40
+
41
+ <!-- Source of truth: src/afquery/constants.py PAR dict -->
42
+
43
+ ### GRCh38
44
+
45
+ **chrX:**
46
+
47
+ | Region | Start | End |
48
+ |--------|-------|-----|
49
+ | PAR1 | 10,001 | 2,781,479 |
50
+ | PAR2 | 155,701,383 | 156,030,895 |
51
+
52
+ **chrY:**
53
+
54
+ | Region | Start | End |
55
+ |--------|-------|-----|
56
+ | PAR1 | 10,001 | 2,781,479 |
57
+ | PAR2 | 56,887,903 | 57,217,415 |
58
+
59
+ ### GRCh37 / hg19
60
+
61
+ **chrX:**
62
+
63
+ | Region | Start | End |
64
+ |--------|-------|-----|
65
+ | PAR1 | 60,001 | 2,699,520 |
66
+ | PAR2 | 154,931,044 | 155,260,560 |
67
+
68
+ **chrY:**
69
+
70
+ | Region | Start | End |
71
+ |--------|-------|-----|
72
+ | PAR1 | 10,001 | 2,649,520 |
73
+ | PAR2 | 59,034,050 | 59,363,566 |
74
+
75
+ Positions within PAR1 or PAR2 on chrX are treated as diploid for all samples; positions within PAR1 or PAR2 on chrY are not genotyped.
76
+
77
+ ---
78
+
79
+ ## Effect on AF Queries
80
+
81
+ ### chrY
82
+
83
+ Querying chrY with `--sex female` returns `AN=0` (females have no Y chromosome):
84
+
85
+ ```bash
86
+ afquery query --db ./db/ --locus chrY:2787758 --sex female
87
+ # chrY:2787758 — no results (AN=0 for all variants)
88
+
89
+ afquery query --db ./db/ --locus chrY:2787758 --sex male
90
+ # chrY:2787758 C>T AC=3 AN=856 AF=0.0035 n_eligible=856 N_HET=0 N_HOM_ALT=0 N_HEMI=3 N_HOM_REF=853 N_FAIL=0 N_NO_COVERAGE=0
91
+ ```
92
+
93
+ Inside a chrY PAR (here GRCh38 PAR1), nothing is reported, whatever the filters:
94
+
95
+ ```bash
96
+ afquery query --db ./db/ --locus chrY:1500000
97
+ # AfqueryWarning: chrY:1500000 lies in a pseudoautosomal region (PAR); PAR variants
98
+ # are counted at their chrX coordinates, so nobody is genotyped here.
99
+ # No variants found for the given filters.
100
+ ```
101
+
102
+ Query the same locus at its chrX coordinates instead (`chrX:1500000`).
103
+
104
+ ### chrX non-PAR
105
+
106
+ Male samples contribute AN=1, female samples contribute AN=2. This means a cohort of 500 females and 500 males has AN = 500×2 + 500×1 = 1500 at a non-PAR X position.
107
+
108
+ ```bash
109
+ afquery query --db ./db/ --locus chrX:100000000
110
+ # N_total = 1000 samples, AN = 1500 (not 2000)
111
+ ```
112
+
113
+ ### chrM
114
+
115
+ All samples are haploid at mitochondrial loci:
116
+
117
+ ```bash
118
+ afquery query --db ./db/ --locus chrM:3243
119
+ # AN = n_samples (one allele per sample)
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Genotype Counting
125
+
126
+ ### Counting Identity
127
+
128
+ For every query result at a biallelic site, the following identity holds:
129
+
130
+ **N_HET + N_HOM_ALT + N_HEMI + N_HOM_REF + N_FAIL + N_NO_COVERAGE = n_eligible**
131
+
132
+ This can be used to validate results. At a multi-allelic site, eligible samples that carry only another ALT allele at the position fall in none of these categories, so the sum is lower by exactly that number of samples (see [Multi-allelic sites](../getting-started/understanding-output.md#multi-allelic-sites)). N_HOM_REF is the number of eligible samples that carry only the reference allele and have no failed call at the position: homozygous reference where they are diploid, and, where they are haploid, hemizygous for the reference (a male on chrX non-PAR or chrY) or a non-carrier on chrM. N_NO_COVERAGE is 0 unless a coverage-evidence filter is active — see [Coverage Evidence](coverage-evidence.md).
133
+
134
+ !!! note "Mutual exclusivity"
135
+ N_HET, N_HOM_ALT, N_HEMI, N_HOM_REF, N_FAIL, and N_NO_COVERAGE are mutually exclusive. A sample with a failed call for any allele at the position is counted in N_FAIL only — it does not appear in N_HET, N_HOM_ALT, N_HEMI or N_HOM_REF, and is left out of AC and AN.
136
+
137
+ The genotype counts are counted per sample, not per allele, and each follows the sample's ploidy at the position:
138
+
139
+ | Count | Who | Copies of the ALT allele (AC) |
140
+ |-------|-----|------------------------------|
141
+ | N_HET | diploid sample, GT `0/1` | 1 |
142
+ | N_HOM_ALT | diploid sample, GT `1/1`; every carrier on chrM | 2; 1 on chrM |
143
+ | N_HEMI | male carrier on chrX non-PAR or chrY (GT `1`, or `1/1` written diploid) | 1 |
144
+
145
+ So `AC = N_HET + 2 × N_HOM_ALT + N_HEMI` everywhere except chrM, where `AC = N_HOM_ALT`. N_HEMI is always 0 on the autosomes, the chrX PARs and chrM, and for females.
146
+
147
+ ### chrX non-PAR
148
+
149
+ - A male with GT=`1` (or `1/1`) is **hemizygous**: he has a single copy of the locus. He contributes AC=1, AN=1 and is counted in **N_HEMI**.
150
+ - A male with GT=`0/1` is a failed call: REF and ALT cannot both be the genotype of a single copy (see [Genotypes inconsistent with ploidy](#genotypes-inconsistent-with-ploidy)).
151
+ - A female with GT=`0/1` contributes AC=1, AN=2 and is counted in N_HET; with GT=`1/1`, AC=2, AN=2 and N_HOM_ALT.
152
+
153
+ N_HET and N_HOM_ALT describe diploid genotypes only, so at a non-PAR chrX position the males are never in them: their carriers are in N_HEMI and the rest in N_HOM_REF (or N_FAIL).
154
+
155
+ ### chrY
156
+
157
+ chrY outside the PARs is haploid in males and absent in females (who are not eligible there):
158
+
159
+ - Every carrier is hemizygous, counted in **N_HEMI**
160
+ - N_HET and N_HOM_ALT are always 0 on chrY
161
+
162
+ ### chrM
163
+
164
+ chrM is haploid for all samples (both sexes contribute AN=1), but it is not hemizygous: a cell holds hundreds to thousands of mtDNA copies, and a variant may be present in all of them (homoplasmy) or in a fraction (heteroplasmy). AFQuery stores the discretized genotypes of the source VCF and records no heteroplasmy level (see the [FAQ](../faq.md#is-heteroplasmy-taken-into-account-when-calculating-allele-frequency-in-mitochondrial-variants)), so:
165
+
166
+ - Every carrier counts once, in **N_HOM_ALT**, whatever its GT (`1`, `0/1` or `1/1`); a `0/1` call is not an error there
167
+ - N_HET and N_HEMI are always 0 on chrM
168
+
169
+ ### Genotypes inconsistent with ploidy
170
+
171
+ Ploidy comes from each sample's sex and the position, not from how the VCF writes the genotype. A male carrier on chrX non-PAR or chrY counts as one allele whether its GT is written haploid (`1`) or diploid (`1/1`): both name a single allele. A call that names more alleles than the sample has cannot be counted that way:
172
+
173
+ - on chrX non-PAR or chrY in a male, a call naming two different alleles: a heterozygous call (`0/1`) or two ALT alleles (`1/2`). A male has a single copy there, so REF and ALT cannot both be his genotype; such a call usually comes from mis-mapped reads or contamination, and a 47,XXY sample registered as male shows it genuinely;
174
+ - on chrM, two different ALT alleles (`1/2`). A `0/1` call on chrM is not inconsistent: it is heteroplasmy, a mix of mtDNA copies, and the sample is a carrier (see [chrM](#chrm_1));
175
+ - on a diploid position, more than two copies across the records at that position (e.g. `1/1` for one ALT and `0/1` for another).
176
+
177
+ `create-db` and `update-db --add-samples` record every call of the sample at such a position as a failed call, so it counts in `N_FAIL` and is left out of AC and AN (counted as hom-ref with `--fail-as-ref`), and log a warning naming the sample and the positions.
178
+
179
+ A cohort called in diploid mode on the sex chromosomes therefore shows male `N_FAIL` at chrX positions where the caller saw both alleles in a male. That is the intended reading, the one gnomAD applies too: those genotypes are unknown, not hom-ref and not carriers. Do not rewrite them with `bcftools +fixploidy` beforehand; it keeps the first allele of each call (`0/1` becomes `0`), which turns them into hom-ref without a trace (see [Preprocessing](../getting-started/preprocessing.md#ploidy-of-sex-chromosomes-and-chrm)).
180
+
181
+ ---
182
+
183
+ ## Sex Filter Interaction
184
+
185
+ When `--sex female` is used on chrX (non-PAR), AN is purely diploid:
186
+
187
+ - Each eligible female contributes AN=2
188
+ - AF is computed over a fully diploid denominator
189
+
190
+ When `--sex male` is used on chrX (non-PAR), AN is purely haploid:
191
+
192
+ - Each eligible male contributes AN=1
193
+ - AF reflects the observed allele frequency in haploid male calls
194
+ - Carriers are all hemizygous: N_HEMI = AC, and N_HET = N_HOM_ALT = 0
195
+
196
+ This makes it straightforward to compare X-linked variant frequencies between sexes without manual ploidy adjustment.
197
+
198
+ ---
199
+
200
+ ## Next Steps
201
+
202
+ - [Sex-Specific AF](../use-cases/sex-specific-af.md) — X-linked variant analysis using sex-stratified queries
203
+ - [Key Concepts](../getting-started/concepts.md) — AC/AN/AF overview and the ploidy table
204
+ - [Sample Filtering](../guides/sample-filtering.md) — `--sex` filter syntax
@@ -191,6 +191,8 @@ As a result, intermediate heteroplasmy levels (such as 20%) are not explicitly r
191
191
 
192
192
  Therefore, this limitation arises from the variant calling step. The application operates on already discretized genotypes according to ploidy and does not model heteroplasmy as a continuous variable.
193
193
 
194
+ In practice, every chrM call carrying the ALT allele (`1`, `0/1` or `1/1`) counts once: in `N_HOM_ALT`, and as `hom` in `variant-info`. A `0/1` call is not treated as an error on chrM, and chrM carriers are never counted as hemizygous (`N_HEMI`), a term that applies to the single-copy sex chromosomes in males.
195
+
194
196
  ## Common Pitfalls
195
197
 
196
198
  ### What if AN is very low?
@@ -226,7 +228,7 @@ Without stratification, rare variant interpretation in mixed cohorts can be misl
226
228
  AFQuery is purpose-built for fast subcohort AF computation and is not a general-purpose genomic database:
227
229
 
228
230
  - **Not a joint genotyper**: AFQuery does not perform joint genotyping. Input VCFs should be individually called before ingestion.
229
- - **Not a genotype store**: AFQuery stores genotype summaries as bitmaps, not raw FORMAT fields. Use `variant-info` to list carriers and their genotype class (het/hom) at a specific position; for full per-sample VCF fields (GQ, DP, AD, etc.), consult the source VCFs.
231
+ - **Not a genotype store**: AFQuery stores genotype summaries as bitmaps, not raw FORMAT fields. Use `variant-info` to list carriers and their genotype class (het/hom/hemi) at a specific position; for full per-sample VCF fields (GQ, DP, AD, etc.), consult the source VCFs.
230
232
  - **No statistical genetics**: AFQuery does not compute Hardy-Weinberg equilibrium, population stratification, or other statistical genetics metrics.
231
233
  - **Batch queries**: The `--from-file` batch mode supports variants across multiple chromosomes in a single call. Point queries (`--locus`) and region queries (`--region`) target a single position or range; for multi-position multi-chromosome lookups, use `--from-file`.
232
234
  - **Cohort size limit**: Performance at >100K samples has not been validated. Memory requirements for the build phase scale with cohort size.
@@ -58,7 +58,7 @@ For a given variant (chromosome, position, ref, alt):
58
58
  - **AN** (Allele Number) — total number of alleles examined (2× diploid samples, 1× haploid). Samples with a failed call (`FILTER≠PASS`) at the position are left out, as their genotype there is unknown; they are reported as `N_FAIL` (see [FILTER=PASS Tracking](../advanced/filter-pass-tracking.md))
59
59
  - **AF** (Allele Frequency) — `AC / AN` (None when AN = 0)
60
60
 
61
- A heterozygous carrier contributes AC=1; a homozygous alt carrier contributes AC=2.
61
+ A heterozygous carrier contributes AC=1; a homozygous alt carrier contributes AC=2; a carrier with a single copy of the locus (a hemizygous male on chrX non-PAR or chrY, or any carrier on chrM) contributes AC=1.
62
62
 
63
63
  ### Ploidy
64
64
 
@@ -69,10 +69,11 @@ AN depends on the chromosome and sex of eligible samples:
69
69
  | Autosomes (chr1–22) | 2 | 2 |
70
70
  | chrX (non-PAR) | 2 | 1 |
71
71
  | chrX (PAR1/PAR2) | 2 | 2 |
72
- | chrY | 0 | 1 |
72
+ | chrY (non-PAR) | 0 | 1 |
73
+ | chrY (PAR1/PAR2) | 0 | 0 |
73
74
  | chrM | 1 | 1 |
74
75
 
75
- See [Ploidy & Special Chromosomes](../advanced/ploidy-and-sex-chroms.md) for PAR coordinates.
76
+ The PARs are the same sequence on chrX and chrY, so AFQuery counts them once, at their chrX coordinates; nobody is genotyped in the chrY PARs. See [Ploidy & Special Chromosomes](../advanced/ploidy-and-sex-chroms.md#pseudoautosomal-regions-par) for PAR coordinates.
76
77
 
77
78
  ### Worked Example
78
79
 
@@ -128,8 +129,10 @@ graph TB
128
129
 
129
130
  For each variant row, AFQuery stores per-sample genotype information as [Roaring Bitmaps](https://roaringbitmap.org/). Three of them drive every query:
130
131
 
131
- - **`het_bitmap`** — sample is heterozygous (`GT=0/1`) with `FILTER=PASS`
132
- - **`hom_bitmap`** — sample is homozygous alt (`GT=1/1`, or `GT=1` on haploid regions) with `FILTER=PASS`
132
+ - **`het_bitmap`** — the sample's genotype holds one copy of the ALT allele (`GT=0/1`, or a haploid `GT=1`) with `FILTER=PASS`
133
+ - **`hom_bitmap`** — the sample's genotype holds two copies of the ALT allele (`GT=1/1`) with `FILTER=PASS`
134
+
135
+ The bitmaps record the genotype as the VCF wrote it; ploidy is applied at query time. A diploid sample in `het_bitmap` is counted in N_HET and one in `hom_bitmap` in N_HOM_ALT, while a haploid carrier — in either bitmap — has a single copy: N_HEMI for a male on chrX non-PAR or chrY, N_HOM_ALT on chrM.
133
136
  - **`fail_bitmap`** — the sample's call at this site failed (`FILTER≠PASS`, or a genotype inconsistent with its ploidy); see [FILTER=PASS Tracking](../advanced/filter-pass-tracking.md)
134
137
 
135
138
  Each sample has a stable integer ID (0-indexed). The bit position in the bitmap equals the sample ID. Databases built with coverage-quality filters carry two additional bitmaps — see [Data Model](../reference/data-model.md#parquet-schema).
@@ -4,6 +4,12 @@ AFQuery ingests single-sample, normalized VCF files. While AFQuery itself does n
4
4
 
5
5
  A ready-to-use normalization script is provided at [`resources/normalize_vcf.sh`](https://github.com/babelomics/afquery/blob/master/resources/normalize_vcf.sh). It requires **bcftools 1.20 or later**: older releases refuse to split multi-allelic records and remove duplicates in the same `bcftools norm` call, and the script exits with an error if it finds one.
6
6
 
7
+ ```bash
8
+ resources/normalize_vcf.sh <vcf_id> <vcf> <ref_genome> [threads]
9
+ # e.g.
10
+ resources/normalize_vcf.sh sample1 input.vcf.gz GRCh38.fa 8 # writes sample1_norm.vcf.gz
11
+ ```
12
+
7
13
  !!! warning "VCFs normalized with the script from afquery 0.4.2 or earlier"
8
14
  Those versions of the script did not split multi-allelic records, and removed
9
15
  one of two different indels at the same position as a duplicate. Indels from
@@ -27,11 +33,15 @@ Multi-allelic variants and complex indels can be represented in multiple equival
27
33
 
28
34
  `bcftools norm -m -both` decomposes multi-allelic sites into biallelic records, and left-aligns and trims each allele against the reference genome, ensuring consistent representation across samples. `-d exact` then drops only records whose alleles are identical, so two different alleles at the same position are both kept.
29
35
 
30
- ### Ploidy correction for sex chromosomes
36
+ ### Ploidy of sex chromosomes and chrM
37
+
38
+ No ploidy correction is needed, and the script makes none: AFQuery takes each sample's ploidy from its sex in the manifest and the position (see [Ploidy & Sex Chromosomes](../advanced/ploidy-and-sex-chroms.md)). Genotypes are read as follows, whether the caller wrote them haploid or diploid:
31
39
 
32
- Male samples should have haploid genotype calls at chrX non-PAR regions (GT=`1`, not GT=`0/1` or `1/1`). Many variant callers output diploid genotypes for males at chrX by default. AFQuery takes ploidy from the sample's sex, so a diploid-coded male call still counts as one allele; but a male call carrying two different ALT alleles (`1/2`) cannot be counted at all and is recorded as a failed call, with a warning during ingestion (see [Genotypes inconsistent with ploidy](../advanced/ploidy-and-sex-chroms.md#genotypes-inconsistent-with-ploidy)). `bcftools +fixploidy` rewrites these genotypes as haploid calls.
40
+ - **Male on chrX non-PAR or chrY**: `1` and `1/1` name a single ALT allele, so he is a hemizygous carrier. A heterozygous call (`0/1`) names two alleles where he has one copy; it is recorded as a failed call (`N_FAIL`), with a warning during ingestion (see [Genotypes inconsistent with ploidy](../advanced/ploidy-and-sex-chroms.md#genotypes-inconsistent-with-ploidy)). In a cohort called in diploid mode on the sex chromosomes this makes male `N_FAIL` visible at chrX positions where the caller saw both alleles, rather than hiding those genotypes.
41
+ - **chrM**: any call carrying the ALT allele (`1`, `0/1`, `1/1`) is a carrier. A `0/1` there is heteroplasmy, not an error.
42
+ - **chrY PARs**: not genotyped; PAR variants are counted at their chrX coordinates.
33
43
 
34
- `bcftools +fixploidy` corrects genotype ploidy based on a sex file.
44
+ Do not run `bcftools +fixploidy` before ingestion. It keeps the first allele of each call when it lowers the ploidy (`0/1` becomes `0`), so a male's heterozygous call on chrX would be stored as hom-ref, and a heteroplasmic chrM call would be dropped (chrM is haploid in its rules for both sexes).
35
45
 
36
46
  ### Filtering and stripping
37
47
 
@@ -70,7 +70,7 @@ afquery query --db ./my_db/ --locus chr1:925952
70
70
 
71
71
  Example output:
72
72
  ```
73
- chr1:925952 G>A AC=2 AN=6 AF=0.3333 n_eligible=3 N_HET=2 N_HOM_ALT=0 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
73
+ chr1:925952 G>A AC=2 AN=6 AF=0.3333 n_eligible=3 N_HET=2 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
74
74
  ```
75
75
 
76
76
  Filter to female samples with a specific phenotype:
@@ -98,7 +98,7 @@ See which samples carry the variant you just queried:
98
98
  afquery variant-info --db ./my_db/ --locus chr1:925952
99
99
  ```
100
100
 
101
- This lists each carrier with their sex, technology, phenotype codes, genotype (het/hom), and FILTER status. See [Variant Info](../guides/variant-info.md) for details.
101
+ This lists each carrier with their sex, technology, phenotype codes, genotype (het/hom/hemi), and FILTER status. See [Variant Info](../guides/variant-info.md) for details.
102
102
 
103
103
  ---
104
104
 
@@ -133,8 +133,9 @@ The output VCF gains INFO fields (see [Annotate a VCF](../guides/annotate-vcf.md
133
133
  | `AFQUERY_AF` | A (per ALT) | Allele frequency |
134
134
  | `AFQUERY_N_HET` | A (per ALT) | Heterozygous sample count |
135
135
  | `AFQUERY_N_HOM_ALT` | A (per ALT) | Homozygous alt sample count |
136
+ | `AFQUERY_N_HEMI` | A (per ALT) | Hemizygous carrier count (males on chrX non-PAR and chrY) |
136
137
  | `AFQUERY_N_HOM_REF` | A (per ALT) | Homozygous ref sample count |
137
- | `AFQUERY_N_FAIL` | 1 (per site) | Samples with a failed call (FILTER≠PASS), left out of AN |
138
+ | `AFQUERY_N_FAIL` | 1 (per site) | Samples with a failed call (FILTER≠PASS, or a genotype inconsistent with ploidy), left out of AN |
138
139
  | `AFQUERY_N_NO_COVERAGE` | A (per ALT) | Eligible samples lacking coverage evidence (0 unless a coverage-evidence filter is active) |
139
140
 
140
141
  ---