afquery 0.4.2__tar.gz → 0.6.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 (170) hide show
  1. {afquery-0.4.2 → afquery-0.6.0}/PKG-INFO +2 -2
  2. {afquery-0.4.2 → afquery-0.6.0}/README.md +1 -1
  3. {afquery-0.4.2 → afquery-0.6.0}/docs/advanced/coverage-evidence.md +15 -7
  4. {afquery-0.4.2 → afquery-0.6.0}/docs/advanced/debugging-results.md +3 -3
  5. afquery-0.6.0/docs/advanced/filter-pass-tracking.md +82 -0
  6. {afquery-0.4.2 → afquery-0.6.0}/docs/advanced/ploidy-and-sex-chroms.md +13 -4
  7. {afquery-0.4.2 → afquery-0.6.0}/docs/faq.md +1 -1
  8. {afquery-0.4.2 → afquery-0.6.0}/docs/getting-started/concepts.md +5 -5
  9. {afquery-0.4.2 → afquery-0.6.0}/docs/getting-started/preprocessing.md +12 -7
  10. {afquery-0.4.2 → afquery-0.6.0}/docs/getting-started/quickstart.md +2 -2
  11. {afquery-0.4.2 → afquery-0.6.0}/docs/getting-started/tutorial.md +26 -31
  12. {afquery-0.4.2 → afquery-0.6.0}/docs/getting-started/understanding-output.md +32 -11
  13. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/annotate-vcf.md +5 -5
  14. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/create-database.md +1 -1
  15. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/dump-export.md +2 -0
  16. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/query.md +6 -3
  17. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/variant-info.md +9 -12
  18. {afquery-0.4.2 → afquery-0.6.0}/docs/reference/cli.md +3 -0
  19. {afquery-0.4.2 → afquery-0.6.0}/docs/reference/data-model.md +2 -2
  20. {afquery-0.4.2 → afquery-0.6.0}/docs/reference/glossary.md +4 -4
  21. {afquery-0.4.2 → afquery-0.6.0}/docs/reference/python-api.md +22 -3
  22. {afquery-0.4.2 → afquery-0.6.0}/docs/use-cases/acmg-use-cases.md +4 -4
  23. {afquery-0.4.2 → afquery-0.6.0}/docs/use-cases/population-specific-af.md +1 -1
  24. {afquery-0.4.2 → afquery-0.6.0}/docs/use-cases/pseudo-controls.md +4 -4
  25. {afquery-0.4.2 → afquery-0.6.0}/docs/use-cases/sex-specific-af.md +3 -3
  26. {afquery-0.4.2 → afquery-0.6.0}/docs/use-cases/technology-integration.md +2 -2
  27. {afquery-0.4.2 → afquery-0.6.0}/resources/normalize_vcf.sh +12 -1
  28. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/_version.py +2 -2
  29. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/annotate.py +60 -53
  30. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/cli.py +12 -8
  31. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/database.py +30 -7
  32. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/dump.py +39 -75
  33. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/models.py +3 -0
  34. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/ploidy.py +14 -0
  35. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/__init__.py +2 -2
  36. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/ingest.py +78 -9
  37. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/update.py +2 -1
  38. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/query.py +207 -129
  39. {afquery-0.4.2 → afquery-0.6.0}/tests/conftest.py +5 -4
  40. {afquery-0.4.2 → afquery-0.6.0}/tests/data/expected_results.json +4 -4
  41. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S00.vcf +2 -1
  42. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S01.vcf +2 -1
  43. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S03.vcf +2 -1
  44. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S05.vcf +2 -1
  45. {afquery-0.4.2 → afquery-0.6.0}/tests/oracle.py +57 -7
  46. {afquery-0.4.2 → afquery-0.6.0}/tests/test_annotate.py +15 -10
  47. {afquery-0.4.2 → afquery-0.6.0}/tests/test_cli.py +20 -8
  48. {afquery-0.4.2 → afquery-0.6.0}/tests/test_cli_docs_consistency.py +5 -0
  49. {afquery-0.4.2 → afquery-0.6.0}/tests/test_dump.py +20 -5
  50. {afquery-0.4.2 → afquery-0.6.0}/tests/test_haploid_stats.py +7 -5
  51. {afquery-0.4.2 → afquery-0.6.0}/tests/test_invariants.py +1 -1
  52. afquery-0.6.0/tests/test_multiallelic.py +365 -0
  53. {afquery-0.4.2 → afquery-0.6.0}/tests/test_no_coverage.py +1 -2
  54. {afquery-0.4.2 → afquery-0.6.0}/tests/test_oracle_consistency.py +82 -5
  55. {afquery-0.4.2 → afquery-0.6.0}/tests/test_preprocess.py +68 -10
  56. {afquery-0.4.2 → afquery-0.6.0}/tests/test_sample_filter.py +7 -5
  57. {afquery-0.4.2 → afquery-0.6.0}/tests/test_update.py +6 -7
  58. {afquery-0.4.2 → afquery-0.6.0}/tests/test_variant_info.py +119 -11
  59. afquery-0.4.2/docs/advanced/filter-pass-tracking.md +0 -111
  60. {afquery-0.4.2 → afquery-0.6.0}/.dockerignore +0 -0
  61. {afquery-0.4.2 → afquery-0.6.0}/.github/workflows/ci.yml +0 -0
  62. {afquery-0.4.2 → afquery-0.6.0}/.github/workflows/docs.yml +0 -0
  63. {afquery-0.4.2 → afquery-0.6.0}/.github/workflows/release.yml +0 -0
  64. {afquery-0.4.2 → afquery-0.6.0}/.gitignore +0 -0
  65. {afquery-0.4.2 → afquery-0.6.0}/CONTRIBUTING.md +0 -0
  66. {afquery-0.4.2 → afquery-0.6.0}/Dockerfile +0 -0
  67. {afquery-0.4.2 → afquery-0.6.0}/LICENSE +0 -0
  68. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/.gitignore +0 -0
  69. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/INSTALL.md +0 -0
  70. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/README.md +0 -0
  71. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/Snakefile +0 -0
  72. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/.gitignore +0 -0
  73. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/01a_assign_samples.py +0 -0
  74. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/01b_write_manifests.py +0 -0
  75. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/02_build_databases.py +0 -0
  76. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/03_compute_metrics.py +0 -0
  77. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/04_classify_acmg.py +0 -0
  78. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/05_plot_figures.py +0 -0
  79. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/README.md +0 -0
  80. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/Snakefile +0 -0
  81. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/__init__.py +0 -0
  82. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/beds/SureSelect_v5.bed +0 -0
  83. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/beds/SureSelect_v6.bed +0 -0
  84. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/beds/SureSelect_v7.bed +0 -0
  85. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/capture_kit/config.py +0 -0
  86. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/config.yaml +0 -0
  87. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/envs/benchmark.yaml +0 -0
  88. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/.gitignore +0 -0
  89. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/01_prepare_data.py +0 -0
  90. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/02_query_scaling.py +0 -0
  91. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/03_build.py +0 -0
  92. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/04_annotate.py +0 -0
  93. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/05_vs_bcftools.py +0 -0
  94. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/06_plot.py +0 -0
  95. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/README.md +0 -0
  96. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/Snakefile +0 -0
  97. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/collect_annotate.py +0 -0
  98. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/collect_bcftools.py +0 -0
  99. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/collect_build_perf.py +0 -0
  100. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/collect_prepare.py +0 -0
  101. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/collect_query_scaling.py +0 -0
  102. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/config.py +0 -0
  103. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/performance/config_smoke.py +0 -0
  104. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/shared/__init__.py +0 -0
  105. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/shared/config.py +0 -0
  106. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/shared/rules/download_1kg.smk +0 -0
  107. {afquery-0.4.2 → afquery-0.6.0}/benchmarks/shared/utils.py +0 -0
  108. {afquery-0.4.2 → afquery-0.6.0}/docs/advanced/benchmarking.md +0 -0
  109. {afquery-0.4.2 → afquery-0.6.0}/docs/advanced/multi-cohort-strategies.md +0 -0
  110. {afquery-0.4.2 → afquery-0.6.0}/docs/advanced/performance.md +0 -0
  111. {afquery-0.4.2 → afquery-0.6.0}/docs/advanced/pipeline-integration.md +0 -0
  112. {afquery-0.4.2 → afquery-0.6.0}/docs/assets/img/gap2_mixed_technologies.png +0 -0
  113. {afquery-0.4.2 → afquery-0.6.0}/docs/getting-started/installation.md +0 -0
  114. {afquery-0.4.2 → afquery-0.6.0}/docs/getting-started/motivation.md +0 -0
  115. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/manifest-format.md +0 -0
  116. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/sample-filtering.md +0 -0
  117. {afquery-0.4.2 → afquery-0.6.0}/docs/guides/update-database.md +0 -0
  118. {afquery-0.4.2 → afquery-0.6.0}/docs/index.md +0 -0
  119. {afquery-0.4.2 → afquery-0.6.0}/docs/scripts/gen_gap2_figure.py +0 -0
  120. {afquery-0.4.2 → afquery-0.6.0}/docs/stylesheets/extra.css +0 -0
  121. {afquery-0.4.2 → afquery-0.6.0}/docs/troubleshooting.md +0 -0
  122. {afquery-0.4.2 → afquery-0.6.0}/docs/use-cases/clinical-prioritization.md +0 -0
  123. {afquery-0.4.2 → afquery-0.6.0}/docs/use-cases/cohort-stratification.md +0 -0
  124. {afquery-0.4.2 → afquery-0.6.0}/examples/demo/README.md +0 -0
  125. {afquery-0.4.2 → afquery-0.6.0}/examples/demo/create_demo_data.py +0 -0
  126. {afquery-0.4.2 → afquery-0.6.0}/mkdocs.yml +0 -0
  127. {afquery-0.4.2 → afquery-0.6.0}/pyproject.toml +0 -0
  128. {afquery-0.4.2 → afquery-0.6.0}/recipes/afquery/meta.yaml +0 -0
  129. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/__init__.py +0 -0
  130. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/benchmark.py +0 -0
  131. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/bitmaps.py +0 -0
  132. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/capture.py +0 -0
  133. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/cli.pyr +0 -0
  134. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/constants.py +0 -0
  135. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/build.py +0 -0
  136. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/compact.py +0 -0
  137. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/manifest.py +0 -0
  138. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/regions.py +0 -0
  139. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/preprocess/synth.py +0 -0
  140. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/storage.py +0 -0
  141. {afquery-0.4.2 → afquery-0.6.0}/src/afquery/variant_info.py +0 -0
  142. {afquery-0.4.2 → afquery-0.6.0}/tests/data/annotate_input.vcf +0 -0
  143. {afquery-0.4.2 → afquery-0.6.0}/tests/data/annotate_multi_bucket.vcf +0 -0
  144. {afquery-0.4.2 → afquery-0.6.0}/tests/data/annotate_multi_chrom.vcf +0 -0
  145. {afquery-0.4.2 → afquery-0.6.0}/tests/data/beds/wes_kit_a.bed +0 -0
  146. {afquery-0.4.2 → afquery-0.6.0}/tests/data/beds/wes_kit_b.bed +0 -0
  147. {afquery-0.4.2 → afquery-0.6.0}/tests/data/beds/wes_kit_nochr.bed +0 -0
  148. {afquery-0.4.2 → afquery-0.6.0}/tests/data/manifest.tsv +0 -0
  149. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S02.vcf +0 -0
  150. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S04.vcf +0 -0
  151. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S06.vcf +0 -0
  152. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S07.vcf +0 -0
  153. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S08.vcf +0 -0
  154. {afquery-0.4.2 → afquery-0.6.0}/tests/data/vcfs/S09.vcf +0 -0
  155. {afquery-0.4.2 → afquery-0.6.0}/tests/test_batch.py +0 -0
  156. {afquery-0.4.2 → afquery-0.6.0}/tests/test_benchmark.py +0 -0
  157. {afquery-0.4.2 → afquery-0.6.0}/tests/test_bitmaps.py +0 -0
  158. {afquery-0.4.2 → afquery-0.6.0}/tests/test_capture.py +0 -0
  159. {afquery-0.4.2 → afquery-0.6.0}/tests/test_compact.py +0 -0
  160. {afquery-0.4.2 → afquery-0.6.0}/tests/test_constants.py +0 -0
  161. {afquery-0.4.2 → afquery-0.6.0}/tests/test_info.py +0 -0
  162. {afquery-0.4.2 → afquery-0.6.0}/tests/test_pass_filter.py +0 -0
  163. {afquery-0.4.2 → afquery-0.6.0}/tests/test_ploidy.py +0 -0
  164. {afquery-0.4.2 → afquery-0.6.0}/tests/test_query.py +0 -0
  165. {afquery-0.4.2 → afquery-0.6.0}/tests/test_storage.py +0 -0
  166. {afquery-0.4.2 → afquery-0.6.0}/tests/test_synth.py +0 -0
  167. {afquery-0.4.2 → afquery-0.6.0}/tests/test_synthetic_stats.py +0 -0
  168. {afquery-0.4.2 → afquery-0.6.0}/tests/test_update_metadata.py +0 -0
  169. {afquery-0.4.2 → afquery-0.6.0}/tests/test_update_partitioned.py +0 -0
  170. {afquery-0.4.2 → afquery-0.6.0}/tests/test_warnings.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: afquery
