plinking_duck

PLINK-2-Genomik-Dateiformate lesen und gängige genetische Analysen direkt in SQL ausführen

Maintainer: teaguesterling

Installation und Laden

INSTALL plinking_duck FROM community;
LOAD plinking_duck;

Beispiel

-- 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;

Über plinking_duck

PlinkingDuck bringt PLINK-2-Genotyp-, Varianten- und Sample-Daten nach DuckDB, sodass Sie Genomik-Datensätze mit Standard-SQL statt format-spezifischer Kommandozeilenwerkzeuge abfragen können.

Dateileser:

  • read_pvar(path | [paths]) — Variantenmetadaten (.pvar/.bim); eine Liste konkateniert mehrere Dateien zeilenweise
  • read_psam(path) — Sample-Metadaten (.psam/.fam)
  • read_pgen(path) — binäre Genotypen (.pgen)
  • read_pfile(prefix | [prefixes]) — einheitlicher Fileset-Reader mit Orient-Modi (variant/genotype/sample), Sample-Subsetting, Regions- und Variantenfilterung; akzeptiert eine Liste von Präfixen, um ein variant-gesplittetes Fileset (identische Samples) als eine Tabelle zu lesen
  • read_plink_vcf(path) — schnelle biallelische Genotypextraktion aus VCF/VCF.gz (~3× schneller als htslib)

Analysefunktionen:

  • plink_freq — Allelhäufigkeiten pro Variante über schnelles Genotypzählen
  • plink_hardy — Exakter Hardy-Weinberg-Gleichgewichtstest
  • plink_missing — Missingness-Raten pro Variante oder Sample
  • plink_ld — paarweises Linkage Disequilibrium (r², D, D’)
  • plink_score — polygenes Risikoscoring mit Mean-Imputation
  • plink_glm — GWAS-Regression pro Variante (linear, logistisch, Firth)
  • plink_pca — Hauptkomponentenanalyse über randomisiertes SVD

Genotyp-Ausgabemodi:

  • genotypes='struct' — STRUCT mit benannten Feldern pro Sample
  • genotypes='counts' — schnelles Genotypzählen (keine Dekompression)
  • genotypes='stats' — Counts + AF, MAF, Missingness, Heterozygotie

Flexible Eingaben:

  • Einheitlicher Parameter variants: Indizes, rsids, CPRA-Strings/Structs, Bereiche
  • Parquet-/CSV-/Tabellen-Begleitdateien für Varianten- und Sample-Metadaten
  • af_range / ac_range Filter-Pushdown sowie include_genotypes (Hardcall- Kategorie) / genotype_range für schnelle Carrier-Lookups — bei orient := 'sample' werden nur die passenden Subjekte materialisiert

Remote-/Cloud-Lesen:

  • .pgen-Filesets direkt von s3://, https:// und anderen DuckDB- Dateisystemen lesen (auch Begleitdateien) — gezielte/Regionsabfragen holen nur die benötigten Bytes über HTTP-Range-Reads. plinking_pgen_io := 'localize' lädt einmal herunter für entfernte Vollscans. Split-Index-(.pgen.pgi-)Filesets werden transparent gelesen.

Alle Funktionen unterstützen Projektions-Pushdown (Genotyp-Dekompression für rein metadatenbezogene Abfragen überspringen), paralleles Scannen, Sample-Subsetting und Regions- Filterung. Legacy-PLINK-1-Formate (.bim/.fam) werden automatisch erkannt.

Aufgebaut auf pgenlib für effizienten Zugriff auf das komprimierte .pgen-Binärformat ohne vollständige Dekompression.

Die vollständige Dokumentation finden Sie unter plinking-duck.readthedocs.io.

Hinzugefügte Funktionen

function_name function_type description comment examples
plink_freq table NULL NULL
plink_glm table NULL NULL
plink_hardy table NULL NULL
plink_ld table NULL NULL
plink_missing table NULL NULL
plink_pca table NULL NULL
plink_score table NULL NULL
read_pfile table NULL NULL
read_pgen table NULL NULL
read_plink_vcf table NULL NULL
read_psam table NULL NULL
read_pvar table NULL NULL

Überladene Funktionen

Diese Erweiterung fügt keine Funktionsüberladungen hinzu.

Hinzugefügte Typen

Diese Erweiterung fügt keine Typen hinzu.

Hinzugefügte Einstellungen

name description input_type scope aliases
plinking_localize_dir Directory (local) for temp copies made by plinking_pgen_io := ‘localize’. Empty (default) uses DuckDB’s temporary_directory, else the current directory. Created if absent (one level only — parent dirs must already exist). Temps are per-query and removed when the query’s bind data is destroyed. VARCHAR GLOBAL []
plinking_max_matrix_elements Maximum genotype matrix elements for orient := ‘sample’ pre-read (variants x samples). Default 16 billion (~16 GB of int8). BIGINT GLOBAL []
plinking_max_threads Maximum threads for parallel scan operations. 0 = default (hardcoded cap of 16), >0 = cap at this value. BIGINT GLOBAL []
plinking_pgen_io How .pgen bytes are read: ‘auto’ (default — remote/VFS paths via DuckDB’s VFS, local via native fopen), ‘native’ (always native fopen; errors on remote), ‘vfs’ (always via DuckDB’s VFS, even local), ‘localize’ (materialize a local temp copy then read natively — best for remote full scans; always copies, even a local source). VARCHAR GLOBAL []
plinking_sample_counts_sparse orient := ‘sample’ + genotypes := ‘counts’|‘stats’: when true, use the sparse (pgen difflist) accumulation path — reads only the non-hom_ref carriers of rare variants (auto-falls-back to the dense full-decode path per variant). When false, always use the dense path. Toggle to A/B time both; both paths produce identical counts. BOOLEAN GLOBAL []
plinking_use_parquet_companions Auto-discover .pvar.parquet and .psam.parquet companion files. When true, parquet companions are preferred over text formats. BOOLEAN GLOBAL []