[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M73HSBTA5WJ540V9C6EMCTW4":3,"skill-same:01M73HSBTA5WJ540V9C6EMCTW4":48},{"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":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M73HSBTA5WJ540V9C6EMCTW4","plink2-gwas-analysis",null,"GWAS and population genetics tool. Processes PLINK (.bed\u002F.bim\u002F.fam), VCF, and BGEN; runs QC (MAF, HWE, missingness), IBD estimation, PCA, and linear\u002Flogistic regression GWAS. Outputs Manhattan-ready summary stats. Use regenie or SAIGE for biobanks (>100k samples) needing mixed models.","bg-szy\u002FTOP-SKILLS","bg-szy","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F106576190?v=4","01M73A4E8KPV67SFXRY8XZGNBX","ShuZhiyong","01M73A4E96MQ294MHM74TZBVQD",6,"GPL-3.0","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fawesome-skills\u002Fplink2-gwas-analysis\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: \"plink2-gwas-analysis\"\ndescription: \"GWAS and population genetics tool. Processes PLINK (.bed\u002F.bim\u002F.fam), VCF, and BGEN; runs QC (MAF, HWE, missingness), IBD estimation, PCA, and linear\u002Flogistic regression GWAS. Outputs Manhattan-ready summary stats. Use regenie or SAIGE for biobanks (>100k samples) needing mixed models.\"\nlicense: \"GPL-3.0\"\n---\n\n# PLINK2 — GWAS and Population Genetics\n\n## Overview\n\nPLINK2 is the high-performance successor to PLINK 1.9, designed for genome-wide association studies (GWAS) and population genetics analysis on large cohorts. It processes genotype data in PLINK binary format (.bed\u002F.bim\u002F.fam), VCF, and BGEN formats — performing sample and variant quality control (QC), kinship estimation, principal component analysis (PCA), and linear\u002Flogistic regression association testing. PLINK2 is 10–100× faster than PLINK 1.9 on most tasks due to multithreading and optimized I\u002FO. Output files are compatible with downstream visualization (Manhattan\u002FQQ plots) and meta-analysis tools.\n\n## When to Use\n\n- Running GWAS on a case-control or quantitative trait cohort after genotyping array QC\n- Performing sample QC: missingness, heterozygosity outliers, sex check, cryptic relatedness\n- Computing genome-wide LD pruning for PCA or relatedness estimation\n- Running PCA on genotype data to identify population stratification\n- Converting between PLINK binary, VCF, and BGEN formats\n- Filtering variants by MAF, HWE, missingness, or INFO score in VCF\u002Fimputed data\n- Use **omics-plotting** SKILL to render Manhattan and QQ plots from the association results\n- Use **regenie** or **SAIGE** instead for biobank-scale GWAS (>100k samples) requiring mixed model association to control for population structure\n- Use **VCFtools** as an alternative for VCF-specific population genetics statistics\n\n## Prerequisites\n\n- **Software**: PLINK2 (pre-compiled binary; no pip\u002Fconda package)\n- **Input**: PLINK binary files (.bed\u002F.bim\u002F.fam) or VCF\u002FBGEN from array genotyping or imputation\n\n> **Check before installing**: The tool may already be available (e.g., inside a `pixi` \u002F `conda` env). Always run `command -v plink2` first and skip the install block if it returns a path. When executing tools inside a pixi project, prefer `pixi run \u003Ctool>` over plain `\u003Ctool>`.\n\n```bash\n# Skip install if already present\nif command -v plink2 >\u002Fdev\u002Fnull 2>&1; then\n    echo \"plink2 already installed: $(plink2 --version)\"\nelse\n    # Download PLINK2 pre-compiled binary (Linux)\n    wget https:\u002F\u002Fs3.amazonaws.com\u002Fplink2-assets\u002Falpha6\u002Fplink2_linux_avx2_20241112.zip\n    unzip plink2_linux_avx2_20241112.zip\n    chmod +x plink2\n    export PATH=\"$PWD:$PATH\"\n\n    # macOS\n    # wget https:\u002F\u002Fs3.amazonaws.com\u002Fplink2-assets\u002Falpha6\u002Fplink2_mac_20241112.zip\n    # unzip plink2_mac_20241112.zip\n\n    plink2 --version\n    # PLINK v2.00a6LM\nfi\n\n# Python for downstream analysis\npip install pandas numpy matplotlib scipy\n```\n\n## Pre-flight Interview\n\nSettle these with the user before writing any analysis code.\n\n```yaml\ndecisions:\n  - id: D1\n    param: phenotype\n    kind: required\n    source: data\n    ask: \"Which column holds the trait being tested, and is it a measurement or a case\u002Fcontrol status?\"\n    default: null\n\n  - id: D2\n    param: regressionMode\n    kind: derived\n    source: data\n    depends_on: [D1]\n    ask: \"Should the association test be linear or logistic?\"\n    default: \"linear for a quantitative trait, logistic for case\u002Fcontrol\"\n\n  - id: D3\n    param: qcThresholds\n    kind: required\n    source: user\n    ask: \"Where should variants and samples be cut for allele frequency, missingness, and Hardy-Weinberg departure?\"\n    default: \"MAF 0.01, variant missingness 0.05, sample missingness 0.02, HWE 1e-6\"\n\n  - id: D4\n    param: covariates\n    kind: required\n    source: data\n    ask: \"Which covariates belong in the model - age, sex, batch, study site?\"\n    default: null\n\n  - id: D5\n    param: populationStructure\n    kind: required\n    source: user\n    ask: \"How many principal components should be included to absorb ancestry differences?\"\n    default: \"10, computed from LD-pruned variants\"\n\n  - id: D6\n    param: ldPruning\n    kind: optional\n    source: user\n    depends_on: [D5]\n    ask: \"Which window and correlation threshold should thin variants before computing the components?\"\n    default: \"50 variant window, step 5, r-squared 0.2\"\n\n  - id: D7\n    param: threads\n    kind: never_ask\n    source: data\n    reason: \"Affects runtime only, not the association statistics\"\n    default: \"min(8, available_cores)\"\n```\n\nD5 hangs on D4 because the components are themselves covariates - how many to\ninclude is a question about the covariate set, not a separate knob. Omitting\nthem entirely is the classic way to produce a genome-wide significant result\nthat reflects ancestry rather than the trait.\n\n## Quick Start\n\n```bash\n# Run GWAS: linear regression for quantitative trait\nplink2 \\\n    --bfile cohort_qc \\\n    --pheno phenotypes.txt \\\n    --covar covariates.txt \\\n    --linear hide-covar \\\n    --out results\u002Fgwas_result \\\n    --threads 8\n\n# View top hits\nhead results\u002Fgwas_result.*.glm.linear | sort -k12,12g | head -20\n```\n\n## Workflow\n\n### Step 1: Convert VCF\u002FImputed Data to PLINK Binary Format\n\nConvert input genotype data to PLINK binary format for fast processing.\n\n```bash\n# Convert VCF to PLINK binary\nplink2 \\\n    --vcf cohort_genotyped.vcf.gz \\\n    --make-bed \\\n    --out cohort_plink \\\n    --threads 8\n\n# Convert BGEN (imputed data from Michigan\u002FTopMed imputation server)\nplink2 \\\n    --bgen cohort_imputed.bgen ref-first \\\n    --sample cohort_imputed.sample \\\n    --make-bed \\\n    --out cohort_imputed_plink \\\n    --threads 8\n\necho \"Files created:\"\nls -lh cohort_plink.{bed,bim,fam}\necho \"Samples: $(wc -l \u003C cohort_plink.fam)\"\necho \"Variants: $(wc -l \u003C cohort_plink.bim)\"\n```\n\n### Step 2: Sample QC — Missingness and Heterozygosity\n\nRemove samples with high missingness or heterozygosity outliers.\n\n```bash\n# Compute per-sample and per-variant missingness\nplink2 \\\n    --bfile cohort_plink \\\n    --missing \\\n    --out qc\u002Fsample_missingness \\\n    --threads 8\n\n# Remove samples with > 2% missingness and variants with > 5% missing\nplink2 \\\n    --bfile cohort_plink \\\n    --mind 0.02 \\\n    --geno 0.05 \\\n    --make-bed \\\n    --out cohort_sample_qc \\\n    --threads 8\n\necho \"After sample QC:\"\necho \"Samples: $(wc -l \u003C cohort_sample_qc.fam)\"\necho \"Variants: $(wc -l \u003C cohort_sample_qc.bim)\"\n```\n\n### Step 3: Variant QC — MAF, HWE, and INFO Score Filtering\n\nFilter variants by minor allele frequency, Hardy-Weinberg equilibrium, and imputation quality.\n\n```bash\n# Variant QC: MAF, HWE, missingness\nplink2 \\\n    --bfile cohort_sample_qc \\\n    --maf 0.01 \\\n    --hwe 1e-6 \\\n    --geno 0.05 \\\n    --make-bed \\\n    --out cohort_variantqc \\\n    --threads 8\n\necho \"After variant QC:\"\necho \"Variants remaining: $(wc -l \u003C cohort_variantqc.bim)\"\n\n# For imputed data: also filter by INFO score (using VCF INFO field)\n# plink2 --bfile cohort_variantqc --var-min-qual 0.8 --make-bed --out cohort_info_qc\n```\n\n### Step 4: LD Pruning and PCA for Population Stratification\n\nCompute principal components from LD-pruned variants.\n\n```bash\n# LD pruning: remove one variant from each pair with r² > 0.2\nplink2 \\\n    --bfile cohort_variantqc \\\n    --indep-pairwise 50 5 0.2 \\\n    --out qc\u002Fld_pruned \\\n    --threads 8\n\n# Compute PCA on LD-pruned variants (top 20 PCs)\nplink2 \\\n    --bfile cohort_variantqc \\\n    --extract qc\u002Fld_pruned.prune.in \\\n    --pca 20 \\\n    --out pca\u002Fcohort_pca \\\n    --threads 8\n\necho \"PCA files: pca\u002Fcohort_pca.eigenvec (PCs) and pca\u002Fcohort_pca.eigenval (variance)\"\nhead pca\u002Fcohort_pca.eigenvec\n```\n\n### Step 5: Run GWAS Association Analysis\n\nPerform logistic regression (case-control) or linear regression (quantitative trait).\n\n```bash\n# Case-control GWAS: logistic regression with covariates\nplink2 \\\n    --bfile cohort_variantqc \\\n    --pheno phenotypes.txt \\\n    --1 \\\n    --covar covariates.txt \\\n    --covar-variance-standardize \\\n    --logistic hide-covar \\\n    --ci 0.95 \\\n    --out results\u002Fgwas_cc \\\n    --threads 8\n\n# Quantitative trait GWAS: linear regression\nplink2 \\\n    --bfile cohort_variantqc \\\n    --pheno phenotypes.txt \\\n    --covar covariates.txt \\\n    --covar-variance-standardize \\\n    --linear hide-covar \\\n    --ci 0.95 \\\n    --out results\u002Fgwas_qt \\\n    --threads 8\n\necho \"GWAS complete. Files: results\u002Fgwas_*.glm.*\"\nwc -l results\u002Fgwas_qt.*.glm.linear\n```\n\n### Step 6: Plot Manhattan and QQ Plots\n\nPrepare the association results as a CHR\u002FBP\u002FP table, then **read `skills\u002Fdata-visualization\u002Fomics-plotting\u002FSKILL.md` and follow its \"Manhattan\" and \"QQ plot\" recipes** on the exported CSV (→ `figures\u002Fmanhattan.png`, `figures\u002Fqq.png`).\n\n```python\nimport pandas as pd\n\n# Load GWAS results (PLINK2 linear output) as a CHR\u002FBP\u002FP table for plotting\ndf = pd.read_csv(\"results\u002Fgwas_qt.PHENO1.glm.linear\", sep=\"\\t\",\n                 usecols=[\"#CHROM\", \"POS\", \"ID\", \"P\"])\ndf.columns = [\"CHR\", \"BP\", \"SNP\", \"P\"]\ndf = df.dropna(subset=[\"P\"])\ndf[\"P\"] = pd.to_numeric(df[\"P\"], errors=\"coerce\")\ndf = df[df[\"P\"] > 0].copy()\ndf.to_csv(\"gwas.csv\", index=False)\n\nprint(f\"Variants: {len(df)}\")\nprint(f\"Genome-wide significant (p\u003C5e-8): {(df['P'] \u003C 5e-8).sum()}\")\n# Render with the omics-plotting SKILL (`skills\u002Fdata-visualization\u002Fomics-plotting\u002FSKILL.md`) \"Manhattan\" and \"QQ plot\" recipes (input columns CHR, BP, P).\n```\n\n## Key Parameters\n\n| Parameter | Default | Range\u002FOptions | Effect |\n|-----------|---------|---------------|--------|\n| `--maf` | — | 0–0.5 | Minor allele frequency threshold; `0.01` removes singletons |\n| `--hwe` | — | 0–1 | Hardy-Weinberg equilibrium p-value threshold; `1e-6` typical |\n| `--geno` | — | 0–1 | Maximum variant missingness; `0.05` = 5% |\n| `--mind` | — | 0–1 | Maximum sample missingness; `0.02` = 2% |\n| `--linear` \u002F `--logistic` | — | flag | Regression mode: linear for quantitative, logistic for case-control |\n| `--covar` | — | file path | Covariate file (FID IID COV1 COV2...); add PCs here |\n| `--pca` | — | integer | Number of PCs to compute from LD-pruned data |\n| `--indep-pairwise` | — | window step r² | LD pruning: window size (variants), step, r² threshold |\n| `--threads` | `1` | 1–64 | CPU threads; 8–16 typical for cluster |\n| `--ci` | — | 0–1 | Confidence interval for effect size output (0.95 for 95% CI) |\n| `--1` | off | flag | Recode phenotype: 1=control, 2=case → 0=control, 1=case (logistic) |\n\n## Common Recipes\n\n### Recipe 1: Relatedness QC and Remove One from Each Related Pair\n\n```bash\n# Compute kinship coefficients (King-robust estimator)\nplink2 \\\n    --bfile cohort_variantqc \\\n    --extract qc\u002Fld_pruned.prune.in \\\n    --king-cutoff 0.0625 \\\n    --out qc\u002Fkinship \\\n    --threads 8\n\n# Remove related individuals (king-cutoff auto-generates exclusion list)\nplink2 \\\n    --bfile cohort_variantqc \\\n    --remove qc\u002Fkinship.king.cutoff.out.id \\\n    --make-bed \\\n    --out cohort_unrelated \\\n    --threads 8\n\necho \"After relatedness QC: $(wc -l \u003C cohort_unrelated.fam) samples\"\n```\n\n### Recipe 2: Parse GWAS Results and Report Top Hits\n\n```python\nimport pandas as pd\nimport numpy as np\n\ndef load_gwas_results(filepath: str, p_threshold: float = 5e-8) -> pd.DataFrame:\n    \"\"\"Load PLINK2 GWAS linear\u002Flogistic output and return genome-wide significant hits.\"\"\"\n    df = pd.read_csv(filepath, sep=\"\\t\",\n                     usecols=[\"#CHROM\", \"POS\", \"ID\", \"REF\", \"ALT\", \"A1\", \"BETA\", \"SE\", \"P\"])\n    df.columns = [\"CHR\", \"POS\", \"SNP\", \"REF\", \"ALT\", \"A1\", \"BETA\", \"SE\", \"P\"]\n    df = df.dropna(subset=[\"P\"])\n    df[\"P\"] = pd.to_numeric(df[\"P\"], errors=\"coerce\")\n    sig = df[df[\"P\"] \u003C p_threshold].sort_values(\"P\")\n    return sig\n\n# Load results for one phenotype\nhits = load_gwas_results(\"results\u002Fgwas_qt.PHENO1.glm.linear\")\nprint(f\"Genome-wide significant loci: {len(hits)}\")\nprint(hits.head(10)[[\"CHR\", \"POS\", \"SNP\", \"BETA\", \"SE\", \"P\"]])\nhits.to_csv(\"gwas_top_hits.tsv\", sep=\"\\t\", index=False)\n```\n\n## Expected Outputs\n\n| Output | Format | Description |\n|--------|--------|-------------|\n| `*.glm.linear` | TSV | Linear GWAS results: CHR, POS, ID, BETA, SE, P per variant |\n| `*.glm.logistic.hybrid` | TSV | Logistic GWAS results: OR, 95% CI, P per variant |\n| `*.eigenvec` | TSV | PCA loadings: FID IID PC1 PC2 ... PC20 |\n| `*.eigenval` | Text | Eigenvalues for PCA variance explained |\n| `*.king.cutoff.out.id` | TSV | Sample IDs to remove for relatedness QC |\n| `*.bed\u002F.bim\u002F.fam` | Binary | PLINK binary format after QC filtering |\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| `Error: No samples left after --mind filter` | Missingness threshold too strict | Relax to `--mind 0.05`; check input data quality |\n| Logistic regression fails to converge | Rare variant, few cases, or collinear covariates | Use `--logistic firth` for Firth regression; remove correlated covariates |\n| PCA shows clear outlier cluster | Admixed population or sample contamination | Remove outliers using PC cutoffs; check ancestry with 1000 Genomes reference panel |\n| `--hwe` removes too many variants | Population structure inflating HWE test | Apply HWE filter to controls only: `--hwe 1e-6 ctrl-only` |\n| BGEN import fails | Wrong ref-first\u002Fref-last flag | Check imputation server documentation; try `--bgen file.bgen ref-last` |\n| Very slow association test | Too many covariates or large file | Pre-filter to GWAS-significant window; use `--threads 16` |\n| Sex mismatch warnings | X chromosome heterozygosity outside sex-specific thresholds | Run `--check-sex` and remove F-statistic outliers |\n| Memory error on large dataset | RAM insufficient for 500k+ variants | Use `--memory 32000` to cap RAM; split by chromosome |\n\n## References\n\n- [PLINK2 documentation](https:\u002F\u002Fwww.cog-genomics.org\u002Fplink\u002F2.0\u002F) — official command reference and tutorials\n- [PLINK2 GitHub: chrchang\u002Fplink-ng](https:\u002F\u002Fgithub.com\u002Fchrchang\u002Fplink-ng) — source code and releases\n- Chang CC et al. (2015) \"Second-generation PLINK: rising to the challenge of larger and richer datasets\" — *GigaScience* 4:7. [DOI:10.1186\u002Fs13742-015-0047-8](https:\u002F\u002Fdoi.org\u002F10.1186\u002Fs13742-015-0047-8)\n- [GWAS best practices (Marees et al. 2018)](https:\u002F\u002Fdoi.org\u002F10.1002\u002Fmpr.1608) — comprehensive QC and analysis guide\n","# PLINK2 — GWAS and Population Genetics\n\n## Overview\n\nPLINK2 is the high-performance successor to PLINK 1.9, designed for genome-wide association studies (GWAS) and population genetics analysis on large cohorts. It processes genotype data in PLINK binary format (.bed\u002F.bim\u002F.fam), VCF, and BGEN formats — performing sample and variant quality control (QC), kinship estimation, principal component analysis (PCA), and linear\u002Flogistic regression association testing. PLINK2 is 10–100× faster than PLINK 1.9 on most tasks due to multithreading and optimized I\u002FO. Output files are compatible with downstream visualization (Manhattan\u002FQQ plots) and meta-analysis tools.\n\n## When to Use\n\n- Running GWAS on a case-control or quantitative trait cohort after genotyping array QC\n- Performing sample QC: missingness, heterozygosity outliers, sex check, cryptic relatedness\n- Computing genome-wide LD pruning for PCA or relatedness estimation\n- Running PCA on genotype data to identify population stratification\n- Converting between PLINK binary, VCF, and BGEN formats\n- Filtering variants by MAF, HWE, missingness, or INFO score in VCF\u002Fimputed data\n- Use **omics-plotting** SKILL to render Manhattan and QQ plots from the association results\n- Use **regenie** or **SAIGE** instead for biobank-scale GWAS (>100k samples) requiring mixed model association to control for population structure\n- Use **VCFtools** as an alternative for VCF-specific population genetics statistics\n\n## Prerequisites\n\n- **Software**: PLINK2 (pre-compiled binary; no pip\u002Fconda package)\n- **Input**: PLINK binary files (.bed\u002F.bim\u002F.fam) or VCF\u002FBGEN from array genotyping or imputation\n\n> **Check before installing**: The tool may already be available (e.g., inside a `pixi` \u002F `conda` env). Always run `command -v plink2` first and skip the install block if it returns a path. When executing tools inside a pixi project, prefer `pixi run \u003Ctool>` over plain `\u003Ctool>`.\n\n```bash\n# Skip install if already present\nif command -v plink2 >\u002Fdev\u002Fnull 2>&1; then\n    echo \"plink2 already installed: $(plink2 --version)\"\nelse\n    # Download PLINK2 pre-compiled binary (Linux)\n    wget https:\u002F\u002Fs3.amazonaws.com\u002Fplink2-assets\u002Falpha6\u002Fplink2_linux_avx2_20241112.zip\n    unzip plink2_linux_avx2_20241112.zip\n    chmod +x plink2\n    export PATH=\"$PWD:$PATH\"\n\n    # macOS\n    # wget https:\u002F\u002Fs3.amazonaws.com\u002Fplink2-assets\u002Falpha6\u002Fplink2_mac_20241112.zip\n    # unzip plink2_mac_20241112.zip\n\n    plink2 --version\n    # PLINK v2.00a6LM\nfi\n\n# Python for downstream analysis\npip install pandas numpy matplotlib scipy\n```\n\n## Pre-flight Interview\n\nSettle these with the user before writing any analysis code.\n\n```yaml\ndecisions:\n  - id: D1\n    param: phenotype\n    kind: required\n    source: data\n    ask: \"Which column holds the trait being tested, and is it a measurement or a case\u002Fcontrol status?\"\n    default: null\n\n  - id: D2\n    param: regressionMode\n    kind: derived\n    source: data\n    depends_on: [D1]\n    ask: \"Should the association test be linear or logistic?\"\n    default: \"linear for a quantitative trait, logistic for case\u002Fcontrol\"\n\n  - id: D3\n    param: qcThresholds\n    kind: required\n    source: user\n    ask: \"Where should variants and samples be cut for allele frequency, missingness, and Hardy-Weinberg departure?\"\n    default: \"MAF 0.01, variant missingness 0.05, sample missingness 0.02, HWE 1e-6\"\n\n  - id: D4\n    param: covariates\n    kind: required\n    source: data\n    ask: \"Which covariates belong in the model - age, sex, batch, study site?\"\n    default: null\n\n  - id: D5\n    param: populationStructure\n    kind: required\n    source: user\n    ask: \"How many principal components should be included to absorb ancestry differences?\"\n    default: \"10, computed from LD-pruned variants\"\n\n  - id: D6\n    param: ldPruning\n    kind: optional\n    source: user\n    depends_on: [D5]\n    ask: \"Which window and correlation threshold should thin variants before computing the components?\"\n    default: \"50 variant window, step 5, r-squared 0.2\"\n\n  - id: D7\n    param: threads\n    kind: never_ask\n    source: data\n    reason: \"Affects runtime only, not the association statistics\"\n    default: \"min(8, available_cores)\"\n```\n\nD5 hangs on D4 because the components are themselves covariates - how many to\ninclude is a question about the covariate set, not a separate knob. Omitting\nthem entirely is the classic way to produce a genome-wide significant result\nthat reflects ancestry rather than the trait.\n\n## Quick Start\n\n```bash\n# Run GWAS: linear regression for quantitative trait\nplink2 \\\n    --bfile cohort_qc \\\n    --pheno phenotypes.txt \\\n    --covar covariates.txt \\\n    --linear hide-covar \\\n    --out results\u002Fgwas_result \\\n    --threads 8\n\n# View top hits\nhead results\u002Fgwas_result.*.glm.linear | sort -k12,12g | head -20\n```\n\n## Workflow\n\n### Step 1: Convert VCF\u002FImputed Data to PLINK Binary Format\n\nConvert input genotype data to PLINK binary format for fast processing.\n\n```bash\n# Convert VCF to PLINK binary\nplink2 \\\n    --vcf cohort_genotyped.vcf.gz \\\n    --make-bed \\\n    --out cohort_plink \\\n    --threads 8\n\n# Convert BGEN (imputed data from Michigan\u002FTopMed imputation server)\nplink2 \\\n    --bgen cohort_imputed.bgen ref-first \\\n    --sample cohort_imputed.sample \\\n    --make-bed \\\n    --out cohort_imputed_plink \\\n    --threads 8\n\necho \"Files created:\"\nls -lh cohort_plink.{bed,bim,fam}\necho \"Samples: $(wc -l \u003C cohort_plink.fam)\"\necho \"Variants: $(wc -l \u003C cohort_plink.bim)\"\n```\n\n### Step 2: Sample QC — Missingness and Heterozygosity\n\nRemove samples with high missingness or heterozygosity outliers.\n\n```bash\n# Compute per-sample and per-variant missingness\nplink2 \\\n    --bfile cohort_plink \\\n    --missing \\\n    --out qc\u002Fsample_missingness \\\n    --threads 8\n\n# Remove samples with > 2% missingness and variants with > 5% missing\nplink2 \\\n    --bfile cohort_plink \\\n    --mind 0.02 \\\n    --geno 0.05 \\\n    --make-bed \\\n    --out cohort_sample_qc \\\n    --threads 8\n\necho \"After sample QC:\"\necho \"Samples: $(wc -l \u003C cohort_sample_qc.fam)\"\necho \"Variants: $(wc -l \u003C cohort_sample_qc.bim)\"\n```\n\n### Step 3: Variant QC — MAF, HWE, and INFO Score Filtering\n\nFilter variants by minor allele frequency, Hardy-Weinberg equilibrium, and imputation quality.\n\n```bash\n# Variant QC: MAF, HWE, missingness\nplink2 \\\n    --bfile cohort_sample_qc \\\n    --maf 0.01 \\\n    --hwe 1e-6 \\\n    --geno 0.05 \\\n    --make-bed \\\n    --out cohort_variantqc \\\n    --threads 8\n\necho \"After variant QC:\"\necho \"Variants remaining: $(wc -l \u003C cohort_variantqc.bim)\"\n\n# For imputed data: also filter by INFO score (using VCF INFO field)\n# plink2 --bfile cohort_variantqc --var-min-qual 0.8 --make-bed --out cohort_info_qc\n```\n\n### Step 4: LD Pruning and PCA for Population Stratification\n\nCompute principal components from LD-pruned variants.\n\n```bash\n# LD pruning: remove one variant from each pair with r² > 0.2\nplink2 \\\n    --bfile cohort_variantqc \\\n    --indep-pairwise 50 5 0.2 \\\n    --out qc\u002Fld_pruned \\\n    --threads 8\n\n# Compute PCA on LD-pruned variants (top 20 PCs)\nplink2 \\\n    --bfile cohort_variantqc \\\n    --extract qc\u002Fld_pruned.prune.in \\\n    --pca 20 \\\n    --out pca\u002Fcohort_pca \\\n    --threads 8\n\necho \"PCA files: pca\u002Fcohort_pca.eigenvec (PCs) and pca\u002Fcohort_pca.eigenval (variance)\"\nhead pca\u002Fcohort_pca.eigenvec\n```\n\n### Step 5: Run GWAS Association Analysis\n\nPerform logistic regression (case-control) or linear regression (quantitative trait).\n\n```bash\n# Case-control GWAS: logistic regression with covariates\nplink2 \\\n    --bfile cohort_variantqc \\\n    --pheno phenotypes.txt \\\n    --1 \\\n    --covar covariates.txt \\\n    --covar-variance-standardize \\\n    --logistic hide-covar \\\n    --ci 0.95 \\\n    --out results\u002Fgwas_cc \\\n    --threads 8\n\n# Quantitative trait GWAS: linear regression\nplink2 \\\n    --bfile cohort_variantqc \\\n    --pheno phenotypes.txt \\\n    --covar covariates.txt \\\n    --covar-variance-standardize \\\n    --linear hide-covar \\\n    --ci 0.95 \\\n    --out results\u002Fgwas_qt \\\n    --threads 8\n\necho \"GWAS complete. Files: results\u002Fgwas_*.glm.*\"\nwc -l results\u002Fgwas_qt.*.glm.linear\n```\n\n### Step 6: Plot Manhattan and QQ Plots\n\nPrepare the association results as a CHR\u002FBP\u002FP table, then **read `skills\u002Fdata-visualization\u002Fomics-plotting\u002FSKILL.md` and follow its \"Manhattan\" and \"QQ plot\" recipes** on the exported CSV (→ `figures\u002Fmanhattan.png`, `figures\u002Fqq.png`).\n\n```python\nimport pandas as pd\n\n# Load GWAS results (PLINK2 linear output) as a CHR\u002FBP\u002FP table for plotting\ndf = pd.read_csv(\"results\u002Fgwas_qt.PHENO1.glm.linear\", sep=\"\\t\",\n                 usecols=[\"#CHROM\", \"POS\", \"ID\", \"P\"])\ndf.columns = [\"CHR\", \"BP\", \"SNP\", \"P\"]\ndf = df.dropna(subset=[\"P\"])\ndf[\"P\"] = pd.to_numeric(df[\"P\"], errors=\"coerce\")\ndf = df[df[\"P\"] > 0].copy()\ndf.to_csv(\"gwas.csv\", index=False)\n\nprint(f\"Variants: {len(df)}\")\nprint(f\"Genome-wide significant (p\u003C5e-8): {(df['P'] \u003C 5e-8).sum()}\")\n# Render with the omics-plotting SKILL (`skills\u002Fdata-visualization\u002Fomics-plotting\u002FSKILL.md`) \"Manhattan\" and \"QQ plot\" recipes (input columns CHR, BP, P).\n```\n\n## Key Parameters\n\n| Parameter | Default | Range\u002FOptions | Effect |\n|-----------|---------|---------------|--------|\n| `--maf` | — | 0–0.5 | Minor allele frequency threshold; `0.01` removes singletons |\n| `--hwe` | — | 0–1 | Hardy-Weinberg equilibrium p-value threshold; `1e-6` typical |\n| `--geno` | — | 0–1 | Maximum variant missingness; `0.05` = 5% |\n| `--mind` | — | 0–1 | Maximum sample missingness; `0.02` = 2% |\n| `--linear` \u002F `--logistic` | — | flag | Regression mode: linear for quantitative, logistic for case-control |\n| `--covar` | — | file path | Covariate file (FID IID COV1 COV2...); add PCs here |\n| `--pca` | — | integer | Number of PCs to compute from LD-pruned data |\n| `--indep-pairwise` | — | window step r² | LD pruning: window size (variants), step, r² threshold |\n| `--threads` | `1` | 1–64 | CPU threads; 8–16 typical for cluster |\n| `--ci` | — | 0–1 | Confidence interval for effect size output (0.95 for 95% CI) |\n| `--1` | off | flag | Recode phenotype: 1=control, 2=case → 0=control, 1=case (logistic) |\n\n## Common Recipes\n\n### Recipe 1: Relatedness QC and Remove One from Each Related Pair\n\n```bash\n# Compute kinship coefficients (King-robust estimator)\nplink2 \\\n    --bfile cohort_variantqc \\\n    --extract qc\u002Fld_pruned.prune.in \\\n    --king-cutoff 0.0625 \\\n    --out qc\u002Fkinship \\\n    --threads 8\n\n# Remove related individuals (king-cutoff auto-generates exclusion list)\nplink2 \\\n    --bfile cohort_variantqc \\\n    --remove qc\u002Fkinship.king.cutoff.out.id \\\n    --make-bed \\\n    --out cohort_unrelated \\\n    --threads 8\n\necho \"After relatedness QC: $(wc -l \u003C cohort_unrelated.fam) samples\"\n```\n\n### Recipe 2: Parse GWAS Results and Report Top Hits\n\n```python\nimport pandas as pd\nimport numpy as np\n\ndef load_gwas_results(filepath: str, p_threshold: float = 5e-8) -> pd.DataFrame:\n    \"\"\"Load PLINK2 GWAS linear\u002Flogistic output and return genome-wide significant hits.\"\"\"\n    df = pd.read_csv(filepath, sep=\"\\t\",\n                     usecols=[\"#CHROM\", \"POS\", \"ID\", \"REF\", \"ALT\", \"A1\", \"BETA\", \"SE\", \"P\"])\n    df.columns = [\"CHR\", \"POS\", \"SNP\", \"REF\", \"ALT\", \"A1\", \"BETA\", \"SE\", \"P\"]\n    df = df.dropna(subset=[\"P\"])\n    df[\"P\"] = pd.to_numeric(df[\"P\"], errors=\"coerce\")\n    sig = df[df[\"P\"] \u003C p_threshold].sort_values(\"P\")\n    return sig\n\n# Load results for one phenotype\nhits = load_gwas_results(\"results\u002Fgwas_qt.PHENO1.glm.linear\")\nprint(f\"Genome-wide significant loci: {len(hits)}\")\nprint(hits.head(10)[[\"CHR\", \"POS\", \"SNP\", \"BETA\", \"SE\", \"P\"]])\nhits.to_csv(\"gwas_top_hits.tsv\", sep=\"\\t\", index=False)\n```\n\n## Expected Outputs\n\n| Output | Format | Description |\n|--------|--------|-------------|\n| `*.glm.linear` | TSV | Linear GWAS results: CHR, POS, ID, BETA, SE, P per variant |\n| `*.glm.logistic.hybrid` | TSV | Logistic GWAS results: OR, 95% CI, P per variant |\n| `*.eigenvec` | TSV | PCA loadings: FID IID PC1 PC2 ... PC20 |\n| `*.eigenval` | Text | Eigenvalues for PCA variance explained |\n| `*.king.cutoff.out.id` | TSV | Sample IDs to remove for relatedness QC |\n| `*.bed\u002F.bim\u002F.fam` | Binary | PLINK binary format after QC filtering |\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| `Error: No samples left after --mind filter` | Missingness threshold too strict | Relax to `--mind 0.05`; check input data quality |\n| Logistic regression fails to converge | Rare variant, few cases, or collinear covariates | Use `--logistic firth` for Firth regression; remove correlated covariates |\n| PCA shows clear outlier cluster | Admixed population or sample contamination | Remove outliers using PC cutoffs; check ancestry with 1000 Genomes reference panel |\n| `--hwe` removes too many variants | Population structure inflating HWE test | Apply HWE filter to controls only: `--hwe 1e-6 ctrl-only` |\n| BGEN import fails | Wrong ref-first\u002Fref-last flag | Check imputation server documentation; try `--bgen file.bgen ref-last` |\n| Very slow association test | Too many covariates or large file | Pre-filter to GWAS-significant window; use `--threads 16` |\n| Sex mismatch warnings | X chromosome heterozygosity outside sex-specific thresholds | Run `--check-sex` and remove F-statistic outliers |\n| Memory error on large dataset | RAM insufficient for 500k+ variants | Use `--memory 32000` to cap RAM; split by chromosome |\n\n## References\n\n- [PLINK2 documentation](https:\u002F\u002Fwww.cog-genomics.org\u002Fplink\u002F2.0\u002F) — official command reference and tutorials\n- [PLINK2 GitHub: chrchang\u002Fplink-ng](https:\u002F\u002Fgithub.com\u002Fchrchang\u002Fplink-ng) — source code and releases\n- Chang CC et al. (2015) \"Second-generation PLINK: rising to the challenge of larger and richer datasets\" — *GigaScience* 4:7. [DOI:10.1186\u002Fs13742-015-0047-8](https:\u002F\u002Fdoi.org\u002F10.1186\u002Fs13742-015-0047-8)\n- [GWAS best practices (Marees et al. 2018)](https:\u002F\u002Fdoi.org\u002F10.1002\u002Fmpr.1608) — comprehensive QC and analysis guide\n",{"name":5,"license":15,"description":7},"master","fd76f882a04e445e899d5cfb2732f2105ea054ee","skills\u002Fawesome-skills\u002Fplink2-gwas-analysis",0,"https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS","https:\u002F\u002Fbg-szy.github.io\u002FTOP-SKILLS\u002F","https:\u002F\u002Fgithub.com\u002Fbg-szy","https:\u002F\u002Fwww.ecust.edu.cn\u002F","a student of East China University of Science and Technology","2026-11-15 03:38:02",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add bg-szy\u002FTOP-SKILLS --skill plink2-gwas-analysis",{"tool":40,"command":41},"bunx","bunx skills add bg-szy\u002FTOP-SKILLS --skill plink2-gwas-analysis",{"tool":43,"command":44},"pnpm","pnpm dlx skills add bg-szy\u002FTOP-SKILLS --skill plink2-gwas-analysis","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fawesome-skills\u002Fplink2-gwas-analysis\u002FSKILL.md",true,[],[49,59,67,75,84,91],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":54,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":58},"01M748668J70YKWKS2VFVZ0ZRF","xlsx","Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like \"the xlsx in my downloads\") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fskills\u002Fxlsx\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fskills\u002Fxlsx\u002FSKILL.md",[],[],"2026-11-12 13:55:43",{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":63,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":58},"01M747X09GNGYJ7V4YE3NGGH7A","pptx","Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions \"deck,\" \"slides,\" \"presentation,\" or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fskills\u002Fpptx\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fskills\u002Fpptx\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":71,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":58},"01M747QR3VN12KXYDZGRXETTGS","docx","Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fskills\u002Fdocx\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fskills\u002Fdocx\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":80,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":58},"01M76KTXGSTXVVDC7YSBM41ZZS","wxpusher-integration","Use when（适用场景）：用户明确询问、指定或上下文已选定 WxPusher，需要了解、接入或排查通知（含微信 ClawBot\u002FiLink、appToken、UID、Topic、SPT）；仅说“微信通知”、未选服务商，或只出现通用 UID\u002FTopic 时不触发。","MIT","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Fwxpusher-integration\u002FLICENSE.md","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Fwxpusher-integration\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M748C5DS5BQBVBMG22FCGG34","branding","When the user wants to define, audit, or apply brand strategy—purpose, values, positioning, storytelling, voice, narrative (not only visuals). Also use when the user mentions \"brand strategy\", \"brand story\", \"brand storytelling\" or \"brand voice\". For typography, colors, design tokens, and frontend visuals, use brand-visual-generator.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fsuperskills\u002Fbranding\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":19},"01M748C1GXJ9WRKP18X45DKP6G","brand-visual-generator","When the user wants to define, audit, or apply visual identity (typography, colors, spacing, design tokens, frontend aesthetics). Also use when the user mentions \"brand style guide\", \"visual identity\", \"design system\" or \"typography\". For brand story, positioning, and voice, use branding.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fsuperskills\u002Fbrand-visual-generator\u002FSKILL.md",[],[]]