3
- Version: 0.4.2
3
+ Version: 0.6.0
4
4
  Summary: Genomic allele frequency query engine with bitmap-encoded genotypes
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -188,7 +188,7 @@ Every query and annotated VCF reports:
188
188
  | `N_HET` | Heterozygous PASS carriers |
189
189
  | `N_HOM_ALT` | Homozygous-alt PASS carriers |
190
190
  | `N_HOM_REF` | Samples trusted as homozygous reference |
191
- | `N_FAIL` | Carriers with FILTER ≠ PASS (excluded from AC/AN) |
191
+ | `N_FAIL` | Samples with a failed call (FILTER ≠ PASS) at the position (excluded from AC/AN) |
192
192
  | `N_NO_COVERAGE` | Non-carriers on a partially-covered tech without sufficient evidence to call hom-ref |
193
193
 
194
194
  VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO_COVERAGE`).
@@ -158,7 +158,7 @@ Every query and annotated VCF reports:
158
158
  | `N_HET` | Heterozygous PASS carriers |
159
159
  | `N_HOM_ALT` | Homozygous-alt PASS carriers |
160
160
  | `N_HOM_REF` | Samples trusted as homozygous reference |
161
- | `N_FAIL` | Carriers with FILTER ≠ PASS (excluded from AC/AN) |
161
+ | `N_FAIL` | Samples with a failed call (FILTER ≠ PASS) at the position (excluded from AC/AN) |
162
162
  | `N_NO_COVERAGE` | Non-carriers on a partially-covered tech without sufficient evidence to call hom-ref |
163
163
 
164
164
  VCF INFO field names use the `AFQUERY_` prefix (e.g. `AFQUERY_AF`, `AFQUERY_N_NO_COVERAGE`).
@@ -17,15 +17,18 @@ into `N_HOM_REF`. The flags below decide *which* samples land there.
17
17
  ## What `N_NO_COVERAGE` represents
18
18
 
19
19
  `N_NO_COVERAGE` counts eligible samples whose hom-ref status is not trusted
20
- under the active criteria. The genotype invariant becomes:
20
+ under the active criteria. At a biallelic site the genotype invariant becomes:
21
21
 
22
22
  ```
