
Bio Population Genetics Plink Basics
- 3 installs
- 1.1k repo stars
- Updated July 25, 2026
- gptomics/bioskills
Convert genotype file formats and apply MAF, call-rate, and HWE quality filters using PLINK 1.9 and 2.0.
About
Handles PLINK file formats, format conversion, and quality-control filtering for population genetics using PLINK 1.9 and 2.0. Developers use it to convert genotype files and apply MAF, call-rate, and HWE filters.
- Convert VCF, BED/BIM/FAM, and PED/MAP formats
- MAF, genotyping-rate, and HWE QC filters in PLINK 1.9/2.0
Bio Population Genetics Plink Basics by the numbers
- 3 all-time installs (skills.sh)
- Ranked #1,661 of 2,064 Data Science & ML skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/gptomics/bioskills --skill bio-population-genetics-plink-basicsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 3 |
|---|---|
| repo stars | ★ 1.1k |
| Last updated | July 25, 2026 |
| Repository | gptomics/bioskills ↗ |
What it does
Convert genotype file formats and apply MAF, call-rate, and HWE quality filters using PLINK 1.9 and 2.0.
Files
PLINK Basics
File formats, conversion, and quality control filtering with PLINK 1.9 and 2.0.
File Formats
Binary Format (Recommended)
| File | Contents |
|---|---|
.bed | Binary genotype data |
.bim | Variant information (chr, ID, cM, pos, A1, A2) |
.fam | Sample information (FID, IID, father, mother, sex, pheno) |
PLINK 2.0 Format
| File | Contents |
|---|---|
.pgen | Binary genotype data (compressed) |
.pvar | Variant information |
.psam | Sample information |
Text Format (Legacy)
| File | Contents |
|---|---|
.ped | Genotypes (FID, IID, father, mother, sex, pheno, genotypes) |
.map | Variant positions (chr, ID, cM, pos) |
Format Conversion
VCF to PLINK Binary
# PLINK 1.9
plink --vcf input.vcf.gz --make-bed --out output
# PLINK 2.0
plink2 --vcf input.vcf.gz --make-bed --out output
# With sample ID handling
plink2 --vcf input.vcf.gz --double-id --make-bed --out outputPLINK Binary to VCF
# PLINK 1.9
plink --bfile input --recode vcf --out output
# PLINK 2.0
plink2 --bfile input --export vcf --out output
# Compressed VCF
plink2 --bfile input --export vcf bgz --out outputPED/MAP to Binary (PLINK 1.9 Only)
# PLINK 1.9 (PLINK 2.0 doesn't support .ped/.map directly)
plink --file input --make-bed --out outputBinary to PED/MAP
# PLINK 1.9
plink --bfile input --recode --out output
# PLINK 2.0
plink2 --bfile input --export ped --out outputPLINK 1.9 to 2.0 Format
# Convert to PGEN format
plink2 --bfile input --make-pgen --out output
# Convert back to BED
plink2 --pfile input --make-bed --out outputQuality Control Filtering
MAF Filter (Minor Allele Frequency)
# Remove variants with MAF < 0.01
plink --bfile input --maf 0.01 --make-bed --out output
# PLINK 2.0
plink2 --bfile input --maf 0.01 --make-bed --out output
# Remove rare variants (MAF < 0.05)
plink2 --bfile input --maf 0.05 --make-bed --out outputGenotyping Rate Filters
# Per-variant missing rate (remove if >5% missing)
plink2 --bfile input --geno 0.05 --make-bed --out output
# Per-sample missing rate (remove if >5% missing)
plink2 --bfile input --mind 0.05 --make-bed --out outputHardy-Weinberg Equilibrium Filter
# Remove variants with HWE p-value < 1e-6
plink2 --bfile input --hwe 1e-6 --make-bed --out output
# Different threshold for cases vs controls
plink2 --bfile input --hwe 1e-6 --hwe-all --make-bed --out outputCombined QC Pipeline
# Standard QC filtering
plink2 --bfile input \
--maf 0.01 \
--geno 0.05 \
--mind 0.05 \
--hwe 1e-6 \
--make-bed --out qc_filteredSample and Variant Selection
Keep/Remove Samples
# Keep specific samples (samples.txt: FID IID per line)
plink2 --bfile input --keep samples.txt --make-bed --out output
# Remove specific samples
plink2 --bfile input --remove samples.txt --make-bed --out output
# Keep single sample
plink2 --bfile input --keep-fam sample_id --make-bed --out outputExtract/Exclude Variants
# Extract specific variants (variants.txt: variant IDs)
plink2 --bfile input --extract variants.txt --make-bed --out output
# Exclude specific variants
plink2 --bfile input --exclude variants.txt --make-bed --out output
# Extract by range
plink2 --bfile input --extract range chr1:1000000-2000000 --make-bed --out outputChromosome Selection
# Single chromosome
plink2 --bfile input --chr 22 --make-bed --out chr22
# Multiple chromosomes
plink2 --bfile input --chr 1-22 --make-bed --out autosomes
# Exclude chromosome
plink2 --bfile input --not-chr 23,24,25,26 --make-bed --out autosomesAllele Frequency
# PLINK 1.9 (MAF-based)
plink --bfile input --freq --out output
# PLINK 2.0 (ALT allele frequency - not MAF!)
plink2 --bfile input --freq --out output
# PLINK 2.0 with MAF
plink2 --bfile input --freq cols=+mac,+mafreq --out outputMissing Data Statistics
# Per-sample and per-variant missing rates
plink2 --bfile input --missing --out output
# Output files:
# output.smiss - sample missing rates
# output.vmiss - variant missing ratesSex Check
Verify reported sex matches X chromosome heterozygosity.
# PLINK 1.9
plink --bfile input --check-sex --out sex_check
# PLINK 2.0
plink2 --bfile input --split-par hg38 --check-sex --out sex_checkInterpret Results
import pandas as pd
sex = pd.read_csv('sex_check.sexcheck', sep='\s+')
problems = sex[sex['STATUS'] == 'PROBLEM']
print(f'Sex mismatches: {len(problems)}')
# F statistic: <0.2 = female, >0.8 = male, between = ambiguous
# PEDSEX: reported sex (1=male, 2=female, 0=unknown)
# SNPSEX: inferred sex (1=male, 2=female, 0=undetermined)Update or Remove
# Update sex from check results
plink2 --bfile input --update-sex sex_check.sexcheck col-num=4 --make-bed --out updated
# Remove sex mismatches
awk '$5 == "PROBLEM" {print $1, $2}' sex_check.sexcheck > sex_problems.txt
plink2 --bfile input --remove sex_problems.txt --make-bed --out outputSample Information
Update Phenotypes
# phenotypes.txt: FID IID pheno (1=control, 2=case, -9=missing)
plink2 --bfile input --pheno phenotypes.txt --make-bed --out output
# Quantitative phenotype
plink2 --bfile input --pheno phenotypes.txt --make-bed --out outputUpdate Sex
# sex.txt: FID IID sex (1=male, 2=female, 0=unknown)
plink2 --bfile input --update-sex sex.txt --make-bed --out outputUpdate Sample IDs
# ids.txt: old_FID old_IID new_FID new_IID
plink2 --bfile input --update-ids ids.txt --make-bed --out outputMerging Datasets
# Merge two datasets (PLINK 1.9)
plink --bfile data1 --bmerge data2.bed data2.bim data2.fam --make-bed --out merged
# Merge list of datasets
plink --bfile data1 --merge-list merge_list.txt --make-bed --out merged
# merge_list.txt contains: data2.bed data2.bim data2.fam (one set per line)
# Handle strand flips
plink --bfile data1 --bmerge data2 --make-bed --out merged
# If error: plink --bfile data2 --flip missnps.txt --make-bed --out data2_flippedVariant Information
Set Variant IDs
# Set ID based on position
plink2 --bfile input --set-all-var-ids @:#:\$r:\$a --make-bed --out output
# Format: chr:pos:ref:altUpdate Variant Names
# update.txt: old_id new_id
plink2 --bfile input --update-name update.txt --make-bed --out outputPLINK 2.0 vs 1.9 Summary
| Feature | PLINK 2.0 | PLINK 1.9 |
|---|---|---|
| Status | Current | Legacy |
| Command | plink2 | plink |
| Format | .pgen/.pvar/.psam | .bed/.bim/.fam |
| Speed | Faster | Baseline |
| Memory | More efficient | Higher for large data |
| Export VCF | --export vcf | --recode vcf |
| Frequency output | ALT frequency | MAF |
| Missing output | .smiss/.vmiss | .imiss/.lmiss |
| PED/MAP support | No (convert via 1.9) | Yes (--file) |
Related Skills
- association-testing - GWAS with filtered data
- population-structure - PCA after QC
- variant-calling/vcf-basics - VCF format before conversion
#!/bin/bash
# PLINK QC pipeline for population genetics
# Usage: ./qc_pipeline.sh <input_vcf> <output_prefix>
INPUT="${1}"
PREFIX="${2:-qc_output}"
if [[ -z "$INPUT" ]]; then
echo "Usage: $0 <input.vcf.gz> [output_prefix]"
exit 1
fi
echo "=== PLINK QC Pipeline ==="
echo "Input: $INPUT"
echo "Output prefix: $PREFIX"
echo -e "\n=== Step 1: Convert VCF to PLINK ==="
plink2 --vcf "$INPUT" --double-id --make-bed --out "${PREFIX}_raw"
echo -e "\n=== Step 2: Initial Statistics ==="
echo "Samples: $(wc -l < ${PREFIX}_raw.fam)"
echo "Variants: $(wc -l < ${PREFIX}_raw.bim)"
plink2 --bfile "${PREFIX}_raw" --missing --out "${PREFIX}_raw"
echo -e "\n=== Step 3: Apply QC Filters ==="
# Thresholds follow PLINK best practices for GWAS; adjust for rare variant studies
plink2 --bfile "${PREFIX}_raw" \
--maf 0.01 \ # Minor allele freq; typical 0.01-0.05 depending on sample size
--geno 0.05 \ # Max 5% missing genotypes per variant
--mind 0.05 \ # Max 5% missing genotypes per sample
--hwe 1e-6 \ # Hardy-Weinberg p-value; stringent to catch genotyping errors
--make-bed --out "$PREFIX"
echo -e "\n=== Step 4: Final Statistics ==="
echo "Samples after QC: $(wc -l < ${PREFIX}.fam)"
echo "Variants after QC: $(wc -l < ${PREFIX}.bim)"
INITIAL_SNPS=$(wc -l < "${PREFIX}_raw.bim")
FINAL_SNPS=$(wc -l < "${PREFIX}.bim")
echo "Variant retention: $(echo "scale=1; $FINAL_SNPS * 100 / $INITIAL_SNPS" | bc)%"
INITIAL_SAMP=$(wc -l < "${PREFIX}_raw.fam")
FINAL_SAMP=$(wc -l < "${PREFIX}.fam")
echo "Sample retention: $(echo "scale=1; $FINAL_SAMP * 100 / $INITIAL_SAMP" | bc)%"
echo -e "\n=== Output Files ==="
ls -lh "${PREFIX}".{bed,bim,fam}
PLINK Basics - Usage Guide
Overview
PLINK is the standard tool for population genetic analysis, handling format conversion, quality control, and basic statistics. PLINK 2.0 is faster and more memory-efficient but doesn't support all legacy formats.
Prerequisites
# PLINK 1.9
conda install -c bioconda plink
# PLINK 2.0
conda install -c bioconda plink2Quick Start
Tell your AI agent what you want to do:
- "Convert my VCF file to PLINK format"
- "Run quality control on my GWAS data"
- "Filter out low-quality variants and samples"
- "Merge these two PLINK datasets"
- "Extract samples from a specific population"
Example Prompts
Format Conversion
"Convert data.vcf.gz to PLINK binary format"
"Convert my PED/MAP files to binary BED format"
"Export my PLINK data back to VCF"
Quality Control
"Run standard QC filtering on my GWAS data with MAF 0.01, genotype missingness 5%, and sample missingness 5%"
"Apply strict QC filters for population structure analysis"
"Check for samples with high missingness rates"
Data Management
"Merge these three PLINK datasets into one"
"Extract only the European samples from my data"
"Remove all variants not in my keep list"
"Calculate allele frequencies for each population"
What the Agent Will Do
1. Assess input data format (VCF, PED/MAP, or binary) 2. Determine appropriate PLINK version (1.9 for legacy formats, 2.0 for analysis) 3. Run quality control or conversion commands 4. Report statistics before and after filtering 5. Verify output file integrity
Tips
- Use
--double-idwhen converting VCF to handle sample ID parsing - PLINK 2.0's
--pfileis faster than--bfilefor large datasets - Always check variant/sample counts before and after QC
- Use
--snps-only just-acgtto remove indels and non-standard alleles - For merging datasets, ensure consistent chromosome naming and strand orientation
Standard QC Workflow
1. Convert VCF to PLINK
plink2 --vcf data.vcf.gz --double-id --make-bed --out data2. Check Initial Statistics
# Sample and variant counts
wc -l data.fam data.bim
# Missing rates
plink2 --bfile data --missing --out data_missing3. Apply QC Filters
plink2 --bfile data \
--maf 0.01 \
--geno 0.05 \
--mind 0.05 \
--hwe 1e-6 \
--make-bed --out data_qc4. Report Filtering
echo "Before QC:"
wc -l data.fam data.bim
echo "After QC:"
wc -l data_qc.fam data_qc.bimChoosing Thresholds
| Filter | Conservative | Standard | Lenient |
|---|---|---|---|
| MAF | 0.05 | 0.01 | 0.001 |
| Geno | 0.02 | 0.05 | 0.10 |
| Mind | 0.02 | 0.05 | 0.10 |
| HWE | 1e-4 | 1e-6 | 1e-10 |
Common Issues
ID Mismatch
VCF sample IDs may need parsing:
# Double ID (same FID and IID)
plink2 --vcf input.vcf.gz --double-id --make-bed --out outputAllele Code Issues
# Handle non-ACGT alleles
plink2 --bfile input --snps-only just-acgt --make-bed --out outputDuplicate IDs
# Check for duplicates
awk '{print $2}' data.bim | sort | uniq -d
# Remove duplicates
plink2 --bfile input --rm-dup force-first --make-bed --out output