Skip to content

dnaext

Compact DNA and k-mer types with IUPAC matching and SP-GiST indexes

database-dna-sequencing · Compact DNA and k-mer types with IUPAC matching and SP-GiST indexes

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102453dnaextdatabase-dna-sequencing1.0TYPEC

PostgreSQL · 16, 17

Usage

Sources:

dnaext 1.0 is an academic C extension for compact DNA sequences and k-mer analysis. The reviewed source documents PostgreSQL 16 and 17. Installation needs a superuser; no preload or restart is required. No explicit license grant was found in this source revision.

Store and Query Sequences

CREATE EXTENSION dnaext;
CREATE TABLE reads (id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, dna_seq dna);
INSERT INTO reads (dna_seq) VALUES ('ACGTACGT'), ('GTCAGTCA');
SELECT r.id, k.value
FROM reads r, generate_kmers(r.dna_seq, 4) AS k(value)
WHERE 'ANGT'::qkmer @> k.value;

CREATE TABLE kmers (value kmer);
INSERT INTO kmers SELECT generate_kmers(dna_seq, 4) FROM reads;
CREATE INDEX kmers_prefix_idx ON kmers USING spgist (value kmer_spgist_ops);
SELECT * FROM kmers WHERE value ^@ 'ACG'::kmer;
SELECT value, count(*) FROM kmers GROUP BY value;

dna and kmer accept case-insensitive A, C, G and T and reject other bases. qkmer accepts IUPAC ambiguity symbols, including N for any base. generate_kmers(dna, k) returns sliding windows with step one; length reports the number of bases for all three types.

Operators and Limits

kmer equality and hashing support GROUP BY, DISTINCT, hash joins and hash indexes. The kmer_spgist_ops operator class accelerates equality and ^@ prefix queries. The pattern operator qkmer @> kmer tests ambiguity matches; it is not an additional SP-GiST strategy. There is no B-tree ordering or ORDER BY support for k-mers.

Both short types hold at most 32 bases. A dna value has a 16-bit length limit of 65,535 bases, but values are not compressed or stored out of line: a row must fit in a database page, so roughly 30,000 bases is the practical single-column limit on an 8 kB page. Split long genomes into reads or fragments.

Server-side FASTQ Loading

load_fastq_data(filename, maximum_insertions, table_to_be_filled) reads a file on the PostgreSQL server and inserts accepted reads into the target table’s dna_seq column. Reads containing unknown bases are skipped. The server process must be able to read the path. PUBLIC execution is revoked and the implementation checks superuser status; this is not a client-side file upload API.

Table reader