23
23
  N_HET + N_HOM_ALT + N_HOM_REF + N_FAIL + N_NO_COVERAGE = n_eligible
24
24
  ```
25
25
 
26
- Samples in `N_NO_COVERAGE` remain in `eligible` and contribute to `AN` (just
27
- like `N_FAIL`), so AC/AN/AF stay conservative — the field never inflates
28
- allele frequencies. Two rules always hold:
26
+ At a multi-allelic site, eligible samples that carry only another ALT allele at
27
+ the position fall in none of these categories for this allele, so the sum is
28
+ lower than `n_eligible` by exactly that number of samples.
29
+
30
+ Samples in `N_NO_COVERAGE` remain in `eligible` and contribute to `AN`, so
31
+ AC/AN/AF stay conservative — the field never inflates allele frequencies. Two rules always hold:
29
32
 
30
33
  - **Carriers are never reclassified.** A sample with a `het`, `hom`, or
31
34
  `fail` call at the position stays in its category. `N_NO_COVERAGE` only
@@ -45,12 +48,17 @@ position. They run at query time, so no database rebuild is needed.
45
48
 
46
49
  | Flag | Effect |
47
50
  |------|--------|
48
- | `--min-pass K` | A partially-covered tech must have ≥K PASS carriers (`het ∪ hom`) at the position. If it falls short, all of its non-carrier samples move from `N_HOM_REF` to `N_NO_COVERAGE`. |
51
+ | `--min-pass K` | A partially-covered tech must have ≥K PASS carriers (`het ∪ hom`) at the position. Carriers of any ALT allele there count, since each shows the position was sequenced. If it falls short, all of its non-carrier samples move from `N_HOM_REF` to `N_NO_COVERAGE`. |
49
52
  | `--min-observed K` | Same shape, but counts every recorded carrier (`het ∪ hom ∪ fail`). Useful when a non-PASS call still proves the position was sequenced. |
50
53
 
51
54
  When both flags are >0, both must hold (AND). The default `0` disables the
52
55
  gate.
53
56
 
57
+ `afquery annotate` applies the same gates to input alleles that are not in the
58
+ database. At a position where no sample has any call, no tech has evidence, so
59
+ under any active gate the non-carriers of partially-covered techs are reported
60
+ as `N_NO_COVERAGE`.
61
+
54
62
  !!! tip
55
63
  If your VCFs do not carry `FORMAT/DP` or `FORMAT/GQ`, these are the
56
64
  flags you want. They are the cheapest option and apply to any database.
@@ -98,7 +106,7 @@ coverage decision is baked in.
98
106
  | `--min-dp D` | Minimum `FORMAT/DP` per carrier. |
99
107
  | `--min-gq G` | Minimum `FORMAT/GQ` per carrier. |
100
108
  | `--min-qual Q` | Minimum VCF `QUAL` per carrier. |
101
- | `--min-covered K`| Per partially-covered tech, the position is "trusted" only if at least K of its carriers pass the quality thresholds. Non-carriers of failing positions are recorded as `N_NO_COVERAGE`. |
109
+ | `--min-covered K`| Per partially-covered tech, the position is "trusted" only if at least K of its carriers pass the quality thresholds. Non-carriers of failing positions are recorded as `N_NO_COVERAGE`. Carriers of any ALT allele at the position count, so every allele of a multi-allelic site gets the same verdict; samples carrying another allele there are never counted as `N_NO_COVERAGE`. |
102
110
 
103
111
  A carrier counts as quality-passing only if **all** active thresholds hold
104
112
  (unset thresholds are simply ignored). At least one of these flags must be
@@ -133,7 +141,7 @@ afquery query --db ./db/ --locus chr1:925952 --min-quality-evidence 5
133
141
  ```
134
142
 
135
143
  `--min-quality-evidence K` requires each partially-covered tech to have ≥K
136
- quality-passing carriers at the position. Non-carriers of failing techs
144
+ quality-passing carriers of any ALT allele at the position. Non-carriers of failing techs
137
145
  (other than those already filtered at build time) move to `N_NO_COVERAGE`.
138
146
 
139
147
  Running the flag against a database that was not built with quality data
@@ -16,7 +16,7 @@ AN=0 means no eligible samples at the queried position. Work through these check
16
16
  | Position exists in database | `afquery query --db ./db/ --locus chr1:12345678` | If no result at all, the variant was not observed in any sample during ingestion. |
17
17
  | BED coverage (WES) | `afquery info --db ./db/` | If all eligible samples are WES and the position is outside capture regions, AN=0 is correct. |
18
18
  | Sample filter too restrictive | Remove `--phenotype` and `--sex` filters | Query with no filters first. If AN>0 without filters, the filter is excluding all samples. |
19
- | WES samples missing from AN | Compare `variant-info` carriers against `query` counts | If `variant-info` shows many WES carriers but AN reflects only the WGS samples, 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. |
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
22
 
@@ -42,13 +42,13 @@ A variant you expect to find is not in the database:
42
42
 
43
43
  ### 4. Unexpected N_FAIL > 0
44
44
 
45
- `N_FAIL > 0` means some eligible samples had a call with `FILTER≠PASS` at this position. These samples are excluded from AC, but they remain eligible and still count in AN. This is usually benign (1–2 samples), but a high N_FAIL warrants investigation:
45
+ `N_FAIL > 0` means some eligible samples had a call with `FILTER≠PASS` at this position. These samples are left out of AC and AN. This is usually benign (1–2 samples), but a high N_FAIL warrants investigation:
46
46
 
47
47
  | N_FAIL relative to n_eligible | Likely cause |
48
48
  |---|---|
49
49
  | 1–2 samples | Isolated low-quality calls — not concerning |
50
50
  | > 5% of n_eligible | Systematic sequencing artifact at this site |
