pg_variant_functions
pg_variant_functions · Variant summary and allele-frequency functions over TINYINT[] genotype arrays
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100660 | pg_variant_functions | pg_variant_functions | 1.0 | FUNC | PostgreSQL | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | tinyint |
Usage
Sources:
pg_variant_functions computes call rates and alternate-allele frequencies from genotype dosage arrays stored as TINYINT[]. It is a small, abandoned work-in-progress rather than a general genomics toolkit, so use it only when its exact array convention matches the data model.
Core Workflow
Install the required tinyint extension first. Genotype positions are addressed by one-based INTEGER[] subscripts, and non-NULL genotype values are summed as alternate-allele dosages and divided by twice the number of called genotypes.
alternate_allele_frequency(genotypes, indices) returns a REAL value for the selected positions and returns NULL when none of those positions has a called genotype.
summarize_variant(genotypes, subset1, subset2) returns the variant_summary composite type with these fields:
call_rateandmaffor the complete genotype array.subset1_call_rateandsubset1_maffor the first optional index array.subset2_call_rateandsubset2_maffor the second optional index array.
Passing NULL for a subset leaves that subset’s fields NULL. Despite the field name maf, the implementation reports the alternate-allele frequency directly and does not transform values above 0.5 into minor-allele frequency.
Caveats
The code expects a one-dimensional dosage array and valid positive one-based indices. It does not validate biological ploidy or genotype range, and it should not receive zero, negative, or otherwise invalid subscripts. Empty arrays and empty subsets need application-level handling. Both functions are immutable and parallel safe, but carry a declared cost of 10000 because they scan arrays. Version 1.0 is marked abandoned; validate numeric results against a trusted implementation before analytical or clinical use.