Skip to content
DuckDB community extension

plinking_duck

Read and write PLINK 2 genomics file formats and run common genetic analyses directly in SQL

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL plinking_duck FROM community;
LOAD plinking_duck FROM community;

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Read variant metadata from a .pvar file

SQL
-- Read variant metadata from a .pvar file
SELECT CHROM, POS, ID, REF, ALT
FROM read_pvar('cohort.pvar')
WHERE CHROM = '22';

-- Read genotypes in tidy format (one row per variant x sample)
SELECT chrom, pos, iid, genotype
FROM read_pfile('cohort', orient := 'genotype')
LIMIT 10;

-- Compute allele frequencies
SELECT * FROM plink_freq('cohort.pgen')
WHERE ALT_FREQ > 0.01;

-- Run a GWAS association test
SELECT * FROM plink_glm('cohort')
WHERE p_value < 5e-8;

Provided by teaguesterling. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

PlinkingDuck brings PLINK 2 genotype, variant, and sample data into DuckDB, letting you query genomics datasets with standard SQL instead of format-specific command-line tools.

All functions support projection pushdown (skip genotype decompression for metadata-only queries), parallel scanning, sample subsetting, and region filtering. Legacy PLINK 1 formats (.bim/.fam) are auto-detected.

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
teaguesterling/plinking_duck
License
MIT
Maintainers
teaguesterling
Written in
C++
Build source
73daba06dd3a
Build definition
Community descriptor