51
- | All eligible samples | Site-wide QC failure — AF=0 but variant is present in source VCFs |
51
+ | All eligible samples | Site-wide QC failure — AN=0 and AF is `NA`, although the variant is present in source VCFs |
52
52
 
53
53
  To inspect a site with high N_FAIL, query with `--format json` to see all fields:
54
54
 
@@ -0,0 +1,82 @@
1
+ # FILTER=PASS Tracking
2
+
3
+ AFQuery keeps the calls that fail quality filters (`FILTER≠PASS`) instead of discarding them. A failed call tells you the position was looked at but the sample's genotype there is unknown, which is different both from "variant not present" and from "variant present".
4
+
5
+ ---
6
+
7
+ ## What counts as a failed call
8
+
9
+ A sample has a failed call at a position when its VCF holds, for any ALT allele there:
10
+
11
+ - a call carrying the ALT allele with `FILTER` other than `PASS` or `.`;
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)).
14
+
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
+
17
+ ---
18
+
19
+ ## How failed calls are counted
20
+
21
+ A failed call is judged per **position**, not per allele: a sample with a failed call for any ALT allele at a position has no reliable genotype there. For every allele at that position, the sample:
22
+
23
+ - adds nothing to **AC**, even if another record at the position called it with `FILTER=PASS`;
24
+ - is left out of **AN**, which counts only the alleles of samples with a usable call;
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).
27
+
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
+
30
+ ```bash
31
+ afquery query --db ./db/ --locus chr1:925952
32
+ ```
33
+
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
36
+ ```
37
+
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.
39
+
40
+ ### When every eligible sample failed
41
+
42
+ If all eligible samples have a failed call at a position, AN is 0 and AF is undefined: `NA` in text and TSV output, `null` in JSON and the Python API, an empty cell in `dump`, and `.` in `AFQUERY_AF`. `N_FAIL` still reports how many samples failed.
43
+
44
+ ---
45
+
46
+ ## Counting failed calls as reference
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`.
49
+
50
+ ```bash
51
+ afquery query --db ./db/ --locus chr1:925952 --fail-as-ref
52
+ ```
53
+
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
56
+ ```
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.
59
+
60
+ ---
61
+
62
+ ## Finding the failed samples
63
+
64
+ `afquery variant-info` lists each sample with a failed call at the position as genotype `alt` with filter `FAIL`, along with its technology and phenotypes. This shows whether failures cluster in one technology or sample group. See [Variant Info](../guides/variant-info.md).
65
+
66
+ ```bash
67
+ afquery variant-info --db ./db/ --locus chr1:925952
68
+ ```
69
+
70
+ ---
71
+
72
+ ## VCF annotation
73
+
74
+ `afquery annotate` writes the same per-position values: `AFQUERY_AN` excludes failed calls and `AFQUERY_N_FAIL` counts each failed sample once per site. See [Understanding Output](../getting-started/understanding-output.md#vcf-annotation-fields) for the full set of `AFQUERY_*` fields.
75
+
76
+ ---
77
+
78
+ ## Next Steps
79
+
80
+ - [Understanding Output](../getting-started/understanding-output.md) — interpreting N_FAIL in query and annotate results
81
+ - [ACMG Criteria](../use-cases/acmg-use-cases.md) — using N_FAIL to assess site quality before applying BA1/PM2
82
+ - [Debugging Results](debugging-results.md) — diagnosing unexpectedly high N_FAIL values
@@ -76,7 +76,7 @@ afquery query --db ./db/ --locus chrY:2787758 --sex female
76
76
  # chrY:2787758 — no results (AN=0 for all variants)
77
77
 
78
78
  afquery query --db ./db/ --locus chrY:2787758 --sex male
79
- # chrY:2787758 C>T AC=3 AN=856 AF=0.0035 n_eligible=856 N_HET=0 N_HOM_ALT=3 N_HOM_REF=853 N_FAIL=0
79
+ # chrY:2787758 C>T AC=3 AN=856 AF=0.0035 n_eligible=856 N_HET=0 N_HOM_ALT=3 N_HOM_REF=853 N_FAIL=0 N_NO_COVERAGE=0
80
80
  ```
81
81
 
82
82
  ### chrX non-PAR
@@ -103,14 +103,14 @@ afquery query --db ./db/ --locus chrM:3243
103
103
 
104
104
  ### Counting Identity
105
105
 
106
- For every query result, the following identity holds:
106
+ For every query result at a biallelic site, the following identity holds:
107
107
 
108
108
  **N_HET + N_HOM_ALT + N_HOM_REF + N_FAIL + N_NO_COVERAGE = n_eligible**
109
109
 
110
- This can be used to validate results. N_HOM_REF is the number of eligible samples that are homozygous reference (i.e., do not carry the alt allele and passed quality filters). N_NO_COVERAGE is 0 unless a coverage-evidence filter is active — see [Coverage Evidence](coverage-evidence.md).
110
+ 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 are homozygous reference (i.e., carry no ALT allele at the position and have no failed call there). N_NO_COVERAGE is 0 unless a coverage-evidence filter is active — see [Coverage Evidence](coverage-evidence.md).
111
111
 
112
112
  !!! note "Mutual exclusivity"
113
- N_HET, N_HOM_ALT, N_HOM_REF, N_FAIL, and N_NO_COVERAGE are mutually exclusive. A sample with a non-ref allele but FILTER≠PASS is counted in N_FAIL only — it does not appear in N_HET or N_HOM_ALT. Likewise, N_HOM_REF counts only PASS-filtered samples.
113
+ N_HET, N_HOM_ALT, N_HOM_REF, N_FAIL, and N_NO_COVERAGE are mutually exclusive. A sample with a failed call (FILTER≠PASS) for any allele at the position is counted in N_FAIL only — it does not appear in N_HET, N_HOM_ALT or N_HOM_REF, and is left out of AC and AN.
114
114
 
115
115
  ### chrX non-PAR
116
116
 
@@ -140,6 +140,15 @@ chrM is haploid for all samples (both sexes contribute AN=1):
140
140
  !!! warning "N_HET is always 0 on haploid regions"
141
141
  On chrY, chrM, and chrX non-PAR for males, all carriers are counted in N_HOM_ALT. N_HET is 0 because haploid samples have only one allele copy — there is no heterozygous state. This is correct behavior, not a bug.
142
142
 
143
+ ### Genotypes inconsistent with ploidy
144
+
145
+ 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 counts as one allele whether its GT is `1`, `0/1` or `1/1`. Calls that carry more alleles than the sample has cannot be counted that way:
146
+
147
+ - on a haploid position, two different ALT alleles (e.g. GT=`1/2` on chrM, or on chrX non-PAR in a male);
148
+ - 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).
149
+
150
+ `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, and log a warning naming the sample and the positions. Running `bcftools +fixploidy` during [preprocessing](../getting-started/preprocessing.md) avoids most of these cases on chrX.
151
+
143
152
  ---
144
153
 
145
154
  ## Sex Filter Interaction
@@ -153,7 +153,7 @@ On chrX non-PAR positions, males contribute AN=1 and females contribute AN=2. Wh
153
153
 
154
154
  ## What does N_FAIL mean in query output?
155
155
 
156
- `N_FAIL` is the count of eligible samples whose call had `FILTER≠PASS` at the position. Shown as `N_FAIL=N` in text output. These samples are excluded from AC, but they stay eligible and still count toward AN. See [FILTER=PASS Tracking](advanced/filter-pass-tracking.md).
156
+ `N_FAIL` is the count of eligible samples whose call had `FILTER≠PASS` at the position. Shown as `N_FAIL=N` in text output. These samples are left out of AC and AN, because their genotype there is unknown. See [FILTER=PASS Tracking](advanced/filter-pass-tracking.md).
157
157
 
158
158
  ---
159
159
 
@@ -9,7 +9,7 @@ For each variant, AFQuery stores a compressed bitset recording which samples car
9
9
  ```
