afquery 0.7.0__tar.gz → 0.8.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 (175) hide show
  1. {afquery-0.7.0 → afquery-0.8.0}/.gitignore +1 -0
  2. {afquery-0.7.0 → afquery-0.8.0}/PKG-INFO +10 -9
  3. {afquery-0.7.0 → afquery-0.8.0}/README.md +9 -8
  4. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/coverage-evidence.md +2 -2
  5. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/filter-pass-tracking.md +4 -4
  6. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/ploidy-and-sex-chroms.md +1 -1
  7. {afquery-0.7.0 → afquery-0.8.0}/docs/getting-started/quickstart.md +1 -1
  8. {afquery-0.7.0 → afquery-0.8.0}/docs/getting-started/tutorial.md +28 -27
  9. {afquery-0.7.0 → afquery-0.8.0}/docs/getting-started/understanding-output.md +19 -8
  10. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/annotate-vcf.md +3 -0
  11. afquery-0.8.0/docs/guides/dump-aggregation.md +136 -0
  12. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/dump-export.md +25 -4
  13. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/query.md +4 -3
  14. {afquery-0.7.0 → afquery-0.8.0}/docs/index.md +1 -1
  15. {afquery-0.7.0 → afquery-0.8.0}/docs/reference/cli.md +6 -4
  16. {afquery-0.7.0 → afquery-0.8.0}/docs/reference/glossary.md +4 -0
  17. {afquery-0.7.0 → afquery-0.8.0}/docs/reference/python-api.md +11 -2
  18. {afquery-0.7.0 → afquery-0.8.0}/docs/use-cases/acmg-use-cases.md +3 -3
  19. {afquery-0.7.0 → afquery-0.8.0}/docs/use-cases/clinical-prioritization.md +2 -0
  20. {afquery-0.7.0 → afquery-0.8.0}/docs/use-cases/population-specific-af.md +1 -1
  21. {afquery-0.7.0 → afquery-0.8.0}/docs/use-cases/pseudo-controls.md +4 -4
  22. {afquery-0.7.0 → afquery-0.8.0}/docs/use-cases/sex-specific-af.md +3 -3
  23. {afquery-0.7.0 → afquery-0.8.0}/docs/use-cases/technology-integration.md +2 -2
  24. {afquery-0.7.0 → afquery-0.8.0}/examples/demo/create_demo_data.py +4 -4
  25. afquery-0.8.0/examples/dump_aggregation/README.md +103 -0
  26. afquery-0.8.0/examples/dump_aggregation/aggregate_groups.py +78 -0
  27. afquery-0.8.0/examples/dump_aggregation/create_example_data.py +110 -0
  28. {afquery-0.7.0 → afquery-0.8.0}/mkdocs.yml +1 -0
  29. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/_version.py +2 -2
  30. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/annotate.py +17 -6
  31. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/cli.py +37 -25
  32. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/dump.py +65 -41
  33. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/models.py +1 -0
  34. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/query.py +53 -3
  35. {afquery-0.7.0 → afquery-0.8.0}/tests/oracle.py +14 -2
  36. {afquery-0.7.0 → afquery-0.8.0}/tests/test_annotate.py +19 -0
  37. {afquery-0.7.0 → afquery-0.8.0}/tests/test_cli_docs_consistency.py +20 -0
  38. {afquery-0.7.0 → afquery-0.8.0}/tests/test_dump.py +156 -5
  39. afquery-0.8.0/tests/test_examples.py +59 -0
  40. {afquery-0.7.0 → afquery-0.8.0}/tests/test_invariants.py +2 -1
  41. {afquery-0.7.0 → afquery-0.8.0}/tests/test_multiallelic.py +183 -0
  42. {afquery-0.7.0 → afquery-0.8.0}/tests/test_oracle_consistency.py +2 -1
  43. {afquery-0.7.0 → afquery-0.8.0}/tests/test_variant_info.py +6 -3
  44. {afquery-0.7.0 → afquery-0.8.0}/.dockerignore +0 -0
  45. {afquery-0.7.0 → afquery-0.8.0}/.github/workflows/ci.yml +0 -0
  46. {afquery-0.7.0 → afquery-0.8.0}/.github/workflows/docs.yml +0 -0
  47. {afquery-0.7.0 → afquery-0.8.0}/.github/workflows/release.yml +0 -0
  48. {afquery-0.7.0 → afquery-0.8.0}/CONTRIBUTING.md +0 -0
  49. {afquery-0.7.0 → afquery-0.8.0}/Dockerfile +0 -0
  50. {afquery-0.7.0 → afquery-0.8.0}/LICENSE +0 -0
  51. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/.gitignore +0 -0
  52. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/INSTALL.md +0 -0
  53. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/README.md +0 -0
  54. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/Snakefile +0 -0
  55. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/.gitignore +0 -0
  56. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/01a_assign_samples.py +0 -0
  57. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/01b_write_manifests.py +0 -0
  58. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/02_build_databases.py +0 -0
  59. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/03_compute_metrics.py +0 -0
  60. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/04_classify_acmg.py +0 -0
  61. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/05_plot_figures.py +0 -0
  62. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/README.md +0 -0
  63. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/Snakefile +0 -0
  64. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/__init__.py +0 -0
  65. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/beds/SureSelect_v5.bed +0 -0
  66. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/beds/SureSelect_v6.bed +0 -0
  67. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/beds/SureSelect_v7.bed +0 -0
  68. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/capture_kit/config.py +0 -0
  69. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/config.yaml +0 -0
  70. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/envs/benchmark.yaml +0 -0
  71. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/.gitignore +0 -0
  72. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/01_prepare_data.py +0 -0
  73. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/02_query_scaling.py +0 -0
  74. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/03_build.py +0 -0
  75. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/04_annotate.py +0 -0
  76. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/05_vs_bcftools.py +0 -0
  77. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/06_plot.py +0 -0
  78. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/README.md +0 -0
  79. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/Snakefile +0 -0
  80. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/collect_annotate.py +0 -0
  81. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/collect_bcftools.py +0 -0
  82. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/collect_build_perf.py +0 -0
  83. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/collect_prepare.py +0 -0
  84. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/collect_query_scaling.py +0 -0
  85. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/config.py +0 -0
  86. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/performance/config_smoke.py +0 -0
  87. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/shared/__init__.py +0 -0
  88. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/shared/config.py +0 -0
  89. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/shared/rules/download_1kg.smk +0 -0
  90. {afquery-0.7.0 → afquery-0.8.0}/benchmarks/shared/utils.py +0 -0
  91. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/benchmarking.md +0 -0
  92. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/debugging-results.md +0 -0
  93. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/multi-cohort-strategies.md +0 -0
  94. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/performance.md +0 -0
  95. {afquery-0.7.0 → afquery-0.8.0}/docs/advanced/pipeline-integration.md +0 -0
  96. {afquery-0.7.0 → afquery-0.8.0}/docs/assets/img/gap2_mixed_technologies.png +0 -0
  97. {afquery-0.7.0 → afquery-0.8.0}/docs/faq.md +0 -0
  98. {afquery-0.7.0 → afquery-0.8.0}/docs/getting-started/concepts.md +0 -0
  99. {afquery-0.7.0 → afquery-0.8.0}/docs/getting-started/installation.md +0 -0
  100. {afquery-0.7.0 → afquery-0.8.0}/docs/getting-started/motivation.md +0 -0
  101. {afquery-0.7.0 → afquery-0.8.0}/docs/getting-started/preprocessing.md +0 -0
  102. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/create-database.md +0 -0
  103. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/manifest-format.md +0 -0
  104. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/sample-filtering.md +0 -0
  105. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/update-database.md +0 -0
  106. {afquery-0.7.0 → afquery-0.8.0}/docs/guides/variant-info.md +0 -0
  107. {afquery-0.7.0 → afquery-0.8.0}/docs/reference/data-model.md +0 -0
  108. {afquery-0.7.0 → afquery-0.8.0}/docs/scripts/gen_gap2_figure.py +0 -0
  109. {afquery-0.7.0 → afquery-0.8.0}/docs/stylesheets/extra.css +0 -0
  110. {afquery-0.7.0 → afquery-0.8.0}/docs/troubleshooting.md +0 -0
  111. {afquery-0.7.0 → afquery-0.8.0}/docs/use-cases/cohort-stratification.md +0 -0
  112. {afquery-0.7.0 → afquery-0.8.0}/examples/demo/README.md +0 -0
  113. {afquery-0.7.0 → afquery-0.8.0}/pyproject.toml +0 -0
  114. {afquery-0.7.0 → afquery-0.8.0}/recipes/afquery/meta.yaml +0 -0
  115. {afquery-0.7.0 → afquery-0.8.0}/resources/normalize_vcf.sh +0 -0
  116. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/__init__.py +0 -0
  117. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/benchmark.py +0 -0
  118. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/bitmaps.py +0 -0
  119. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/capture.py +0 -0
  120. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/constants.py +0 -0
  121. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/database.py +0 -0
  122. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/ploidy.py +0 -0
  123. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/__init__.py +0 -0
  124. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/build.py +0 -0
  125. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/compact.py +0 -0
  126. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/ingest.py +0 -0
  127. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/manifest.py +0 -0
  128. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/regions.py +0 -0
  129. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/synth.py +0 -0
  130. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/preprocess/update.py +0 -0
  131. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/storage.py +0 -0
  132. {afquery-0.7.0 → afquery-0.8.0}/src/afquery/variant_info.py +0 -0
  133. {afquery-0.7.0 → afquery-0.8.0}/tests/conftest.py +0 -0
  134. {afquery-0.7.0 → afquery-0.8.0}/tests/data/annotate_input.vcf +0 -0
  135. {afquery-0.7.0 → afquery-0.8.0}/tests/data/annotate_multi_bucket.vcf +0 -0
  136. {afquery-0.7.0 → afquery-0.8.0}/tests/data/annotate_multi_chrom.vcf +0 -0
  137. {afquery-0.7.0 → afquery-0.8.0}/tests/data/beds/wes_kit_a.bed +0 -0
  138. {afquery-0.7.0 → afquery-0.8.0}/tests/data/beds/wes_kit_b.bed +0 -0
  139. {afquery-0.7.0 → afquery-0.8.0}/tests/data/beds/wes_kit_nochr.bed +0 -0
  140. {afquery-0.7.0 → afquery-0.8.0}/tests/data/expected_results.json +0 -0
  141. {afquery-0.7.0 → afquery-0.8.0}/tests/data/manifest.tsv +0 -0
  142. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S00.vcf +0 -0
  143. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S01.vcf +0 -0
  144. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S02.vcf +0 -0
  145. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S03.vcf +0 -0
  146. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S04.vcf +0 -0
  147. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S05.vcf +0 -0
  148. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S06.vcf +0 -0
  149. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S07.vcf +0 -0
  150. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S08.vcf +0 -0
  151. {afquery-0.7.0 → afquery-0.8.0}/tests/data/vcfs/S09.vcf +0 -0
  152. {afquery-0.7.0 → afquery-0.8.0}/tests/test_batch.py +0 -0
  153. {afquery-0.7.0 → afquery-0.8.0}/tests/test_benchmark.py +0 -0
  154. {afquery-0.7.0 → afquery-0.8.0}/tests/test_bitmaps.py +0 -0
  155. {afquery-0.7.0 → afquery-0.8.0}/tests/test_capture.py +0 -0
  156. {afquery-0.7.0 → afquery-0.8.0}/tests/test_chrY_par.py +0 -0
  157. {afquery-0.7.0 → afquery-0.8.0}/tests/test_cli.py +0 -0
  158. {afquery-0.7.0 → afquery-0.8.0}/tests/test_compact.py +0 -0
  159. {afquery-0.7.0 → afquery-0.8.0}/tests/test_constants.py +0 -0
  160. {afquery-0.7.0 → afquery-0.8.0}/tests/test_haploid_stats.py +0 -0
  161. {afquery-0.7.0 → afquery-0.8.0}/tests/test_info.py +0 -0
  162. {afquery-0.7.0 → afquery-0.8.0}/tests/test_no_coverage.py +0 -0
  163. {afquery-0.7.0 → afquery-0.8.0}/tests/test_normalize_script.py +0 -0
  164. {afquery-0.7.0 → afquery-0.8.0}/tests/test_pass_filter.py +0 -0
  165. {afquery-0.7.0 → afquery-0.8.0}/tests/test_ploidy.py +0 -0
  166. {afquery-0.7.0 → afquery-0.8.0}/tests/test_preprocess.py +0 -0
  167. {afquery-0.7.0 → afquery-0.8.0}/tests/test_query.py +0 -0
  168. {afquery-0.7.0 → afquery-0.8.0}/tests/test_sample_filter.py +0 -0
  169. {afquery-0.7.0 → afquery-0.8.0}/tests/test_storage.py +0 -0
  170. {afquery-0.7.0 → afquery-0.8.0}/tests/test_synth.py +0 -0
  171. {afquery-0.7.0 → afquery-0.8.0}/tests/test_synthetic_stats.py +0 -0
  172. {afquery-0.7.0 → afquery-0.8.0}/tests/test_update.py +0 -0
  173. {afquery-0.7.0 → afquery-0.8.0}/tests/test_update_metadata.py +0 -0
  174. {afquery-0.7.0 → afquery-0.8.0}/tests/test_update_partitioned.py +0 -0
  175. {afquery-0.7.0 → afquery-0.8.0}/tests/test_warnings.py +0 -0
