Design notes¶
A condensed version of the design plan the project started from.
Why¶
- Split sketching from the database. Every process that uses pysylph deserialises the database
into its own memory. For GTDB r232
c200that takes about 2 s and about 2 GB of RAM per process (the screening index; the 20 GB second stage is read lazily from the file and shared through the page cache). GlobDB r232 is larger: a server with GlobDB, UHGV and fungi holds 4.15 GiB after loading and needs 7.5 GiB at start-up (see the GlobDB evaluation). A server pays this once and shares one copy across runs, parallel jobs and users, while clients do the per-sample sketching work locally. - Sketches are small enough for a public server. Once sketching and database lookup were split,
it became clear that sketches are tiny compared with both the input reads and the reference
databases (e.g., 74.5 MB for a 1.2 GB
FASTQ.gzagainst ~32 GB of databases; ~0.1 MB for a bacterial assembly) and contain only k-mer hashes and counts. Sending only the sketch over HTTP made a public server (sylphd.abrinca.com) and an in-browser WebAssembly sketcher practical.
Decisions¶
| Topic | Decision |
|---|---|
| Commands | serve, profile, query, info, download, setup and assembly |
| Transport | HTTP over a Unix socket by default, --tcp host:port as an option. No TLS, no auth |
| Server stack | Starlette and uvicorn, exactly one worker process. Blocking pysylph calls run in a thread pool, and a semaphore caps concurrent profiling jobs (the rest queue). One Profiler per parameter set, cached and shared by all threads: with one database it only holds references, but with two or more its constructor scans every genome, so it must not be rebuilt per request. A pysylph.Profiler is read-only and safe to use concurrently |
| Sketch transfer | SampleSketch.to_bytes() and from_bytes() in the pysylph multi-db branch. The server enforces an upload limit and checks the sketch's c and k against the database |
| Requests | Several samples per request |
| Responses | JSON rows from the server; the CLI writes TSV (sylph-like columns plus metadata columns) |
| Database identity | File name and size, plus an optional hash (off by default), reported by /info |
| Fallback | None. The client requires a server |
| Service | sylphd serve; deploy/ ships an optional systemd unit (deploy/sylphd.service) and setup script |
| Databases | serve --db [NAME=]PATH, repeatable: one pool per server process, all with the same k; samples are sketched at the smallest c |
| Tests | pytest on Python 3.14 with pysylph's small test data; GTDB only for manual runs |
Architecture¶
- Server. Loads the databases at startup (in parallel threads) and offers
/health,/info,/profile,/query,/assemblyand/contigs. - Client library and CLI. Ask the server for
candk, sketch locally, send the sketches and write the rows. Inputs: single-end reads (also long reads and assemblies), paired reads, interleaved reads, several files per sample (combined into one sketch) and existing.sylspfiles, which are sent as they are. - Why sketches and not reads. Sketching is per-sample CPU work and belongs to the client. Sketches are small (about 1-2 MB for a 40 Mb read pool). No file paths cross the boundary.
Pysylph fork¶
sylphd depends on the multi-db branch of the
MrTomRod/pysylph fork, which in turn builds on the
expose-library-api branch of a sylph fork. It is installed as a uv git dependency, which is why
a Rust toolchain is needed at install time.
Metadata¶
The metadata database is a SQLite file, built from GTDB's TSV files by sylphd setup. It is keyed
by accession, with repetitive text dictionary-encoded, and it stores the taxonomy strings as one
column each. See Metadata database.
The web front end¶
The aim: a public page where a visitor pastes one assembly and gets its closest GTDB genomes, with no install. The page sketches the assembly in the browser (WebAssembly) and sends only the sketch.
- Server.
POST /assemblytakes the sketch of one assembly (always accepted), or, with the optional--allow-sequences, raw FASTA or FASTQ, plain or gzip, which it sketches itself, with size caps for the raw body and its decompressed form,topandmin_aniparameters, and flat metadata in each hit.Profiler(no_adjust=True)gives the naive containment ANI, which is the meaningful ANI for a genome.sylphd assemblyis a client for it. - Public-deployment flags.
--allow-sequences,--max-sequence-mb,--rate-limit,--max-queue,--trusted-proxyand--cors-origin. Everything is off by default, and raw sequence uploads to/assemblyare a 404 without--allow-sequences, so local behaviour is unchanged. - Deployment. A reverse proxy terminates TLS on a small host.
- Page. The static page calls the API directly from the browser with
fetch, so the server needs the CORS origin and a rate limit per client IP.
The result classification (species assignment at 95 % ANI and relations from the GTDB lineage) replaced an earlier ANI-only label; see Identifying an assembly.