10
10
  Samples → Metadata → Filters → Eligible Bitmap
11
11
  Variants → Genotypes → het/hom Bitmaps
12
- Query: (eligible bitmap) AND (carrier bitmap) → AC; count(eligible) → AN; AC/AN → AF
12
+ Query: (eligible bitmap) AND (carrier bitmap) → AC; count(eligible − failed) → AN; AC/AN → AF
13
13
  ```
14
14
 
15
15
  ```mermaid
@@ -25,7 +25,7 @@ flowchart LR
25
25
  end
26
26
 
27
27
  subgraph Result
28
- R["AC = popcount(eligible AND carrier)<br/>AN = popcount(eligible) × ploidy<br/>AF = AC / AN"]
28
+ R["AC = popcount(eligible AND carrier)<br/>AN = popcount(eligible − failed) × ploidy<br/>AF = AC / AN"]
29
29
  end
30
30
 
31
31
  S --> E
@@ -55,7 +55,7 @@ For a detailed discussion of the methodological gaps AFQuery addresses, includin
55
55
  For a given variant (chromosome, position, ref, alt):
56
56
 
57
57
  - **AC** (Allele Count) — number of copies of the alt allele observed across eligible samples
58
- - **AN** (Allele Number) — total number of alleles examined (2× diploid samples, 1× haploid)
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
61
  A heterozygous carrier contributes AC=1; a homozygous alt carrier contributes AC=2.
@@ -130,7 +130,7 @@ For each variant row, AFQuery stores per-sample genotype information as [Roaring
130
130
 
131
131
  - **`het_bitmap`** — sample is heterozygous (`GT=0/1`) with `FILTER=PASS`
132
132
  - **`hom_bitmap`** — sample is homozygous alt (`GT=1/1`, or `GT=1` on haploid regions) with `FILTER=PASS`
133
- - **`fail_bitmap`** — the sample's call at this site has `FILTER≠PASS`
133
+ - **`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
134
 
135
135
  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).
136
136
 
@@ -214,7 +214,7 @@ When planning phenotype codes, consider:
214
214
 
215
215
  ---
216
216
 
217
- PASS-only ingestion is always enforced. See [FILTER=PASS Tracking](../advanced/filter-pass-tracking.md) for details.
217
+ Only `FILTER=PASS` calls count towards AC. Failed calls are stored too, and their samples are reported as `N_FAIL` and left out of AN. See [FILTER=PASS Tracking](../advanced/filter-pass-tracking.md) for details.
218
218
 
219
219
  ---
220
220
 
@@ -2,7 +2,15 @@
2
2
 
3
3
  AFQuery ingests single-sample, normalized VCF files. While AFQuery itself does not perform VCF normalization, the accuracy of your allele frequency estimates depends on the quality and consistency of your input VCFs. This page explains why normalization matters and provides a reference pipeline.
4
4
 
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).
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
+
7
+ !!! warning "VCFs normalized with the script from afquery 0.4.2 or earlier"
8
+ Those versions of the script did not split multi-allelic records, and removed
9
+ one of two different indels at the same position as a duplicate. Indels from
10
+ multi-allelic sites could therefore be stored untrimmed (e.g. `CAAAAAAA>CAAAAAAAAAAAA`
11
+ instead of `C>CAAAAA`), so the same variant appeared under two representations, or
12
+ were dropped. Re-normalize those VCFs with the current script and rebuild the
13
+ database to correct them.
6
14
 
7
15
 
8
16
  ---
@@ -17,20 +25,17 @@ Multi-allelic variants and complex indels can be represented in multiple equival
17
25
  - Multi-allelic sites may not be decomposed into biallelic records
18
26
  - Duplicate records can inflate AC
19
27
 
20
- `bcftools norm` left-aligns indels against the reference genome and decomposes multi-allelic sites, ensuring consistent representation across samples.
28
+ `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.
21
29
 
22
30
  ### Ploidy correction for sex chromosomes
23
31
 
24
- 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. Without ploidy correction:
25
-
26
- - Males at chrX are counted as diploid → AN is inflated by up to 50%
27
- - AF estimates for X-linked variants are systematically underestimated
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.
28
33
 
29
34
  `bcftools +fixploidy` corrects genotype ploidy based on a sex file.
30
35
 
31
36
  ### Filtering and stripping
32
37
 
33
- - **Non-PASS genotypes**: Masking them as missing ensures that low-quality calls do not inflate AC. AFQuery tracks these as N_FAIL.
38
+ - **Non-PASS genotypes**: Masking every genotype at a failed site as missing ensures that low-quality calls do not inflate AC, and that no sample there is taken for hom-ref. AFQuery tracks these samples as N_FAIL and leaves them out of AN.
34
39
  - **Homozygous reference calls**: Removing ref/ref genotypes reduces file size and speeds ingestion; they contribute AC=0 and are not needed
35
40
  - **INFO fields**: Stripping INFO reduces file size and speeds ingestion. Additionally, malformed or non-standard INFO fields produced by some variant callers can break downstream parsing; stripping them pre-emptively prevents these errors.
36
41
  - **FORMAT fields**: Only `GT`, `DP`, and `GQ` are preserved. `GT` is the genotype required by AFQuery for all queries. `DP` and `GQ` are read by the [coverage-evidence](../advanced/coverage-evidence.md) quality flags (`afquery create-db --min-dp / --min-gq / --min-qual / --min-covered`). VCFs without `DP`/`GQ` are still valid; their carriers simply contribute no quality evidence to the cohort. All other FORMAT fields (`PL`, `AD`, etc.) are dropped to reduce file size.
@@ -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
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
74
74
  ```
75
75
 
76
76
  Filter to female samples with a specific phenotype:
@@ -134,7 +134,7 @@ The output VCF gains INFO fields (see [Annotate a VCF](../guides/annotate-vcf.md
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
136
  | `AFQUERY_N_HOM_REF` | A (per ALT) | Homozygous ref sample count |
137
- | `AFQUERY_N_FAIL` | 1 (per site) | Samples with FILTER≠PASS |
137
+ | `AFQUERY_N_FAIL` | 1 (per site) | Samples with a failed call (FILTER≠PASS), left out of AN |
138
138
  | `AFQUERY_N_NO_COVERAGE` | A (per ALT) | Eligible samples lacking coverage evidence (0 unless a coverage-evidence filter is active) |
139
139
 
140
140
  ---
@@ -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_HOM_REF=5 N_FAIL=0
77
+ chr1:925952 G>A AC=6 AN=20 AF=0.3000 n_eligible=10 N_HET=4 N_HOM_ALT=1 N_HOM_REF=5 N_FAIL=0 N_NO_COVERAGE=0
78
78
  ```
79
79
 
80
80
  ### Reading the output
@@ -107,15 +107,10 @@ afquery query --db ./demo_db/ --locus chr1:946000
107
107
  Example output:
108
108
 
109
109
  ```
110
- chr1:946000 T>C AC=2 AN=20 AF=0.1000 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HOM_REF=6 N_FAIL=2
110
+ chr1:946000 T>C AC=2 AN=16 AF=0.1250 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HOM_REF=6 N_FAIL=2 N_NO_COVERAGE=0
111
111
  ```
112
112
 
113
- Here, 2 samples were flagged as `LowQual` in their source VCF at this position. N_FAIL samples are:
114
-
115
- - **Counted in AN** — they are eligible and contribute to the denominator
116
- - **Excluded from AC** — their alleles are not counted in the numerator
117
-
118
- This makes AF a conservative estimate: `AF=2/20=0.1000` even though 2 additional samples may carry the variant. Verify: 10 = 2+0+6+2 ✓.
113
+ 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).
119
114
 
