From genotypes to findings: QC, structure and scans
The order a genotype analysis runs in. Clean the markers and people first, look for structure, then scan, and read every result as research evidence, not a diagnosis.
What runs in CodeSplash
- STAT298Tajima D neutrality test Runs in CodeSplash (Experimental)
- STAT299Sequence kernel association test or SKAT Runs in CodeSplash (Experimental)
- STAT300SKAT O Runs in CodeSplash (Experimental)
- STAT301Weighted genetic burden test Runs in CodeSplash (Experimental)
- STAT302Transmission disequilibrium test Runs in CodeSplash (Experimental)
- STAT303McDonald–Kreitman test Runs in CodeSplash (Experimental)
- Genotype quality control Experimental
- Linkage disequilibrium (D′, r²) Experimental
- Population differentiation (F_ST) Experimental
- Genome-wide association scan (single markers, λ_GC) Experimental
- Neutrality test (Tajima's D) Experimental
- Rare-variant set tests (SKAT, SKAT-O, burden) Experimental
- Transmission disequilibrium test (TDT) Experimental
- McDonald–Kreitman test Experimental
You will be able to
- Say which quality checks come before any association test, and why
- Read linkage disequilibrium and F_ST as descriptions of structure
- Interpret λ_GC and a genome-wide threshold in a marker scan
Read first
Genotypes come in messy
ReadA genotype table has one row per person and one column per marker. Each cell is a dose (0, 1 or 2 copies of an allele), a VCF call such as 0/1, or a pair of letters. Some cells are no-calls.
Every later step trusts these calls. A marker that fails mostly in heterozygotes looks like a Hardy–Weinberg departure, and a contaminated sample looks like a person with too many heterozygotes. So quality control comes first, and it decides what the scan can see.
These methods are for research. Genotypes are personal data, and nothing here is a clinical result.
Quality control first
PredictPredict first
You have 24 markers on 300 simulated people. When should markers with low call rates or strong Hardy–Weinberg departures be removed?
Reveal
Before any test. In this sample the failure counts are 1 for call rate, 1 for minor-allele frequency and 1 for the HWE exact test. Removing markers after seeing the scan lets the results choose the data.
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.
The exact R script · R 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
))
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.
The exact Python script · Python 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 card also gives each person's call rate and , an inbreeding coefficient from homozygosity. well below 0 suggests a contaminated sample.
Markers travel together
PredictPredict first
Markers v01 to v08 were simulated from four founder haplotypes. What do you expect for the average linkage disequilibriumLinkage disequilibriumAlleles at two markers inherited together more often than chance. D′ scales D by its largest possible value; r² is the squared correlation. between them?
Reveal
Well above 0. The mean is 0.31 and the largest 0.80. Markers in LD carry the same signal, so a scan finds a region, not one causal site.
Populations differ
ExploreRun the F_ST card on the three simulated populations. Weir and Cockerham's θ corrects for sample size and combines markers as a ratio of sums.
F_ST (Weir & Cockerham) = 0.039, 3 populations, 16 markers, p = .005
- F_ST (Weir & Cockerham)
- 0.0385
- Informative markers
- 16
- p (permutation)
- .005
Assumptions
- Random mating within populations — Not checkable here: check Hardy–Weinberg proportions within each population.
- Markers not chosen for differences — 16 informative markers; markers chosen because they differ overstate F_ST.
- Enough people per population — Smallest population: 100 people.
Populations
| Population | People | Mean counted-allele frequency |
|---|---|---|
| east | 100 | 0.2770 |
| north | 100 | 0.2597 |
| south | 100 | 0.2193 |
F_ST per marker
| Marker | Counted allele | F_ST |
|---|---|---|
| v09 | B | 0.0189 |
| v10 | B | 0.0730 |
| v11 | B | 2.612e-5 |
| v12 | B | 0.0441 |
| v13 | B | 0.1059 |
| v14 | B | 0.0597 |
| v15 | B | −0.0038 |
| v16 | B | 0.0022 |
| v17 | B | 0.1547 |
| v18 | B | 0.0339 |
| v19 | B | 0.0024 |
| v20 | B | 0.0246 |
| v21 | B | 0.0172 |
| v22 | B | 0.0218 |
| v23 | B | 0.0157 |
| v24 | B | 0.0151 |
Pairwise F_ST (Weir & Cockerham)
| Population A | Population B | F_ST |
|---|---|---|
| east | north | 0.0424 |
| east | south | 0.0331 |
| north | south | 0.0397 |
- Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
- Markers are combined as a ratio of summed variance components, which weights informative markers more than an average of per-marker F_ST would.
- Wright's rough guide: below 0.05 little differentiation, 0.05–0.15 moderate, 0.15–0.25 great, above 0.25 very great.
The exact R script · R R version 4.5.1 (2025-06-13)
# Population differentiation (F_ST)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.fst 1.0.1 · spec 31353921bc7ab1dd
# 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_wc_fst, cs_gen_hudson_fst, cs_gen_fst_permutation (twins 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("population", "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."
# %% People and markers
pop_col <- "population"
variants <- c("v09", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24")
keep <- !is.na(df[[pop_col]])
if (sum(!keep) > 0) warnings <- c(warnings, sprintf("%d people without a population were left out.", sum(!keep)))
df <- df[keep, , drop = FALSE]
if (nrow(df) == 0) cs_error("CS_E_NO_ROWS")
pops <- as.character(df[[pop_col]])
levels <- sort(unique(pops), method = "radix")
if (length(levels) < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = pop_col, min = 2, k = length(levels)) # F_ST compares populations
dm <- cs_gen_dose_matrix(df[variants])
g <- dm$g
# Populations with at least one genotype call: F_ST needs two of them.
k_called <- sum(vapply(levels, function(lev) any(!is.na(g[pops == lev, , drop = FALSE])), logical(1)))
if (k_called < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = pop_col, min = 2, k = k_called)
estimator <- "weir_cockerham"
if (estimator == "hudson" && length(levels) != 2) {
cs_error("CS_E_GROUP_COUNT", column = pop_col, expected = 2, k = length(levels)) # Hudson's estimator compares two populations
}
pairwise <- TRUE
test <- "permutation"
n_perm <- as.integer(199)
seed <- 42 # shared Wichmann-Hill stream: the same shuffles in Python and R
sizes <- vapply(levels, function(lev) sum(pops == lev), numeric(1))
# %% F_ST
if (estimator == "weir_cockerham") {
w <- cs_gen_wc_fst(g, pops, levels)
label <- "Weir & Cockerham"
} else {
w <- cs_gen_hudson_fst(g, pops, levels)
label <- "Hudson"
}
fst <- w$fst
per <- w$per
n_used <- sum(!is.na(per))
if (n_used == 0) cs_error("CS_E_UNDEFINED", what = "F_ST", reason = "every marker is monomorphic here or lacks calls in a population")
p <- if (test == "permutation") cs_gen_fst_permutation(g, pops, levels, fst, estimator, n_perm, seed) else NA
pair_rows <- list()
if (pairwise && length(levels) > 2) {
for (i in seq_len(length(levels) - 1)) {
for (j in (i + 1):length(levels)) {
sub <- pops == levels[i] | pops == levels[j]
f <- cs_gen_wc_fst(g[sub, , drop = FALSE], pops[sub], c(levels[i], levels[j]))$fst
pair_rows[[length(pair_rows) + 1]] <- list(a = levels[i], b = levels[j], fst = f)
}
}
}
if (n_used < length(variants)) {
warnings <- c(warnings, sprintf("%d markers are monomorphic here or lack calls in a population, so they add nothing.", length(variants) - n_used))
}
# %% Assumptions
small <- min(sizes) < 20
assumptions <- list(
list(key = "hwe_within", label = "Random mating within populations", status = "info", detail = "Not checkable here: check Hardy–Weinberg proportions within each population."),
list(key = "neutral_markers", label = "Markers not chosen for differences", status = "info", detail = sprintf("%d informative markers; markers chosen because they differ overstate F_ST.", n_used)),
list(key = "sample_size", label = "Enough people per population", status = if (small) "warn" else "pass",
detail = paste0(sprintf("Smallest population: %d people", as.integer(min(sizes))), if (small) " (per-marker F_ST will be noisy)." else "."))
)
# %% Result
has_p <- test == "permutation"
summary <- paste0(sprintf("%s F_ST = %.4f across %d markers and %d populations (%d people)", label, fst, n_used, length(levels), length(pops)),
if (has_p) sprintf("; permutation test, %s (%d shuffles, seed %d).", cs_fmt_p(p), n_perm, as.integer(seed)) else ".")
apa <- paste0(sprintf("F_ST (%s) = %s, %d populations, %d markers", label, cs_fmt_num(fst, 3), length(levels), n_used), if (has_p) sprintf(", %s", cs_fmt_p(p)) else "")
marker_rows <- lapply(seq_along(variants), function(i) list(marker = variants[i], counted = dm$counted[i], fst = per[i]))
pop_rows <- lapply(seq_along(levels), function(i) {
sub <- g[pops == levels[i], , drop = FALSE]
list(population = levels[i], n = sizes[[i]], freq = if (any(!is.na(sub))) mean(colMeans(sub, na.rm = TRUE)) / 2 else NaN)
})
notes <- list(research_note,
"Markers are combined as a ratio of summed variance components, which weights informative markers more than an average of per-marker F_ST would.",
"Wright's rough guide: below 0.05 little differentiation, 0.05–0.15 moderate, 0.15–0.25 great, above 0.25 very great.")
result_values <- list(
n = length(pops), n_pops = length(levels), n_variants = length(variants), n_used = n_used, fst = fst, p = p,
n_perm = if (has_p) n_perm else NA, test = test, estimator = estimator, estimator_label = label, pop_sizes = I(unname(sizes)),
fst_marker = I(unname(per)), pair_fst = I(vapply(pair_rows, function(x) x$fst, numeric(1))),
pair_labels = I(vapply(pair_rows, function(x) paste0(x$a, "|", x$b), character(1)))
)
tables <- list(
list(key = "populations", title = "Populations",
columns = list(list(key = "population", label = "Population", type = "string"), list(key = "n", label = "People", type = "integer"),
list(key = "freq", label = "Mean counted-allele frequency", type = "number")),
rows = pop_rows),
list(key = "markers", title = "F_ST per marker",
columns = list(list(key = "marker", label = "Marker", type = "string"), list(key = "counted", label = "Counted allele", type = "string"),
list(key = "fst", label = "F_ST", type = "number")),
rows = marker_rows)
)
if (length(pair_rows)) {
tables[[3]] <- list(key = "pairs", title = "Pairwise F_ST (Weir & Cockerham)",
columns = list(list(key = "a", label = "Population A", type = "string"), list(key = "b", label = "Population B", type = "string"),
list(key = "fst", label = "F_ST", type = "number")),
rows = pair_rows)
}
stats_rows <- list(list(key = "fst", label = sprintf("F_ST (%s)", label), value = fst), list(key = "n_used", label = "Informative markers", value = n_used))
if (has_p) stats_rows[[3]] <- list(key = "p", label = "p (permutation)", value = p, format = "p")
cs_publish(list(
method = "genetics.fst",
methodVersion = "1.0.1",
title = "Population differentiation (F_ST)",
engine = cs_engine_info("stats", "nanoparquet"),
n = length(pops),
summary = summary,
apa = apa,
statistics = stats_rows,
tables = tables,
assumptions = assumptions,
warnings = warnings,
notes = notes,
charts = list(),
values = result_values
))
F_ST (Weir & Cockerham) = 0.039, 3 populations, 16 markers, p = .005
- F_ST (Weir & Cockerham)
- 0.0385
- Informative markers
- 16
- p (permutation)
- .005
Assumptions
- Random mating within populations — Not checkable here: check Hardy–Weinberg proportions within each population.
- Markers not chosen for differences — 16 informative markers; markers chosen because they differ overstate F_ST.
- Enough people per population — Smallest population: 100 people.
Populations
| Population | People | Mean counted-allele frequency |
|---|---|---|
| east | 100 | 0.2770 |
| north | 100 | 0.2597 |
| south | 100 | 0.2193 |
F_ST per marker
| Marker | Counted allele | F_ST |
|---|---|---|
| v09 | B | 0.0189 |
| v10 | B | 0.0730 |
| v11 | B | 2.612e-5 |
| v12 | B | 0.0441 |
| v13 | B | 0.1059 |
| v14 | B | 0.0597 |
| v15 | B | −0.0038 |
| v16 | B | 0.0022 |
| v17 | B | 0.1547 |
| v18 | B | 0.0339 |
| v19 | B | 0.0024 |
| v20 | B | 0.0246 |
| v21 | B | 0.0172 |
| v22 | B | 0.0218 |
| v23 | B | 0.0157 |
| v24 | B | 0.0151 |
Pairwise F_ST (Weir & Cockerham)
| Population A | Population B | F_ST |
|---|---|---|
| east | north | 0.0424 |
| east | south | 0.0331 |
| north | south | 0.0397 |
- Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
- Markers are combined as a ratio of summed variance components, which weights informative markers more than an average of per-marker F_ST would.
- Wright's rough guide: below 0.05 little differentiation, 0.05–0.15 moderate, 0.15–0.25 great, above 0.25 very great.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Population differentiation (F_ST)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.fst 1.0.1 · spec 31353921bc7ab1dd
# 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 # Weir & Cockerham θ, Hudson F_ST, permutations (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=["population", "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."
# %% People and markers
pop_col = "population"
variants = ["v09", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24"]
keep = df[pop_col].notna().to_numpy()
if (~keep).sum():
warnings.append(f"{int((~keep).sum())} people without a population were left out.")
df = df[keep].reset_index(drop=True)
if not len(df):
cs.cs_error("CS_E_NO_ROWS")
pops = np.array([str(v) for v in df[pop_col]], dtype=object)
levels = sorted(set(pops))
if len(levels) < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=pop_col, min=2, k=len(levels)) # F_ST compares populations
g, counted, other = gen.dose_matrix({v: df[v].to_numpy() for v in variants})
# Populations with at least one genotype call: F_ST needs two of them.
k_called = sum(1 for lev in levels if np.any(~np.isnan(g[pops == lev])))
if k_called < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=pop_col, min=2, k=k_called)
estimator = "weir_cockerham"
if estimator == "hudson" and len(levels) != 2:
cs.cs_error("CS_E_GROUP_COUNT", column=pop_col, expected=2, k=len(levels)) # Hudson's estimator compares two populations
pairwise = True
test = "permutation"
n_perm = int(199)
seed = 42 # shared Wichmann–Hill stream: the same shuffles in Python and R
sizes = [int(np.sum(pops == lev)) for lev in levels]
# %% F_ST
if estimator == "weir_cockerham":
fst, per, a, b, c = gen.wc_fst(g, pops, levels)
label = "Weir & Cockerham"
else:
fst, per, num_, den_ = gen.hudson_fst(g, pops, levels)
label = "Hudson"
n_used = int(np.sum(~np.isnan(per)))
if n_used == 0:
cs.cs_error("CS_E_UNDEFINED", what="F_ST", reason="every marker is monomorphic here or lacks calls in a population")
p = gen.fst_permutation(g, pops, levels, fst, estimator, n_perm, seed) if test == "permutation" else None
pair_rows = []
if pairwise and len(levels) > 2:
for i in range(len(levels)):
for j in range(i + 1, len(levels)):
sub = (pops == levels[i]) | (pops == levels[j])
f = gen.wc_fst(g[sub], pops[sub], [levels[i], levels[j]])[0]
pair_rows.append({"a": levels[i], "b": levels[j], "fst": f})
if n_used < len(variants):
warnings.append(f"{len(variants) - n_used} markers are monomorphic here or lack calls in a population, so they add nothing.")
# %% Assumptions
small = min(sizes) < 20
assumptions = [
{"key": "hwe_within", "label": "Random mating within populations", "status": "info", "detail": "Not checkable here: check Hardy–Weinberg proportions within each population."},
{"key": "neutral_markers", "label": "Markers not chosen for differences", "status": "info", "detail": f"{n_used} informative markers; markers chosen because they differ overstate F_ST."},
{"key": "sample_size", "label": "Enough people per population", "status": "warn" if small else "pass",
"detail": f"Smallest population: {min(sizes)} people" + (" (per-marker F_ST will be noisy)." if small else ".")},
]
# %% Result
summary = (f"{label} F_ST = {fst:.4f} across {n_used} markers and {len(levels)} populations ({len(pops)} people)"
+ (f"; permutation test, {cs.fmt_p(p)} ({n_perm} shuffles, seed {seed})." if p is not None else "."))
apa = f"F_ST ({label}) = {cs.fmt_num(fst, 3)}, {len(levels)} populations, {n_used} markers" + (f", {cs.fmt_p(p)}" if p is not None else "")
marker_rows = [{"marker": v, "counted": counted[i], "fst": float(per[i])} for i, v in enumerate(variants)]
pop_rows = [{"population": lev, "n": sizes[i], "freq": float(np.nanmean(g[pops == lev], axis=0).mean() / 2) if np.any(~np.isnan(g[pops == lev])) else math.nan}
for i, lev in enumerate(levels)]
notes = [research_note,
"Markers are combined as a ratio of summed variance components, which weights informative markers more than an average of per-marker F_ST would.",
"Wright's rough guide: below 0.05 little differentiation, 0.05–0.15 moderate, 0.15–0.25 great, above 0.25 very great."]
values = {
"n": len(pops), "n_pops": len(levels), "n_variants": len(variants), "n_used": n_used, "fst": fst, "p": p,
"n_perm": n_perm if p is not None else None, "test": test, "estimator": estimator, "estimator_label": label, "pop_sizes": sizes,
"fst_marker": per.tolist(), "pair_fst": [x["fst"] for x in pair_rows], "pair_labels": [f"{x['a']}|{x['b']}" for x in pair_rows],
}
cs.publish({
"method": "genetics.fst",
"methodVersion": "1.0.1",
"title": "Population differentiation (F_ST)",
"engine": cs.engine_info("pandas", "numpy"),
"n": len(pops),
"summary": summary,
"apa": apa,
"statistics": [
{"key": "fst", "label": f"F_ST ({label})", "value": fst},
{"key": "n_used", "label": "Informative markers", "value": n_used},
] + ([{"key": "p", "label": "p (permutation)", "value": p, "format": "p"}] if p is not None else []),
"tables": [
{"key": "populations", "title": "Populations",
"columns": [{"key": "population", "label": "Population", "type": "string"}, {"key": "n", "label": "People", "type": "integer"},
{"key": "freq", "label": "Mean counted-allele frequency", "type": "number"}],
"rows": pop_rows},
{"key": "markers", "title": "F_ST per marker",
"columns": [{"key": "marker", "label": "Marker", "type": "string"}, {"key": "counted", "label": "Counted allele", "type": "string"},
{"key": "fst", "label": "F_ST", "type": "number"}],
"rows": marker_rows},
] + ([{"key": "pairs", "title": "Pairwise F_ST (Weir & Cockerham)",
"columns": [{"key": "a", "label": "Population A", "type": "string"}, {"key": "b", "label": "Population B", "type": "string"},
{"key": "fst", "label": "F_ST", "type": "number"}],
"rows": pair_rows}] if pair_rows else []),
"assumptions": assumptions,
"warnings": warnings,
"notes": notes,
"charts": [],
"values": values,
})
Here F_STF_STThe share of genetic variance that lies between populations; 0 means identical allele frequencies. = 0.039, with permutation p = .005. That is small by Wright's guide, but large enough to matter: if cases came mostly from one population, any marker that differs between populations would look associated.
Scan, then check the scan
PredictPredict first
The scan tests each marker against BMI, adjusting for age and sex. Most markers have no effect. What should λ_GCGenomic controlλ = median χ² / 0.455. Near 1 means the scan's test statistics look like chance; above 1 suggests inflation from structure or relatedness., the median χ² divided by its median under chance, be?
Reveal
Close to 1 if chance alone drives most markers. Here λ_GC = 2.01, but with only 24 markers, eight of them in one LD block around an associated marker, the median isn't a null median. λ_GC means little until hundreds of mostly null markers are tested. The strongest marker is v03 at p < .001. The number below is 0.
The named tests have methods too
ReflectThe tests from the earlier lessons now run as methods. Tajima's D on the guide's 8 sites is 0.392, with p = .639 from neutral simulations. SKAT-O on the guide's 12 variants gives p = .554. Its smallest grid p was p = .366, so the search costs something.
Which of these results would change if the people came from two populations? Think about which tests compare people and which compare transmissions within families.
exact TDT, b = 30, c = 18, p = .111, OR = 1.67
- Transmissions of tested (b)
- 30
- Transmissions of other (c)
- 18
- b
- 30
- p (exact TDT)
- .111
Effect size
- Transmission odds ratio b/c 1.667 95% CI [0.9291, 2.990]
- Share of transmissions that carry tested 0.6250 95% CI [0.4735, 0.7605]
Assumptions
- Mendelian transmission — Counts were given directly, so this isn't checkable.
- Enough informative parents — b + c = 48 informative transmissions.
- Independent transmissions — Use one affected child per family; extra siblings' transmissions aren't independent.
- Reliable genotype calls — Calling errors create false transmissions; check Mendelian errors and call rates first.
Transmissions from heterozygous parents
| Allele | Transmitted | Not transmitted |
|---|---|---|
| tested | 30 | 18 |
| other | 18 | 30 |
All the tests of these counts
| Test | Statistic | p |
|---|---|---|
| McNemar χ² | 3 | 0.0833 |
| McNemar χ², continuity-corrected | 2.521 | 0.1124 |
| Exact binomial, two-sided | — | 0.1114 |
| Exact binomial, mid-p | — | 0.0854 |
| Exact, tested over-transmitted | — | 0.0557 |
| Exact, tested under-transmitted | — | 0.9703 |
- Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
- Only heterozygous parents are informative: homozygous parents transmit the same allele whichever copy they pass on.
- Within-family comparison protects against population stratification, but not against genotyping error or biased ascertainment.
The exact R script · R R version 4.5.1 (2025-06-13)
# Transmission disequilibrium test (TDT)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.tdt 1.0.1 · spec 0543d53845218ec8
# Dataset: ge_tdt_counts (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_tdt_trios, cs_gen_tdt_counts (Spielman et al. 1993; twins 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_tdt_counts.parquet", col_select = c("transmitted", "untransmitted")))
n_input <- nrow(df)
warnings <- list()
research_note <- "Research use only: not for clinical or diagnostic decisions. Genotypes are personal data."
# %% Transmissions
trio_roles <- c(NULL, NULL, NULL)
count_roles <- c("transmitted", "untransmitted")
test <- "exact"
continuity <- FALSE
alternative <- "two_sided"
conf <- 0.95
if (length(trio_roles) == 3) {
input_kind <- "trios"
t <- cs_gen_tdt_trios(df[[trio_roles[1]]], df[[trio_roles[2]]], df[[trio_roles[3]]])
b <- t$b
c <- t$c
allele_a <- t$allele_a
allele_b <- t$allele_b
if (t$n_missing > 0) warnings <- c(warnings, sprintf("%d trios had a no-call and were left out.", as.integer(t$n_missing)))
if (t$n_mendel > 0) warnings <- c(warnings, sprintf("%d trios break Mendelian inheritance (a calling or pedigree error) and were left out.", as.integer(t$n_mendel)))
} else if (length(count_roles) == 2 && length(trio_roles) == 0) {
input_kind <- "counts"
tb <- as.numeric(df[[count_roles[1]]])
tc <- as.numeric(df[[count_roles[2]]])
ok <- !(is.na(tb) | is.na(tc))
if (sum(!ok) > 0) warnings <- c(warnings, sprintf("%d rows had a missing count and were left out.", sum(!ok)))
if (!any(ok)) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df[ok, , drop = FALSE], count_roles) # infinite values stop the run (registry/errors.yaml)
b <- sum(tb[ok])
c <- sum(tc[ok])
if (b != floor(b) || c != floor(c) || b < 0 || c < 0) stop("Transmission counts must be whole numbers of at least 0.", call. = FALSE)
t <- list(n_trios = NA, n_used = NA, n_missing = NA, n_mendel = NA, n_uninformative = NA, n_het_parents = NA)
allele_a <- "other"
allele_b <- "tested"
} else {
stop("Bind the child, father and mother genotypes (one row per trio), or the transmitted and not-transmitted counts.", call. = FALSE)
}
# %% Tests
r <- cs_gen_tdt_counts(b, c, conf)
m <- r$n_informative
if (test == "chisq") {
stat <- if (continuity) r$tdt_cc else r$tdt
p <- if (continuity) r$p_chisq_cc else r$p_chisq
label <- paste0("TDT (McNemar χ²", if (continuity) ", continuity-corrected)" else ")")
} else {
stat <- b
p <- switch(alternative, two_sided = r$p_exact, greater = r$p_exact_greater, less = r$p_exact_less)
label <- paste0("exact TDT", if (alternative == "two_sided") "" else ", one-sided")
}
# %% Assumptions
small <- m < 10
mendel_status <- if (input_kind == "trios") (if (t$n_mendel > 0) "warn" else "pass") else "info"
mendel_detail <- if (input_kind == "trios") {
if (t$n_mendel > 0) sprintf("%d of %d trios break Mendelian inheritance and were left out.", as.integer(t$n_mendel), as.integer(t$n_trios)) else
"Every complete trio is consistent with Mendelian inheritance."
} else "Counts were given directly, so this isn't checkable."
assumptions <- list(
list(key = "mendelian", label = "Mendelian transmission", status = mendel_status, detail = mendel_detail),
list(key = "informative", label = "Enough informative parents", status = if (small) (if (test == "exact") "info" else "warn") else "pass",
detail = paste0(sprintf("b + c = %d informative transmissions", as.integer(m)),
if (small && test == "exact") "; the exact test doesn't need many." else if (small) "; use the exact test." else ".")),
list(key = "independence", label = "Independent transmissions", status = "info", detail = "Use one affected child per family; extra siblings' transmissions aren't independent."),
list(key = "genotype_quality", label = "Reliable genotype calls", status = "info", detail = "Calling errors create false transmissions; check Mendelian errors and call rates first.")
)
# %% Result
summary <- sprintf("Heterozygous parents transmitted %s %s times and %s %s times (proportion %.3f, %.0f%% CI %.3f to %.3f): %s, %s.",
allele_b, format(b), allele_a, format(c), r$transmission, 100 * conf, r$transmission_low, r$transmission_high, label, cs_fmt_p(p))
apa <- paste0(if (test == "chisq") sprintf("TDT χ²(1, N = %d) = %s, %s", as.integer(m), cs_fmt_num(stat), cs_fmt_p(p)) else
sprintf("exact TDT, b = %s, c = %s, %s", format(b), format(c), cs_fmt_p(p)),
if (is.finite(r$odds_ratio)) sprintf(", OR = %s", cs_fmt_num(r$odds_ratio)) else "")
tests <- list(
list(test = "McNemar χ²", statistic = r$tdt, p = r$p_chisq),
list(test = "McNemar χ², continuity-corrected", statistic = r$tdt_cc, p = r$p_chisq_cc),
list(test = "Exact binomial, two-sided", statistic = NA, p = r$p_exact),
list(test = "Exact binomial, mid-p", statistic = NA, p = r$p_midp),
list(test = sprintf("Exact, %s over-transmitted", allele_b), statistic = NA, p = r$p_exact_greater),
list(test = sprintf("Exact, %s under-transmitted", allele_b), statistic = NA, p = r$p_exact_less)
)
counts <- list(list(allele = allele_b, transmitted = b, not_transmitted = c), list(allele = allele_a, transmitted = c, not_transmitted = b))
notes <- list(research_note, "Only heterozygous parents are informative: homozygous parents transmit the same allele whichever copy they pass on.",
"Within-family comparison protects against population stratification, but not against genotyping error or biased ascertainment.")
result_values <- c(
r[c("b", "c", "n_informative", "tdt", "tdt_cc", "p_chisq", "p_chisq_cc", "p_exact", "p_midp", "p_exact_greater",
"p_exact_less", "transmission", "transmission_low", "transmission_high", "odds_ratio", "or_low", "or_high")],
list(p = p, statistic = stat, test = test, input = input_kind, allele_a = allele_a, allele_b = allele_b),
t[c("n_trios", "n_used", "n_missing", "n_mendel", "n_uninformative", "n_het_parents")]
)
cs_publish(list(
method = "genetics.tdt",
methodVersion = "1.0.1",
title = "Transmission disequilibrium test",
engine = cs_engine_info("stats", "nanoparquet"),
n = m,
summary = summary,
apa = apa,
statistics = list(
list(key = "b", label = sprintf("Transmissions of %s (b)", allele_b), value = b),
list(key = "c", label = sprintf("Transmissions of %s (c)", allele_a), value = c),
list(key = "statistic", label = if (test == "chisq") "χ²" else "b", value = stat),
list(key = "p", label = sprintf("p (%s)", label), value = p, format = "p")
),
tables = list(
list(key = "counts", title = "Transmissions from heterozygous parents",
columns = list(list(key = "allele", label = "Allele", type = "string"), list(key = "transmitted", label = "Transmitted", type = "integer"),
list(key = "not_transmitted", label = "Not transmitted", type = "integer")),
rows = counts),
list(key = "tests", title = "All the tests of these counts",
columns = list(list(key = "test", label = "Test", type = "string"), list(key = "statistic", label = "Statistic", type = "number"), list(key = "p", label = "p", type = "p")),
rows = tests)
),
effectSizes = list(
list(key = "odds_ratio", label = "Transmission odds ratio b/c", value = r$odds_ratio, ciLow = r$or_low, ciHigh = r$or_high, ciLevel = conf, method = "Wald interval on log(b/c)"),
list(key = "transmission", label = sprintf("Share of transmissions that carry %s", allele_b), value = r$transmission, ciLow = r$transmission_low,
ciHigh = r$transmission_high, ciLevel = conf, method = "Clopper–Pearson")
),
assumptions = assumptions,
warnings = warnings,
notes = notes,
charts = list(),
values = result_values
))
exact TDT, b = 30, c = 18, p = .111, OR = 1.67
- Transmissions of tested (b)
- 30
- Transmissions of other (c)
- 18
- b
- 30
- p (exact TDT)
- .111
Effect size
- Transmission odds ratio b/c 1.667 95% CI [0.9291, 2.990]
- Share of transmissions that carry tested 0.6250 95% CI [0.4735, 0.7605]
Assumptions
- Mendelian transmission — Counts were given directly, so this isn't checkable.
- Enough informative parents — b + c = 48 informative transmissions.
- Independent transmissions — Use one affected child per family; extra siblings' transmissions aren't independent.
- Reliable genotype calls — Calling errors create false transmissions; check Mendelian errors and call rates first.
Transmissions from heterozygous parents
| Allele | Transmitted | Not transmitted |
|---|---|---|
| tested | 30 | 18 |
| other | 18 | 30 |
All the tests of these counts
| Test | Statistic | p |
|---|---|---|
| McNemar χ² | 3 | 0.0833 |
| McNemar χ², continuity-corrected | 2.521 | 0.1124 |
| Exact binomial, two-sided | — | 0.1114 |
| Exact binomial, mid-p | — | 0.0854 |
| Exact, tested over-transmitted | — | 0.0557 |
| Exact, tested under-transmitted | — | 0.9703 |
- Research use only: not for clinical or diagnostic decisions. Genotypes are personal data.
- Only heterozygous parents are informative: homozygous parents transmit the same allele whichever copy they pass on.
- Within-family comparison protects against population stratification, but not against genotyping error or biased ascertainment.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Transmission disequilibrium test (TDT)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method genetics.tdt 1.0.1 · spec 0543d53845218ec8
# Dataset: ge_tdt_counts (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 # TDT from trios or counts (Spielman et al. 1993; twins of cs_gen_tdt_*)
# %% Data (no rows dropped here: genotype no-calls and missing values are handled by the analysis)
df = pd.read_parquet("tests/parity/fixtures/ge_tdt_counts.parquet", columns=["transmitted", "untransmitted"])
n_input = len(df)
warnings = []
research_note = "Research use only: not for clinical or diagnostic decisions. Genotypes are personal data."
# %% Transmissions
trio_roles = [None, None, None]
count_roles = ["transmitted", "untransmitted"]
test = "exact"
continuity = False
alternative = "two_sided"
conf = float(0.95)
if all(trio_roles):
input_kind = "trios"
t = gen.tdt_trios(df[trio_roles[0]].to_numpy(), df[trio_roles[1]].to_numpy(), df[trio_roles[2]].to_numpy())
b, c = t["b"], t["c"]
allele_a, allele_b = t["allele_a"], t["allele_b"]
if t["n_missing"]:
warnings.append(f"{t['n_missing']} trios had a no-call and were left out.")
if t["n_mendel"]:
warnings.append(f"{t['n_mendel']} trios break Mendelian inheritance (a calling or pedigree error) and were left out.")
elif all(count_roles) and not any(trio_roles):
input_kind = "counts"
tb = df[count_roles[0]].to_numpy(dtype=float)
tc = df[count_roles[1]].to_numpy(dtype=float)
ok = ~(np.isnan(tb) | np.isnan(tc))
if (~ok).sum():
warnings.append(f"{int((~ok).sum())} rows had a missing count and were left out.")
if not ok.any():
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df[ok], count_roles) # infinite values stop the run (registry/errors.yaml)
b, c = float(tb[ok].sum()), float(tc[ok].sum())
if b != math.floor(b) or c != math.floor(c) or b < 0 or c < 0:
raise ValueError("Transmission counts must be whole numbers of at least 0.")
t = {"n_trios": None, "n_used": None, "n_missing": None, "n_mendel": None, "n_uninformative": None, "n_het_parents": None}
allele_a, allele_b = "other", "tested"
else:
raise ValueError("Bind the child, father and mother genotypes (one row per trio), or the transmitted and not-transmitted counts.")
# %% Tests
r = gen.tdt_counts(b, c, conf)
m = r["n_informative"]
if test == "chisq":
stat = r["tdt_cc"] if continuity else r["tdt"]
p = r["p_chisq_cc"] if continuity else r["p_chisq"]
label = "TDT (McNemar χ²" + (", continuity-corrected)" if continuity else ")")
else:
stat = b
p = {"two_sided": r["p_exact"], "greater": r["p_exact_greater"], "less": r["p_exact_less"]}[alternative]
label = "exact TDT" + ("" if alternative == "two_sided" else ", one-sided")
# %% Assumptions
small = m < 10
assumptions = [
{"key": "mendelian", "label": "Mendelian transmission", "status": ("warn" if t["n_mendel"] else "pass") if input_kind == "trios" else "info",
"detail": (f"{t['n_mendel']} of {t['n_trios']} trios break Mendelian inheritance and were left out." if t["n_mendel"]
else "Every complete trio is consistent with Mendelian inheritance.") if input_kind == "trios" else "Counts were given directly, so this isn't checkable."},
{"key": "informative", "label": "Enough informative parents", "status": ("info" if test == "exact" else "warn") if small else "pass",
"detail": f"b + c = {int(m)} informative transmissions" + ("; the exact test doesn't need many." if small and test == "exact" else "; use the exact test." if small else ".")},
{"key": "independence", "label": "Independent transmissions", "status": "info", "detail": "Use one affected child per family; extra siblings' transmissions aren't independent."},
{"key": "genotype_quality", "label": "Reliable genotype calls", "status": "info", "detail": "Calling errors create false transmissions; check Mendelian errors and call rates first."},
]
# %% Result
summary = (f"Heterozygous parents transmitted {allele_b} {b:g} times and {allele_a} {c:g} times "
f"(proportion {r['transmission']:.3f}, {conf:.0%} CI {r['transmission_low']:.3f} to {r['transmission_high']:.3f}): {label}, {cs.fmt_p(p)}.")
apa = (f"TDT χ²(1, N = {int(m)}) = {cs.fmt_num(stat)}, {cs.fmt_p(p)}" if test == "chisq" else f"exact TDT, b = {b:g}, c = {c:g}, {cs.fmt_p(p)}") \
+ (f", OR = {cs.fmt_num(r['odds_ratio'])}" if math.isfinite(r["odds_ratio"]) else "")
tests = [
{"test": "McNemar χ²", "statistic": r["tdt"], "p": r["p_chisq"]},
{"test": "McNemar χ², continuity-corrected", "statistic": r["tdt_cc"], "p": r["p_chisq_cc"]},
{"test": "Exact binomial, two-sided", "statistic": None, "p": r["p_exact"]},
{"test": "Exact binomial, mid-p", "statistic": None, "p": r["p_midp"]},
{"test": f"Exact, {allele_b} over-transmitted", "statistic": None, "p": r["p_exact_greater"]},
{"test": f"Exact, {allele_b} under-transmitted", "statistic": None, "p": r["p_exact_less"]},
]
counts = [{"allele": allele_b, "transmitted": b, "not_transmitted": c}, {"allele": allele_a, "transmitted": c, "not_transmitted": b}]
notes = [research_note, "Only heterozygous parents are informative: homozygous parents transmit the same allele whichever copy they pass on.",
"Within-family comparison protects against population stratification, but not against genotyping error or biased ascertainment."]
values = {
**{k: r[k] for k in ("b", "c", "n_informative", "tdt", "tdt_cc", "p_chisq", "p_chisq_cc", "p_exact", "p_midp", "p_exact_greater",
"p_exact_less", "transmission", "transmission_low", "transmission_high", "odds_ratio", "or_low", "or_high")},
"p": p, "statistic": stat, "test": test, "input": input_kind, "allele_a": allele_a, "allele_b": allele_b,
**{k: t[k] for k in ("n_trios", "n_used", "n_missing", "n_mendel", "n_uninformative", "n_het_parents")},
}
cs.publish({
"method": "genetics.tdt",
"methodVersion": "1.0.1",
"title": "Transmission disequilibrium test",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": int(m),
"summary": summary,
"apa": apa,
"statistics": [
{"key": "b", "label": f"Transmissions of {allele_b} (b)", "value": b},
{"key": "c", "label": f"Transmissions of {allele_a} (c)", "value": c},
{"key": "statistic", "label": "χ²" if test == "chisq" else "b", "value": stat},
{"key": "p", "label": f"p ({label})", "value": p, "format": "p"},
],
"tables": [
{"key": "counts", "title": "Transmissions from heterozygous parents",
"columns": [{"key": "allele", "label": "Allele", "type": "string"}, {"key": "transmitted", "label": "Transmitted", "type": "integer"},
{"key": "not_transmitted", "label": "Not transmitted", "type": "integer"}],
"rows": counts},
{"key": "tests", "title": "All the tests of these counts",
"columns": [{"key": "test", "label": "Test", "type": "string"}, {"key": "statistic", "label": "Statistic", "type": "number"}, {"key": "p", "label": "p", "type": "p"}],
"rows": tests},
],
"effectSizes": [
{"key": "odds_ratio", "label": "Transmission odds ratio b/c", "value": r["odds_ratio"], "ciLow": r["or_low"], "ciHigh": r["or_high"], "ciLevel": conf, "method": "Wald interval on log(b/c)"},
{"key": "transmission", "label": f"Share of transmissions that carry {allele_b}", "value": r["transmission"], "ciLow": r["transmission_low"],
"ciHigh": r["transmission_high"], "ciLevel": conf, "method": "Clopper–Pearson"},
],
"assumptions": assumptions,
"warnings": warnings,
"notes": notes,
"charts": [],
"values": values,
})
Check your understanding
CheckpointCheck yourself
A scan of 500,000 markers gives λ_GC = 1.35. What is the most likely reading?
Show the answer
Answer: b
λ_GC uses the median, which a few true hits barely move. Inflation across the whole scan points to structure or relatedness; add ancestry components or use a family design.
Check yourself
Why does QC drop markers with a Hardy–Weinberg exact p below ?
Show the answer
Answer: b
Calling errors such as allelic dropout produce heterozygote deficits. The strict threshold keeps real but modest departures.
Check yourself
The McDonald–Kreitman card shows a neutrality index NI = 2.00. What does NI above 1 point to?
Show the answer
Answer: b
NI above 1 means extra nonsynonymous polymorphism. α = 1 − NI is then negative, and adaptive evolution can't be estimated from this table.
Run it in code
In the appThe same helpers run the QC checks in both languages. Both read doses, VCF calls or allele pairs, and count the second allele in code-point order.
import pandas as pd
from codesplash.stats import genetics as gen
df = pd.read_csv("ge_people.csv")
markers = [f"v{i:02d}" for i in range(1, 25)]
g, counted, other = gen.dose_matrix({m: df[m].to_numpy() for m in markers})
qc = gen.qc(g)
print(qc["call_rate"].round(3))
print(qc["hwe_p"])library(codesplashr)
df <- read.csv("ge_people.csv")
markers <- sprintf("v%02d", 1:24)
dm <- cs_gen_dose_matrix(df[markers])
qc <- cs_gen_qc(dm$g)
round(qc$call_rate, 3)
qc$hwe_pRecap
Recap- Run QC before any test: call rates, minor-allele frequency and the HWE exact filter, plus each person's call rate and .
- LD means a hit marks a region. F_ST describes how far populations differ, which is what confounds a scan.
- Read λ_GC before reading the hits, and use a genome-wide threshold.
- These are research tools; genotypes are personal data.
Concepts in this lesson