← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-population-genetics-scikit-allel-analysis / references / usage-guide.md

scikit-allel Analysis - Usage Guide

Overview

scikit-allel is the in-memory Python toolkit for population genetics, built on three array types (GenotypeArray, HaplotypeArray, AlleleCountsArray), but its statistics are mostly ratios and densities with one denominator bug in two faces: per-base diversity (pi, theta, Dxy) silently divides by total span instead of accessible bases unless an is_accessible= callability mask is passed, and a genome-wide FST must be a ratio-of-sums (sum(a)/(sum(a)+sum(b)+sum(c))), not a mean of per-SNP FST - scikit-allel deliberately returns the variance components so the aggregation is done correctly. Both bugs run silently and return plausible numbers, so correctness is a choice the analyst makes.

Prerequisites

Quick Start

Tell your AI agent what you want to do: - "Calculate nucleotide diversity from my VCF using an accessibility mask" - "Compute genome-wide Hudson FST between two populations with a jackknife standard error" - "Run a Patterson f3 admixture test to check whether my target population is admixed" - "LD-prune my genotypes and run a Patterson-scaled PCA" - "Scan phased haplotypes for selection with iHS and standardize the scores" - "Convert my large VCF to Zarr and compute statistics out-of-core"

Example Prompts

Diversity and the SFS

"Compute pi and Watterson's theta in 100kb windows using a callable-loci mask, and report the accessible base count per window."

"Build a folded site frequency spectrum because I don't trust my ancestral-allele calls."

Population differentiation

"Estimate genome-wide FST between population A and population B with a block-jackknife standard error, using the Hudson estimator."

"Give me a per-window FST landscape across the chromosome and flag the top outlier windows."

Admixture

"Run a Patterson f3 test with my target population as C to see if it is admixed between A and B."

"Compute an ABBA-BABA D-statistic with a jackknife z-score for my four populations."

Structure and selection

"LD-prune my genotypes over three rounds and run a randomized Patterson PCA, then plot PC1 vs PC2."

"Compute iHS across phased chromosome 2 and standardize the scores binned by derived-allele frequency."

Large data

"Convert my whole-genome VCF to Zarr and count alleles out-of-core with dask."

What the Agent Will Do

  1. Load the VCF region into a GenotypeArray with only the needed fields, and derive allele counts (missing-aware) and per-population counts.
  2. For per-base diversity, require and apply an accessibility mask, and report the accessible base count per window.
  3. For differentiation, aggregate FST as a ratio-of-sums (or use average_hudson_fst) with a block-jackknife SE, never a mean of per-SNP FST.
  4. For admixture, run f3 with the test population first or a D-statistic, and interpret the jackknife z-score against the conventional thresholds.
  5. For structure, build a missing-free 012 matrix, LD-prune iteratively, mask known inversions, and run Patterson-scaled PCA.
  6. For selection, reshape phased haplotypes, run the scan, and standardize binned by derived-allele frequency.
  7. At biobank scale, convert to Zarr once and use dask-backed arrays for out-of-core counting and filtering.

Tips