120
115
  !!! tip
121
116
  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.
@@ -131,9 +126,9 @@ afquery query --db ./demo_db/ --region chr1:900000-950000
131
126
  Example output:
132
127
 
133
128
  ```
134
- chr1:925100 C>T AC=4 AN=20 AF=0.2000 n_eligible=10 N_HET=4 N_HOM_ALT=0 N_HOM_REF=6 N_FAIL=0
135
- chr1:925952 G>A AC=6 AN=20 AF=0.3000 n_eligible=10 N_HET=4 N_HOM_ALT=1 N_HOM_REF=5 N_FAIL=0
136
- chr1:946000 T>C AC=2 AN=20 AF=0.1000 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HOM_REF=6 N_FAIL=2
129
+ chr1:925100 C>T AC=4 AN=20 AF=0.2000 n_eligible=10 N_HET=4 N_HOM_ALT=0 N_HOM_REF=6 N_FAIL=0 N_NO_COVERAGE=0
130
+ chr1:925952 G>A AC=6 AN=20 AF=0.3000 n_eligible=10 N_HET=4 N_HOM_ALT=1 N_HOM_REF=5 N_FAIL=0 N_NO_COVERAGE=0
131
+ chr1:946000 T>C AC=2 AN=16 AF=0.1250 n_eligible=10 N_HET=2 N_HOM_ALT=0 N_HOM_REF=6 N_FAIL=2 N_NO_COVERAGE=0
137
132
  ```
138
133
 
139
134
  ---
@@ -181,7 +176,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --sex female
181
176
  Example output:
182
177
 
183
178
  ```
184
- chr1:925952 G>A AC=3 AN=10 AF=0.3000 n_eligible=5 N_HET=3 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0
179
+ chr1:925952 G>A AC=3 AN=10 AF=0.3000 n_eligible=5 N_HET=3 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
185
180
  ```
186
181
 
187
182
  Now query male samples:
@@ -193,7 +188,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --sex male
193
188
  Example output:
194
189
 
195
190
  ```
196
- chr1:925952 G>A AC=3 AN=10 AF=0.3000 n_eligible=5 N_HET=1 N_HOM_ALT=1 N_HOM_REF=3 N_FAIL=0
191
+ chr1:925952 G>A AC=3 AN=10 AF=0.3000 n_eligible=5 N_HET=1 N_HOM_ALT=1 N_HOM_REF=3 N_FAIL=0 N_NO_COVERAGE=0
197
192
  ```
198
193
 
199
194
  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.
@@ -211,7 +206,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --phenotype E11.9
211
206
  Example output:
212
207
 
213
208
  ```
214
- chr1:925952 G>A AC=5 AN=8 AF=0.6250 n_eligible=4 N_HET=3 N_HOM_ALT=1 N_HOM_REF=0 N_FAIL=0
209
+ chr1:925952 G>A AC=5 AN=8 AF=0.6250 n_eligible=4 N_HET=3 N_HOM_ALT=1 N_HOM_REF=0 N_FAIL=0 N_NO_COVERAGE=0
215
210
  ```
216
211
 
217
212
  Exclude control samples:
@@ -223,7 +218,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --phenotype ^control
223
218
  Example output:
224
219
 
225
220
  ```
226
- chr1:925952 G>A AC=6 AN=12 AF=0.5000 n_eligible=6 N_HET=4 N_HOM_ALT=1 N_HOM_REF=1 N_FAIL=0
221
+ chr1:925952 G>A AC=6 AN=12 AF=0.5000 n_eligible=6 N_HET=4 N_HOM_ALT=1 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
227
222
  ```
228
223
 
229
224
  The `^` prefix means "exclude". Excluding controls removes 4 samples, leaving 6. See [Sample Filtering](../guides/sample-filtering.md) for the full syntax.
@@ -241,7 +236,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --tech wgs
241
236
  Example output:
242
237
 
243
238
  ```
244
- chr1:925952 G>A AC=4 AN=8 AF=0.5000 n_eligible=4 N_HET=2 N_HOM_ALT=1 N_HOM_REF=1 N_FAIL=0
239
+ chr1:925952 G>A AC=4 AN=8 AF=0.5000 n_eligible=4 N_HET=2 N_HOM_ALT=1 N_HOM_REF=1 N_FAIL=0 N_NO_COVERAGE=0
245
240
  ```
246
241
 
247
242
  Now query each WES technology separately:
@@ -251,7 +246,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --tech wes_v1
251
246
  ```
252
247
 
253
248
  ```
254
- chr1:925952 G>A AC=1 AN=6 AF=0.1667 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0
249
+ chr1:925952 G>A AC=1 AN=6 AF=0.1667 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
255
250
  ```
256
251
 
257
252
  ```bash
@@ -259,7 +254,7 @@ afquery query --db ./demo_db/ --locus chr1:925952 --tech wes_v2
259
254
  ```
260
255
 
261
256
  ```
262
- chr1:925952 G>A AC=1 AN=6 AF=0.1667 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0
257
+ chr1:925952 G>A AC=1 AN=6 AF=0.1667 n_eligible=3 N_HET=1 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
263
258
  ```
264
259
 
265
260
  `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.
@@ -273,7 +268,7 @@ afquery query --db ./demo_db/ --locus chr1:1399914 --tech wgs
273
268
  ```
274
269
 
275
270
  ```
276
- chr1:1399914 G>T AC=2 AN=8 AF=0.2500 n_eligible=4 N_HET=2 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0
271
+ chr1:1399914 G>T AC=2 AN=8 AF=0.2500 n_eligible=4 N_HET=2 N_HOM_ALT=0 N_HOM_REF=2 N_FAIL=0 N_NO_COVERAGE=0
277
272
  ```
278
273
 
279
274
  ```bash
@@ -307,7 +302,7 @@ afquery query \
307
302
  Example output:
308
303
 
