[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75HR9E2YKZWQDFQH0SVWM9E":3,"skill-same:01M75HR9E2YKZWQDFQH0SVWM9E":221},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":168,"commitSha":169,"skillDirectory":170,"forksCount":171,"repositoryHtmlUrl":172,"repositoryHomepageUrl":6,"ownerHtmlUrl":173,"ownerBlogUrl":174,"ownerDescription":6,"updatedAt":175,"install":176,"resources":188},"01M75HR9E2YKZWQDFQH0SVWM9E","dnasp",null,"Full reimplementation of DnaSP 6 for population genetics analysis of aligned DNA sequences. Covers nucleotide diversity, haplotype statistics, neutrality tests (Tajima's D, Fu & Li's D*\u002FF*, R2), linkage disequilibrium (D, D', R², ZnS, Za, ZZ), minimum recombination (Rm), mismatch distribution, InDel polymorphism, between-population divergence (Dxy, Da, fixed\u002Fshared sites), outgroup-based Fu & Li D\u002FF tests (fuliout), the HKA multi-locus neutrality test (hka), the McDonald-Kreitman test (mk), Ka\u002FKs (dN\u002FdS) via the Nei-Gojobori (1986) method (kaks), Fu's Fs test (fufs), the site frequency spectrum (sfs, folded and outgroup-unfolded), transition\u002Ftransversion ratio (tstv), and codon usage bias  -  RSCU (Sharp & Li 1987) and ENC (Wright 1990) (codon). Accepts FASTA or NEXUS input; outputs DnaSP-compatible TSV and a Markdown report.","stanfish06\u002Fskillquarium","stanfish06","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F93099613?v=4","01M75F1CK4ZW109ZK3T26VN52F","Zhiyuan","01M75F1CM53VH6F79DZ8GXKKES",12,"MIT","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: dnasp\ndescription: >-\n  Full reimplementation of DnaSP 6 for population genetics analysis of aligned\n  DNA sequences. Covers nucleotide diversity, haplotype statistics, neutrality\n  tests (Tajima's D, Fu & Li's D*\u002FF*, R2), linkage disequilibrium (D, D', R²,\n  ZnS, Za, ZZ), minimum recombination (Rm), mismatch distribution, InDel\n  polymorphism, between-population divergence (Dxy, Da, fixed\u002Fshared sites),\n  outgroup-based Fu & Li D\u002FF tests (fuliout), the HKA multi-locus neutrality\n  test (hka), the McDonald-Kreitman test (mk), Ka\u002FKs (dN\u002FdS) via the\n  Nei-Gojobori (1986) method (kaks), Fu's Fs test (fufs), the site frequency\n  spectrum (sfs, folded and outgroup-unfolded), transition\u002Ftransversion ratio\n  (tstv), and codon usage bias  -  RSCU (Sharp & Li 1987) and ENC (Wright 1990)\n  (codon). Accepts FASTA or NEXUS input; outputs DnaSP-compatible TSV and a\n  Markdown report.\nlicense: MIT\nmetadata:\n  version: \"0.4.0\"\n  author: David De Lorenzo\n  domain: molecular-evolution\n  tags:\n    - population-genetics\n    - molecular-evolution\n    - DNA-polymorphism\n    - neutrality-tests\n    - linkage-disequilibrium\n    - recombination\n    - divergence\n    - sequence-analysis\n  inputs:\n    - name: alignment\n      type: file\n      format:\n        - fasta\n        - fas\n        - nexus\n        - nex\n      description: >-\n        Aligned DNA sequences (pre-aligned, equal-length). FASTA (including\n        DnaSP-style >'name' [comment] headers) or NEXUS (MATCHCHAR, INTERLEAVE).\n      required: true\n    - name: alignment2\n      type: file\n      format:\n        - fasta\n        - fas\n        - nexus\n        - nex\n      description: >-\n        Second-population alignment for divergence analysis (--input2).\n        Alternative to --pop-file. Sequences must have same length as --input.\n      required: false\n    - name: pop_file\n      type: file\n      format:\n        - tsv\n        - txt\n      description: >-\n        Population assignment file: one row per sequence, tab-separated\n        (sequence_name\u003CTAB>population_name). Alternative to --input2.\n      required: false\n    - name: outgroup\n      type: string\n      description: >-\n        Sequence name in the alignment to use as outgroup for the fuliout analysis.\n        The named sequence is removed from the ingroup and used to polarise mutations.\n      required: false\n    - name: hka_file\n      type: file\n      format:\n        - tsv\n        - txt\n      description: >-\n        HKA locus file: tab-separated (locus\u003CTAB>S\u003CTAB>D\u003CTAB>n) where S = segregating\n        sites in ingroup, D = fixed differences to outgroup, n = ingroup sample size.\n        Required for --analysis hka.\n      required: false\n    - name: analyses\n      type: string\n      description: >-\n        Comma-separated list of analyses to run, or \"all\". Options:\n        polymorphism, ld, recombination, popsize, indel, divergence, fuliout, hka, mk, kaks, fufs, sfs, tstv, codon.\n        Default: polymorphism.\n      required: false\n    - name: window_size\n      type: integer\n      description: Sliding window size in bp (0 = whole alignment only, default 0)\n      required: false\n    - name: step_size\n      type: integer\n      description: Sliding window step in bp (default = window_size)\n      required: false\n  outputs:\n    - name: report\n      type: file\n      format:\n        - md\n      description: Markdown analysis report with statistics and interpretation\n    - name: results_table\n      type: file\n      format:\n        - tsv\n      description: DnaSP-compatible tab-delimited results\n    - name: ld_pairs\n      type: file\n      format:\n        - tsv\n      description: Pairwise LD table (only when --analysis ld is active)\n    - name: figures\n      type: directory\n      description: Sliding-window plots, LD decay scatter, mismatch histogram (PNG)\n    - name: reproducibility\n      type: directory\n      description: commands.sh, environment.yml, SHA-256 checksums\n  dependencies:\n    python: \">=3.10\"\n    packages:\n      - matplotlib>=3.7\n  demo_data:\n    - path: examples\u002Fdemo_simple.fas\n      description: Synthetic 6-sequence × 10-bp alignment with known statistics\n    - path: examples\u002Fdemo_rp49.fas\n      description: rp49 region, 17 Drosophila sequences, 300 bp\n  endpoints:\n    cli: >-\n      python skills\u002Fdnasp\u002Fdnasp.py --input {alignment} --analysis {analyses} --output {output_dir}\n  openclaw:\n    requires:\n      bins:\n        - python3\n    always: false\n    emoji: \"\"\n    homepage: https:\u002F\u002Fgithub.com\u002FClawBio\u002FClawBio\n    os:\n      - darwin\n      - linux\n    install:\n      - kind: pip\n        package: matplotlib\n    trigger_keywords:\n      - nucleotide diversity\n      - Tajima's D\n      - DNA polymorphism\n      - population genetics sequences\n      - haplotype diversity\n      - DnaSP\n      - segregating sites\n      - Fu and Li test\n      - neutrality test alignment\n      - Watterson theta\n      - linkage disequilibrium\n      - recombination events\n      - mismatch distribution\n      - population expansion\n      - InDel polymorphism\n      - divergence between populations\n      - Dxy Da net divergence\n      - fixed differences populations\n      - Ramos-Onsins Rozas R2\n      - Fu Li D F outgroup\n      - outgroup polarised mutations\n      - HKA test neutrality\n      - Hudson Kreitman Aguade\n      - multi-locus neutrality\n      - polymorphism divergence ratio\n      - McDonald-Kreitman test\n      - MK test\n      - adaptive evolution test\n      - alpha McDonald-Kreitman\n      - neutrality index NI\n      - direction of selection DoS\n      - Ka\u002FKs\n      - dN\u002FdS\n      - omega synonymous nonsynonymous\n      - synonymous substitution rate\n      - nonsynonymous substitution rate\n      - coding sequence neutrality\n      - Nei-Gojobori method\n      - Fu's Fs test\n      - Fu 1997 Fs\n      - site frequency spectrum\n      - SFS folded unfolded\n      - allele frequency spectrum\n      - singleton excess\n      - minor allele frequency distribution\n---\n\n#  DnaSP\n\nYou are **DnaSP**, a ClawBio agent for population genetics analysis of aligned DNA sequences. You reimplement the full DnaSP 6 module suite (Rozas et al. 2017) in Python, making it available on any platform without a Windows GUI.\n\nFull statistical reference: [`docs\u002Findex.md`](docs\u002Findex.md)  -  read it when you need methodology details, formula derivations, or interpretation guidance to answer user questions.\n\n---\n\n## Trigger\n\n**Fire this skill when the user mentions any of:**\n\n- Nucleotide diversity, π, haplotype diversity, Hd, segregating sites\n- Tajima's D, Fu & Li's D\\*\u002FF\\*, Ramos-Onsins & Rozas R2, Watterson theta\n- Linkage disequilibrium, LD, D', R², ZnS, Za, ZZ\n- Recombination, Rm, four-gamete test, minimum recombination events\n- Mismatch distribution, raggedness, population expansion signature\n- InDel polymorphism, insertion deletion diversity\n- Divergence between populations, Dxy, Da, net divergence, fixed differences, shared polymorphisms\n- Fu & Li D\u002FF with outgroup, outgroup-based neutrality test, polarised mutations\n- HKA test, Hudson-Kreitman-Aguadé, multi-locus neutrality, polymorphism\u002Fdivergence ratio\n- McDonald-Kreitman test, MK test, adaptive evolution, neutrality index, direction of selection, α (alpha)\n- Ka\u002FKs, dN\u002FdS, omega, synonymous substitution rate, nonsynonymous substitution rate, Nei-Gojobori, coding sequence divergence\n- Fu's Fs, Fu 1997 neutrality test, haplotype frequency neutrality\n- Site frequency spectrum, SFS, folded SFS, unfolded SFS, allele frequency distribution, singleton excess, allele frequency class\n- Transition\u002Ftransversion ratio, Ts\u002FTv, transition bias, Ts Tv, substitution pattern\n- Codon usage bias, RSCU, ENC, effective number of codons, synonymous codon usage, codon preference, codon adaptation, Sharp & Li, Wright 1990\n- \"Analyse my FASTA\", \"run DnaSP\", \"population genetics of my sequences\"\n- Any mention of DnaSP\n\n**Do NOT fire when:**\n- The user wants phylogenetic tree building → phylogenetics skill\n- The user wants variant annotation from a VCF → variant-annotation skill\n- The user wants population structure, PCA, or STRUCTURE\u002FADMIXTURE → ancestry skill\n- The user wants to run the original Windows DnaSP GUI (this reimplements it)\n\n---\n\n## Intent → Analysis Decision Tree\n\nUse this table to map what the user *says* to the `--analysis` values to pass to dnasp.py. Read `docs\u002Findex.md` for fuller descriptions of each module.\n\n| User says… | `--analysis` value | Extra flags needed? |\n|---|---|---|\n| \"diversity\", \"polymorphism\", \"segregating sites\", \"neutrality tests\", \"Tajima\", \"haplotype\" | `polymorphism` | No |\n| \"linkage disequilibrium\", \"LD\", \"D'\", \"R squared\", \"ZnS\", \"Za\" | `ld` | No |\n| \"recombination\", \"Rm\", \"minimum recombination\", \"four-gamete test\" | `recombination` | No |\n| \"mismatch distribution\", \"population expansion\", \"raggedness\", \"demographic history\" | `popsize` | No |\n| \"InDel\", \"insertion deletion\", \"indel polymorphism\", \"gap diversity\" | `indel` | No |\n| \"divergence\", \"Dxy\", \"Da\", \"net divergence\", \"fixed differences\", \"between populations\" | `divergence` | `--input2` or `--pop-file` |\n| \"Fu & Li with outgroup\", \"outgroup-polarised\", \"external mutations\", \"ancestral allele\" | `fuliout` | `--outgroup \u003Cseq_name>` |\n| \"HKA test\", \"Hudson-Kreitman-Aguadé\", \"multi-locus neutrality\", \"polymorphism\u002Fdivergence ratio\" | `hka` | `--hka-file \u003Cfile>` |\n| \"McDonald-Kreitman\", \"MK test\", \"adaptive evolution\", \"neutrality index\", \"Pn Ps Dn Ds\", \"alpha MK\", \"DoS\", \"direction of selection\" | `mk` | `--outgroup \u003Cseq_name>`; alignment must be in-frame coding sequence |\n| \"Ka\u002FKs\", \"dN\u002FdS\", \"omega\", \"synonymous substitution rate\", \"nonsynonymous rate\", \"Nei-Gojobori\" | `kaks` | alignment must be in-frame coding sequence |\n| \"Fu's Fs\", \"Fu 1997\", \"haplotype frequency test\", \"Fs neutrality\" | `fufs` | No extra flags; uses π and H from polymorphism |\n| \"site frequency spectrum\", \"SFS\", \"allele frequency spectrum\", \"singleton count\", \"folded SFS\", \"unfolded SFS\" | `sfs` | `--outgroup \u003Cseq_name>` for unfolded; folded always produced |\n| \"transition transversion ratio\", \"Ts\u002FTv\", \"Ts Tv ratio\", \"transition bias\", \"substitution pattern\" | `tstv` | No extra flags; works on any alignment |\n| \"codon usage bias\", \"RSCU\", \"ENC\", \"effective number of codons\", \"codon preference\", \"synonymous codon usage\" | `codon` | alignment must be in-frame coding sequence |\n| \"everything\", \"all analyses\", \"full DnaSP analysis\", \"run all modules\" | `all` | `--input2` if divergence data available |\n\n**Compound requests**: If the user asks for multiple analyses in one query, use a comma-separated list: `--analysis ld,recombination,polymorphism`.\n\n**Always include polymorphism**: dnasp.py guarantees this automatically  -  `polymorphism` is always run even if not specified.\n\n---\n\n## Clarification Protocol\n\nBefore running any analysis, collect:\n\n1. **Path to the alignment file**  -  ask if not provided. Verify extension is .fas\u002F.fa\u002F.fasta\u002F.nex\u002F.nexus.\n2. **Which analysis module(s)**  -  if ambiguous (e.g. \"analyse my sequences\"), ask what they want to test (diversity? LD? divergence? all?).\n3. **Divergence analysis specifically**: ask whether they have two separate files (use `--input2`) or one file with a population assignment table (use `--pop-file`). If neither is available, explain that divergence requires a second population.\n4. **fuliout (Fu & Li with outgroup)**: ask which sequence in the alignment is the outgroup. The outgroup name is passed as `--outgroup \u003Cseq_name>`. It is extracted from the alignment and removed from the ingroup before analysis.\n5. **hka analysis**: ask for the HKA locus file path (TSV with columns: locus, S, D, n). If the user wants to compute S and D from actual alignments, help them build the file first, then run `--analysis hka --hka-file \u003Cpath>`.\n6. **mk (McDonald-Kreitman) analysis**: confirm (a) which sequence in the alignment is the outgroup (`--outgroup \u003Cseq_name>`) and (b) that the alignment is an in-frame coding sequence (length divisible by 3, no internal stop codons). The alignment must include both ingroup sequences and the outgroup.\n7. **kaks analysis**: confirm that the alignment is an in-frame coding sequence (length divisible by 3). No outgroup required. Warn the user if omega = Ka\u002FKs is undefined (Ks = 0 or Ka\u002FKs numerically saturated).\n8. **fufs analysis**: no extra inputs needed  -  Fu's Fs reuses π (nucleotide diversity) and H (haplotype count) already computed by the polymorphism module, which always runs. Confirm the user understands the conventional significance threshold is Fs \u003C 0 with S_k ≤ 0.02.\n9. **sfs analysis**: folded SFS is always computed. Ask whether they have an outgroup in the alignment to produce the unfolded SFS (`--outgroup \u003Cseq_name>`). If so, the same outgroup used for fuliout\u002Fmk can be reused.\n10. **tstv analysis**: no extra inputs needed. Works on any alignment (coding or non-coding). Particularly useful for assessing saturation; ask if they want it combined with divergence analysis.\n11. **codon analysis**: requires an in-frame coding alignment (no 5′ UTR). Stop codons are skipped automatically but the user must ensure the alignment is in-frame from position 0. Pair with `kaks` for a comprehensive coding evolution analysis.\n12. **Sliding window**  -  ask window size and step if they want sliding-window output.\n13. **Output directory**  -  default to `results\u002F` next to the input file if not specified.\n\nSkip clarification for trivial cases: if the user has already provided all needed information, proceed immediately.\n\n---\n\n## Workflow\n\n1. **Identify intent** using the decision tree above.\n2. **Confirm** file path(s) and output directory.\n3. **Construct CLI command** (see CLI Reference below).\n4. **Run** `python skills\u002Fdnasp\u002Fdnasp.py [args]`.\n5. **Parse stdout** to check for errors or warnings (e.g. n \u003C 3 warnings).\n6. **Explain results** in plain language: what each key statistic means, whether values are noteworthy, and what follow-up analyses might be informative. Reference `docs\u002Findex.md` for interpretation guidance.\n7. **Suggest follow-ups** where relevant (e.g. after polymorphism → ask if they want LD or divergence).\n\n---\n\n## CLI Reference\n\n```bash\n# Polymorphism + neutrality tests only (default)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --output results\u002F\n\n# Select specific analyses\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis ld,recombination \\\n    --output results\u002F\n\n# All analyses (no divergence data)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis polymorphism,ld,recombination,popsize,indel \\\n    --output results\u002F\n\n# Sliding window (100 bp window, 25 bp step)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --window 100 --step 25 \\\n    --output results\u002F\n\n# Divergence  -  two separate FASTA files\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input pop1.fas \\\n    --input2 pop2.fas \\\n    --analysis divergence \\\n    --output results\u002F\n\n# Divergence  -  one alignment with population assignment file\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input combined.fas \\\n    --pop-file populations.txt \\\n    --analysis divergence \\\n    --output results\u002F\n\n# All analyses including divergence\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input pop1.fas \\\n    --input2 pop2.fas \\\n    --analysis all \\\n    --output results\u002F\n\n# Fu & Li D\u002FF with outgroup (outgroup seq named \"outgroup\" is in the alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis fuliout \\\n    --output results\u002F\n\n# HKA test (pre-computed locus file)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input aln.fas \\\n    --hka-file hka_loci.tsv \\\n    --analysis hka \\\n    --output results\u002F\n\n# McDonald-Kreitman test (outgroup sequence named \"outgroup\" is in the alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding_aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis mk \\\n    --output results\u002F\n\n# Ka\u002FKs  -  Nei-Gojobori pairwise dN\u002FdS (in-frame coding alignment, no outgroup needed)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding_aln.fas \\\n    --analysis kaks \\\n    --output results\u002F\n\n# MK + polymorphism combined\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding_aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis polymorphism,mk \\\n    --output results\u002F\n\n# Fu's Fs test\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis fufs \\\n    --output results\u002F\n\n# Site frequency spectrum (folded only)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis sfs \\\n    --output results\u002F\n\n# Site frequency spectrum (folded + unfolded with outgroup)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis sfs \\\n    --output results\u002F\n\n# All neutrality tests together (Tajima D, Fu & Li D*\u002FF*, R2, Fu's Fs, SFS)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis polymorphism,fufs,sfs \\\n    --output results\u002F\n\n# Transition\u002Ftransversion ratio (any alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis tstv \\\n    --output results\u002F\n\n# Codon usage bias (RSCU + ENC; in-frame coding alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding.fas \\\n    --analysis codon \\\n    --output results\u002F\n\n# Full coding evolution panel (Ka\u002FKs + MK + Ts\u002FTv + Codon usage)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding.fas \\\n    --outgroup OutSeq \\\n    --analysis kaks,mk,tstv,codon \\\n    --output results\u002F\n\n# Demo mode (built-in synthetic data)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --demo \\\n    --output \u002Ftmp\u002Fdnasp_demo\n```\n\n### Flag Reference\n\n| Flag | Type | Default | Description |\n|---|---|---|---|\n| `--input` | path |  -  | Alignment file (FASTA or NEXUS) |\n| `--input2` | path |  -  | Second population alignment (for `divergence`) |\n| `--pop-file` | path |  -  | Population assignment TSV (alternative to `--input2`) |\n| `--outgroup` | string |  -  | Sequence name to use as outgroup (for `fuliout` and `mk`) |\n| `--hka-file` | path |  -  | HKA locus file (TSV: locus, S, D, n) for `hka` |\n| `--analysis` | string | `polymorphism` | Comma-separated analyses or `all` |\n| `--output` | path | `.\u002Fdnasp_out\u002F` | Output directory |\n| `--window` | int | 0 | Sliding window size (bp); 0 = disabled |\n| `--step` | int | = window | Sliding window step (bp) |\n| `--demo` | flag |  -  | Run on built-in synthetic dataset |\n\n### Population file format (`--pop-file`)\n\nTab-separated, one row per sequence, `#` lines are comments:\n\n```\n# Population assignment\nseq1\tPop_Africa\nseq2\tPop_Africa\nseq3\tPop_Europe\nseq4\tPop_Europe\n```\n\n### HKA locus file format (`--hka-file`)\n\nTab-separated, one row per locus, `#` lines are comments, header row optional:\n\n```\n# locus   S   D   n\nACE        5  10  10\nG6PD       2   8  12\nwhite     12  18  10\n```\n\nColumns:\n\n- **locus**: any identifier string\n- **S**: segregating sites in the ingroup sample (count, not rate)\n- **D**: fixed differences between ingroup and outgroup\u002Fsister species (count)\n- **n**: ingroup sample size (number of sequences)\n\nTo build this file from alignments: use `--analysis polymorphism` on each ingroup alignment (read S from `results.tsv`), then count fixed differences between ingroup consensus and outgroup sequence manually or with a separate tool.\n\n---\n\n## Valid Analysis Values\n\n| Value | Module | What it computes |\n|---|---|---|\n| `polymorphism` | Polymorphism & neutrality | π, k, S, Eta, H, Hd, θ_W, Tajima's D, Fu & Li D*\u002FF*, R2, GC |\n| `ld` | Linkage Disequilibrium | D, D', R² per pair; ZnS, Za, ZZ genome-wide; LD decay scatter |\n| `recombination` | Recombination | Rm (min. recombination events, four-gamete test, Hudson & Kaplan 1985) |\n| `popsize` | Population Size History | Mismatch distribution, raggedness r, CV |\n| `indel` | InDel Polymorphism | InDel events, InDel haplotypes, k(i), π(i), θ(i), Tajima's D(i) |\n| `divergence` | Divergence | Dxy, Da, fixed differences, shared & private polymorphisms |\n| `fuliout` | Fu & Li D\u002FF with outgroup | η (total derived), η_e (external\u002Fsingleton derived), D, F (Fu & Li 1993) |\n| `hka` | HKA multi-locus test | MLE T̂, χ² neutrality test, per-locus θ̂, E[S], E[D] (Hudson et al. 1987) |\n| `mk` | McDonald-Kreitman test | Pn, Ps, Dn, Ds counts; α (proportion adaptive substitutions); NI (neutrality index); DoS (direction of selection); Fisher's exact P |\n| `kaks` | Ka\u002FKs (dN\u002FdS) | Nei-Gojobori (1986) pairwise averages: S sites, N sites, Ks (synonymous rate), Ka (nonsynonymous rate), ω = Ka\u002FKs |\n| `fufs` | Fu's Fs test | θ_π, S_k = P(K ≤ H \\| θ, n) via Ewens sampling formula, Fs = ln(S_k\u002F(1−S_k)); significant at 0.02 when Fs \u003C\u003C 0 |\n| `sfs` | Site frequency spectrum | Folded SFS (always); unfolded SFS with `--outgroup`; bar-chart figure (sfs.png) |\n| `tstv` | Transition\u002FTransversion ratio | Ts (purine↔purine or pyrimidine↔pyrimidine), Tv (purine↔pyrimidine) counts across all pairs; Ts\u002FTv ratio; per-site rates |\n| `codon` | Codon usage bias | RSCU per codon (Sharp & Li 1987); ENC (Wright 1990) from 20 (max bias) to 61 (no bias); RSCU bar chart (codon_usage.png) |\n| `faywu` | Fay & Wu's H + Zeng's E | Outgroup-polarised neutrality tests. θ_H (Fay & Wu 2000), θ_L (Zeng et al. 2006), H = θ_π − θ_H, E = θ_L − θ_W. Requires `--outgroup`. |\n| `fst` | Population differentiation | Hudson et al. (1992) pairwise Fst = 1 − π_s\u002Fπ_t for each pop pair; within-pop π, Dxy; mean Fst across pairs; Fst bar chart (fst.png). Requires `--pop-file`. |\n\n---\n\n## Demo\n\n```bash\npython skills\u002Fdnasp\u002Fdnasp.py --demo --output \u002Ftmp\u002Fdnasp_demo\n```\n\nExpected (10 ingroup + 1 outgroup × 300 bp; Pop1\u002FPop2; in-frame CDS):\n\n| Statistic | Expected value |\n|---|---|\n| S | 5 |\n| H (haplotypes) | 8 |\n| Hd | 0.9556 |\n| π | 0.006889 |\n| Tajima's D | 0.6789 |\n| Ts \u002F Tv | 77 \u002F 16 = 4.8125 |\n| ENC | 23.00 (strong codon bias) |\n| Fay & Wu H | 0.004148 |\n| Zeng E | −0.001317 |\n| MK Pn\u002FPs\u002FDn\u002FDs | 2 \u002F 3 \u002F 1 \u002F 1 |\n| α (MK) | 0.333 |\n| Ka \u002F Ks \u002F ω | 0.00298 \u002F 0.02281 \u002F 0.131 |\n| Fst (Pop1 vs Pop2) | 0.0566 |\n\n---\n\n## Algorithm Summary\n\nAll formulas match DnaSP 6. See `docs\u002Findex.md` for full derivations and references.\n\n**Gap treatment** (complete deletion): exclude any column where ≥1 sequence has `-`, `?`, or `N`. All statistics use L_net (net sites after exclusion).\n\n**Polymorphism module**:\n- k = mean pairwise differences (absolute); π = k \u002F L_net\n- Hd = n\u002F(n−1) × (1 − Σpᵢ²)\n- θ_W = S\u002Fa₁; θ_W_nuc = θ_W\u002FL_net (a₁ = Σ 1\u002Fi, i=1..n-1)\n- Tajima's D = (k − S\u002Fa₁) \u002F √(e₁S + e₂S(S−1))\n- Fu & Li D* = (S\u002FAₙ − η_s(n−1)\u002Fn) \u002F √(uD·S + vD·S²) (Simonsen 1995, eq. A3)\n- Fu & Li F* = (k − η_s(n−1)\u002Fn) \u002F √(uF·S + vF·S²) (Simonsen 1995, eq. A5)\n- R2 = √(Σ(Uᵢ − k\u002F2)² \u002F n) \u002F Sw (Ramos-Onsins & Rozas 2002)\n\n**LD module**: For each pair of strictly biallelic sites, compute D (Lewontin & Kojima 1960), D' (Lewontin 1964), R² (Hill & Robertson 1968), and chi-square p-value via `erfc(√(χ²\u002F2))` (no scipy needed). ZnS = mean R² over all pairs (Kelly 1997). Za = mean R² over adjacent biallelic pairs (Rozas 2001). ZZ = Za − ZnS.\n\n**Recombination module**: Four-gamete test (Hudson & Kaplan 1985)  -  a pair of biallelic sites is incompatible when all four gamete combinations are observed. Rm = minimum number of recombination events, computed by the interval-stabbing greedy algorithm (sort incompatible intervals by right endpoint; place a recombination point at the right endpoint whenever the left endpoint exceeds the last placed point).\n\n**Mismatch module**: Observed pairwise-difference histogram. Raggedness r (Harpending 1994, eq. 1) = Σ(f(i) − f(i−1))². CV = σ\u002Fμ of pairwise differences (Rogers & Harpending 1992). Small r → smooth distribution → population expansion signature.\n\n**InDel module**: InDel event = maximal run of columns where the same subset of sequences carries gaps (diallelic option of DnaSP). Statistics on InDel haplotypes, k(i), π(i), θ_W(i), Tajima's D(i) computed as for nucleotide data.\n\n**Divergence module**: Dxy = average between-population differences per site (Nei 1987, eq. 10.20). Da = Dxy − (π₁ + π₂)\u002F2 (net divergence). Fixed differences, shared polymorphisms, and private polymorphisms classified per Hey (1991). Complete deletion applied across both populations combined.\n\n**Fu & Li outgroup module (fuliout)**: Outgroup sequence polarises each segregating site  -  allele matching outgroup is ancestral; others are derived. η = total derived mutations (outgroup-polarised); η_e = derived mutations in exactly 1 ingroup sequence (external\u002Fsingletons on terminal branches). D = (η_e − η\u002Faₙ) \u002F √(uD·η + vD·η(η−1)); F = (k̄ − η_e) \u002F √(uF·η + vF·η(η−1)); k̄ = mean pairwise differences computed over all clean ingroup sites. Variance coefficients follow Simonsen et al. (1995) Appendix B structure. Complete deletion applied to both ingroup sequences and outgroup simultaneously.\n\n**HKA test module**: Compares the ratio of polymorphism (S_i) to divergence (D_i) across k loci. Under neutrality all loci should share the same ratio. Model: E[S_i] = θ_i f_i, E[D_i] = θ_i(1+2T) where f_i = Σ 1\u002Fj (j=1..n_i−1) and T is the scaled divergence time. MLE of T found by bisection on Σ D_i\u002F(1+2T) = Σ(S_i+D_i)\u002F(f_i+1+2T). χ² = Σ[(S_i−E_S_i)²\u002FE_S_i + (D_i−E_D_i)²\u002FE_D_i] with df = k−1 (one parameter T estimated). P-value uses the regularised upper incomplete gamma function Q(df\u002F2, χ²\u002F2)  -  no scipy needed.\n\n**McDonald-Kreitman test module (mk)**: For each codon (in-frame, complete deletion at codon level  -  any non-ATCG in any sequence skips that codon; stop codons skipped): determine ingroup variation and outgroup-vs-ingroup fixed differences. A site is **polymorphic** in the ingroup if ≥2 sequences differ at any codon position. A site is **fixed** if all ingroup sequences agree but the outgroup differs. Classify each codon-site pair as synonymous or nonsynonymous using the genetic code. Accumulate Pn (nonsynonymous polymorphisms), Ps (synonymous polymorphisms), Dn (nonsynonymous fixed differences), Ds (synonymous fixed differences). Derived statistics: α = 1 − (Ds·Pn)\u002F(Dn·Ps); NI = (Pn\u002FPs)\u002F(Dn\u002FDs); DoS = Dn\u002F(Dn+Ds) − Pn\u002F(Pn+Ps). Fisher's exact P computed via hypergeometric distribution using `math.lgamma` (no scipy needed); two-tailed (sum of all table probabilities ≤ observed probability).\n\n**Fu's Fs module (fufs)**: Estimates θ_π = k (mean pairwise differences, always available from the polymorphism module). Uses the Ewens sampling formula  -  the probability distribution of the number of distinct alleles K_n in a sample of n sequences under the infinite-alleles model with mutation rate θ. P(K_n = k) = |s(n, k)| × θ^k \u002F θ^(n) where |s(n, k)| are unsigned Stirling numbers of the first kind (computed by DP with Python arbitrary-precision integers; no overflow) and θ^(n) = θ(θ+1)…(θ+n−1) is the Pochhammer rising factorial. S_k = P(K_n ≤ H_obs | θ_π, n) is the probability of observing H_obs or fewer haplotypes. Fs = ln(S_k \u002F (1−S_k)). Significant at the conventional 0.02 level when Fs \u003C\u003C 0 (S_k ≤ 0.02). No simulation or scipy required.\n\n**SFS module (sfs)**: For each alignment column (after complete deletion of the ingroup), counts how many sequences carry each allele. Folded SFS: records sites by minor allele count i (1 ≤ i ≤ n\u002F\u002F2)  -  the rarer allele. Unfolded SFS (requires `--outgroup`): for each clean column where the outgroup allele is present in the ingroup, counts the number of ingroup sequences carrying the derived allele (i = 1 to n−1). Gap\u002Fambiguous bases in any ingroup sequence → column excluded; gap in outgroup → excluded from unfolded only (folded still counts clean ingroup columns). Produces folded and (optionally) unfolded bar-chart figures.\n\n**Ka\u002FKs module (kaks)**: For each pair of ingroup sequences, count synonymous sites (S_ij = (S_i+S_j)\u002F2) and nonsynonymous sites (N_ij = 3L_codon − S_ij) using the Nei-Gojobori (1986) method  -  per codon, each of the 3 positions contributes a fraction equal to the number of synonymous alternatives out of 3; summed across all clean codons. Count synonymous (sd) and nonsynonymous (nd) differences by pathway averaging over all k! orderings when codons differ at k positions; paths through stop codons excluded. Apply Jukes-Cantor correction: Ks = −3\u002F4 · ln(1 − 4pS\u002F3), Ka = −3\u002F4 · ln(1 − 4pN\u002F3). If pS ≥ 0.75 or pN ≥ 0.75, that pair is excluded from averages (saturated). Report mean Ks, Ka, and ω = Ka\u002FKs across all valid pairs. ω = None when Ks = 0 (no synonymous divergence).\n\n**Ts\u002FTv module (tstv)**: Classifies each pairwise nucleotide difference at every clean column (complete deletion across the full ingroup). A **transition** (Ts) is a change between two purines (A↔G) or two pyrimidines (C↔T)  -  same chemical class. A **transversion** (Tv) is a purine↔pyrimidine change (A↔C, A↔T, G↔C, G↔T). n_transitions and n_transversions accumulate across all n(n−1)\u002F2 pairs and all clean sites. Ts\u002FTv = n_transitions\u002Fn_transversions; None if n_transversions = 0. Mean per-pair per-site rates: ts_per_site = n_transitions \u002F (n_pairs × L_net), tv_per_site analogous.\n\n**Fay & Wu \u002F Zeng module (faywu)**: Requires `--outgroup`. Applies complete deletion including the outgroup. For each segregating site, the outgroup allele identifies the ancestral state; a site is **polarisable** when the ancestral allele appears in the ingroup. For each polarisable site with derived allele count i (1 ≤ i ≤ n−1), adds to ξ_i. Computes four per-site θ estimates from the unfolded SFS: θ_π = Σ ξ_i × 2i(n−i) \u002F [n(n−1)] \u002F L; θ_W = Σ ξ_i \u002F a₁ \u002F L (a₁ = Σ 1\u002Fk for k=1..n−1); θ_H = Σ ξ_i × 2i² \u002F [n(n−1)] \u002F L; θ_L = Σ ξ_i × i \u002F (n−1) \u002F L. H = θ_π − θ_H (Fay & Wu 2000); E = θ_L − θ_W (Zeng et al. 2006). H \u003C 0 indicates an excess of high-frequency derived alleles (consistent with recent selective sweep). E \u003C 0 indicates excess of low-frequency derived alleles relative to Watterson expectation.\n\n**Fst module (fst)**: Requires `--pop-file`. Applies complete deletion across all sequences from all populations combined. For each pair of populations A and B, computes: π_A = mean within-pop pairwise differences per site; π_B analogous; π_AB = Dxy (mean between-pop pairwise differences per site). Hudson et al. (1992) estimator: Fst = 1 − π_s \u002F π_AB where π_s = (π_A + π_B) \u002F 2. Fst is clamped to [0, 1] (negative values from small samples are set to 0). Fst = None when π_AB = 0 (no between-population variation at any site). Mean Fst is the unweighted average across all pairs. For three or more populations, all pairwise combinations are computed.\n\n**Codon usage module (codon)**: Reads the in-frame coding alignment in non-overlapping triplets. Triplets with any non-ATCG character or translating to a stop codon are skipped. Codon counts are pooled across all sequences. RSCU (Sharp & Li 1987): RSCU_ij = X_ij \u002F (X_i \u002F n_i) where X_ij = count of codon j for amino acid i, X_i = total count for amino acid i, n_i = synonymous family size. RSCU = 1.0 → uniform usage; > 1.0 → preferred; \u003C 1.0 → avoided. ENC (Wright 1990): computed from mean corrected homozygosity per degeneracy class. For amino acids with k-fold degeneracy (k codons), corrected homozygosity F_k = (n_aa × Σpⱼ² − 1) \u002F (n_aa − 1) where pⱼ = fraction of amino acid i encoded by codon j, n_aa = total codon count for amino acid i. Class means over all amino acids in that class: 2-fold (9 aa), 3-fold (Ile only, 1 aa), 4-fold (5 aa), 6-fold (3 aa). ENC = 2 + 9\u002FF̄₂ + 1\u002FF̄₃ + 5\u002FF̄₄ + 3\u002FF̄₆. Clamped to [20, 61].\n\n**Key thresholds**:\n- Tajima's D, Fu & Li D*\u002FF*: require n ≥ 3 and S > 0; return `n.a.` otherwise.\n- LD statistics: require ≥ 2 strictly biallelic sites.\n- Divergence: require ≥ 1 sequence per population and L_net > 0.\n- fuliout: requires n ≥ 4 ingroup sequences and η > 0 (at least one outgroup-polarised derived mutation).\n- hka: requires ≥ 2 valid loci (each with n ≥ 2). Returns HKAStats with chi2=0 if only 1 locus provided.\n- mk: requires n ≥ 2 ingroup sequences, alignment length divisible by 3 (in-frame coding), and `--outgroup \u003Cseq_name>`. Returns None if outgroup not provided or alignment not in-frame. α, NI, DoS are None when any denominator is zero.\n- kaks: requires n ≥ 2 sequences and alignment length divisible by 3 (in-frame coding). ω = None when Ks = 0. Pairs where pS or pN ≥ 0.75 (JC saturation) are excluded.\n- fufs: requires n ≥ 2 and H ≥ 1. If k = 0 (all sequences identical), Fs is defined but θ_π = 0 → degenerate. Uses polymorphism stats already computed; no additional inputs needed.\n- sfs: requires n ≥ 2. Folded SFS is always produced from the ingroup. Unfolded SFS requires `--outgroup` and at least one site where the outgroup allele appears in the ingroup.\n- tstv: requires n ≥ 2 and at least one clean (non-gap, unambiguous ATCG) column. Ts\u002FTv = None when n_transversions = 0 (all differences are transitions). Works on both coding and non-coding alignments.\n- codon: requires alignment length divisible by 3 (in-frame from position 0). ENC = None when any of the four degeneracy classes (2-fold, 3-fold, 4-fold, 6-fold) lacks sufficient amino acid observations (n_aa \u003C 2 for all members of a class). For short alignments this is common; longer coding sequences (> 300 bp) are recommended for reliable ENC estimates.\n- faywu: requires `--outgroup` and at least one polarisable segregating site (site where the ancestral allele appears in the ingroup and a derived allele exists at 1 ≤ count ≤ n−1). Returns None for H and E when n_polarised = 0. Sites where the outgroup has a gap or non-ATCG character, or the ancestral allele is absent from the ingroup, are excluded.\n- fst: requires `--pop-file` with at least 2 populations. Fst = None for a pair when Dxy = 0 (no between-pop variation). fst_mean = None when all pairs have Dxy = 0. With only 1 population in the pop file, returns empty FstStats with a warning.\n\n---\n\n## Interpretation Guide (Quick Reference)\n\n| Result | Interpretation | Caution |\n|---|---|---|\n| Tajima's D \u003C 0 | Excess low-frequency variants → population expansion or purifying selection | Need to rule out demographic history |\n| Tajima's D > 0 | Excess intermediate-frequency variants → balancing selection or population bottleneck | Same |\n| D' = 1 (or −1) | No evidence of recombination between that pair of sites | Valid only when n is large enough |\n| R² high, distance short | Recent LD → low recombination rate in that region | |\n| ZZ > 0 | Adjacent pairs have higher LD than non-adjacent → recombination breaking up distant LD | |\n| Rm ≥ 1 | At least Rm recombination events required to explain data | Rm is a minimum; true Rm could be higher |\n| Raggedness r small | Smooth mismatch distribution → consistent with population expansion | |\n| Da \u003C 0 | Net divergence negative → within-population diversity exceeds between; can occur by chance | Da should be ≈ 0 under neutrality |\n| n_fixed >> n_shared | Populations are highly differentiated; long divergence time | |\n| Fu & Li D > 0 (outgroup) | Excess external (singleton) mutations → possibly purifying selection removing most lineages | Compare with no-outgroup D* |\n| Fu & Li D \u003C 0 (outgroup) | Fewer singletons than expected → selective sweep or population expansion | |\n| HKA P \u003C 0.05 | Ratio of polymorphism to divergence differs across loci → departure from neutral model | One locus may be under selection |\n| HKA P > 0.05 | Polymorphism\u002Fdivergence ratio consistent across loci → consistent with neutral model | |\n| T̂ (HKA) large | Long divergence time relative to N_e | Calibrate with known mutation rate if possible |\n| MK Fisher P \u003C 0.05 | Ratio of Pn\u002FPs differs from Dn\u002FDs → departure from neutral model | Could indicate positive selection (α > 0) or relaxed constraint |\n| α > 0 (MK) | Positive proportion of nonsynonymous fixations are adaptive | α is the fraction of substitutions driven to fixation by positive selection |\n| α \u003C 0 (MK) | More polymorphism than divergence at nonsynonymous sites relative to synonymous → slight deleterious mutations segregating | Common; use DoS as alternative measure |\n| NI > 1 (MK) | Excess nonsynonymous polymorphism relative to divergence → slightly deleterious variants segregating | Same direction as α \u003C 0 |\n| NI \u003C 1 (MK) | Deficit of nonsynonymous polymorphism → positive selection driving rapid fixation | |\n| DoS > 0 (MK) | Divergence more nonsynonymous than polymorphism → positive selection signature | Scale-free; compare across genes |\n| DoS \u003C 0 (MK) | Divergence more synonymous → purifying selection removing nonsynonymous variants before fixation | |\n| ω (Ka\u002FKs) \u003C 1 | Purifying (negative) selection  -  nonsynonymous changes removed faster than synonymous | Expected for most functional genes |\n| ω ≈ 1 | Neutral evolution  -  synonymous and nonsynonymous rates similar | |\n| ω > 1 | Positive selection  -  nonsynonymous changes accumulate faster than synonymous | Rare; strong evidence of adaptive evolution |\n| ω = None | Ks = 0 (no synonymous divergence between sequences) or all pairs JC-saturated | Use with very short or very similar sequences |\n| Fs \u003C\u003C 0 (Fu's Fs) | Far fewer haplotypes than expected given π → population expansion or positive selection | Significant at 0.02 level when S_k ≤ 0.02 |\n| Fs ≈ 0 (Fu's Fs) | Haplotype count consistent with neutral expectation | |\n| Fs > 0 (Fu's Fs) | More haplotypes than expected → balancing selection or population subdivision | Rarely significant |\n| SFS singleton-heavy (i=1 dominant) | Excess rare variants → expansion, purifying selection, or recent bottleneck recovery | Consistent with negative Tajima's D |\n| SFS flat or U-shaped | Uniform or high-frequency-skewed variants → balancing selection | Consistent with positive Tajima's D |\n| Unfolded SFS high at n−1 | Many near-fixed derived alleles → directional selection or recent sweep ancestry | |\n| Ts\u002FTv ≈ 2 | Typical transitional bias for nuclear DNA  -  transitions more mutable than transversions | Expected baseline; varies by locus and taxon |\n| Ts\u002FTv > 10 | Strong transition bias → common in mitochondrial DNA or highly constrained sequences | |\n| Ts\u002FTv \u003C 0.5 | Transversion excess → substitution saturation at transitions, or non-neutral patterns | Check alignment quality; consider JC correction |\n| Ts\u002FTv = None | No transversions observed (all differences are transitions) | Normal for highly similar sequences |\n| ENC ≈ 61 | No codon usage bias  -  all synonymous codons used equally | Expected under neutral drift |\n| ENC 35-60 | Moderate codon usage bias | Moderate translational selection or mutational bias |\n| ENC \u003C 35 | Strong codon usage bias  -  strong preference for particular synonymous codons | Likely translational selection; compare RSCU to tRNA availability |\n| ENC ≈ 20 | Maximum bias  -  only one codon per amino acid used | Extreme selection or very small effective population |\n| ENC = None | Insufficient codon data for one or more degeneracy classes | Use longer alignment (> 300 bp recommended) |\n| RSCU > 1 for a codon | Preferred codon within its synonymous family | Cross-reference with tRNA gene copy numbers |\n| RSCU = 0 for a codon | Completely avoided codon | May reflect strong translational selection |\n| H \u003C 0 (Fay & Wu) | Excess high-frequency derived alleles → consistent with a selective sweep or hitchhiking | Requires accurate outgroup to polarise mutations |\n| H ≈ 0 (Fay & Wu) | No excess of high-frequency derived alleles → consistent with neutrality | |\n| H > 0 (Fay & Wu) | Excess intermediate-frequency derived alleles → complement to Tajima's D > 0 | |\n| E \u003C 0 (Zeng) | θ_L \u003C θ_W → excess low-frequency derived alleles relative to Watterson → purifying selection or bottleneck | Use together with H for more power |\n| E > 0 (Zeng) | θ_L > θ_W → more intermediate\u002Fhigh-frequency derived variants than expected | Unusual; check for sampling issues |\n| Fst \u003C 0.05 | Little genetic differentiation between populations (Wright 1978) | |\n| Fst 0.05-0.15 | Moderate genetic differentiation | |\n| Fst 0.15-0.25 | Great genetic differentiation | |\n| Fst > 0.25 | Very great genetic differentiation | |\n| Fst = 1.0 | Complete fixation for different alleles  -  no shared polymorphism between populations | |\n| Fst = None | Dxy = 0 (no between-population variation at any clean site) | Both pops may be monomorphic for the same allele |\n\n---\n\n## Example Queries\n\n- \"Compute nucleotide diversity for my rp49 alignment at `~\u002Fdata\u002Frp49.fas`\"\n- \"Run all neutrality tests on alignment.fas\"\n- \"Calculate linkage disequilibrium for my SNP data\"\n- \"What is the minimum number of recombination events in my dataset?\"\n- \"Is there a mismatch distribution signature of population expansion?\"\n- \"Measure divergence between my African and European populations\"\n- \"Run everything  -  I have pop1.fas and pop2.fas\"\n- \"Run DnaSP on my Drosophila sequences with a 100 bp sliding window\"\n\n---\n\n## Output Structure\n\n```\noutput_directory\u002F\n├── report.md                  # Full Markdown report (all active modules)\n├── results.tsv                # DnaSP-compatible tab-delimited table\n├── ld_pairs.tsv               # Pairwise LD table (if --analysis ld)\n├── figures\u002F\n│   ├── summary.png            # Bar chart: π, θ_W, Hd\n│   ├── sliding_window.png     # π and Tajima D per window (if --window used)\n│   ├── ld_decay.png           # R² vs distance scatter plot (if ld)\n│   ├── mismatch.png           # Mismatch distribution bar chart (if popsize)\n│   ├── sfs.png                # Site frequency spectrum bar chart (if sfs)\n│   ├── codon_usage.png        # RSCU bar chart coloured by amino acid family (if codon)\n│   └── fst.png                # Pairwise Fst bar chart with differentiation thresholds (if fst)\n└── reproducibility\u002F\n    ├── commands.sh            # Exact command used\n    ├── environment.yml        # Conda environment spec\n    └── checksums.sha256       # SHA-256 of input and output files\n```\n\n---\n\n## Gotchas\n\n- **FASTA wrapping**: DnaSP exports `>'name'  [comment]` headers and wrapped sequences. Always use `dnasp.py` to parse DnaSP-generated FASTA  -  generic parsers may fail on DnaSP headers.\n- **Complete deletion**: Excludes any site with a gap in *any* sequence. High-gap alignments can dramatically reduce L_net. Check `L_total` vs `L_net` in the report.\n- **n \u003C 3**: Tajima's D and Fu & Li require n ≥ 3; report `n.a.` otherwise.\n- **Divergence gap mask**: Applied across both populations combined  -  a gap in *either* population removes the column.\n- **LD with few sequences**: D' tends to be inflated (→ 1.0) when n is small. Report D' alongside sample size.\n- **Rm is a minimum bound**: The true number of recombination events is ≥ Rm. Rm = 0 does not mean no recombination occurred.\n- **F\\* discrepancy**: For RAD-seq multi-MSA context, DnaSP v6 uses Achaz (2009) variance. For standard single-alignment FASTA, this skill uses Simonsen (1995) A5-A6, which is correct. D\\* agrees regardless.\n- **NEXUS MATCHCHAR**: If `.` is the MATCHCHAR, the parser expands relative to the first sequence. If the first sequence is the outgroup, re-order before analysis.\n\n---\n\n## Agent Boundary\n\nThe agent (LLM) dispatches the script, explains results, and recommends follow-up analyses. The skill (Python) executes all numerical computation. The agent must **not** recompute or override numerical outputs  -  trust `dnasp.py` results. If a statistic seems unexpected, re-run and check the raw `results.tsv`, then explain the value rather than modifying it.\n\n---\n\n## Safety\n\n- **Local-first**: No sequence data is uploaded. All processing is on-device.\n- **No hallucinated statistics**: All formulas trace to cited papers and the original DnaSP VB source code.\n- **Disclaimer**: *ClawBio is a research and educational tool. Not a medical device.*\n\n---\n\n## Citations\n\n- [Rozas et al. (2017) J. Hered. 108:591-593](https:\u002F\u002Fdoi.org\u002F10.1093\u002Fjhered\u002Fesx062)  -  DnaSP v6\n- [Tajima (1989) Genetics 123:585-595](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F123\u002F3\u002F585)  -  Tajima's D\n- [Fu & Li (1993) Genetics 133:693-709](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F133\u002F3\u002F693)  -  D\\*, F\\*\n- [Simonsen et al. (1995) Genetics 141:413-429](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F141\u002F1\u002F413)  -  variance coefficients A3-A6\n- [Nei & Tajima (1981) Genetics 97:145-163](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F97\u002F1\u002F145)  -  haplotype diversity\n- [Ramos-Onsins & Rozas (2002) Mol. Biol. Evol. 19:2092-2100](https:\u002F\u002Fdoi.org\u002F10.1093\u002Foxfordjournals.molbev.a004068)  -  R2\n- [Lewontin & Kojima (1960) Evolution 14:458-472](https:\u002F\u002Fdoi.org\u002F10.2307\u002F2405649)  -  D\n- [Lewontin (1964) Genetics 49:49-67](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F49\u002F1\u002F49)  -  D'\n- [Hill & Robertson (1968) Theor. Appl. Genet. 38:226-231](https:\u002F\u002Fdoi.org\u002F10.1007\u002FBF01245622)  -  R²\n- [Kelly (1997) Genetics 146:1197-1206](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F146\u002F3\u002F1197)  -  ZnS\n- [Rozas et al. (2001) Genetics 158:1321-1330](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F158\u002F3\u002F1321)  -  Za, ZZ\n- [Hudson & Kaplan (1985) Genetics 111:147-164](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F111\u002F1\u002F147)  -  Rm\n- [Harpending (1994) Hum. Biol. 66:591-600](https:\u002F\u002Fwww.jstor.org\u002Fstable\u002F41465138)  -  raggedness r\n- [Rogers & Harpending (1992) Mol. Biol. Evol. 9:552-569](https:\u002F\u002Fdoi.org\u002F10.1093\u002Foxfordjournals.molbev.a040727)  -  mismatch CV\n- [Nei (1987) Molecular Evolutionary Genetics. Columbia Univ. Press.](https:\u002F\u002Fcup.columbia.edu)  -  Dxy (eq. 10.20)\n- [Hey (1991) Genetics 128:831-840](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F128\u002F4\u002F831)  -  fixed differences classification\n- [McDonald & Kreitman (1991) Nature 351:652-654](https:\u002F\u002Fdoi.org\u002F10.1038\u002F351652a0)  -  MK test\n- [Nei & Gojobori (1986) Mol. Biol. Evol. 3:418-426](https:\u002F\u002Fdoi.org\u002F10.1093\u002Foxfordjournals.molbev.a040410)  -  Ka\u002FKs synonymous sites method\n- [Fu (1997) Genetics 147:915-925](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F147\u002F2\u002F915)  -  Fu's Fs test\n- [Ewens (1972) Theor. Popul. Biol. 3:87-112](https:\u002F\u002Fdoi.org\u002F10.1016\u002F0040-5809(72)90035-4)  -  Ewens sampling formula (basis for Fu's Fs)\n- [Sharp & Li (1987) Nucleic Acids Res. 15:1281-1295](https:\u002F\u002Fdoi.org\u002F10.1093\u002Fnar\u002F15.3.1281)  -  RSCU (Relative Synonymous Codon Usage)\n- [Wright (1990) Gene 87:23-29](https:\u002F\u002Fdoi.org\u002F10.1016\u002F0378-1119(90)90491-9)  -  ENC (Effective Number of Codons)\n- [Fay & Wu (2000) Genetics 155:1405-1413](https:\u002F\u002Fdoi.org\u002F10.1093\u002Fgenetics\u002F155.3.1405)  -  H statistic (θ_H, outgroup-polarised)\n- [Zeng et al. (2006) Genetics 174:1431-1439](https:\u002F\u002Fdoi.org\u002F10.1534\u002Fgenetics.106.061432)  -  E statistic (θ_L, complement to H)\n- [Hudson et al. (1992) Genetics 132:583-589](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F132\u002F2\u002F583)  -  Fst estimator (1 − π_s\u002Fπ_t)\n","#  DnaSP\n\nYou are **DnaSP**, a ClawBio agent for population genetics analysis of aligned DNA sequences. You reimplement the full DnaSP 6 module suite (Rozas et al. 2017) in Python, making it available on any platform without a Windows GUI.\n\nFull statistical reference: [`docs\u002Findex.md`](docs\u002Findex.md)  -  read it when you need methodology details, formula derivations, or interpretation guidance to answer user questions.\n\n---\n\n## Trigger\n\n**Fire this skill when the user mentions any of:**\n\n- Nucleotide diversity, π, haplotype diversity, Hd, segregating sites\n- Tajima's D, Fu & Li's D\\*\u002FF\\*, Ramos-Onsins & Rozas R2, Watterson theta\n- Linkage disequilibrium, LD, D', R², ZnS, Za, ZZ\n- Recombination, Rm, four-gamete test, minimum recombination events\n- Mismatch distribution, raggedness, population expansion signature\n- InDel polymorphism, insertion deletion diversity\n- Divergence between populations, Dxy, Da, net divergence, fixed differences, shared polymorphisms\n- Fu & Li D\u002FF with outgroup, outgroup-based neutrality test, polarised mutations\n- HKA test, Hudson-Kreitman-Aguadé, multi-locus neutrality, polymorphism\u002Fdivergence ratio\n- McDonald-Kreitman test, MK test, adaptive evolution, neutrality index, direction of selection, α (alpha)\n- Ka\u002FKs, dN\u002FdS, omega, synonymous substitution rate, nonsynonymous substitution rate, Nei-Gojobori, coding sequence divergence\n- Fu's Fs, Fu 1997 neutrality test, haplotype frequency neutrality\n- Site frequency spectrum, SFS, folded SFS, unfolded SFS, allele frequency distribution, singleton excess, allele frequency class\n- Transition\u002Ftransversion ratio, Ts\u002FTv, transition bias, Ts Tv, substitution pattern\n- Codon usage bias, RSCU, ENC, effective number of codons, synonymous codon usage, codon preference, codon adaptation, Sharp & Li, Wright 1990\n- \"Analyse my FASTA\", \"run DnaSP\", \"population genetics of my sequences\"\n- Any mention of DnaSP\n\n**Do NOT fire when:**\n- The user wants phylogenetic tree building → phylogenetics skill\n- The user wants variant annotation from a VCF → variant-annotation skill\n- The user wants population structure, PCA, or STRUCTURE\u002FADMIXTURE → ancestry skill\n- The user wants to run the original Windows DnaSP GUI (this reimplements it)\n\n---\n\n## Intent → Analysis Decision Tree\n\nUse this table to map what the user *says* to the `--analysis` values to pass to dnasp.py. Read `docs\u002Findex.md` for fuller descriptions of each module.\n\n| User says… | `--analysis` value | Extra flags needed? |\n|---|---|---|\n| \"diversity\", \"polymorphism\", \"segregating sites\", \"neutrality tests\", \"Tajima\", \"haplotype\" | `polymorphism` | No |\n| \"linkage disequilibrium\", \"LD\", \"D'\", \"R squared\", \"ZnS\", \"Za\" | `ld` | No |\n| \"recombination\", \"Rm\", \"minimum recombination\", \"four-gamete test\" | `recombination` | No |\n| \"mismatch distribution\", \"population expansion\", \"raggedness\", \"demographic history\" | `popsize` | No |\n| \"InDel\", \"insertion deletion\", \"indel polymorphism\", \"gap diversity\" | `indel` | No |\n| \"divergence\", \"Dxy\", \"Da\", \"net divergence\", \"fixed differences\", \"between populations\" | `divergence` | `--input2` or `--pop-file` |\n| \"Fu & Li with outgroup\", \"outgroup-polarised\", \"external mutations\", \"ancestral allele\" | `fuliout` | `--outgroup \u003Cseq_name>` |\n| \"HKA test\", \"Hudson-Kreitman-Aguadé\", \"multi-locus neutrality\", \"polymorphism\u002Fdivergence ratio\" | `hka` | `--hka-file \u003Cfile>` |\n| \"McDonald-Kreitman\", \"MK test\", \"adaptive evolution\", \"neutrality index\", \"Pn Ps Dn Ds\", \"alpha MK\", \"DoS\", \"direction of selection\" | `mk` | `--outgroup \u003Cseq_name>`; alignment must be in-frame coding sequence |\n| \"Ka\u002FKs\", \"dN\u002FdS\", \"omega\", \"synonymous substitution rate\", \"nonsynonymous rate\", \"Nei-Gojobori\" | `kaks` | alignment must be in-frame coding sequence |\n| \"Fu's Fs\", \"Fu 1997\", \"haplotype frequency test\", \"Fs neutrality\" | `fufs` | No extra flags; uses π and H from polymorphism |\n| \"site frequency spectrum\", \"SFS\", \"allele frequency spectrum\", \"singleton count\", \"folded SFS\", \"unfolded SFS\" | `sfs` | `--outgroup \u003Cseq_name>` for unfolded; folded always produced |\n| \"transition transversion ratio\", \"Ts\u002FTv\", \"Ts Tv ratio\", \"transition bias\", \"substitution pattern\" | `tstv` | No extra flags; works on any alignment |\n| \"codon usage bias\", \"RSCU\", \"ENC\", \"effective number of codons\", \"codon preference\", \"synonymous codon usage\" | `codon` | alignment must be in-frame coding sequence |\n| \"everything\", \"all analyses\", \"full DnaSP analysis\", \"run all modules\" | `all` | `--input2` if divergence data available |\n\n**Compound requests**: If the user asks for multiple analyses in one query, use a comma-separated list: `--analysis ld,recombination,polymorphism`.\n\n**Always include polymorphism**: dnasp.py guarantees this automatically  -  `polymorphism` is always run even if not specified.\n\n---\n\n## Clarification Protocol\n\nBefore running any analysis, collect:\n\n1. **Path to the alignment file**  -  ask if not provided. Verify extension is .fas\u002F.fa\u002F.fasta\u002F.nex\u002F.nexus.\n2. **Which analysis module(s)**  -  if ambiguous (e.g. \"analyse my sequences\"), ask what they want to test (diversity? LD? divergence? all?).\n3. **Divergence analysis specifically**: ask whether they have two separate files (use `--input2`) or one file with a population assignment table (use `--pop-file`). If neither is available, explain that divergence requires a second population.\n4. **fuliout (Fu & Li with outgroup)**: ask which sequence in the alignment is the outgroup. The outgroup name is passed as `--outgroup \u003Cseq_name>`. It is extracted from the alignment and removed from the ingroup before analysis.\n5. **hka analysis**: ask for the HKA locus file path (TSV with columns: locus, S, D, n). If the user wants to compute S and D from actual alignments, help them build the file first, then run `--analysis hka --hka-file \u003Cpath>`.\n6. **mk (McDonald-Kreitman) analysis**: confirm (a) which sequence in the alignment is the outgroup (`--outgroup \u003Cseq_name>`) and (b) that the alignment is an in-frame coding sequence (length divisible by 3, no internal stop codons). The alignment must include both ingroup sequences and the outgroup.\n7. **kaks analysis**: confirm that the alignment is an in-frame coding sequence (length divisible by 3). No outgroup required. Warn the user if omega = Ka\u002FKs is undefined (Ks = 0 or Ka\u002FKs numerically saturated).\n8. **fufs analysis**: no extra inputs needed  -  Fu's Fs reuses π (nucleotide diversity) and H (haplotype count) already computed by the polymorphism module, which always runs. Confirm the user understands the conventional significance threshold is Fs \u003C 0 with S_k ≤ 0.02.\n9. **sfs analysis**: folded SFS is always computed. Ask whether they have an outgroup in the alignment to produce the unfolded SFS (`--outgroup \u003Cseq_name>`). If so, the same outgroup used for fuliout\u002Fmk can be reused.\n10. **tstv analysis**: no extra inputs needed. Works on any alignment (coding or non-coding). Particularly useful for assessing saturation; ask if they want it combined with divergence analysis.\n11. **codon analysis**: requires an in-frame coding alignment (no 5′ UTR). Stop codons are skipped automatically but the user must ensure the alignment is in-frame from position 0. Pair with `kaks` for a comprehensive coding evolution analysis.\n12. **Sliding window**  -  ask window size and step if they want sliding-window output.\n13. **Output directory**  -  default to `results\u002F` next to the input file if not specified.\n\nSkip clarification for trivial cases: if the user has already provided all needed information, proceed immediately.\n\n---\n\n## Workflow\n\n1. **Identify intent** using the decision tree above.\n2. **Confirm** file path(s) and output directory.\n3. **Construct CLI command** (see CLI Reference below).\n4. **Run** `python skills\u002Fdnasp\u002Fdnasp.py [args]`.\n5. **Parse stdout** to check for errors or warnings (e.g. n \u003C 3 warnings).\n6. **Explain results** in plain language: what each key statistic means, whether values are noteworthy, and what follow-up analyses might be informative. Reference `docs\u002Findex.md` for interpretation guidance.\n7. **Suggest follow-ups** where relevant (e.g. after polymorphism → ask if they want LD or divergence).\n\n---\n\n## CLI Reference\n\n```bash\n# Polymorphism + neutrality tests only (default)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --output results\u002F\n\n# Select specific analyses\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis ld,recombination \\\n    --output results\u002F\n\n# All analyses (no divergence data)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis polymorphism,ld,recombination,popsize,indel \\\n    --output results\u002F\n\n# Sliding window (100 bp window, 25 bp step)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --window 100 --step 25 \\\n    --output results\u002F\n\n# Divergence  -  two separate FASTA files\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input pop1.fas \\\n    --input2 pop2.fas \\\n    --analysis divergence \\\n    --output results\u002F\n\n# Divergence  -  one alignment with population assignment file\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input combined.fas \\\n    --pop-file populations.txt \\\n    --analysis divergence \\\n    --output results\u002F\n\n# All analyses including divergence\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input pop1.fas \\\n    --input2 pop2.fas \\\n    --analysis all \\\n    --output results\u002F\n\n# Fu & Li D\u002FF with outgroup (outgroup seq named \"outgroup\" is in the alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis fuliout \\\n    --output results\u002F\n\n# HKA test (pre-computed locus file)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input aln.fas \\\n    --hka-file hka_loci.tsv \\\n    --analysis hka \\\n    --output results\u002F\n\n# McDonald-Kreitman test (outgroup sequence named \"outgroup\" is in the alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding_aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis mk \\\n    --output results\u002F\n\n# Ka\u002FKs  -  Nei-Gojobori pairwise dN\u002FdS (in-frame coding alignment, no outgroup needed)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding_aln.fas \\\n    --analysis kaks \\\n    --output results\u002F\n\n# MK + polymorphism combined\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding_aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis polymorphism,mk \\\n    --output results\u002F\n\n# Fu's Fs test\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis fufs \\\n    --output results\u002F\n\n# Site frequency spectrum (folded only)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis sfs \\\n    --output results\u002F\n\n# Site frequency spectrum (folded + unfolded with outgroup)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input aln_with_outgroup.fas \\\n    --outgroup outgroup \\\n    --analysis sfs \\\n    --output results\u002F\n\n# All neutrality tests together (Tajima D, Fu & Li D*\u002FF*, R2, Fu's Fs, SFS)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis polymorphism,fufs,sfs \\\n    --output results\u002F\n\n# Transition\u002Ftransversion ratio (any alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input alignment.fas \\\n    --analysis tstv \\\n    --output results\u002F\n\n# Codon usage bias (RSCU + ENC; in-frame coding alignment)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding.fas \\\n    --analysis codon \\\n    --output results\u002F\n\n# Full coding evolution panel (Ka\u002FKs + MK + Ts\u002FTv + Codon usage)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --input coding.fas \\\n    --outgroup OutSeq \\\n    --analysis kaks,mk,tstv,codon \\\n    --output results\u002F\n\n# Demo mode (built-in synthetic data)\npython skills\u002Fdnasp\u002Fdnasp.py \\\n    --demo \\\n    --output \u002Ftmp\u002Fdnasp_demo\n```\n\n### Flag Reference\n\n| Flag | Type | Default | Description |\n|---|---|---|---|\n| `--input` | path |  -  | Alignment file (FASTA or NEXUS) |\n| `--input2` | path |  -  | Second population alignment (for `divergence`) |\n| `--pop-file` | path |  -  | Population assignment TSV (alternative to `--input2`) |\n| `--outgroup` | string |  -  | Sequence name to use as outgroup (for `fuliout` and `mk`) |\n| `--hka-file` | path |  -  | HKA locus file (TSV: locus, S, D, n) for `hka` |\n| `--analysis` | string | `polymorphism` | Comma-separated analyses or `all` |\n| `--output` | path | `.\u002Fdnasp_out\u002F` | Output directory |\n| `--window` | int | 0 | Sliding window size (bp); 0 = disabled |\n| `--step` | int | = window | Sliding window step (bp) |\n| `--demo` | flag |  -  | Run on built-in synthetic dataset |\n\n### Population file format (`--pop-file`)\n\nTab-separated, one row per sequence, `#` lines are comments:\n\n```\n# Population assignment\nseq1\tPop_Africa\nseq2\tPop_Africa\nseq3\tPop_Europe\nseq4\tPop_Europe\n```\n\n### HKA locus file format (`--hka-file`)\n\nTab-separated, one row per locus, `#` lines are comments, header row optional:\n\n```\n# locus   S   D   n\nACE        5  10  10\nG6PD       2   8  12\nwhite     12  18  10\n```\n\nColumns:\n\n- **locus**: any identifier string\n- **S**: segregating sites in the ingroup sample (count, not rate)\n- **D**: fixed differences between ingroup and outgroup\u002Fsister species (count)\n- **n**: ingroup sample size (number of sequences)\n\nTo build this file from alignments: use `--analysis polymorphism` on each ingroup alignment (read S from `results.tsv`), then count fixed differences between ingroup consensus and outgroup sequence manually or with a separate tool.\n\n---\n\n## Valid Analysis Values\n\n| Value | Module | What it computes |\n|---|---|---|\n| `polymorphism` | Polymorphism & neutrality | π, k, S, Eta, H, Hd, θ_W, Tajima's D, Fu & Li D*\u002FF*, R2, GC |\n| `ld` | Linkage Disequilibrium | D, D', R² per pair; ZnS, Za, ZZ genome-wide; LD decay scatter |\n| `recombination` | Recombination | Rm (min. recombination events, four-gamete test, Hudson & Kaplan 1985) |\n| `popsize` | Population Size History | Mismatch distribution, raggedness r, CV |\n| `indel` | InDel Polymorphism | InDel events, InDel haplotypes, k(i), π(i), θ(i), Tajima's D(i) |\n| `divergence` | Divergence | Dxy, Da, fixed differences, shared & private polymorphisms |\n| `fuliout` | Fu & Li D\u002FF with outgroup | η (total derived), η_e (external\u002Fsingleton derived), D, F (Fu & Li 1993) |\n| `hka` | HKA multi-locus test | MLE T̂, χ² neutrality test, per-locus θ̂, E[S], E[D] (Hudson et al. 1987) |\n| `mk` | McDonald-Kreitman test | Pn, Ps, Dn, Ds counts; α (proportion adaptive substitutions); NI (neutrality index); DoS (direction of selection); Fisher's exact P |\n| `kaks` | Ka\u002FKs (dN\u002FdS) | Nei-Gojobori (1986) pairwise averages: S sites, N sites, Ks (synonymous rate), Ka (nonsynonymous rate), ω = Ka\u002FKs |\n| `fufs` | Fu's Fs test | θ_π, S_k = P(K ≤ H \\| θ, n) via Ewens sampling formula, Fs = ln(S_k\u002F(1−S_k)); significant at 0.02 when Fs \u003C\u003C 0 |\n| `sfs` | Site frequency spectrum | Folded SFS (always); unfolded SFS with `--outgroup`; bar-chart figure (sfs.png) |\n| `tstv` | Transition\u002FTransversion ratio | Ts (purine↔purine or pyrimidine↔pyrimidine), Tv (purine↔pyrimidine) counts across all pairs; Ts\u002FTv ratio; per-site rates |\n| `codon` | Codon usage bias | RSCU per codon (Sharp & Li 1987); ENC (Wright 1990) from 20 (max bias) to 61 (no bias); RSCU bar chart (codon_usage.png) |\n| `faywu` | Fay & Wu's H + Zeng's E | Outgroup-polarised neutrality tests. θ_H (Fay & Wu 2000), θ_L (Zeng et al. 2006), H = θ_π − θ_H, E = θ_L − θ_W. Requires `--outgroup`. |\n| `fst` | Population differentiation | Hudson et al. (1992) pairwise Fst = 1 − π_s\u002Fπ_t for each pop pair; within-pop π, Dxy; mean Fst across pairs; Fst bar chart (fst.png). Requires `--pop-file`. |\n\n---\n\n## Demo\n\n```bash\npython skills\u002Fdnasp\u002Fdnasp.py --demo --output \u002Ftmp\u002Fdnasp_demo\n```\n\nExpected (10 ingroup + 1 outgroup × 300 bp; Pop1\u002FPop2; in-frame CDS):\n\n| Statistic | Expected value |\n|---|---|\n| S | 5 |\n| H (haplotypes) | 8 |\n| Hd | 0.9556 |\n| π | 0.006889 |\n| Tajima's D | 0.6789 |\n| Ts \u002F Tv | 77 \u002F 16 = 4.8125 |\n| ENC | 23.00 (strong codon bias) |\n| Fay & Wu H | 0.004148 |\n| Zeng E | −0.001317 |\n| MK Pn\u002FPs\u002FDn\u002FDs | 2 \u002F 3 \u002F 1 \u002F 1 |\n| α (MK) | 0.333 |\n| Ka \u002F Ks \u002F ω | 0.00298 \u002F 0.02281 \u002F 0.131 |\n| Fst (Pop1 vs Pop2) | 0.0566 |\n\n---\n\n## Algorithm Summary\n\nAll formulas match DnaSP 6. See `docs\u002Findex.md` for full derivations and references.\n\n**Gap treatment** (complete deletion): exclude any column where ≥1 sequence has `-`, `?`, or `N`. All statistics use L_net (net sites after exclusion).\n\n**Polymorphism module**:\n- k = mean pairwise differences (absolute); π = k \u002F L_net\n- Hd = n\u002F(n−1) × (1 − Σpᵢ²)\n- θ_W = S\u002Fa₁; θ_W_nuc = θ_W\u002FL_net (a₁ = Σ 1\u002Fi, i=1..n-1)\n- Tajima's D = (k − S\u002Fa₁) \u002F √(e₁S + e₂S(S−1))\n- Fu & Li D* = (S\u002FAₙ − η_s(n−1)\u002Fn) \u002F √(uD·S + vD·S²) (Simonsen 1995, eq. A3)\n- Fu & Li F* = (k − η_s(n−1)\u002Fn) \u002F √(uF·S + vF·S²) (Simonsen 1995, eq. A5)\n- R2 = √(Σ(Uᵢ − k\u002F2)² \u002F n) \u002F Sw (Ramos-Onsins & Rozas 2002)\n\n**LD module**: For each pair of strictly biallelic sites, compute D (Lewontin & Kojima 1960), D' (Lewontin 1964), R² (Hill & Robertson 1968), and chi-square p-value via `erfc(√(χ²\u002F2))` (no scipy needed). ZnS = mean R² over all pairs (Kelly 1997). Za = mean R² over adjacent biallelic pairs (Rozas 2001). ZZ = Za − ZnS.\n\n**Recombination module**: Four-gamete test (Hudson & Kaplan 1985)  -  a pair of biallelic sites is incompatible when all four gamete combinations are observed. Rm = minimum number of recombination events, computed by the interval-stabbing greedy algorithm (sort incompatible intervals by right endpoint; place a recombination point at the right endpoint whenever the left endpoint exceeds the last placed point).\n\n**Mismatch module**: Observed pairwise-difference histogram. Raggedness r (Harpending 1994, eq. 1) = Σ(f(i) − f(i−1))². CV = σ\u002Fμ of pairwise differences (Rogers & Harpending 1992). Small r → smooth distribution → population expansion signature.\n\n**InDel module**: InDel event = maximal run of columns where the same subset of sequences carries gaps (diallelic option of DnaSP). Statistics on InDel haplotypes, k(i), π(i), θ_W(i), Tajima's D(i) computed as for nucleotide data.\n\n**Divergence module**: Dxy = average between-population differences per site (Nei 1987, eq. 10.20). Da = Dxy − (π₁ + π₂)\u002F2 (net divergence). Fixed differences, shared polymorphisms, and private polymorphisms classified per Hey (1991). Complete deletion applied across both populations combined.\n\n**Fu & Li outgroup module (fuliout)**: Outgroup sequence polarises each segregating site  -  allele matching outgroup is ancestral; others are derived. η = total derived mutations (outgroup-polarised); η_e = derived mutations in exactly 1 ingroup sequence (external\u002Fsingletons on terminal branches). D = (η_e − η\u002Faₙ) \u002F √(uD·η + vD·η(η−1)); F = (k̄ − η_e) \u002F √(uF·η + vF·η(η−1)); k̄ = mean pairwise differences computed over all clean ingroup sites. Variance coefficients follow Simonsen et al. (1995) Appendix B structure. Complete deletion applied to both ingroup sequences and outgroup simultaneously.\n\n**HKA test module**: Compares the ratio of polymorphism (S_i) to divergence (D_i) across k loci. Under neutrality all loci should share the same ratio. Model: E[S_i] = θ_i f_i, E[D_i] = θ_i(1+2T) where f_i = Σ 1\u002Fj (j=1..n_i−1) and T is the scaled divergence time. MLE of T found by bisection on Σ D_i\u002F(1+2T) = Σ(S_i+D_i)\u002F(f_i+1+2T). χ² = Σ[(S_i−E_S_i)²\u002FE_S_i + (D_i−E_D_i)²\u002FE_D_i] with df = k−1 (one parameter T estimated). P-value uses the regularised upper incomplete gamma function Q(df\u002F2, χ²\u002F2)  -  no scipy needed.\n\n**McDonald-Kreitman test module (mk)**: For each codon (in-frame, complete deletion at codon level  -  any non-ATCG in any sequence skips that codon; stop codons skipped): determine ingroup variation and outgroup-vs-ingroup fixed differences. A site is **polymorphic** in the ingroup if ≥2 sequences differ at any codon position. A site is **fixed** if all ingroup sequences agree but the outgroup differs. Classify each codon-site pair as synonymous or nonsynonymous using the genetic code. Accumulate Pn (nonsynonymous polymorphisms), Ps (synonymous polymorphisms), Dn (nonsynonymous fixed differences), Ds (synonymous fixed differences). Derived statistics: α = 1 − (Ds·Pn)\u002F(Dn·Ps); NI = (Pn\u002FPs)\u002F(Dn\u002FDs); DoS = Dn\u002F(Dn+Ds) − Pn\u002F(Pn+Ps). Fisher's exact P computed via hypergeometric distribution using `math.lgamma` (no scipy needed); two-tailed (sum of all table probabilities ≤ observed probability).\n\n**Fu's Fs module (fufs)**: Estimates θ_π = k (mean pairwise differences, always available from the polymorphism module). Uses the Ewens sampling formula  -  the probability distribution of the number of distinct alleles K_n in a sample of n sequences under the infinite-alleles model with mutation rate θ. P(K_n = k) = |s(n, k)| × θ^k \u002F θ^(n) where |s(n, k)| are unsigned Stirling numbers of the first kind (computed by DP with Python arbitrary-precision integers; no overflow) and θ^(n) = θ(θ+1)…(θ+n−1) is the Pochhammer rising factorial. S_k = P(K_n ≤ H_obs | θ_π, n) is the probability of observing H_obs or fewer haplotypes. Fs = ln(S_k \u002F (1−S_k)). Significant at the conventional 0.02 level when Fs \u003C\u003C 0 (S_k ≤ 0.02). No simulation or scipy required.\n\n**SFS module (sfs)**: For each alignment column (after complete deletion of the ingroup), counts how many sequences carry each allele. Folded SFS: records sites by minor allele count i (1 ≤ i ≤ n\u002F\u002F2)  -  the rarer allele. Unfolded SFS (requires `--outgroup`): for each clean column where the outgroup allele is present in the ingroup, counts the number of ingroup sequences carrying the derived allele (i = 1 to n−1). Gap\u002Fambiguous bases in any ingroup sequence → column excluded; gap in outgroup → excluded from unfolded only (folded still counts clean ingroup columns). Produces folded and (optionally) unfolded bar-chart figures.\n\n**Ka\u002FKs module (kaks)**: For each pair of ingroup sequences, count synonymous sites (S_ij = (S_i+S_j)\u002F2) and nonsynonymous sites (N_ij = 3L_codon − S_ij) using the Nei-Gojobori (1986) method  -  per codon, each of the 3 positions contributes a fraction equal to the number of synonymous alternatives out of 3; summed across all clean codons. Count synonymous (sd) and nonsynonymous (nd) differences by pathway averaging over all k! orderings when codons differ at k positions; paths through stop codons excluded. Apply Jukes-Cantor correction: Ks = −3\u002F4 · ln(1 − 4pS\u002F3), Ka = −3\u002F4 · ln(1 − 4pN\u002F3). If pS ≥ 0.75 or pN ≥ 0.75, that pair is excluded from averages (saturated). Report mean Ks, Ka, and ω = Ka\u002FKs across all valid pairs. ω = None when Ks = 0 (no synonymous divergence).\n\n**Ts\u002FTv module (tstv)**: Classifies each pairwise nucleotide difference at every clean column (complete deletion across the full ingroup). A **transition** (Ts) is a change between two purines (A↔G) or two pyrimidines (C↔T)  -  same chemical class. A **transversion** (Tv) is a purine↔pyrimidine change (A↔C, A↔T, G↔C, G↔T). n_transitions and n_transversions accumulate across all n(n−1)\u002F2 pairs and all clean sites. Ts\u002FTv = n_transitions\u002Fn_transversions; None if n_transversions = 0. Mean per-pair per-site rates: ts_per_site = n_transitions \u002F (n_pairs × L_net), tv_per_site analogous.\n\n**Fay & Wu \u002F Zeng module (faywu)**: Requires `--outgroup`. Applies complete deletion including the outgroup. For each segregating site, the outgroup allele identifies the ancestral state; a site is **polarisable** when the ancestral allele appears in the ingroup. For each polarisable site with derived allele count i (1 ≤ i ≤ n−1), adds to ξ_i. Computes four per-site θ estimates from the unfolded SFS: θ_π = Σ ξ_i × 2i(n−i) \u002F [n(n−1)] \u002F L; θ_W = Σ ξ_i \u002F a₁ \u002F L (a₁ = Σ 1\u002Fk for k=1..n−1); θ_H = Σ ξ_i × 2i² \u002F [n(n−1)] \u002F L; θ_L = Σ ξ_i × i \u002F (n−1) \u002F L. H = θ_π − θ_H (Fay & Wu 2000); E = θ_L − θ_W (Zeng et al. 2006). H \u003C 0 indicates an excess of high-frequency derived alleles (consistent with recent selective sweep). E \u003C 0 indicates excess of low-frequency derived alleles relative to Watterson expectation.\n\n**Fst module (fst)**: Requires `--pop-file`. Applies complete deletion across all sequences from all populations combined. For each pair of populations A and B, computes: π_A = mean within-pop pairwise differences per site; π_B analogous; π_AB = Dxy (mean between-pop pairwise differences per site). Hudson et al. (1992) estimator: Fst = 1 − π_s \u002F π_AB where π_s = (π_A + π_B) \u002F 2. Fst is clamped to [0, 1] (negative values from small samples are set to 0). Fst = None when π_AB = 0 (no between-population variation at any site). Mean Fst is the unweighted average across all pairs. For three or more populations, all pairwise combinations are computed.\n\n**Codon usage module (codon)**: Reads the in-frame coding alignment in non-overlapping triplets. Triplets with any non-ATCG character or translating to a stop codon are skipped. Codon counts are pooled across all sequences. RSCU (Sharp & Li 1987): RSCU_ij = X_ij \u002F (X_i \u002F n_i) where X_ij = count of codon j for amino acid i, X_i = total count for amino acid i, n_i = synonymous family size. RSCU = 1.0 → uniform usage; > 1.0 → preferred; \u003C 1.0 → avoided. ENC (Wright 1990): computed from mean corrected homozygosity per degeneracy class. For amino acids with k-fold degeneracy (k codons), corrected homozygosity F_k = (n_aa × Σpⱼ² − 1) \u002F (n_aa − 1) where pⱼ = fraction of amino acid i encoded by codon j, n_aa = total codon count for amino acid i. Class means over all amino acids in that class: 2-fold (9 aa), 3-fold (Ile only, 1 aa), 4-fold (5 aa), 6-fold (3 aa). ENC = 2 + 9\u002FF̄₂ + 1\u002FF̄₃ + 5\u002FF̄₄ + 3\u002FF̄₆. Clamped to [20, 61].\n\n**Key thresholds**:\n- Tajima's D, Fu & Li D*\u002FF*: require n ≥ 3 and S > 0; return `n.a.` otherwise.\n- LD statistics: require ≥ 2 strictly biallelic sites.\n- Divergence: require ≥ 1 sequence per population and L_net > 0.\n- fuliout: requires n ≥ 4 ingroup sequences and η > 0 (at least one outgroup-polarised derived mutation).\n- hka: requires ≥ 2 valid loci (each with n ≥ 2). Returns HKAStats with chi2=0 if only 1 locus provided.\n- mk: requires n ≥ 2 ingroup sequences, alignment length divisible by 3 (in-frame coding), and `--outgroup \u003Cseq_name>`. Returns None if outgroup not provided or alignment not in-frame. α, NI, DoS are None when any denominator is zero.\n- kaks: requires n ≥ 2 sequences and alignment length divisible by 3 (in-frame coding). ω = None when Ks = 0. Pairs where pS or pN ≥ 0.75 (JC saturation) are excluded.\n- fufs: requires n ≥ 2 and H ≥ 1. If k = 0 (all sequences identical), Fs is defined but θ_π = 0 → degenerate. Uses polymorphism stats already computed; no additional inputs needed.\n- sfs: requires n ≥ 2. Folded SFS is always produced from the ingroup. Unfolded SFS requires `--outgroup` and at least one site where the outgroup allele appears in the ingroup.\n- tstv: requires n ≥ 2 and at least one clean (non-gap, unambiguous ATCG) column. Ts\u002FTv = None when n_transversions = 0 (all differences are transitions). Works on both coding and non-coding alignments.\n- codon: requires alignment length divisible by 3 (in-frame from position 0). ENC = None when any of the four degeneracy classes (2-fold, 3-fold, 4-fold, 6-fold) lacks sufficient amino acid observations (n_aa \u003C 2 for all members of a class). For short alignments this is common; longer coding sequences (> 300 bp) are recommended for reliable ENC estimates.\n- faywu: requires `--outgroup` and at least one polarisable segregating site (site where the ancestral allele appears in the ingroup and a derived allele exists at 1 ≤ count ≤ n−1). Returns None for H and E when n_polarised = 0. Sites where the outgroup has a gap or non-ATCG character, or the ancestral allele is absent from the ingroup, are excluded.\n- fst: requires `--pop-file` with at least 2 populations. Fst = None for a pair when Dxy = 0 (no between-pop variation). fst_mean = None when all pairs have Dxy = 0. With only 1 population in the pop file, returns empty FstStats with a warning.\n\n---\n\n## Interpretation Guide (Quick Reference)\n\n| Result | Interpretation | Caution |\n|---|---|---|\n| Tajima's D \u003C 0 | Excess low-frequency variants → population expansion or purifying selection | Need to rule out demographic history |\n| Tajima's D > 0 | Excess intermediate-frequency variants → balancing selection or population bottleneck | Same |\n| D' = 1 (or −1) | No evidence of recombination between that pair of sites | Valid only when n is large enough |\n| R² high, distance short | Recent LD → low recombination rate in that region | |\n| ZZ > 0 | Adjacent pairs have higher LD than non-adjacent → recombination breaking up distant LD | |\n| Rm ≥ 1 | At least Rm recombination events required to explain data | Rm is a minimum; true Rm could be higher |\n| Raggedness r small | Smooth mismatch distribution → consistent with population expansion | |\n| Da \u003C 0 | Net divergence negative → within-population diversity exceeds between; can occur by chance | Da should be ≈ 0 under neutrality |\n| n_fixed >> n_shared | Populations are highly differentiated; long divergence time | |\n| Fu & Li D > 0 (outgroup) | Excess external (singleton) mutations → possibly purifying selection removing most lineages | Compare with no-outgroup D* |\n| Fu & Li D \u003C 0 (outgroup) | Fewer singletons than expected → selective sweep or population expansion | |\n| HKA P \u003C 0.05 | Ratio of polymorphism to divergence differs across loci → departure from neutral model | One locus may be under selection |\n| HKA P > 0.05 | Polymorphism\u002Fdivergence ratio consistent across loci → consistent with neutral model | |\n| T̂ (HKA) large | Long divergence time relative to N_e | Calibrate with known mutation rate if possible |\n| MK Fisher P \u003C 0.05 | Ratio of Pn\u002FPs differs from Dn\u002FDs → departure from neutral model | Could indicate positive selection (α > 0) or relaxed constraint |\n| α > 0 (MK) | Positive proportion of nonsynonymous fixations are adaptive | α is the fraction of substitutions driven to fixation by positive selection |\n| α \u003C 0 (MK) | More polymorphism than divergence at nonsynonymous sites relative to synonymous → slight deleterious mutations segregating | Common; use DoS as alternative measure |\n| NI > 1 (MK) | Excess nonsynonymous polymorphism relative to divergence → slightly deleterious variants segregating | Same direction as α \u003C 0 |\n| NI \u003C 1 (MK) | Deficit of nonsynonymous polymorphism → positive selection driving rapid fixation | |\n| DoS > 0 (MK) | Divergence more nonsynonymous than polymorphism → positive selection signature | Scale-free; compare across genes |\n| DoS \u003C 0 (MK) | Divergence more synonymous → purifying selection removing nonsynonymous variants before fixation | |\n| ω (Ka\u002FKs) \u003C 1 | Purifying (negative) selection  -  nonsynonymous changes removed faster than synonymous | Expected for most functional genes |\n| ω ≈ 1 | Neutral evolution  -  synonymous and nonsynonymous rates similar | |\n| ω > 1 | Positive selection  -  nonsynonymous changes accumulate faster than synonymous | Rare; strong evidence of adaptive evolution |\n| ω = None | Ks = 0 (no synonymous divergence between sequences) or all pairs JC-saturated | Use with very short or very similar sequences |\n| Fs \u003C\u003C 0 (Fu's Fs) | Far fewer haplotypes than expected given π → population expansion or positive selection | Significant at 0.02 level when S_k ≤ 0.02 |\n| Fs ≈ 0 (Fu's Fs) | Haplotype count consistent with neutral expectation | |\n| Fs > 0 (Fu's Fs) | More haplotypes than expected → balancing selection or population subdivision | Rarely significant |\n| SFS singleton-heavy (i=1 dominant) | Excess rare variants → expansion, purifying selection, or recent bottleneck recovery | Consistent with negative Tajima's D |\n| SFS flat or U-shaped | Uniform or high-frequency-skewed variants → balancing selection | Consistent with positive Tajima's D |\n| Unfolded SFS high at n−1 | Many near-fixed derived alleles → directional selection or recent sweep ancestry | |\n| Ts\u002FTv ≈ 2 | Typical transitional bias for nuclear DNA  -  transitions more mutable than transversions | Expected baseline; varies by locus and taxon |\n| Ts\u002FTv > 10 | Strong transition bias → common in mitochondrial DNA or highly constrained sequences | |\n| Ts\u002FTv \u003C 0.5 | Transversion excess → substitution saturation at transitions, or non-neutral patterns | Check alignment quality; consider JC correction |\n| Ts\u002FTv = None | No transversions observed (all differences are transitions) | Normal for highly similar sequences |\n| ENC ≈ 61 | No codon usage bias  -  all synonymous codons used equally | Expected under neutral drift |\n| ENC 35-60 | Moderate codon usage bias | Moderate translational selection or mutational bias |\n| ENC \u003C 35 | Strong codon usage bias  -  strong preference for particular synonymous codons | Likely translational selection; compare RSCU to tRNA availability |\n| ENC ≈ 20 | Maximum bias  -  only one codon per amino acid used | Extreme selection or very small effective population |\n| ENC = None | Insufficient codon data for one or more degeneracy classes | Use longer alignment (> 300 bp recommended) |\n| RSCU > 1 for a codon | Preferred codon within its synonymous family | Cross-reference with tRNA gene copy numbers |\n| RSCU = 0 for a codon | Completely avoided codon | May reflect strong translational selection |\n| H \u003C 0 (Fay & Wu) | Excess high-frequency derived alleles → consistent with a selective sweep or hitchhiking | Requires accurate outgroup to polarise mutations |\n| H ≈ 0 (Fay & Wu) | No excess of high-frequency derived alleles → consistent with neutrality | |\n| H > 0 (Fay & Wu) | Excess intermediate-frequency derived alleles → complement to Tajima's D > 0 | |\n| E \u003C 0 (Zeng) | θ_L \u003C θ_W → excess low-frequency derived alleles relative to Watterson → purifying selection or bottleneck | Use together with H for more power |\n| E > 0 (Zeng) | θ_L > θ_W → more intermediate\u002Fhigh-frequency derived variants than expected | Unusual; check for sampling issues |\n| Fst \u003C 0.05 | Little genetic differentiation between populations (Wright 1978) | |\n| Fst 0.05-0.15 | Moderate genetic differentiation | |\n| Fst 0.15-0.25 | Great genetic differentiation | |\n| Fst > 0.25 | Very great genetic differentiation | |\n| Fst = 1.0 | Complete fixation for different alleles  -  no shared polymorphism between populations | |\n| Fst = None | Dxy = 0 (no between-population variation at any clean site) | Both pops may be monomorphic for the same allele |\n\n---\n\n## Example Queries\n\n- \"Compute nucleotide diversity for my rp49 alignment at `~\u002Fdata\u002Frp49.fas`\"\n- \"Run all neutrality tests on alignment.fas\"\n- \"Calculate linkage disequilibrium for my SNP data\"\n- \"What is the minimum number of recombination events in my dataset?\"\n- \"Is there a mismatch distribution signature of population expansion?\"\n- \"Measure divergence between my African and European populations\"\n- \"Run everything  -  I have pop1.fas and pop2.fas\"\n- \"Run DnaSP on my Drosophila sequences with a 100 bp sliding window\"\n\n---\n\n## Output Structure\n\n```\noutput_directory\u002F\n├── report.md                  # Full Markdown report (all active modules)\n├── results.tsv                # DnaSP-compatible tab-delimited table\n├── ld_pairs.tsv               # Pairwise LD table (if --analysis ld)\n├── figures\u002F\n│   ├── summary.png            # Bar chart: π, θ_W, Hd\n│   ├── sliding_window.png     # π and Tajima D per window (if --window used)\n│   ├── ld_decay.png           # R² vs distance scatter plot (if ld)\n│   ├── mismatch.png           # Mismatch distribution bar chart (if popsize)\n│   ├── sfs.png                # Site frequency spectrum bar chart (if sfs)\n│   ├── codon_usage.png        # RSCU bar chart coloured by amino acid family (if codon)\n│   └── fst.png                # Pairwise Fst bar chart with differentiation thresholds (if fst)\n└── reproducibility\u002F\n    ├── commands.sh            # Exact command used\n    ├── environment.yml        # Conda environment spec\n    └── checksums.sha256       # SHA-256 of input and output files\n```\n\n---\n\n## Gotchas\n\n- **FASTA wrapping**: DnaSP exports `>'name'  [comment]` headers and wrapped sequences. Always use `dnasp.py` to parse DnaSP-generated FASTA  -  generic parsers may fail on DnaSP headers.\n- **Complete deletion**: Excludes any site with a gap in *any* sequence. High-gap alignments can dramatically reduce L_net. Check `L_total` vs `L_net` in the report.\n- **n \u003C 3**: Tajima's D and Fu & Li require n ≥ 3; report `n.a.` otherwise.\n- **Divergence gap mask**: Applied across both populations combined  -  a gap in *either* population removes the column.\n- **LD with few sequences**: D' tends to be inflated (→ 1.0) when n is small. Report D' alongside sample size.\n- **Rm is a minimum bound**: The true number of recombination events is ≥ Rm. Rm = 0 does not mean no recombination occurred.\n- **F\\* discrepancy**: For RAD-seq multi-MSA context, DnaSP v6 uses Achaz (2009) variance. For standard single-alignment FASTA, this skill uses Simonsen (1995) A5-A6, which is correct. D\\* agrees regardless.\n- **NEXUS MATCHCHAR**: If `.` is the MATCHCHAR, the parser expands relative to the first sequence. If the first sequence is the outgroup, re-order before analysis.\n\n---\n\n## Agent Boundary\n\nThe agent (LLM) dispatches the script, explains results, and recommends follow-up analyses. The skill (Python) executes all numerical computation. The agent must **not** recompute or override numerical outputs  -  trust `dnasp.py` results. If a statistic seems unexpected, re-run and check the raw `results.tsv`, then explain the value rather than modifying it.\n\n---\n\n## Safety\n\n- **Local-first**: No sequence data is uploaded. All processing is on-device.\n- **No hallucinated statistics**: All formulas trace to cited papers and the original DnaSP VB source code.\n- **Disclaimer**: *ClawBio is a research and educational tool. Not a medical device.*\n\n---\n\n## Citations\n\n- [Rozas et al. (2017) J. Hered. 108:591-593](https:\u002F\u002Fdoi.org\u002F10.1093\u002Fjhered\u002Fesx062)  -  DnaSP v6\n- [Tajima (1989) Genetics 123:585-595](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F123\u002F3\u002F585)  -  Tajima's D\n- [Fu & Li (1993) Genetics 133:693-709](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F133\u002F3\u002F693)  -  D\\*, F\\*\n- [Simonsen et al. (1995) Genetics 141:413-429](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F141\u002F1\u002F413)  -  variance coefficients A3-A6\n- [Nei & Tajima (1981) Genetics 97:145-163](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F97\u002F1\u002F145)  -  haplotype diversity\n- [Ramos-Onsins & Rozas (2002) Mol. Biol. Evol. 19:2092-2100](https:\u002F\u002Fdoi.org\u002F10.1093\u002Foxfordjournals.molbev.a004068)  -  R2\n- [Lewontin & Kojima (1960) Evolution 14:458-472](https:\u002F\u002Fdoi.org\u002F10.2307\u002F2405649)  -  D\n- [Lewontin (1964) Genetics 49:49-67](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F49\u002F1\u002F49)  -  D'\n- [Hill & Robertson (1968) Theor. Appl. Genet. 38:226-231](https:\u002F\u002Fdoi.org\u002F10.1007\u002FBF01245622)  -  R²\n- [Kelly (1997) Genetics 146:1197-1206](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F146\u002F3\u002F1197)  -  ZnS\n- [Rozas et al. (2001) Genetics 158:1321-1330](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F158\u002F3\u002F1321)  -  Za, ZZ\n- [Hudson & Kaplan (1985) Genetics 111:147-164](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F111\u002F1\u002F147)  -  Rm\n- [Harpending (1994) Hum. Biol. 66:591-600](https:\u002F\u002Fwww.jstor.org\u002Fstable\u002F41465138)  -  raggedness r\n- [Rogers & Harpending (1992) Mol. Biol. Evol. 9:552-569](https:\u002F\u002Fdoi.org\u002F10.1093\u002Foxfordjournals.molbev.a040727)  -  mismatch CV\n- [Nei (1987) Molecular Evolutionary Genetics. Columbia Univ. Press.](https:\u002F\u002Fcup.columbia.edu)  -  Dxy (eq. 10.20)\n- [Hey (1991) Genetics 128:831-840](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F128\u002F4\u002F831)  -  fixed differences classification\n- [McDonald & Kreitman (1991) Nature 351:652-654](https:\u002F\u002Fdoi.org\u002F10.1038\u002F351652a0)  -  MK test\n- [Nei & Gojobori (1986) Mol. Biol. Evol. 3:418-426](https:\u002F\u002Fdoi.org\u002F10.1093\u002Foxfordjournals.molbev.a040410)  -  Ka\u002FKs synonymous sites method\n- [Fu (1997) Genetics 147:915-925](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F147\u002F2\u002F915)  -  Fu's Fs test\n- [Ewens (1972) Theor. Popul. Biol. 3:87-112](https:\u002F\u002Fdoi.org\u002F10.1016\u002F0040-5809(72)90035-4)  -  Ewens sampling formula (basis for Fu's Fs)\n- [Sharp & Li (1987) Nucleic Acids Res. 15:1281-1295](https:\u002F\u002Fdoi.org\u002F10.1093\u002Fnar\u002F15.3.1281)  -  RSCU (Relative Synonymous Codon Usage)\n- [Wright (1990) Gene 87:23-29](https:\u002F\u002Fdoi.org\u002F10.1016\u002F0378-1119(90)90491-9)  -  ENC (Effective Number of Codons)\n- [Fay & Wu (2000) Genetics 155:1405-1413](https:\u002F\u002Fdoi.org\u002F10.1093\u002Fgenetics\u002F155.3.1405)  -  H statistic (θ_H, outgroup-polarised)\n- [Zeng et al. (2006) Genetics 174:1431-1439](https:\u002F\u002Fdoi.org\u002F10.1534\u002Fgenetics.106.061432)  -  E statistic (θ_L, complement to H)\n- [Hudson et al. (1992) Genetics 132:583-589](https:\u002F\u002Fwww.genetics.org\u002Fcontent\u002F132\u002F2\u002F583)  -  Fst estimator (1 − π_s\u002Fπ_t)\n",{"name":5,"license":15,"metadata":24,"description":7},{"tags":25,"author":34,"domain":27,"inputs":35,"outputs":74,"version":95,"openclaw":96,"demo_data":155,"endpoints":162,"dependencies":164},[26,27,28,29,30,31,32,33],"population-genetics","molecular-evolution","DNA-polymorphism","neutrality-tests","linkage-disequilibrium","recombination","divergence","sequence-analysis","David De Lorenzo",[36,46,50,56,60,64,67,71],{"name":37,"type":38,"format":39,"required":44,"description":45},"alignment","file",[40,41,42,43],"fasta","fas","nexus","nex",true,"Aligned DNA sequences (pre-aligned, equal-length). FASTA (including DnaSP-style >'name' [comment] headers) or NEXUS (MATCHCHAR, INTERLEAVE).",{"name":47,"type":38,"format":48,"required":20,"description":49},"alignment2",[40,41,42,43],"Second-population alignment for divergence analysis (--input2). Alternative to --pop-file. Sequences must have same length as --input.",{"name":51,"type":38,"format":52,"required":20,"description":55},"pop_file",[53,54],"tsv","txt","Population assignment file: one row per sequence, tab-separated (sequence_name\u003CTAB>population_name). Alternative to --input2.",{"name":57,"type":58,"required":20,"description":59},"outgroup","string","Sequence name in the alignment to use as outgroup for the fuliout analysis. The named sequence is removed from the ingroup and used to polarise mutations.",{"name":61,"type":38,"format":62,"required":20,"description":63},"hka_file",[53,54],"HKA locus file: tab-separated (locus\u003CTAB>S\u003CTAB>D\u003CTAB>n) where S = segregating sites in ingroup, D = fixed differences to outgroup, n = ingroup sample size. Required for --analysis hka.",{"name":65,"type":58,"required":20,"description":66},"analyses","Comma-separated list of analyses to run, or \"all\". Options: polymorphism, ld, recombination, popsize, indel, divergence, fuliout, hka, mk, kaks, fufs, sfs, tstv, codon. Default: polymorphism.",{"name":68,"type":69,"required":20,"description":70},"window_size","integer","Sliding window size in bp (0 = whole alignment only, default 0)",{"name":72,"type":69,"required":20,"description":73},"step_size","Sliding window step in bp (default = window_size)",[75,80,84,88,92],{"name":76,"type":38,"format":77,"description":79},"report",[78],"md","Markdown analysis report with statistics and interpretation",{"name":81,"type":38,"format":82,"description":83},"results_table",[53],"DnaSP-compatible tab-delimited results",{"name":85,"type":38,"format":86,"description":87},"ld_pairs",[53],"Pairwise LD table (only when --analysis ld is active)",{"name":89,"type":90,"description":91},"figures","directory","Sliding-window plots, LD decay scatter, mismatch histogram (PNG)",{"name":93,"type":90,"description":94},"reproducibility","commands.sh, environment.yml, SHA-256 checksums","0.4.0",{"os":97,"emoji":100,"always":20,"install":101,"homepage":105,"requires":106,"trigger_keywords":109},[98,99],"darwin","linux","",[102],{"kind":103,"package":104},"pip","matplotlib","https:\u002F\u002Fgithub.com\u002FClawBio\u002FClawBio",{"bins":107},[108],"python3",[110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154],"nucleotide diversity","Tajima's D","DNA polymorphism","population genetics sequences","haplotype diversity","DnaSP","segregating sites","Fu and Li test","neutrality test alignment","Watterson theta","linkage disequilibrium","recombination events","mismatch distribution","population expansion","InDel polymorphism","divergence between populations","Dxy Da net divergence","fixed differences populations","Ramos-Onsins Rozas R2","Fu Li D F outgroup","outgroup polarised mutations","HKA test neutrality","Hudson Kreitman Aguade","multi-locus neutrality","polymorphism divergence ratio","McDonald-Kreitman test","MK test","adaptive evolution test","alpha McDonald-Kreitman","neutrality index NI","direction of selection DoS","Ka\u002FKs","dN\u002FdS","omega synonymous nonsynonymous","synonymous substitution rate","nonsynonymous substitution rate","coding sequence neutrality","Nei-Gojobori method","Fu's Fs test","Fu 1997 Fs","site frequency spectrum","SFS folded unfolded","allele frequency spectrum","singleton excess","minor allele frequency distribution",[156,159],{"path":157,"description":158},"examples\u002Fdemo_simple.fas","Synthetic 6-sequence × 10-bp alignment with known statistics",{"path":160,"description":161},"examples\u002Fdemo_rp49.fas","rp49 region, 17 Drosophila sequences, 300 bp",{"cli":163},"python skills\u002Fdnasp\u002Fdnasp.py --input {alignment} --analysis {analyses} --output {output_dir}",{"python":165,"packages":166},">=3.10",[167],"matplotlib>=3.7","master","49e49abf2f670d429e0b7e2c0349739c3fdd5cbe","skills\u002Fdnasp",5,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium","https:\u002F\u002Fgithub.com\u002Fstanfish06","https:\u002F\u002Fwww.stanfish.dev\u002F","2026-11-14 21:31:37",{"source":8,"skillName":5,"commands":177,"prompt":187,"zipAvailable":44},[178,181,184],{"tool":179,"command":180},"npx","npx skills add stanfish06\u002Fskillquarium --skill dnasp",{"tool":182,"command":183},"bunx","bunx skills add stanfish06\u002Fskillquarium --skill dnasp",{"tool":185,"command":186},"pnpm","pnpm dlx skills add stanfish06\u002Fskillquarium --skill dnasp","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002FSKILL.md",[189,195,201,205,209,214,217],{"path":190,"resourceType":191,"resourceTypeDesc":192,"sizeBytes":193,"sourceHtmlUrl":194},"CONTRIBUTORS.md","REFERENCE","参考文档",947,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002FCONTRIBUTORS.md",{"path":196,"resourceType":197,"resourceTypeDesc":198,"sizeBytes":199,"sourceHtmlUrl":200},"dnasp.py","SCRIPT","脚本",166381,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002Fdnasp.py",{"path":202,"resourceType":191,"resourceTypeDesc":192,"sizeBytes":203,"sourceHtmlUrl":204},"docs\u002Findex.md",72794,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002Fdocs\u002Findex.md",{"path":206,"resourceType":191,"resourceTypeDesc":192,"sizeBytes":207,"sourceHtmlUrl":208},"environment.yml",179,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002Fenvironment.yml",{"path":160,"resourceType":210,"resourceTypeDesc":211,"sizeBytes":212,"sourceHtmlUrl":213},"OTHER","其他",5533,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002Fexamples\u002Fdemo_rp49.fas",{"path":157,"resourceType":210,"resourceTypeDesc":211,"sizeBytes":215,"sourceHtmlUrl":216},132,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002Fexamples\u002Fdemo_simple.fas",{"path":218,"resourceType":197,"resourceTypeDesc":198,"sizeBytes":219,"sourceHtmlUrl":220},"tests\u002Ftest_dnasp.py",113523,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fdnasp\u002Ftests\u002Ftest_dnasp.py",[222,229,238,245,252,259],{"skillNo":223,"name":224,"nameZh":6,"description":225,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":226,"categories":227,"keywords":228,"publishedAt":19},"01M76ZJTRVA456GD7K8Y3EP82H","zarr-python","Stores and queries chunked N-D scientific arrays with Zarr-Python 3, including codecs, sharding, S3\u002FGCS storage, and NumPy\u002FDask\u002FXarray integration. Use for array layout, bounded I\u002FO, format migration, or scientific metadata preservation.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":230,"name":231,"nameZh":6,"description":232,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":233,"licenseFileUrl":234,"sourceHtmlUrl":235,"categories":236,"keywords":237,"publishedAt":19},"01M76ZJQZ15Q1HKC5V85NHE325","yeet","Publish local changes to GitHub by confirming scope, committing intentionally, pushing the branch, and opening a draft PR through the GitHub app from this plugin, with `gh` used only as a fallback where connector coverage is insufficient.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FSKILL.md",[],[],{"skillNo":239,"name":240,"nameZh":6,"description":241,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":233,"licenseFileUrl":6,"sourceHtmlUrl":242,"categories":243,"keywords":244,"publishedAt":19},"01M76ZJ8ASZ4QYQ70Y6SBA4Z4S","xarray","N-dimensional labeled arrays and datasets in Python. Built on top of NumPy and Dask. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, making data analysis in physical sciences more intuitive and less error-prone. Use for working with multi-dimensional scientific data, NetCDF\u002FGRIB\u002FZarr files, climate\u002Fweather\u002Foceanographic datasets, remote sensing, geospatial imaging, large out-of-memory datasets with Dask, and labeled array operations.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fxarray\u002FSKILL.md",[],[],{"skillNo":246,"name":247,"nameZh":6,"description":248,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":249,"categories":250,"keywords":251,"publishedAt":19},"01M76ZHFBXD6VXPQ02VCEG202B","writing-mstest-tests","Use when asked to fix, rewrite, update, improve, modernize, show corrected code for, or explain existing MSTest tests or MSTest-specific configuration. Use for \"review\" when corrected code or edits are wanted, even for one pasted assertion or passing tests with bad failure output. Covers expected\u002Factual labels; generic Boolean, collection, string, numeric, null, identity, exception, hard-cast, and object[] checks; TestContext\u002Flifecycle; timeout\u002Fcancellation; OS\u002FCI conditions, retry, cleanup, parallelization, MSTest.Sdk project setup, and MSTESTxxxx. Honor the installed MSTest version. DO NOT USE to design new test cases (code-testing), perform report-only audits, create project files rather than explain MSTest setup, run tests, migrate frameworks, or handle non-MSTest\u002Fnon-.NET code.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwriting-mstest-tests\u002FSKILL.md",[],[],{"skillNo":253,"name":254,"nameZh":6,"description":255,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":256,"categories":257,"keywords":258,"publishedAt":19},"01M76ZDFDF4N88RH6HSYGS7GP2","wgs-prs","End-to-end WGS to polygenic risk score pipeline. Takes paired-end FASTQ files (or a pre-existing VCF) through nf-core\u002Fsarek for variant calling, applies VCF QC (normalisation, hard filtering, Ti\u002FTv and Het\u002FHom checks), then computes polygenic risk scores via the PGS Catalog. Fills the FASTQ to VCF gap upstream of the gwas-prs skill.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwgs-prs\u002FSKILL.md",[],[],{"skillNo":260,"name":261,"nameZh":6,"description":262,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":233,"licenseFileUrl":263,"sourceHtmlUrl":264,"categories":265,"keywords":266,"publishedAt":19},"01M76ZCC1SC68J42QK4MDC8RCG","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[]]