--- name: bio-annotation description: Annotate proteins with functions, domains, and homology-based taxonomy. Use when assigning functional or taxonomic labels to proteins from genomes, contigs, or MAGs. disable-model-invocation: true --- # Bio Annotation Functional annotation and taxonomy inference from sequence homology. Shared pipeline rules: read `../omics-pipeline/SKILL.md` first. `SKILL_DIR` is the directory that holds this `SKILL.md`. ## Instructions 1. Read [docs/README.md](docs/README.md) for the tool choice and its pitfalls, and verify databases with `check_databases.py --stage annotation` before running anything. 2. Normalize tool outputs and generate the complete comparison bundle with the schema-backed driver. `RUN_DIR` is the run directory that `bioinformatics-project` defines (`results/_/`): ```bash uv run --script "$SKILL_DIR/scripts/build_annotation_artifacts.py" \ raw_annotations.tsv --genomes genomes.tsv --markers marker_catalog.tsv \ --out "$RUN_DIR/annotation" ``` `raw_annotations.tsv` is one row per protein and family hit with columns `genome, protein_id, family_id, family_name, category, e_value, annotation, taxonomy, confidence`, merged by you from the tool outputs below. `genomes.tsv` has `genome, role (query|reference), domain, route, protein_count`, where `protein_count` is the total number of proteins of the genome, with or without a hit (it sets `unannotated_count`, and the run fails when it is missing or lower than the proteins in `raw_annotations.tsv`); `marker_catalog.tsv` has `category, family_id, family_name, expected`, where `expected` is `yes` or `no`. `fixtures/` holds a runnable example. The driver refuses a non-empty destination, rejects any `role` other than `query` or `reference`, validates all inputs before it writes a file (a failed run leaves the destination empty, so you can rerun into it), enforces globally unique protein identifiers, writes normalized Parquet tables, adds explicit absent-marker rows (an absent marker with `expected` `yes` is noted in `notes`, and the final envelope lists each one in `warnings`), and computes query-specific/missing/expanded/contracted families against the reference median. The artifact contract is in `schemas/artifacts.schema.json`. 3. Take the domain route for each genome from `results/taxonomy/domain_routing.tsv` before interpreting protein annotations. Domain-specific taxonomy follows the route: GTDB-Tk (HPC) or QuickClade + marker trees (workstation) for Bacteria and Archaea; `bio-viromics` for viruses (`GVClass` suffices for giant viruses; `vConTACT3` and `Phold` for phages; `ViroSync` for endogenized viruses); Tiara/EukCC for Eukaryota without CheckM or GTDB-Tk assumptions. 4. Run `pyhmmer` with Pfam 39.0 and group-appropriate profile HMMs (fix `Z` to the whole target set when splitting searches). 5. Run `eggNOG-mapper` v2 (without `--dbmem` under 128 GB RAM) and optionally **Bakta** (`light` or `full`, bacteria and plasmids only; PGAP/Prokka for archaea). Use `InterProScan 6` with `--no-matches-api` (unless the user approves sending MD5 hashes to EBI). 6. Run DIAMOND (or MMseqs2-GPU on CUDA nodes) against a clustered database and resolve taxonomy with TaxonKit v0.20.0+, piping multi-taxid DIAMOND `staxids` through `taxonkit lca -s ";"` before `taxonkit lineage`. 7. Send stubborn hypothetical proteins to **Phold** (phage) or optional **Baktfold** (bacteria, preprint) via [structure.md](../omics-pipeline/references/structure.md); **DeepKOALA** (standalone beta) is an optional KO cross-check against eggNOG-mapper. 9. Build an annotation-wide feature inventory by genome or contig and by gene family, domain and pathway. 10. **Marker-gene census** (the driver writes it from your hits): for each diagnostic marker or machinery category of the inferred group (for example replication, transcription, translation-related, packaging, capsid/structural, chromatin/SMC/topoisomerase, host-interaction), record presence and copy number for each query genome and each comparison genome as `marker_census.tsv` with columns `genome, category, family_id, family_name, copy_number, evidence_source, e_value, notes, expected`. Expected-but-absent markers are rows, not silent omissions. 11. **Per-family copy-number matrix**: a Pfam/InterPro/HMM-family by genome integer matrix covering the query and the supplied relatives, persisted as `family_copy_number_matrix.parquet`. Compute per-family fold change against the relative median, and flag query-specific, missing-expected, expanded and contracted families in `family_expansion_candidates.tsv`. 12. Mine the inventory for discovery candidates against the literature-derived playbook: missing expected features, rare or expanded families, unusual combinations, annotation/taxonomy conflicts, high-value unknowns. 13. `query_specific` requires the family to be absent from every reference. When the reference median is 0 but at least one reference carries the family, the status is `present_in_reference_minority` with an empty `fold_change`: report it as a signal, never as a discovery. 14. Order `family_expansion_candidates.tsv` deterministically before reporting. Sort by `status` in the order `query_specific`, `missing_expected`, `expanded`, `contracted`, `present_in_reference_minority`; then by `fold_change` descending, with `inf` first and blank or non-numeric values last; then by `genome` and `family_id` ascending. Report the top rows in that order and keep the full table. ## Input Requirements - Tools from the project's pinned pixi environment (`docs/README.md`); `BIO_DB_ROOT` set to the database directory. - `proteins.faa` (FASTA protein sequences) and `reference_db/` (eggNOG, InterPro, DIAMOND databases and taxdump). - For the driver: `raw_annotations.tsv`, `genomes.tsv` (at least one query and one reference), and `marker_catalog.tsv` with the columns in step 2. ## Output The driver writes every file below except the agent-authored report and `logs/`, and also writes `run_manifest.json`. All files sit in the stage directory under the run directory that `bioinformatics-project` defines (`results/_//`, stage `annotation`). - annotations.parquet - domain_routing.tsv (the driver's normalized copy of the genome routes, not the QuickClade table) - taxonomy.parquet - feature_inventory.parquet - marker_census.tsv - family_copy_number_matrix.parquet - family_expansion_candidates.tsv - annotation_report.md (agent-authored) - logs/ - Artifact contract: [schemas/artifacts.schema.json](schemas/artifacts.schema.json) ## Quality Gates - [ ] `proteins.faa` is non-empty, amino acid encoded, and free of `*` stop symbols before InterProScan (or they are stripped deliberately). - [ ] InterProScan output options use `-b` or `-d`, never both. Packaged installs are initialized with `python3 setup.py -f interproscan.properties` when required, and the helper binaries `ps_scan.pl`, `pfscan` and `pfsearch` resolve. - [ ] A short smoke test on 1-2 proteins passes before a large cluster job (`hpc-slurm` for submission). - [ ] The reference databases exist under `BIO_DB_ROOT`. - [ ] The normalized bundle is produced in a fresh directory, matches `schemas/artifacts.schema.json`, and has globally unique protein identifiers. - [ ] `marker_census.tsv` covers every literature-derived marker category for the inferred group, with explicit zero rows for absent markers; each expected marker the envelope lists in `warnings` appears in the report as a result. - [ ] `family_copy_number_matrix.parquet` includes the query and the supplied relatives, and `family_expansion_candidates.tsv` carries fold change against the relative median. - [ ] Reported discovery candidates (step 12) carry gene or protein ID, annotation source, confidence, why notable, and recommended validation. ## Non-Goals - No causal or phenotype claims from homology alone. An annotation transfer is a hypothesis about function, not a demonstration of it. - No taxonomy for nucleotide assemblies, MAGs, or contigs outside the QuickClade route and its domain-specific follow-up. - No reference database downloads or builds. The databases under `$BIO_DB_ROOT` are an input; report a missing database instead of fetching it. - No structure-based inference. High-value unknowns go to the [structure page](../omics-pipeline/references/structure.md).