309
304
  ```
310
- chr1:925952 G>A AC=1 AN=2 AF=0.5000 n_eligible=1 N_HET=1 N_HOM_ALT=0 N_HOM_REF=0 N_FAIL=0
305
+ chr1:925952 G>A AC=1 AN=2 AF=0.5000 n_eligible=1 N_HET=1 N_HOM_ALT=0 N_HOM_REF=0 N_FAIL=0 N_NO_COVERAGE=0
311
306
  ```
312
307
 
313
308
  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).
@@ -325,18 +320,18 @@ afquery annotate \
325
320
  --output ./annotated_demo.vcf
326
321
  ```
327
322
 
328
- The output VCF gains `AFQUERY_AC`, `AFQUERY_AN`, `AFQUERY_AF`, `AFQUERY_N_HET`, `AFQUERY_N_HOM_ALT`, `AFQUERY_N_HOM_REF`, and `AFQUERY_N_FAIL` INFO fields. Inspect the chr1 variants:
323
+ The output VCF gains `AFQUERY_AC`, `AFQUERY_AN`, `AFQUERY_AF`, `AFQUERY_N_HET`, `AFQUERY_N_HOM_ALT`, `AFQUERY_N_HOM_REF`, `AFQUERY_N_FAIL`, and `AFQUERY_N_NO_COVERAGE` INFO fields. Inspect the chr1 variants:
329
324
 
330
325
  ```bash
331
- grep -v "^##" ./annotated_demo.vcf | grep "^chr1" | head -5
326
+ grep -v "^##" ./annotated_demo.vcf | grep "^chr1" | head -3
332
327
  ```
333
328
 
334
329
  Example output (columns: CHROM, POS, ID, REF, ALT, QUAL, FILTER, INFO, FORMAT, DEMO_001):
335
330
 
336
331
  ```
337
- 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_HOM_REF=6;AFQUERY_N_FAIL=0 GT 0/1
338
- 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_HOM_REF=5;AFQUERY_N_FAIL=0 GT 0/1
339
- chr1 946000 . T C 50 PASS AFQUERY_AC=2;AFQUERY_AN=20;AFQUERY_AF=0.1;AFQUERY_N_HET=2;AFQUERY_N_HOM_ALT=0;AFQUERY_N_HOM_REF=6;AFQUERY_N_FAIL=2 GT 0/1
332
+ 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_HOM_REF=6;AFQUERY_N_FAIL=0;AFQUERY_N_NO_COVERAGE=0 GT 0/1
333
+ 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_HOM_REF=5;AFQUERY_N_FAIL=0;AFQUERY_N_NO_COVERAGE=0 GT 0/1
334
+ 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_HOM_REF=6;AFQUERY_N_FAIL=2;AFQUERY_N_NO_COVERAGE=0 GT 0/1
340
335
  ```
341
336
 
342
337
  `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.
@@ -362,12 +357,12 @@ head -6 demo_dump.csv
362
357
  Example output:
363
358
 
364
359
  ```
365
- chrom,pos,ref,alt,AC,AN,AF,N_HET,N_HOM_ALT,N_HOM_REF,N_FAIL
366
- chr1,925100,C,T,4,20,0.2,4,0,6,0
367
- chr1,925952,G,A,6,20,0.3,4,1,5,0
368
- chr1,946000,T,C,2,20,0.1,2,0,6,2
369
- chr1,1225000,A,G,5,20,0.25,5,0,5,0
370
- chr1,1399914,G,T,2,8,0.25,2,0,2,0
360
+ chrom,pos,ref,alt,AC,AN,AF,N_HET,N_HOM_ALT,N_HOM_REF,N_FAIL,N_NO_COVERAGE
361
+ chr1,925100,C,T,4,20,0.2,4,0,6,0,0
362
+ chr1,925952,G,A,6,20,0.3,4,1,5,0,0
363
+ chr1,946000,T,C,2,16,0.125,2,0,6,2,0
364
+ chr1,1225000,A,G,5,20,0.25,5,0,5,0,0
365
+ chr1,1399914,G,T,2,8,0.25,2,0,2,0,0
371
366
  ```
372
367
 
373
368
  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).
@@ -9,14 +9,14 @@ This page explains what each field in AFQuery output means and how to interpret
9
9
  | Field | Type | Description |
10
10
  |-------|------|-------------|
11
11
  | **AC** | int | Allele count — number of alt allele copies in eligible samples |
12
- | **AN** | int | Allele number — total alleles examined (adjusted for ploidy and eligible samples) |
13
- | **AF** | float | Allele frequency — `AC / AN`. `None` when AN=0 |
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
+ | **AF** | float | Allele frequency — `AC / AN`. `NA` (text/TSV) or `null` (JSON) when AN=0 |
14
14
  | **N_HET** | int | Number of eligible samples heterozygous for the alt allele (GT=0/1) |