@@ -61,3 +61,4 @@ src/afquery/_version.py
61
61
  db/*
62
62
  site
63
63
  CONTEXT.md
64
+ examples/dump_aggregation/example_output/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: afquery
3
- Version: 0.7.0
3
+ Version: 0.8.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_HEMI/N_HOM_REF/N_FAIL/N_NO_COVERAGE` INFO fields.
80
+ - **Parallel VCF annotation** — multi-threaded; adds `AFQUERY_AC/AN/AF/AC_REF/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,6 +185,7 @@ 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
+ | `AC_REF` | Reference alleles at the position: `AN` minus the AC of every alt allele there (the reference frequency is `AC_REF / AN`) |
188
189
  | `N_HET` | Heterozygous PASS carriers (diploid) |
189
190
  | `N_HOM_ALT` | Homozygous-alt PASS carriers (diploid); every carrier on chrM |
190
191
  | `N_HEMI` | Hemizygous PASS carriers: males on chrX outside the PARs and on chrY |
@@ -209,11 +210,11 @@ VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO
209
210
  | `version show` / `version set` | Inspect or set the database version label |
210
211
  | `benchmark` | Run synthetic or on-database performance benchmarks |
211
212
 
212
- See the [CLI reference](https://babelomics.github.io/afquery/reference/cli/) for all options.
213
+ See the [CLI reference](https://babelomics.github.io/afquery/latest/reference/cli/) for all options.
213
214
 
214
215
  ## How it works
215
216
 
216
- AFQuery indexes each variant as three Roaring Bitmaps — heterozygous PASS carriers, homozygous-alt PASS carriers, and FILTER≠PASS carriers — stored in Apache Parquet, partitioned by chromosome and 1-Mbp positional buckets. Sample metadata (sex, technology, phenotype) is precomputed as bitmaps in SQLite. A query resolves its sample filter into a single candidate bitmap by intersection/difference in microseconds, then intersects it against each variant's genotype bitmaps to compute AC. AN is computed per position from the same candidate bitmap, restricted to samples whose technology actually covers the position (via BED-derived capture indices) and adjusted for ploidy on sex chromosomes. See the [data model reference](https://babelomics.github.io/afquery/reference/data-model/) for details.
217
+ AFQuery indexes each variant as three Roaring Bitmaps — heterozygous PASS carriers, homozygous-alt PASS carriers, and FILTER≠PASS carriers — stored in Apache Parquet, partitioned by chromosome and 1-Mbp positional buckets. Sample metadata (sex, technology, phenotype) is precomputed as bitmaps in SQLite. A query resolves its sample filter into a single candidate bitmap by intersection/difference in microseconds, then intersects it against each variant's genotype bitmaps to compute AC. AN is computed per position from the same candidate bitmap, restricted to samples whose technology actually covers the position (via BED-derived capture indices) and adjusted for ploidy on sex chromosomes. See the [data model reference](https://babelomics.github.io/afquery/latest/reference/data-model/) for details.
217
218
 
218
219
  ## How AFQuery compares
219
220
 
@@ -238,11 +239,11 @@ Point-query latency on AFQuery is ~14 ms and constant from 1K to 50K samples (me
238
239
  ## Documentation
239
240
 
240
241
  - [Full documentation](https://babelomics.github.io/afquery/)
241
- - [Getting started](https://babelomics.github.io/afquery/getting-started/)
242
- - [Why local allele frequencies?](https://babelomics.github.io/afquery/getting-started/motivation/)
243
- - [Manifest format](https://babelomics.github.io/afquery/guides/manifest-format/)
244
- - [CLI reference](https://babelomics.github.io/afquery/reference/cli/)
245
- - [FAQ](https://babelomics.github.io/afquery/faq/)
242
+ - [Getting started](https://babelomics.github.io/afquery/latest/getting-started/quickstart/)
243
+ - [Why local allele frequencies?](https://babelomics.github.io/afquery/latest/getting-started/motivation/)
244
+ - [Manifest format](https://babelomics.github.io/afquery/latest/guides/manifest-format/)
245
+ - [CLI reference](https://babelomics.github.io/afquery/latest/reference/cli/)
246
+ - [FAQ](https://babelomics.github.io/afquery/latest/faq/)
246
247
 
247
248
  ## Citation
248
249
 
@@ -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_HEMI/N_HOM_REF/N_FAIL/N_NO_COVERAGE` INFO fields.
50
+ - **Parallel VCF annotation** — multi-threaded; adds `AFQUERY_AC/AN/AF/AC_REF/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,6 +155,7 @@ 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
+ | `AC_REF` | Reference alleles at the position: `AN` minus the AC of every alt allele there (the reference frequency is `AC_REF / AN`) |
158
159
  | `N_HET` | Heterozygous PASS carriers (diploid) |
159
160
  | `N_HOM_ALT` | Homozygous-alt PASS carriers (diploid); every carrier on chrM |
160
161
  | `N_HEMI` | Hemizygous PASS carriers: males on chrX outside the PARs and on chrY |
@@ -179,11 +180,11 @@ VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO
179
180
  | `version show` / `version set` | Inspect or set the database version label |
180
181
  | `benchmark` | Run synthetic or on-database performance benchmarks |
181
182
 
182
- See the [CLI reference](https://babelomics.github.io/afquery/reference/cli/) for all options.
183
+ See the [CLI reference](https://babelomics.github.io/afquery/latest/reference/cli/) for all options.
183
184
 
184
185
  ## How it works
185
186
 
186
- AFQuery indexes each variant as three Roaring Bitmaps — heterozygous PASS carriers, homozygous-alt PASS carriers, and FILTER≠PASS carriers — stored in Apache Parquet, partitioned by chromosome and 1-Mbp positional buckets. Sample metadata (sex, technology, phenotype) is precomputed as bitmaps in SQLite. A query resolves its sample filter into a single candidate bitmap by intersection/difference in microseconds, then intersects it against each variant's genotype bitmaps to compute AC. AN is computed per position from the same candidate bitmap, restricted to samples whose technology actually covers the position (via BED-derived capture indices) and adjusted for ploidy on sex chromosomes. See the [data model reference](https://babelomics.github.io/afquery/reference/data-model/) for details.
187
+ AFQuery indexes each variant as three Roaring Bitmaps — heterozygous PASS carriers, homozygous-alt PASS carriers, and FILTER≠PASS carriers — stored in Apache Parquet, partitioned by chromosome and 1-Mbp positional buckets. Sample metadata (sex, technology, phenotype) is precomputed as bitmaps in SQLite. A query resolves its sample filter into a single candidate bitmap by intersection/difference in microseconds, then intersects it against each variant's genotype bitmaps to compute AC. AN is computed per position from the same candidate bitmap, restricted to samples whose technology actually covers the position (via BED-derived capture indices) and adjusted for ploidy on sex chromosomes. See the [data model reference](https://babelomics.github.io/afquery/latest/reference/data-model/) for details.
187
188
 
188
189
  ## How AFQuery compares
189
190
 
@@ -208,11 +209,11 @@ Point-query latency on AFQuery is ~14 ms and constant from 1K to 50K samples (me
208
209
  ## Documentation
209
210
 
210
211
  - [Full documentation](https://babelomics.github.io/afquery/)
211
- - [Getting started](https://babelomics.github.io/afquery/getting-started/)
212
- - [Why local allele frequencies?](https://babelomics.github.io/afquery/getting-started/motivation/)
213
- - [Manifest format](https://babelomics.github.io/afquery/guides/manifest-format/)
214
- - [CLI reference](https://babelomics.github.io/afquery/reference/cli/)
215
- - [FAQ](https://babelomics.github.io/afquery/faq/)
212
+ - [Getting started](https://babelomics.github.io/afquery/latest/getting-started/quickstart/)
213
+ - [Why local allele frequencies?](https://babelomics.github.io/afquery/latest/getting-started/motivation/)
214
+ - [Manifest format](https://babelomics.github.io/afquery/latest/guides/manifest-format/)
215
+ - [CLI reference](https://babelomics.github.io/afquery/latest/reference/cli/)
216
+ - [FAQ](https://babelomics.github.io/afquery/latest/faq/)
216
217
 
217
218
  ## Citation
218
219
 
@@ -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_HEMI=0 N_HOM_REF=1231 N_FAIL=0 N_NO_COVERAGE=0
77
+ chr1:925952 G>A AC=142 AN=2742 AF=0.0518 AC_REF=2600 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_HEMI=0 N_HOM_REF=1108 N_FAIL=0 N_NO_COVERAGE=123
87
+ chr1:925952 G>A AC=142 AN=2742 AF=0.0518 AC_REF=2600 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
@@ -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_HEMI=0 N_HOM_REF=1224 N_FAIL=7 N_NO_COVERAGE=0
35
+ chr1:925952 G>A AC=142 AN=2728 AF=0.0521 AC_REF=2586 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.
@@ -45,17 +45,17 @@ If all eligible samples have a failed call at a position, AN is 0 and AF is unde
45
45
 
46
46
  ## Counting failed calls as reference
47
47
 
48
- `--fail-as-ref` (`fail_as_ref=True` in the Python API) keeps samples with a failed call in AN, counting them as homozygous reference. It is available on `query`, `annotate` and `dump`, and changes only AN and AF: the failed samples still add nothing to AC and are still reported in `N_FAIL`.
48
+ `--fail-as-ref` (`fail_as_ref=True` in the Python API) keeps samples with a failed call in AN, counting them as homozygous reference. It is available on `query`, `annotate` and `dump`, and changes only AN, AF and `AC_REF`. The failed samples still add nothing to AC and are still reported in `N_FAIL`.
49
49
 
50
50
  ```bash
51
51
  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_HEMI=0 N_HOM_REF=1224 N_FAIL=7 N_NO_COVERAGE=0
55
+ chr1:925952 G>A AC=142 AN=2742 AF=0.0518 AC_REF=2600 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
- 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.
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. Their alleles are counted as reference in `AC_REF`, so `AN = AC_REF + ΣAC` still holds, but `AC_REF` then includes alleles that were never called reference. A sample whose call failed for one allele of a multi-allelic position is failed for all of them, so a confirmed ALT call of that sample at the same position is also counted as reference.
59
59
 
60
60
  ---
61
61
 
@@ -87,7 +87,7 @@ afquery query --db ./db/ --locus chrY:2787758 --sex female
87
87
  # chrY:2787758 — no results (AN=0 for all variants)
88
88
 
89
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
90
+ # chrY:2787758 C>T AC=3 AN=856 AF=0.0035 AC_REF=853 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
91
  ```
92
92
 
93
93
  Inside a chrY PAR (here GRCh38 PAR1), nothing is reported, whatever the filters:
@@ -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_HEMI=0 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
73
+ chr1:925952 G>A AC=2 AN=6 AF=0.3333 AC_REF=4 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:
@@ -74,7 +74,7 @@ afquery query --db ./demo_db/ --locus chr1:925952
74
74
  Example output:
75
75
 
76
76
  ```
77
- chr1:925952 G>A AC=6 AN=20 AF=0.3000 n_eligible=10 N_HET=4 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=5 N_FAIL=0 N_NO_COVERAGE=0
77
+ chr1:925952 G>A AC=6 AN=20 AF=0.3000 AC_REF=14 n_eligible=10 N_HET=4 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=5 N_FAIL=0 N_NO_COVERAGE=0
78
78
  ```
79
79
 
80
80
  ### Reading the output
@@ -86,6 +86,7 @@ Every query result includes the following fields:
86
86
  | **AC** | Allele count — alt allele copies in eligible samples |
87
87
  | **AN** | Allele number — total alleles examined (adjusted for coverage and ploidy) |
88
88
  | **AF** | Allele frequency — `AC / AN` |
89
+ | **AC_REF** | Reference allele count at the position — `AN` minus the AC of every alt allele stored there. At a biallelic site it is `AN − AC`; the reference frequency is `AC_REF / AN` |
89
90
  | **n_eligible** | Eligible samples at this position — those passing the metadata filters *and* covered here. Ploidy is applied afterwards, to AN. Here, 10 = no filter applied and every sample is covered. |
90
91
  | **N_HET** | Eligible samples heterozygous for the alt allele |
91
92
  | **N_HOM_ALT** | Eligible samples homozygous for the alt allele |
@@ -93,7 +94,7 @@ Every query result includes the following fields:
93
94
  | **N_HOM_REF** | Eligible samples homozygous reference |
94
95
  | **N_FAIL** | Eligible samples with a non-ref allele called but `FILTER≠PASS` in the source VCF |
95
96
 
96
- For `chr1:925952`: AN=20 = 10 diploid samples × 2 alleles; AC=6 = 4 het samples (1 copy each) + 1 hom-alt (2 copies).
97
+ At `chr1:925952`, AN=20 comes from 10 diploid samples with 2 alleles each, and AC=6 from 4 het samples with one copy each plus 1 hom-alt sample with two. The remaining 14 alleles are reference, so AC_REF=14.
97
98
 
98
99
  **Accounting identity:** `n_eligible = N_HET + N_HOM_ALT + N_HEMI + N_HOM_REF + N_FAIL + N_NO_COVERAGE` always holds at a biallelic site. `N_HEMI` and `N_NO_COVERAGE` are 0 here (an autosome, and no coverage-evidence filter), so 10 = 4+1+0+5+0+0 ✓.
99
100
 
@@ -108,10 +109,10 @@ afquery query --db ./demo_db/ --locus chr1:946000
108
109
  Example output:
109
110
 
110
111
  ```
111
- chr1:946000 T>C AC=2 AN=16 AF=0.1250 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=6 N_FAIL=2 N_NO_COVERAGE=0
112
+ chr1:946000 T>C AC=2 AN=16 AF=0.1250 AC_REF=14 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=6 N_FAIL=2 N_NO_COVERAGE=0
112
113
  ```
113
114
 
114
- Here, 2 samples were flagged as `LowQual` in their source VCF at this position. Their genotype there is unknown, so they are left out of both AC and AN: `AN=2×(10−2)=16` and `AF=2/16=0.1250`. They remain eligible, so the accounting identity still holds: 10 = 2+0+6+2+0 ✓. See [FILTER=PASS Tracking](../advanced/filter-pass-tracking.md).
115
+ Here, 2 samples were flagged as `LowQual` in their source VCF at this position. Their genotype there is unknown, so they are left out of both AC and AN, which gives `AN=2×(10−2)=16` and `AF=2/16=0.1250`. They remain eligible, so the accounting identity still holds (10 = 2+0+0+6+2+0 ✓). See [FILTER=PASS Tracking](../advanced/filter-pass-tracking.md).
115
116
 
116
117
  !!! tip
117
118
  N_FAIL > 0 is a signal to inspect source VCF quality at this site. A high N_FAIL relative to n_eligible may indicate a systematic sequencing artifact. See [Understanding Output](understanding-output.md) for thresholds.
@@ -127,9 +128,9 @@ afquery query --db ./demo_db/ --region chr1:900000-950000
127
128
  Example output:
128
129
 
129
130
  ```
130
- chr1:925100 C>T AC=4 AN=20 AF=0.2000 n_eligible=10 N_HET=4 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=6 N_FAIL=0 N_NO_COVERAGE=0
131
- chr1:925952 G>A AC=6 AN=20 AF=0.3000 n_eligible=10 N_HET=4 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=5 N_FAIL=0 N_NO_COVERAGE=0
132
- chr1:946000 T>C AC=2 AN=16 AF=0.1250 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=6 N_FAIL=2 N_NO_COVERAGE=0
131
+ chr1:925100 C>T AC=4 AN=20 AF=0.2000 AC_REF=16 n_eligible=10 N_HET=4 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=6 N_FAIL=0 N_NO_COVERAGE=0
132
+ chr1:925952 G>A AC=6 AN=20 AF=0.3000 AC_REF=14 n_eligible=10 N_HET=4 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=5 N_FAIL=0 N_NO_COVERAGE=0
133
+ chr1:946000 T>C AC=2 AN=16 AF=0.1250 AC_REF=14 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=6 N_FAIL=2 N_NO_COVERAGE=0
133
134
  ```
134
135
 
135
136
  ---
@@ -193,7 +194,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --sex female
193
194
  Example output:
194
195
 
195
196
  ```
196
- chr1:925952 G>A AC=3 AN=10 AF=0.3000 n_eligible=5 N_HET=3 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
197
+ chr1:925952 G>A AC=3 AN=10 AF=0.3000 AC_REF=7 n_eligible=5 N_HET=3 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
197
198
  ```
198
199
 
199
200
  Now query male samples:
@@ -205,7 +206,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --sex male
205
206
  Example output:
206
207
 
207
208
  ```
208
- chr1:925952 G>A AC=3 AN=10 AF=0.3000 n_eligible=5 N_HET=1 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=3 N_FAIL=0 N_NO_COVERAGE=0
209
+ chr1:925952 G>A AC=3 AN=10 AF=0.3000 AC_REF=7 n_eligible=5 N_HET=1 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=3 N_FAIL=0 N_NO_COVERAGE=0
209
210
  ```
210
211
 
211
212
  AN drops from 20 to 10 in both cases because only 5 samples are eligible. The AF happens to be identical here (0.3000), but the genotype distributions differ: the male group has one homozygous-alt carrier while the female group has three heterozygous carriers.
@@ -223,7 +224,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --phenotype E11.9
223
224
  Example output:
224
225
 
225
226
  ```
226
- chr1:925952 G>A AC=5 AN=8 AF=0.6250 n_eligible=4 N_HET=3 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=0 N_FAIL=0 N_NO_COVERAGE=0
227
+ chr1:925952 G>A AC=5 AN=8 AF=0.6250 AC_REF=3 n_eligible=4 N_HET=3 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=0 N_FAIL=0 N_NO_COVERAGE=0
227
228
  ```
228
229
 
229
230
  Exclude control samples:
@@ -235,7 +236,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --phenotype ^control
235
236
  Example output:
236
237
 
237
238
  ```
238
- chr1:925952 G>A AC=6 AN=12 AF=0.5000 n_eligible=6 N_HET=4 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
239
+ chr1:925952 G>A AC=6 AN=12 AF=0.5000 AC_REF=6 n_eligible=6 N_HET=4 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
239
240
  ```
240
241
 
241
242
  The `^` prefix means "exclude". Excluding controls removes 4 samples, leaving 6. See [Sample Filtering](../guides/sample-filtering.md) for the full syntax.
@@ -253,7 +254,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --tech wgs
253
254
  Example output:
254
255
 
255
256
  ```
256
- chr1:925952 G>A AC=4 AN=8 AF=0.5000 n_eligible=4 N_HET=2 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
257
+ chr1:925952 G>A AC=4 AN=8 AF=0.5000 AC_REF=4 n_eligible=4 N_HET=2 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
257
258
  ```
258
259
 
259
260
  Now query each WES technology separately:
@@ -263,7 +264,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --tech wes_v1
263
264
  ```
264
265
 
265
266
  ```
266
- chr1:925952 G>A AC=1 AN=6 AF=0.1667 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
267
+ chr1:925952 G>A AC=1 AN=6 AF=0.1667 AC_REF=5 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
267
268
  ```
268
269
 
269
270
  ```bash
@@ -271,7 +272,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --tech wes_v2
271
272
  ```
272
273
 
273
274
  ```
274
- chr1:925952 G>A AC=1 AN=6 AF=0.1667 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
275
+ chr1:925952 G>A AC=1 AN=6 AF=0.1667 AC_REF=5 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
275
276
  ```
276
277
 
277
278
  `chr1:925952` falls inside the `chr1:900000-950000` capture region shared by both WES kits. All 3 wes_v1 samples and all 3 wes_v2 samples are covered, so AN=6 (3 samples × 2 alleles) for both.
@@ -285,7 +286,7 @@ afquery query --db ./demo_db/ --locus chr1:1399914 --tech wgs
285
286
  ```
286
287
 
287
288
  ```
288
- chr1:1399914 G>T AC=2 AN=8 AF=0.2500 n_eligible=4 N_HET=2 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
289
+ chr1:1399914 G>T AC=2 AN=8 AF=0.2500 AC_REF=6 n_eligible=4 N_HET=2 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
289
290
  ```
290
291
 
291
292
  ```bash
@@ -319,7 +320,7 @@ afquery query \
319
320
  Example output:
320
321
 
321
322
  ```
322
- chr1:925952 G>A AC=1 AN=2 AF=0.5000 n_eligible=1 N_HET=1 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=0 N_FAIL=0 N_NO_COVERAGE=0
323
+ chr1:925952 G>A AC=1 AN=2 AF=0.5000 AC_REF=1 n_eligible=1 N_HET=1 N_HOM_ALT=0 N_HEMI=0 N_HOM_REF=0 N_FAIL=0 N_NO_COVERAGE=0
323
324
  ```
324
325
 
325
326
  Only one sample meets all three criteria (DEMO_001: female, wgs, E11.9). With n_eligible=1, AN=2 (one diploid sample on an autosome) and AC=1 (heterozygous carrier).
@@ -337,7 +338,7 @@ afquery annotate \
337
338
  --output ./annotated_demo.vcf
338
339
  ```
339
340
 
340
- The output VCF gains `AFQUERY_AC`, `AFQUERY_AN`, `AFQUERY_AF`, `AFQUERY_N_HET`, `AFQUERY_N_HOM_ALT`, `AFQUERY_N_HEMI`, `AFQUERY_N_HOM_REF`, `AFQUERY_N_FAIL`, and `AFQUERY_N_NO_COVERAGE` INFO fields. Inspect the chr1 variants:
341
+ The output VCF gains `AFQUERY_AC`, `AFQUERY_AN`, `AFQUERY_AF`, `AFQUERY_AC_REF`, `AFQUERY_N_HET`, `AFQUERY_N_HOM_ALT`, `AFQUERY_N_HEMI`, `AFQUERY_N_HOM_REF`, `AFQUERY_N_FAIL`, and `AFQUERY_N_NO_COVERAGE` INFO fields. Inspect the chr1 variants:
341
342
 
342
343
  ```bash
343
344
  grep -v "^##" ./annotated_demo.vcf | grep "^chr1" | head -3
@@ -346,9 +347,9 @@ grep -v "^##" ./annotated_demo.vcf | grep "^chr1" | head -3
346
347
  Example output (columns: CHROM, POS, ID, REF, ALT, QUAL, FILTER, INFO, FORMAT, DEMO_001):
347
348
 
348
349
  ```
349
- chr1 925100 . C T 50 PASS AFQUERY_AC=4;AFQUERY_AN=20;AFQUERY_AF=0.2;AFQUERY_N_HET=4;AFQUERY_N_HOM_ALT=0;AFQUERY_N_HEMI=0;AFQUERY_N_HOM_REF=6;AFQUERY_N_FAIL=0;AFQUERY_N_NO_COVERAGE=0 GT 0/1
350
- chr1 925952 . G A 50 PASS AFQUERY_AC=6;AFQUERY_AN=20;AFQUERY_AF=0.3;AFQUERY_N_HET=4;AFQUERY_N_HOM_ALT=1;AFQUERY_N_HEMI=0;AFQUERY_N_HOM_REF=5;AFQUERY_N_FAIL=0;AFQUERY_N_NO_COVERAGE=0 GT 0/1
351
- chr1 946000 . T C 50 PASS AFQUERY_AC=2;AFQUERY_AN=16;AFQUERY_AF=0.125;AFQUERY_N_HET=2;AFQUERY_N_HOM_ALT=0;AFQUERY_N_HEMI=0;AFQUERY_N_HOM_REF=6;AFQUERY_N_FAIL=2;AFQUERY_N_NO_COVERAGE=0 GT 0/1
350
+ chr1 925100 . C T 50 PASS AFQUERY_AC=4;AFQUERY_AN=20;AFQUERY_AF=0.2;AFQUERY_AC_REF=16;AFQUERY_N_HET=4;AFQUERY_N_HOM_ALT=0;AFQUERY_N_HEMI=0;AFQUERY_N_HOM_REF=6;AFQUERY_N_FAIL=0;AFQUERY_N_NO_COVERAGE=0 GT 0/1
351
+ chr1 925952 . G A 50 PASS AFQUERY_AC=6;AFQUERY_AN=20;AFQUERY_AF=0.3;AFQUERY_AC_REF=14;AFQUERY_N_HET=4;AFQUERY_N_HOM_ALT=1;AFQUERY_N_HEMI=0;AFQUERY_N_HOM_REF=5;AFQUERY_N_FAIL=0;AFQUERY_N_NO_COVERAGE=0 GT 0/1
352
+ chr1 946000 . T C 50 PASS AFQUERY_AC=2;AFQUERY_AN=16;AFQUERY_AF=0.125;AFQUERY_AC_REF=14;AFQUERY_N_HET=2;AFQUERY_N_HOM_ALT=0;AFQUERY_N_HEMI=0;AFQUERY_N_HOM_REF=6;AFQUERY_N_FAIL=2;AFQUERY_N_NO_COVERAGE=0 GT 0/1
352
353
  ```
353
354
 
354
355
  `AFQUERY_N_FAIL=2` for `chr1:946000` matches the query output from Step 4. The annotated values reflect cohort-wide frequencies across all 10 samples, not just DEMO_001.
@@ -374,12 +375,12 @@ head -6 demo_dump.csv
374
375
  Example output:
375
376
 
376
377
  ```
377
- chrom,pos,ref,alt,AC,AN,AF,n_eligible,N_HET,N_HOM_ALT,N_HEMI,N_HOM_REF,N_FAIL,N_NO_COVERAGE
378
- chr1,925100,C,T,4,20,0.2,10,4,0,0,6,0,0
379
- chr1,925952,G,A,6,20,0.3,10,4,1,0,5,0,0
380
- chr1,946000,T,C,2,16,0.125,10,2,0,0,6,2,0
381
- chr1,1225000,A,G,5,20,0.25,10,5,0,0,5,0,0
382
- chr1,1399914,G,T,2,8,0.25,4,2,0,0,2,0,0
378
+ chrom,pos,ref,alt,AC,AN,AF,AC_REF,n_eligible,N_HET,N_HOM_ALT,N_HEMI,N_HOM_REF,N_FAIL,N_NO_COVERAGE
379
+ chr1,925100,C,T,4,20,0.2,16,10,4,0,0,6,0,0
380
+ chr1,925952,G,A,6,20,0.3,14,10,4,1,0,5,0,0
381
+ chr1,946000,T,C,2,16,0.125,14,10,2,0,0,6,2,0
382
+ chr1,1225000,A,G,5,20,0.25,15,10,5,0,0,5,0,0
383
+ chr1,1399914,G,T,2,8,0.25,6,4,2,0,0,2,0,0
383
384
  ```
384
385
 
385
386
  Note that `chr1:1399914` has AN=8 even in the full-cohort dump — technology-aware AN is applied automatically (WES samples are excluded for positions outside their capture regions).
@@ -390,7 +391,7 @@ Disaggregate by sex and technology:
390
391
  afquery dump --db ./demo_db/ --output demo_dump_stratified.csv --by-sex --by-tech
391
392
  ```
392
393
 
393
- This adds columns following the pattern `AC_{sex}_{tech}`, `AN_{sex}_{tech}`, `AF_{sex}_{tech}` (and genotype counts) for each sex-technology combination. The stratified dump is useful for case-control comparisons and population-specific frequency analysis.
394
+ This adds columns following the pattern `AC_{sex}_{tech}`, `AN_{sex}_{tech}`, `AF_{sex}_{tech}`, `AC_REF_{sex}_{tech}` (and genotype counts) for each sex-technology combination. The stratified dump is useful for case-control comparisons and population-specific frequency analysis. Sex and technology groups are disjoint, so the counts of any selection of them can be summed; see [Summing Dump Groups](../guides/dump-aggregation.md).
394
395
 
395
396
  ---
396
397
 
@@ -11,6 +11,7 @@ This page explains what each field in AFQuery output means and how to interpret
11
11
  | **AC** | int | Allele count — number of alt allele copies in eligible samples |
12
12
  | **AN** | int | Allele number — alleles of the eligible samples with a usable call at this position, adjusted for ploidy. Samples in `N_FAIL` are left out (counted as hom-ref with `--fail-as-ref`) |
13
13
  | **AF** | float | Allele frequency — `AC / AN`. `NA` (text/TSV) or `null` (JSON) when AN=0 |
14
+ | **AC_REF** | int | Reference allele count — the alleles in AN not taken by any ALT allele stored at this position (`AN` minus the AC of every ALT there, whatever its REF). It is the same on every line of a position and equals `AN − AC` at a biallelic site. The reference frequency is `AC_REF / AN` (see [Multi-allelic sites](#multi-allelic-sites)) |
14
15
  | **N_HET** | int | Number of eligible samples heterozygous for the alt allele: a diploid `0/1` genotype |
15
16
  | **N_HOM_ALT** | int | Number of eligible samples homozygous for the alt allele: a diploid `1/1` genotype. On chrM every carrier is counted here, whatever its GT, because AFQuery records no heteroplasmy. See [Ploidy](../advanced/ploidy-and-sex-chroms.md#genotype-counting). |
16
17
  | **N_HEMI** | int | Number of eligible hemizygous carriers: males carrying the alt allele on chrX outside the PARs or on chrY, where they have a single copy (GT `1`, or `1/1` written diploid). Always `0` on autosomes, chrX PARs, chrM and for females. |
@@ -31,7 +32,7 @@ afquery query --db ./db/ --locus chr1:925952 --ref G --alt A
31
32
  ```
32
33
 
33
34
  ```
34
- chr1:925952 G>A AC=3 AN=120 AF=0.0250 n_eligible=60 N_HET=1 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=57 N_FAIL=0 N_NO_COVERAGE=0
35
+ chr1:925952 G>A AC=3 AN=120 AF=0.0250 AC_REF=117 n_eligible=60 N_HET=1 N_HOM_ALT=1 N_HEMI=0 N_HOM_REF=58 N_FAIL=0 N_NO_COVERAGE=0
35
36
  ```
36
37
 
37
38
  ### TSV
@@ -41,8 +42,8 @@ afquery query --db ./db/ --locus chr1:925952 --ref G --alt A --format tsv
41
42
  ```
42
43
 
43
44
  ```
44
- chrom pos ref alt AC AN AF n_eligible N_HET N_HOM_ALT N_HEMI N_HOM_REF N_FAIL N_NO_COVERAGE
45
- chr1 925952 G A 3 120 0.025000 60 1 1 0 57 0 0
45
+ chrom pos ref alt AC AN AF AC_REF n_eligible N_HET N_HOM_ALT N_HEMI N_HOM_REF N_FAIL N_NO_COVERAGE
46
+ chr1 925952 G A 3 120 0.025000 117 60 1 1 0 58 0 0
46
47
  ```
47
48
 
48
49
  ### JSON
@@ -60,11 +61,12 @@ afquery query --db ./db/ --locus chr1:925952 --ref G --alt A --format json
60
61
  "AC": 3,
61
62
  "AN": 120,
62
63
  "AF": 0.025,
64
+ "AC_REF": 117,
63
65
  "n_eligible": 60,
64
66
  "N_HET": 1,
65
67
  "N_HOM_ALT": 1,
66
68
  "N_HEMI": 0,
67
- "N_HOM_REF": 57,
69
+ "N_HOM_REF": 58,
68
70
  "N_FAIL": 0,
69
71
  "N_NO_COVERAGE": 0
70
72
  }
@@ -99,10 +101,18 @@ reference for this allele, so it appears in none of `N_HET`, `N_HOM_ALT`,
99
101
  `n_eligible` at biallelic sites; at a multi-allelic site they fall short by the
100
102
  number of such samples. AC, AN and AF are not affected.
101
103
 
102
- AN and `N_FAIL` describe the position, so they are the same on every line of a
103
- multi-allelic site, and AN equals the reference alleles plus the AC of all its
104
- ALT alleles. A sample with a failed call for any of the alleles is counted in
105
- `N_FAIL` on every line.
104
+ AN, `AC_REF` and `N_FAIL` describe the position, so they are the same on every
105
+ line of a multi-allelic site, and AN equals `AC_REF` plus the AC of all its ALT
106
+ alleles. A sample with a failed call for any of the alleles is counted in
107
+ `N_FAIL` on every line. Sites are defined by position whatever the REF of their
108
+ alleles, so after normalization an insertion, a deletion and a SNV starting at
109
+ the same position share AN, `AC_REF` and `N_FAIL`.
110
+
111
+ The reference frequency is therefore `AC_REF / AN`, not `1 − AF`. With AN=16,
112
+ a deletion with AC=4 and an insertion with AC=2 at one position, `AC_REF` is 10
113
+ and the reference frequency 0.625, while `1 − AF` gives 0.75 and 0.875.
114
+ `N_HOM_REF` cannot replace `AC_REF` either, because it counts samples rather
115
+ than alleles and leaves out the reference copy of heterozygous carriers.
106
116
 
107
117
  A sample with two different ALT alleles (`GT=1/2`) is counted as heterozygous on
108
118
  both lines.
@@ -147,6 +157,7 @@ When using `afquery annotate`, the following INFO fields are added to each varia
147
157
  | `AFQUERY_AC` | A (per ALT) | Allele count — one value per ALT allele |
148
158
  | `AFQUERY_AN` | 1 (per site) | Allele number — shared across all ALT alleles; excludes samples in `AFQUERY_N_FAIL` |
149
159
  | `AFQUERY_AF` | A (per ALT) | Allele frequency — one value per ALT allele; `.` when `AFQUERY_AN=0` |
160
+ | `AFQUERY_AC_REF` | 1 (per site) | Reference allele count — `AFQUERY_AN` minus the AC of every ALT allele stored at the position, including alleles the record does not list |
150
161
  | `AFQUERY_N_HET` | A (per ALT) | Heterozygous sample count per ALT allele (diploid) |
151
162
  | `AFQUERY_N_HOM_ALT` | A (per ALT) | Homozygous alt sample count per ALT allele (diploid; every carrier on chrM) |
152
163
  | `AFQUERY_N_HEMI` | A (per ALT) | Hemizygous carrier count per ALT allele: males on chrX outside the PARs and on chrY |
@@ -23,6 +23,7 @@ afquery annotate \
23
23
  | `AFQUERY_AC` | Integer | A (per ALT) | Allele count in eligible samples |
24
24
  | `AFQUERY_AN` | Integer | 1 (per site) | Allele number (total alleles examined, excluding samples in `AFQUERY_N_FAIL`) |
25
25
  | `AFQUERY_AF` | Float | A (per ALT) | Allele frequency (`AC / AN`); `.` when `AFQUERY_AN=0` |
26
+ | `AFQUERY_AC_REF` | Integer | 1 (per site) | Reference allele count (`AFQUERY_AN` minus the AC of every ALT allele stored in the database at the position, including alleles absent from the input record). The reference frequency is `AFQUERY_AC_REF / AFQUERY_AN`. It is not `1 − AFQUERY_AF` at a multi-allelic site, nor `AN − ΣAFQUERY_AC` when the record does not list every stored allele. Not written when no sample is eligible, in which case only `AFQUERY_AN=0` is |
26
27
  | `AFQUERY_N_HET` | Integer | A (per ALT) | Heterozygous sample count (diploid genotypes) |
27
28
  | `AFQUERY_N_HOM_ALT` | Integer | A (per ALT) | Homozygous alt sample count (diploid genotypes); on chrM, every carrier |
28
29
  | `AFQUERY_N_HEMI` | Integer | A (per ALT) | Hemizygous carrier count: males carrying the allele on chrX outside the PARs or on chrY. `0` on autosomes, chrX PARs and chrM |
@@ -33,6 +34,8 @@ afquery annotate \
33
34
  !!! note "Multi-allelic sites"
34
35
  Number=A fields have one value per ALT allele (comma-separated for multi-allelic sites). Number=1 fields are shared across all ALT alleles at the same position.
35
36
 
37
+ Sites are defined by position whatever the REF of their alleles, so an insertion, a deletion and a SNV starting at the same position share `AFQUERY_AN`, `AFQUERY_AC_REF` and `AFQUERY_N_FAIL`.
38
+
36
39
  ---
37
40
 
38
41
  ## Sample Filtering
@@ -0,0 +1,136 @@
1
+ # Summing Dump Groups
2
+
3
+ A dump disaggregated by group (`--by-sex`, `--by-tech`, `--by-phenotype` or
4
+ `--all-groups`) reports the counts of every group in its own columns. Adding
5
+ up the counts of several groups gives the frequency of a variant in their
6
+ union, for example all the samples sequenced with any exome kit, or the
7
+ females of two technologies, without running a new query. This page explains
8
+ which columns can be added, how to derive frequencies from the sums and when
9
+ the result is exact.
10
+
11
+ A small worked example, with a database, its dump and a script that sums
12
+ groups, is available in
13
+ [`examples/dump_aggregation/`](https://github.com/babelomics/afquery/tree/master/examples/dump_aggregation).
14
+
15
+ ---
16
+
17
+ ## Columns that can be summed
18
+
19
+ | Column | Summable | Notes |
20
+ |---|---|---|
21
+ | `AC` | Yes | Copies of the ALT allele of the row |
22
+ | `AN` | Yes | Alleles with a usable call at the position |
23
+ | `AC_REF` | Yes | Reference alleles at the position |
24
+ | `n_eligible` | Yes | Samples that can be genotyped at the position |
25
+ | `N_HET`, `N_HOM_ALT`, `N_HEMI`, `N_HOM_REF`, `N_FAIL`, `N_NO_COVERAGE` | Yes | Samples by genotype |
26
+ | `AF` | No | Recompute it from the summed `AC` and `AN` |
27
+
28
+ `AN`, `AC_REF`, `n_eligible` and `N_FAIL` describe the position, so they take
29
+ the same value on every row of a multi-allelic site. Add them up across groups
30
+ within a row, never across the rows of a position, which would count the same
31
+ samples more than once.
32
+
33
+ Ploidy, capture coverage and failed calls are already taken into account in
34
+ the counts of each group, so the sums need no further correction. See
35
+ [Understanding Output](../getting-started/understanding-output.md) for the
36
+ definition of each column.
37
+
38
+ ---
39
+
40
+ ## Frequencies
41
+
42
+ For a selection `S` of disjoint groups:
43
+
44
+ ```
45
+ AC(S) = Σ AC_g
46
+ AN(S) = Σ AN_g
47
+ AC_REF(S) = Σ AC_REF_g
48
+
49
+ AF(S) = AC(S) / AN(S) alternate allele frequency
50
+ REF_AF(S) = AC_REF(S) / AN(S) reference allele frequency
51
+ ```
52
+
53
+ The genotype counts are added in the same way. Both frequencies are undefined
54
+ when `AN(S)` is 0, which means that no sample in the selection has a usable
55
+ call at the position, and should be reported as unavailable rather than as 0.
56
+
57
+ The identity `AN = AC_REF + ΣAC`, with `AC` summed over every allele stored at
58
+ the position (including alleles that have no row in the dump), holds in every
59
+ group and in any selection of groups.
60
+
61
+ !!! warning "Common mistakes"
62
+ - **Summing `AF`.** Frequencies are not additive. Sum `AC` and `AN`, then divide.
63
+ - **Using `1 − AF` as the reference frequency.** At a multi-allelic
64
+ position the other ALT alleles also take part of `AN`. With `AN` = 16, a
65
+ deletion with `AC` = 4 and an insertion with `AC` = 2 at the same
66
+ position, `AC_REF` is 10 and the reference frequency is 0.625, whereas
67
+ `1 − AF` would give 0.75 and 0.875.
68
+
69
+ ---
70
+
71
+ ## When groups are disjoint
72
+
73
+ Sums are exact only when no sample belongs to two of the selected groups.
74
+
75
+ | Axis | Disjoint |
76
+ |---|---|
77
+ | Sex (`--by-sex`) | Always, since each sample has one sex |
78
+ | Technology (`--by-tech`) | Always, since each sample has one technology |
79
+ | Phenotype (`--by-phenotype`) | Only if no sample has more than one of the selected codes |
80
+ | Combinations (`--all-groups`, or several `--by-*` options) | When every axis is disjoint |
81
+
82
+ A sample with the codes `E11.9,I10` is counted in both the `E11.9` and the
83
+ `I10` groups, so adding those two groups counts it twice. This command lists
84
+ the samples that have more than one phenotype code:
85
+
86
+ ```bash
87
+ afquery info --db ./db/ --samples --format tsv | awk -F'\t' 'NR > 1 && $5 ~ /,/'
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Producing a dump for summing
93
+
94
+ ```bash
95
+ afquery dump --db ./db/ --all-groups --output groups.csv
96
+ ```
97
+
98
+ Some options change which samples each group contains.
99
+
100
+ - **Base filters.** The axis of a group replaces the matching inclusion
101
+ filter of the command. With `--sex male --by-sex` the `_female` columns
102
+ still count the female samples, while `--tech wgs --by-sex` restricts both
103
+ sex groups to WGS. Exclusions (`--phenotype ^CODE`, `--tech ^NAME`) apply to
104
+ every group. With no base filters and disjoint groups that together include
105
+ every sample, the base columns are the sum of all the groups. `--by-sex`,
106
+ `--by-tech` and `--all-groups` always include every sample, whereas
107
+ `--by-phenotype` leaves out the samples that have none of the requested
108
+ codes. Groups that involve phenotypes are disjoint only under the condition
109
+ described in the previous section.
110
+ - **Coverage gates.** `--min-pass`, `--min-observed` and
111
+ `--min-quality-evidence` are evaluated on the samples of each group, so a
112
+ group can fail a gate that the whole cohort passes. Under a gate
113
+ `N_HOM_REF` and `N_NO_COVERAGE` stop adding up to the base row, while the
114
+ other counts still do. A database built with `--min-covered` checks the
115
+ evidence over the whole cohort, which keeps every sum exact.
116
+ - **`--fail-as-ref`** applies to every group in the same way and keeps every
117
+ count additive.
118
+ - **Rows with `AC` = 0** in the base columns are written only with
119
+ `--all-variants`. Without base filters, an allele missing from the dump has
120
+ no carrier in any group.
121
+
122
+ Group columns are named `<FIELD>_<label>`. How labels are built is described
123
+ in [Bulk Export](dump-export.md#disaggregate-output).
124
+
125
+ ---
126
+
127
+ ## Limitations
128
+
129
+ - Sites are defined by position. An insertion, a deletion and a SNV starting
130
+ at the same position share `AN` and `AC_REF`, but a deletion is not carried
131
+ over to the positions it spans, and its carriers count as reference at a
132
+ SNV inside the deleted bases.
133
+ - A missing genotype (`./.`) with `FILTER=PASS` is not stored, so the sample
134
+ counts as reference. If those samples should be left out of `AN`, give the
135
+ record a failing `FILTER` value before ingestion so that the call is stored
136
+ as failed.