EGenetics · genetics.qc
Genotype quality control
Which markers and people are reliable enough to analyze?
The checks to run before any association or population analysis. Per marker: call rate, minor-allele frequency, observed and expected heterozygosity and the Hardy–Weinberg exact test. Per person: call rate and the inbreeding coefficient F from homozygosity, which flags contamination (F well below 0) or relatedness and inbreeding (F well above 0). Thresholds follow PLINK's common defaults and can be changed; nothing is removed, the card lists what fails. Research use only.
A real result
Example “People common”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
Quality control: 21 of 24 markers and 273 of 300 people passed
- Markers passing
- 21
- People passing
- 273
- Overall call rate
- 0.9772
Plots
View data
| MAF |
|---|
| 0.4379 |
| 0.4799 |
| 0.4521 |
| 0.4524 |
| 0.4291 |
| 0.4711 |
| 0.4555 |
| 0.4493 |
| 0.2908 |
| 0.2045 |
| 0.0017 |
| 0.3670 |
| 0.1156 |
| 0.0889 |
| 0.1814 |
| 0.4983 |
| 0.3259 |
| 0.4916 |
| 0.2024 |
| 0.0859 |
| 0.4966 |
| 0.1803 |
| 0.0814 |
| 0.4017 |
View data
| Homozygous (other) | Heterozygous | Homozygous (counted) | HWE | Marker |
|---|---|---|---|---|
| 58 | 138 | 94 | Passes HWE | v01 |
| 82 | 146 | 70 | Passes HWE | v02 |
| 88 | 144 | 60 | Passes HWE | v03 |
| 64 | 138 | 92 | Passes HWE | v04 |
| 97 | 144 | 55 | Passes HWE | v05 |
| 66 | 145 | 83 | Passes HWE | v06 |
| 62 | 142 | 88 | Passes HWE | v07 |
| 85 | 156 | 55 | Passes HWE | v08 |
| 174 | 69 | 51 | Fails HWE | v09 |
| 165 | 90 | 9 | Passes HWE | v10 |
| 294 | 1 | 0 | Passes HWE | v11 |
| 116 | 144 | 37 | Passes HWE | v12 |
| 229 | 62 | 3 | Passes HWE | v13 |
| 250 | 43 | 5 | Passes HWE | v14 |
| 199 | 85 | 11 | Passes HWE | v15 |
| 74 | 145 | 73 | Passes HWE | v16 |
| 142 | 111 | 40 | Passes HWE | v17 |
| 75 | 144 | 80 | Passes HWE | v18 |
| 188 | 93 | 13 | Passes HWE | v19 |
| 246 | 40 | 5 | Passes HWE | v20 |
| 73 | 150 | 71 | Passes HWE | v21 |
| 203 | 76 | 15 | Passes HWE | v22 |
| 249 | 44 | 2 | Passes HWE | v23 |
| 99 | 155 | 41 | Passes HWE | v24 |
Assumptions
- One population — If people come from several populations, run QC within each: mixing them fails HWE and lowers heterozygosity.
- Unrelated people — 0 people have F above 0.2, as relatives or inbreeding produce.
- Biallelic markers — All 24 markers show at most two alleles.
Markers
| Marker | Counted allele | Call rate | MAF | Observed het. | Expected het. | HWE exact p | Fails |
|---|---|---|---|---|---|---|---|
| v01 | B | 0.9667 | 0.4379 | 0.4759 | 0.4923 | 0.5533 | |
| v02 | B | 0.9933 | 0.4799 | 0.4899 | 0.4992 | 0.7293 | |
| v03 | B | 0.9733 | 0.4521 | 0.4932 | 0.4954 | 1 | |
| v04 | B | 0.9800 | 0.4524 | 0.4694 | 0.4955 | 0.4096 | |
| v05 | B | 0.9867 | 0.4291 | 0.4865 | 0.4899 | 0.9058 | |
| v06 | B | 0.9800 | 0.4711 | 0.4932 | 0.4983 | 0.9068 | |
| v07 | B | 0.9733 | 0.4555 | 0.4863 | 0.4960 | 0.7247 | |
| v08 | B | 0.9867 | 0.4493 | 0.5270 | 0.4949 | 0.2918 | |
| v09 | B | 0.9800 | 0.2908 | 0.2347 | 0.4125 | 9.998e-13 | HWE |
| v10 | B | 0.8800 | 0.2045 | 0.3409 | 0.3254 | 0.5702 | call rate |
| v11 | B | 0.9833 | 0.0017 | 0.0034 | 0.0034 | 1 | MAF |
| v12 | B | 0.9900 | 0.3670 | 0.4848 | 0.4646 | 0.5323 | |
| v13 | B | 0.9800 | 0.1156 | 0.2109 | 0.2045 | 0.7791 | |
| v14 | B | 0.9933 | 0.0889 | 0.1443 | 0.1620 | 0.0671 | |
| v15 | B | 0.9833 | 0.1814 | 0.2881 | 0.2969 | 0.5607 | |
| v16 | B | 0.9733 | 0.4983 | 0.4966 | 0.5000 | 0.9071 | |
| v17 | B | 0.9767 | 0.3259 | 0.3788 | 0.4394 | 0.0233 | |
| v18 | B | 0.9967 | 0.4916 | 0.4816 | 0.4999 | 0.5629 | |
| v19 | B | 0.9800 | 0.2024 | 0.3163 | 0.3228 | 0.7186 | |
| v20 | B | 0.9700 | 0.0859 | 0.1375 | 0.1571 | 0.0465 | |
| v21 | B | 0.9800 | 0.4966 | 0.5102 | 0.5000 | 0.8155 | |
| v22 | B | 0.9800 | 0.1803 | 0.2585 | 0.2955 | 0.0457 | |
| v23 | B | 0.9833 | 0.0814 | 0.1492 | 0.1495 | 1 | |
| v24 | B | 0.9833 | 0.4017 | 0.5254 | 0.4807 | 0.1455 |
People who fail
| Row | Call rate | Heterozygosity | F | Fails |
|---|---|---|---|---|
| 6 | 0.5833 | 0.5714 | −0.3357 | call rate |
| 7 | 0.4583 | 0.3636 | −0.0935 | call rate |
| 12 | 0.9167 | 0.4091 | −0.0359 | call rate |
| 18 | 0.9167 | 0.2727 | 0.2682 | call rate |
| 23 | 0.9167 | 0.3636 | 0.1134 | call rate |
| 27 | 0.9167 | 0.5000 | −0.3306 | call rate |
| 46 | 0.8750 | 0.3333 | 0.0890 | call rate |
| 48 | 0.9167 | 0.4091 | −0.0353 | call rate |
| 52 | 0.9167 | 0.4545 | −0.2214 | call rate |
| 76 | 0.9167 | 0.4545 | −0.2224 | call rate |
| 86 | 0.9167 | 0.4545 | −0.1926 | call rate |
| 109 | 0.9167 | 0.5455 | −0.4337 | call rate |
| 114 | 0.9167 | 0.5000 | −0.3439 | call rate |
| 125 | 0.9167 | 0.1818 | 0.5244 | call rate |
| 129 | 0.9167 | 0.3182 | 0.1501 | call rate |
| 137 | 0.8750 | 0.6190 | −0.6550 | call rate |
| 142 | 0.9167 | 0.1818 | 0.5160 | call rate |
| 149 | 0.9167 | 0.3182 | 0.1678 | call rate |
| 153 | 0.9167 | 0.2727 | 0.2670 | call rate |
| 159 | 0.9167 | 0.5000 | −0.3169 | call rate |
| 177 | 0.9167 | 0.2273 | 0.3975 | call rate |
| 182 | 0.9167 | 0.4091 | −0.0995 | call rate |
| 209 | 0.9167 | 0.3182 | 0.1457 | call rate |
| 213 | 0.9167 | 0.6364 | −0.6038 | call rate |
| 250 | 0.9167 | 0.4091 | −0.0715 | call rate |
| 255 | 0.9167 | 0.4545 | −0.1500 | call rate |
| 285 | 0.9167 | 0.3636 | 0.0223 | call rate |
- 300 people have fewer than 100 polymorphic markers called, too few for a stable F; the |F| check skips them.
- Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
- Thresholds: marker call rate ≥ 0.95, MAF ≥ 0.01, HWE p ≥ 1e-06; person call rate ≥ 0.95, |F| ≤ 0.2.
- F = (observed − expected homozygous markers) / (called markers − expected), over polymorphic markers (PLINK --het); checked from 100 markers.
- Nothing is removed: filter the failing markers and people in Prepare or in the Genetics studio.
Quality control: 21 of 24 markers and 273 of 300 people passed
- Markers passing
- 21
- People passing
- 273
- Overall call rate
- 0.9772
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- One population — If people come from several populations, run QC within each: mixing them fails HWE and lowers heterozygosity.
- Unrelated people — 0 people have F above 0.2, as relatives or inbreeding produce.
- Biallelic markers — All 24 markers show at most two alleles.
Markers
| Marker | Counted allele | Call rate | MAF | Observed het. | Expected het. | HWE exact p | Fails |
|---|---|---|---|---|---|---|---|
| v01 | B | 0.9667 | 0.4379 | 0.4759 | 0.4923 | 0.5533 | |
| v02 | B | 0.9933 | 0.4799 | 0.4899 | 0.4992 | 0.7293 | |
| v03 | B | 0.9733 | 0.4521 | 0.4932 | 0.4954 | 1 | |
| v04 | B | 0.9800 | 0.4524 | 0.4694 | 0.4955 | 0.4096 | |
| v05 | B | 0.9867 | 0.4291 | 0.4865 | 0.4899 | 0.9058 | |
| v06 | B | 0.9800 | 0.4711 | 0.4932 | 0.4983 | 0.9068 | |
| v07 | B | 0.9733 | 0.4555 | 0.4863 | 0.4960 | 0.7247 | |
| v08 | B | 0.9867 | 0.4493 | 0.5270 | 0.4949 | 0.2918 | |
| v09 | B | 0.9800 | 0.2908 | 0.2347 | 0.4125 | 9.998e-13 | HWE |
| v10 | B | 0.8800 | 0.2045 | 0.3409 | 0.3254 | 0.5702 | call rate |
| v11 | B | 0.9833 | 0.0017 | 0.0034 | 0.0034 | 1 | MAF |
| v12 | B | 0.9900 | 0.3670 | 0.4848 | 0.4646 | 0.5323 | |
| v13 | B | 0.9800 | 0.1156 | 0.2109 | 0.2045 | 0.7791 | |
| v14 | B | 0.9933 | 0.0889 | 0.1443 | 0.1620 | 0.0671 | |
| v15 | B | 0.9833 | 0.1814 | 0.2881 | 0.2969 | 0.5607 | |
| v16 | B | 0.9733 | 0.4983 | 0.4966 | 0.5000 | 0.9071 | |
| v17 | B | 0.9767 | 0.3259 | 0.3788 | 0.4394 | 0.0233 | |
| v18 | B | 0.9967 | 0.4916 | 0.4816 | 0.4999 | 0.5629 | |
| v19 | B | 0.9800 | 0.2024 | 0.3163 | 0.3228 | 0.7186 | |
| v20 | B | 0.9700 | 0.0859 | 0.1375 | 0.1571 | 0.0465 | |
| v21 | B | 0.9800 | 0.4966 | 0.5102 | 0.5000 | 0.8155 | |
| v22 | B | 0.9800 | 0.1803 | 0.2585 | 0.2955 | 0.0457 | |
| v23 | B | 0.9833 | 0.0814 | 0.1492 | 0.1495 | 1.0000 | |
| v24 | B | 0.9833 | 0.4017 | 0.5254 | 0.4807 | 0.1455 |
People who fail
| Row | Call rate | Heterozygosity | F | Fails |
|---|---|---|---|---|
| 6 | 0.5833 | 0.5714 | −0.3357 | call rate |
| 7 | 0.4583 | 0.3636 | −0.0935 | call rate |
| 12 | 0.9167 | 0.4091 | −0.0359 | call rate |
| 18 | 0.9167 | 0.2727 | 0.2682 | call rate |
| 23 | 0.9167 | 0.3636 | 0.1134 | call rate |
| 27 | 0.9167 | 0.5000 | −0.3306 | call rate |
| 46 | 0.8750 | 0.3333 | 0.0890 | call rate |
| 48 | 0.9167 | 0.4091 | −0.0353 | call rate |
| 52 | 0.9167 | 0.4545 | −0.2214 | call rate |
| 76 | 0.9167 | 0.4545 | −0.2224 | call rate |
| 86 | 0.9167 | 0.4545 | −0.1926 | call rate |
| 109 | 0.9167 | 0.5455 | −0.4337 | call rate |
| 114 | 0.9167 | 0.5000 | −0.3439 | call rate |
| 125 | 0.9167 | 0.1818 | 0.5244 | call rate |
| 129 | 0.9167 | 0.3182 | 0.1501 | call rate |
| 137 | 0.8750 | 0.6190 | −0.6550 | call rate |
| 142 | 0.9167 | 0.1818 | 0.5160 | call rate |
| 149 | 0.9167 | 0.3182 | 0.1678 | call rate |
| 153 | 0.9167 | 0.2727 | 0.2670 | call rate |
| 159 | 0.9167 | 0.5000 | −0.3169 | call rate |
| 177 | 0.9167 | 0.2273 | 0.3975 | call rate |
| 182 | 0.9167 | 0.4091 | −0.0995 | call rate |
| 209 | 0.9167 | 0.3182 | 0.1457 | call rate |
| 213 | 0.9167 | 0.6364 | −0.6038 | call rate |
| 250 | 0.9167 | 0.4091 | −0.0715 | call rate |
| 255 | 0.9167 | 0.4545 | −0.1500 | call rate |
| 285 | 0.9167 | 0.3636 | 0.0223 | call rate |
- 300 people have fewer than 100 polymorphic markers called, too few for a stable F; the |F| check skips them.
- Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
- Thresholds: marker call rate ≥ 0.95, MAF ≥ 0.01, HWE p ≥ 1e-06; person call rate ≥ 0.95, |F| ≤ 0.2.
- F = (observed − expected homozygous markers) / (called markers − expected), over polymorphic markers (PLINK --het); checked from 100 markers.
- Nothing is removed: filter the failing markers and people in Prepare or in the Genetics studio.
Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.
Worked examples in the app
- People commonge_people · variants: v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24
- People vcf strictge_people · variants: gt1, gt2, gt3, gt4, v01, v09
- People rare keepge_people · variants: r01, r02, r03, r04, r05, r06, r07, r08, r09, r10, r11, r12, r13, r14, r15
- Degenerate infge_people · variants: v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24
- Degenerate tiesge_people · variants: v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24
In the guides
Where it sits in the decision guides
- Goodness of fit · Statistics Guide · E — Compare proportions / frequencies
What you need
- Markersnumeric / categorical · 1–10000 columns
- One column per marker, one row per person: doses 0/1/2, VCF calls (0/1, 1|1, ./.) or two alleles.
Choices you make
statistics
- Lowest marker call ratedefault 0.95
Markers called in a smaller share of people fail (PLINK --geno 0.05).
- Lowest minor-allele frequencydefault 0.01
Rarer markers fail for common-variant analyses (PLINK --maf 0.01); set 0 to keep rare variants.
- HWE exact-test thresholddefault 0.000001
Markers with a Hardy–Weinberg exact p below it fail, as calling errors often do (PLINK --hwe 1e-6).
- Lowest person call ratedefault 0.95
People called at a smaller share of markers fail (PLINK --mind 0.05).
- Largest |F| per persondefault 0.2
People further from 0 fail (low F: contamination; high: inbreeding). Needs 100 polymorphic markers per person.
Checks and remedies
CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.
One population
Mixed ancestry lowers heterozygosity and fails HWE without any error; run QC within populations.
Unrelated people
Relatives raise F; check relatedness separately.
Biallelic markers
Each marker is read with two alleles; split multi-allelic sites first.
What it reports
- n_samples
- The share of genotypes the assay could read, per marker or per person. Low call rates flag failed assays or poor DNA.
- n_variants
- The share of genotypes the assay could read, per marker or per person. Low call rates flag failed assays or poor DNA.
- n_monomorphic
- The frequency of the less common allele at a marker, between 0 and 0.5.
- n_fail_call
- The share of genotypes the assay could read, per marker or per person. Low call rates flag failed assays or poor DNA.
- n_fail_maf
- The frequency of the less common allele at a marker, between 0 and 0.5.
- n_fail_hwe
- In QC, markers whose genotype counts fail the Hardy–Weinberg exact test at a strict threshold (often 10⁻⁶) are treated as calling errors.
- n_fail_any
- In QC, markers whose genotype counts fail the Hardy–Weinberg exact test at a strict threshold (often 10⁻⁶) are treated as calling errors.
- n_pass
- In QC, markers whose genotype counts fail the Hardy–Weinberg exact test at a strict threshold (often 10⁻⁶) are treated as calling errors.
- n_samples_fail_call
- The share of genotypes the assay could read, per marker or per person. Low call rates flag failed assays or poor DNA.
- n_samples_fail_f
- Each person's F compares observed with expected homozygous markers. Far below 0 suggests contamination; far above 0, inbreeding or kin.
- n_samples_pass
- Each person's F compares observed with expected homozygous markers. Far below 0 suggests contamination; far above 0, inbreeding or kin.
- call_rate
- The share of genotypes the assay could read, per marker or per person. Low call rates flag failed assays or poor DNA.
- variant_call_rate
- The share of genotypes the assay could read, per marker or per person. Low call rates flag failed assays or poor DNA.
- variant_maf
- The frequency of the less common allele at a marker, between 0 and 0.5.
- variant_hwe_p
- In QC, markers whose genotype counts fail the Hardy–Weinberg exact test at a strict threshold (often 10⁻⁶) are treated as calling errors.
- variant_het_obs
- In QC, markers whose genotype counts fail the Hardy–Weinberg exact test at a strict threshold (often 10⁻⁶) are treated as calling errors.
- variant_het_exp
- In QC, markers whose genotype counts fail the Hardy–Weinberg exact test at a strict threshold (often 10⁻⁶) are treated as calling errors.
- variant_pass
- In QC, markers whose genotype counts fail the Hardy–Weinberg exact test at a strict threshold (often 10⁻⁶) are treated as calling errors.
- sample_call_rate
- The share of genotypes the assay could read, per marker or per person. Low call rates flag failed assays or poor DNA.
- sample_f
- Each person's F compares observed with expected homozygous markers. Far below 0 suggests contamination; far above 0, inbreeding or kin.
- sample_pass
- Each person's F compares observed with expected homozygous markers. Far below 0 suggests contamination; far above 0, inbreeding or kin.
Python and R
Python and R agree to 10 decimals (relative tolerance 1e-10). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.
The exact script CodeSplash ran for example “People common” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Genotype quality control
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.qc 1.0.1 · spec 3cb6a5d0c445a953
# Dataset: ge_people (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import math
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.stats import genetics as gen # per-marker and per-person QC, HWE exact (twins of cs_gen_*)
# %% Data (no rows dropped here: genotype no-calls and missing values are handled by the analysis)
df = pd.read_parquet("tests/parity/fixtures/ge_people.parquet", columns=["v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24"])
n_input = len(df)
warnings = []
research_note = "Research use only: not for clinical or diagnostic decisions. Genotypes are personal data."
# %% Genotypes
variants = ["v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24"]
g, counted, other = gen.dose_matrix({v: df[v].to_numpy() for v in variants})
min_call_v = float(0.95)
min_maf = float(0.01)
hwe_thr = float(1e-6)
min_call_s = float(0.95)
max_f = float(0.2)
# %% Checks
q = gen.qc(g)
n, m = g.shape
fail_call = q["call_rate"] < min_call_v
fail_maf = np.nan_to_num(q["maf"], nan=0.0) < min_maf
fail_hwe = np.nan_to_num(q["hwe_p"], nan=1.0) < hwe_thr
fail_any = fail_call | fail_maf | fail_hwe
s_fail_call = q["sample_call_rate"] < min_call_s
# F from a few markers is mostly noise, so the |F| check needs 100 polymorphic markers called per person.
f_ok = q["sample_n_poly"] >= 100
s_fail_f = (np.abs(np.nan_to_num(q["sample_f"], nan=0.0)) > max_f) & f_ok
if not f_ok.all():
warnings.append(f"{int((~f_ok).sum())} people have fewer than 100 polymorphic markers called, too few for a stable F; the |F| check skips them.")
s_pass = ~(s_fail_call | s_fail_f)
call_rate = float(np.sum(~np.isnan(g))) / (n * m)
if int(np.sum(q["monomorphic"])):
warnings.append(f"{int(np.sum(q['monomorphic']))} markers are monomorphic here: they carry no information and are left out of each person's F.")
# %% Assumptions
assumptions = [
{"key": "one_population", "label": "One population", "status": "info", "detail": "If people come from several populations, run QC within each: mixing them fails HWE and lowers heterozygosity."},
{"key": "unrelated", "label": "Unrelated people", "status": "warn" if int(np.sum((np.nan_to_num(q["sample_f"]) > max_f) & f_ok)) else "info",
"detail": f"{int(np.sum((np.nan_to_num(q['sample_f']) > max_f) & f_ok))} people have F above {max_f:g}, as relatives or inbreeding produce."},
{"key": "biallelic", "label": "Biallelic markers", "status": "pass", "detail": f"All {m} markers show at most two alleles."},
]
# %% Result
summary = (f"{int(np.sum(~fail_any))} of {m} markers pass (call rate {int(fail_call.sum())} fail, MAF {int(fail_maf.sum())}, HWE {int(fail_hwe.sum())}); "
f"{int(s_pass.sum())} of {n} people pass (call rate {int(s_fail_call.sum())} fail, |F| {int(s_fail_f.sum())}). Overall call rate {call_rate:.3f}.")
apa = f"Quality control: {int(np.sum(~fail_any))} of {m} markers and {int(s_pass.sum())} of {n} people passed"
marker_rows = [{"marker": v, "counted": counted[j], "call_rate": float(q["call_rate"][j]), "maf": float(q["maf"][j]), "het_obs": float(q["het_obs"][j]),
"het_exp": float(q["het_exp"][j]), "hwe_p": float(q["hwe_p"][j]),
"flags": ", ".join(f for f, on in (("call rate", fail_call[j]), ("MAF", fail_maf[j]), ("HWE", fail_hwe[j])) if on)} for j, v in enumerate(variants)]
person_rows = [{"row": i + 1, "call_rate": float(q["sample_call_rate"][i]), "het": float(q["sample_het"][i]), "f": float(q["sample_f"][i]),
"flags": ", ".join(f for f, on in (("call rate", s_fail_call[i]), ("|F|", s_fail_f[i])) if on)} for i in range(n) if not s_pass[i]]
notes = [research_note,
f"Thresholds: marker call rate ≥ {min_call_v:g}, MAF ≥ {min_maf:g}, HWE p ≥ {hwe_thr:g}; person call rate ≥ {min_call_s:g}, |F| ≤ {max_f:g}.",
"F = (observed − expected homozygous markers) / (called markers − expected), over polymorphic markers (PLINK --het); checked from 100 markers.",
"Nothing is removed: filter the failing markers and people in Prepare or in the Genetics studio."]
values = {
"n_samples": n, "n_variants": m, "n_monomorphic": int(np.sum(q["monomorphic"])), "n_fail_call": int(fail_call.sum()),
"n_fail_maf": int(fail_maf.sum()), "n_fail_hwe": int(fail_hwe.sum()), "n_fail_any": int(fail_any.sum()), "n_pass": int(np.sum(~fail_any)),
"n_samples_fail_call": int(s_fail_call.sum()), "n_samples_fail_f": int(s_fail_f.sum()), "n_samples_pass": int(s_pass.sum()),
"call_rate": call_rate, "variant_call_rate": q["call_rate"].tolist(), "variant_maf": q["maf"].tolist(), "variant_hwe_p": q["hwe_p"].tolist(),
"variant_het_obs": q["het_obs"].tolist(), "variant_het_exp": q["het_exp"].tolist(), "variant_pass": (~fail_any).tolist(),
"sample_call_rate": q["sample_call_rate"].tolist(), "sample_f": q["sample_f"].tolist(), "sample_pass": s_pass.tolist(),
}
cs.publish({
"method": "genetics.qc",
"methodVersion": "1.0.1",
"title": "Genotype quality control",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": n,
"summary": summary,
"apa": apa,
"statistics": [
{"key": "n_pass", "label": "Markers passing", "value": int(np.sum(~fail_any))},
{"key": "n_samples_pass", "label": "People passing", "value": int(s_pass.sum())},
{"key": "call_rate", "label": "Overall call rate", "value": call_rate},
],
"tables": [
{"key": "markers", "title": "Markers",
"columns": [{"key": "marker", "label": "Marker", "type": "string"}, {"key": "counted", "label": "Counted allele", "type": "string"},
{"key": "call_rate", "label": "Call rate", "type": "number"}, {"key": "maf", "label": "MAF", "type": "number"},
{"key": "het_obs", "label": "Observed het.", "type": "number"}, {"key": "het_exp", "label": "Expected het.", "type": "number"},
{"key": "hwe_p", "label": "HWE exact p", "type": "p"}, {"key": "flags", "label": "Fails", "type": "string"}],
"rows": marker_rows},
{"key": "people", "title": "People who fail",
"columns": [{"key": "row", "label": "Row", "type": "integer"}, {"key": "call_rate", "label": "Call rate", "type": "number"},
{"key": "het", "label": "Heterozygosity", "type": "number"}, {"key": "f", "label": "F", "type": "number"},
{"key": "flags", "label": "Fails", "type": "string"}],
"rows": person_rows},
],
"assumptions": assumptions,
"warnings": warnings,
"notes": notes,
"charts": [
cs.chart("maf", "histogram", "Minor-allele frequencies", {"x": cs.col("MAF", q["maf"].tolist())}),
cs.chart("definetti", "definetti", "Genotype shares and Hardy–Weinberg proportions", {
"aa": cs.col("Homozygous (other)", np.sum(g == 0, axis=0).astype(int).tolist(), "numeric"),
"ab": cs.col("Heterozygous", np.sum(g == 1, axis=0).astype(int).tolist(), "numeric"),
"bb": cs.col("Homozygous (counted)", np.sum(g == 2, axis=0).astype(int).tolist(), "numeric"),
"label": cs.col("Marker", variants, "categorical"),
"group": cs.col("HWE", ["Fails HWE" if f else "Passes HWE" for f in fail_hwe], "categorical")}),
],
"values": values,
})
The exact script CodeSplash ran for example “People common” · R version 4.5.1 (2025-06-13)
# Genotype quality control
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.qc 1.0.1 · spec 3cb6a5d0c445a953
# Dataset: ge_people (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr) # cs_gen_qc (per-marker and per-person QC, HWE exact; twin of codesplash.stats.genetics)
# %% Data (no rows dropped here: genotype no-calls and missing values are handled by the analysis)
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ge_people.parquet", col_select = c("v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24")))
n_input <- nrow(df)
warnings <- list()
research_note <- "Research use only: not for clinical or diagnostic decisions. Genotypes are personal data."
# %% Genotypes
variants <- c("v01", "v02", "v03", "v04", "v05", "v06", "v07", "v08", "v09", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24")
dm <- cs_gen_dose_matrix(df[variants])
g <- dm$g
min_call_v <- 0.95
min_maf <- 0.01
hwe_thr <- 1e-6
min_call_s <- 0.95
max_f <- 0.2
# %% Checks
q <- cs_gen_qc(g)
n <- nrow(g)
m <- ncol(g)
nz <- function(x, v) ifelse(is.na(x), v, x)
fail_call <- q$call_rate < min_call_v
fail_maf <- nz(q$maf, 0) < min_maf
fail_hwe <- nz(q$hwe_p, 1) < hwe_thr
fail_any <- fail_call | fail_maf | fail_hwe
s_fail_call <- q$sample_call_rate < min_call_s
# F from a few markers is mostly noise, so the |F| check needs 100 polymorphic markers called per person.
f_ok <- q$sample_n_poly >= 100
s_fail_f <- (abs(nz(q$sample_f, 0)) > max_f) & f_ok
if (!all(f_ok)) {
warnings <- c(warnings, sprintf("%d people have fewer than 100 polymorphic markers called, too few for a stable F; the |F| check skips them.", sum(!f_ok)))
}
s_pass <- !(s_fail_call | s_fail_f)
call_rate <- sum(!is.na(g)) / (n * m)
if (sum(q$monomorphic) > 0) {
warnings <- c(warnings, sprintf("%d markers are monomorphic here: they carry no information and are left out of each person's F.", sum(q$monomorphic)))
}
# %% Assumptions
n_high_f <- sum((nz(q$sample_f, 0) > max_f) & f_ok)
assumptions <- list(
list(key = "one_population", label = "One population", status = "info", detail = "If people come from several populations, run QC within each: mixing them fails HWE and lowers heterozygosity."),
list(key = "unrelated", label = "Unrelated people", status = if (n_high_f > 0) "warn" else "info",
detail = sprintf("%d people have F above %s, as relatives or inbreeding produce.", n_high_f, format(max_f))),
list(key = "biallelic", label = "Biallelic markers", status = "pass", detail = sprintf("All %d markers show at most two alleles.", m))
)
# %% Result
summary <- sprintf("%d of %d markers pass (call rate %d fail, MAF %d, HWE %d); %d of %d people pass (call rate %d fail, |F| %d). Overall call rate %.3f.",
sum(!fail_any), m, sum(fail_call), sum(fail_maf), sum(fail_hwe), sum(s_pass), n, sum(s_fail_call), sum(s_fail_f), call_rate)
apa <- sprintf("Quality control: %d of %d markers and %d of %d people passed", sum(!fail_any), m, sum(s_pass), n)
flags <- function(...) {
x <- c(...)
paste(names(x)[x], collapse = ", ")
}
marker_rows <- lapply(seq_len(m), function(j) list(marker = variants[j], counted = dm$counted[j], call_rate = q$call_rate[j], maf = q$maf[j],
het_obs = q$het_obs[j], het_exp = q$het_exp[j], hwe_p = q$hwe_p[j],
flags = flags(`call rate` = fail_call[j], MAF = fail_maf[j], HWE = fail_hwe[j])))
person_rows <- lapply(which(!s_pass), function(i) list(row = i, call_rate = q$sample_call_rate[i], het = q$sample_het[i], f = q$sample_f[i],
flags = flags(`call rate` = s_fail_call[i], `|F|` = s_fail_f[i])))
notes <- list(research_note,
sprintf("Thresholds: marker call rate ≥ %s, MAF ≥ %s, HWE p ≥ %s; person call rate ≥ %s, |F| ≤ %s.",
format(min_call_v), format(min_maf), format(hwe_thr), format(min_call_s), format(max_f)),
"F = (observed − expected homozygous markers) / (called markers − expected), over polymorphic markers (PLINK --het); checked from 100 markers.",
"Nothing is removed: filter the failing markers and people in Prepare or in the Genetics studio.")
result_values <- list(
n_samples = n, n_variants = m, n_monomorphic = sum(q$monomorphic), n_fail_call = sum(fail_call), n_fail_maf = sum(fail_maf),
n_fail_hwe = sum(fail_hwe), n_fail_any = sum(fail_any), n_pass = sum(!fail_any), n_samples_fail_call = sum(s_fail_call),
n_samples_fail_f = sum(s_fail_f), n_samples_pass = sum(s_pass), call_rate = call_rate,
variant_call_rate = I(q$call_rate), variant_maf = I(q$maf), variant_hwe_p = I(q$hwe_p), variant_het_obs = I(q$het_obs),
variant_het_exp = I(q$het_exp), variant_pass = I(!fail_any), sample_call_rate = I(q$sample_call_rate), sample_f = I(q$sample_f),
sample_pass = I(s_pass)
)
cs_publish(list(
method = "genetics.qc",
methodVersion = "1.0.1",
title = "Genotype quality control",
engine = cs_engine_info("stats", "nanoparquet"),
n = n,
summary = summary,
apa = apa,
statistics = list(
list(key = "n_pass", label = "Markers passing", value = sum(!fail_any)),
list(key = "n_samples_pass", label = "People passing", value = sum(s_pass)),
list(key = "call_rate", label = "Overall call rate", value = call_rate)
),
tables = list(
list(key = "markers", title = "Markers",
columns = list(list(key = "marker", label = "Marker", type = "string"), list(key = "counted", label = "Counted allele", type = "string"),
list(key = "call_rate", label = "Call rate", type = "number"), list(key = "maf", label = "MAF", type = "number"),
list(key = "het_obs", label = "Observed het.", type = "number"), list(key = "het_exp", label = "Expected het.", type = "number"),
list(key = "hwe_p", label = "HWE exact p", type = "p"), list(key = "flags", label = "Fails", type = "string")),
rows = marker_rows),
list(key = "people", title = "People who fail",
columns = list(list(key = "row", label = "Row", type = "integer"), list(key = "call_rate", label = "Call rate", type = "number"),
list(key = "het", label = "Heterozygosity", type = "number"), list(key = "f", label = "F", type = "number"),
list(key = "flags", label = "Fails", type = "string")),
rows = person_rows)
),
assumptions = assumptions,
warnings = warnings,
notes = notes,
charts = list(
cs_chart("maf", "histogram", "Minor-allele frequencies", list(x = cs_col("MAF", q$maf))),
cs_chart("definetti", "definetti", "Genotype shares and Hardy–Weinberg proportions",
list(aa = cs_col("Homozygous (other)", unname(colSums(g == 0, na.rm = TRUE)), "numeric"),
ab = cs_col("Heterozygous", unname(colSums(g == 1, na.rm = TRUE)), "numeric"),
bb = cs_col("Homozygous (counted)", unname(colSums(g == 2, na.rm = TRUE)), "numeric"),
label = cs_col("Marker", variants, "categorical"),
group = cs_col("HWE", ifelse(fail_hwe, "Fails HWE", "Passes HWE"), "categorical")))
),
values = result_values
))
Sources
- Purcell, S., Neale, B., Todd-Brown, K., et al. (2007). PLINK: a tool set for whole-genome association and population-based linkage analyses. American Journal of Human Genetics, 81, 559–575.
- Anderson, C. A., Pettersson, F. H., Clarke, G. M., Cardon, L. R., Morris, A. P., & Zondervan, K. T. (2010). Data quality control in genetic case-control association studies. Nature Protocols, 5, 1564–1573.
- Wigginton, J. E., Cutler, D. J., & Abecasis, G. R. (2005). A note on exact tests of Hardy–Weinberg equilibrium. American Journal of Human Genetics, 76, 887–893.
From the CodeSplash method registry · genetics.qc v1.0.1.