15
15
  | **N_HOM_ALT** | int | Number of eligible samples homozygous for the alt allele (GT=1/1 or GT=1). Includes haploid carriers on sex chromosomes and chrM. See [Ploidy](../advanced/ploidy-and-sex-chroms.md#genotype-counting). |
16
- | **N_HOM_REF** | int | Number of eligible samples homozygous reference (GT=0/0 or GT=0) |
16
+ | **N_HOM_REF** | int | Number of eligible samples homozygous reference (GT=0/0 or GT=0). Samples carrying another ALT allele at the same position are not counted (see [Multi-allelic sites](#multi-allelic-sites)). |
17
17
  | **n_eligible** | int | Number of eligible samples — those passing the sex/phenotype/tech filters *and* covered at this position |
18
- | **N_FAIL** | int | Number of eligible samples whose call at this position had FILTER≠PASS. These samples are counted *only* in N_FAIL — not in N_HET, N_HOM_ALT, or N_HOM_REF — but they stay eligible and still count toward AN. |
19
- | **N_NO_COVERAGE** | int | Number of eligible samples whose tech lacks coverage evidence at this position. Excluded from `N_HOM_REF` to keep AC/AN conservative. Always `0` unless a coverage-evidence filter is active. See [Coverage Evidence](../advanced/coverage-evidence.md). |
18
+ | **N_FAIL** | int | Number of eligible samples with a failed call (FILTER≠PASS) for any allele at this position — the same value for every allele there. These samples are counted *only* in N_FAIL, not in N_HET, N_HOM_ALT or N_HOM_REF, and are left out of AC and AN. See [FILTER=PASS Tracking](../advanced/filter-pass-tracking.md). |
19
+ | **N_NO_COVERAGE** | int | Number of eligible samples whose tech lacks coverage evidence at this position. Excluded from `N_HOM_REF`; they still count in AN. Always `0` unless a coverage-evidence filter is active. See [Coverage Evidence](../advanced/coverage-evidence.md). |
20
20
 
21
21
 
22
22
  ---
@@ -74,16 +74,37 @@ afquery query --db ./db/ --locus chr1:925952 --ref G --alt A --format json
74
74
 
75
75
  ### AN=0 and AF=None
76
76
 
77
- AN=0 means no eligible samples have coverage at this position. This happens when:
77
+ AN=0 means no eligible sample has a usable call at this position. This happens when:
78
78
 
79
79
  - All eligible samples are WES or panels and the position is outside capture regions
80
80
  - The phenotype/sex/technology filter excludes all samples
81
81
  - The chromosome is not in the database
82
+ - Every eligible sample has a failed call there (`N_FAIL` = `n_eligible`)
83
+
84
+ In the first three cases `query` returns no line for the position; in the last one it reports the variant with AN=0.
82
85
 
83
86
 
84
87
  !!! warning "AN=0 does not mean the variant is absent"
85
88
  AN=0 means AFQuery has no data to compute frequency. It is not evidence of rarity.
86
89
 
90
+ ### Multi-allelic sites
91
+
92
+ Each ALT allele at a position is reported on its own line, and its counts refer to
93
+ that allele only. A sample carrying a different ALT allele at the same position
94
+ (for example `G/T` on the `G>A` line) is neither a carrier nor homozygous
95
+ reference for this allele, so it appears in none of `N_HET`, `N_HOM_ALT`,
96
+ `N_HOM_REF`, `N_FAIL` or `N_NO_COVERAGE`. The five counts add up to
97
+ `n_eligible` at biallelic sites; at a multi-allelic site they fall short by the
98
+ number of such samples. AC, AN and AF are not affected.
99
+
100
+ AN and `N_FAIL` describe the position, so they are the same on every line of a
101
+ multi-allelic site, and AN equals the reference alleles plus the AC of all its
102
+ ALT alleles. A sample with a failed call for any of the alleles is counted in
103
+ `N_FAIL` on every line.
104
+
105
+ A sample with two different ALT alleles (`GT=1/2`) is counted as heterozygous on
106
+ both lines.
107
+
87
108
  ### Warnings
88
109
 
89
110
  afquery emits a `AfqueryWarning` to stderr when a query may silently return fewer or no results. Common causes:
@@ -111,7 +132,7 @@ AC=0 with a high AN (e.g., AN=4000) means the variant was **genuinely not observ
111
132
 
112
133
  ### N_FAIL > 0
113
134
 
114
- When N_FAIL > 0, some eligible samples had a non-PASS filter at this position in their source VCF. A high N_FAIL relative to AN may indicate a problematic site (e.g., systematic sequencing artifacts). Consider filtering positions with more than 10% of failing (`N_FAIL / (AN / 2) > 0.1`).
135
+ When N_FAIL > 0, some eligible samples had a non-PASS filter at this position in their source VCF, and AF is computed over the remaining samples. A high N_FAIL relative to `n_eligible` may indicate a problematic site (e.g., systematic sequencing artifacts). Consider filtering positions where more than 10% of eligible samples failed (`N_FAIL / n_eligible > 0.1`).
115
136
 
116
137
  ---
117
138
 
@@ -122,12 +143,12 @@ When using `afquery annotate`, the following INFO fields are added to each varia
122
143
  | INFO field | Number | Description |
123
144
  |-----------|--------|-------------|
124
145
  | `AFQUERY_AC` | A (per ALT) | Allele count — one value per ALT allele |
125
- | `AFQUERY_AN` | 1 (per site) | Allele number — shared across all ALT alleles |
126
- | `AFQUERY_AF` | A (per ALT) | Allele frequency — one value per ALT allele |
146
+ | `AFQUERY_AN` | 1 (per site) | Allele number — shared across all ALT alleles; excludes samples in `AFQUERY_N_FAIL` |
147
+ | `AFQUERY_AF` | A (per ALT) | Allele frequency — one value per ALT allele; `.` when `AFQUERY_AN=0` |
127
148
  | `AFQUERY_N_HET` | A (per ALT) | Heterozygous sample count per ALT allele |
128
149
  | `AFQUERY_N_HOM_ALT` | A (per ALT) | Homozygous alt sample count per ALT allele |
129
- | `AFQUERY_N_HOM_REF` | A (per ALT) | Homozygous ref sample count per ALT allele |
130
- | `AFQUERY_N_FAIL` | 1 (per site) | Fail sample count — shared across all ALT alleles |
150
+ | `AFQUERY_N_HOM_REF` | A (per ALT) | Homozygous ref sample count per ALT allele, excluding carriers of other ALT alleles at the position |
151
+ | `AFQUERY_N_FAIL` | 1 (per site) | Samples with a failed call for any ALT allele at the position, each counted once |
131
152
  | `AFQUERY_N_NO_COVERAGE` | A (per ALT) | Eligible samples whose tech lacks coverage evidence at this position. Always `0` unless a coverage-evidence filter is active. See [Coverage Evidence](../advanced/coverage-evidence.md). |
132
153
 
133
154
  !!! note "Multi-allelic sites"
@@ -21,13 +21,13 @@ afquery annotate \
21
21
  | Field | Type | Number | Description |
22
22
  |-------|------|--------|-------------|
23
23
  | `AFQUERY_AC` | Integer | A (per ALT) | Allele count in eligible samples |
24
- | `AFQUERY_AN` | Integer | 1 (per site) | Allele number (total alleles examined) |
25
- | `AFQUERY_AF` | Float | A (per ALT) | Allele frequency (`AC / AN`) |
24
+ | `AFQUERY_AN` | Integer | 1 (per site) | Allele number (total alleles examined, excluding samples in `AFQUERY_N_FAIL`) |
25
+ | `AFQUERY_AF` | Float | A (per ALT) | Allele frequency (`AC / AN`); `.` when `AFQUERY_AN=0` |
26
26
  | `AFQUERY_N_HET` | Integer | A (per ALT) | Heterozygous sample count |
27
27
  | `AFQUERY_N_HOM_ALT` | Integer | A (per ALT) | Homozygous alt sample count |
28
- | `AFQUERY_N_HOM_REF` | Integer | A (per ALT) | Homozygous ref sample count |
29
- | `AFQUERY_N_FAIL` | Integer | 1 (per site) | Eligible samples whose call had FILTER≠PASS. Excluded from AC, but still counted in AN. Mutually exclusive with N_HET/N_HOM_ALT/N_HOM_REF. |
30
- | `AFQUERY_N_NO_COVERAGE` | Integer | A (per ALT) | Eligible samples whose tech lacks coverage evidence at this position. Excluded from `N_HOM_REF` to keep AC/AN conservative. Always `0` unless a coverage-evidence filter is active. See [Coverage Evidence](../advanced/coverage-evidence.md). |
28
+ | `AFQUERY_N_HOM_REF` | Integer | A (per ALT) | Homozygous ref sample count, excluding carriers of other ALT alleles at the position (including alleles stored in the database but absent from the input record) |
29
+ | `AFQUERY_N_FAIL` | Integer | 1 (per site) | Eligible samples with a failed call (FILTER≠PASS) for any ALT allele at the position, each counted once. Excluded from AC and AN. Mutually exclusive with N_HET/N_HOM_ALT/N_HOM_REF. |
30
+ | `AFQUERY_N_NO_COVERAGE` | Integer | A (per ALT) | Eligible samples whose tech lacks coverage evidence at this position. Excluded from `N_HOM_REF`; still counted in AN. Always `0` unless a coverage-evidence filter is active. See [Coverage Evidence](../advanced/coverage-evidence.md). |
31
31
 
32
32
  !!! note "Multi-allelic sites"
33
33
  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.