Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
^misc$
^inst/backup$
^vignettes/Outline_workflow\.(png|svg)$
^AGENTS\.md$
^\.pi$
23 changes: 23 additions & 0 deletions .pi/crucible.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://raw.githubusercontent.com/seandavi/pi-crucible/main/schema/crucible.schema.json",
"design": "AGENTS.md, README.md, the vignettes and inst/scripts/README.md (the inst/extdata tables) are the design record; bugphyzzExports docs/adr/ holds the data decisions. Read them before changing anything, and say in the spec when a change departs from them.",
"spec": {
"design": "files to add or change, the functions or interfaces and their signatures, data and config changes, the tests that prove it"
},
"implement": "Tests must not use the network or real credentials; use small fixtures written in the test. Follow AGENTS.md for setup and conventions.",
"checks": [
{
"name": "document",
"command": "Rscript -e 'devtools::document()' && git diff --exit-code -- man NAMESPACE"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git diff --exit-code -- man NAMESPACE compares against the index, not HEAD. It also ignores new untracked man/*.Rd files. If the agent stages changes or document() creates a new Rd file, this check passes even though man/ or NAMESPACE is out of date. Use git diff --exit-code HEAD -- man NAMESPACE && test -z "$(git ls-files --others --exclude-standard man NAMESPACE)", or compare against git status --porcelain -- man NAMESPACE.

},
{
"name": "test",
"command": "Rscript -e 'devtools::test(stop_on_failure = TRUE)'"
}
],
"lenses": {
"code": "CODE review. Correctness against the spec and the issue's acceptance criteria; tests that would catch a regression; clear module boundaries; dead code; error handling; the spec and the code agree (a stale spec is \"major\").",
"security": "SECURITY review. Input validation; secrets never in code, fixtures, logs or CI; injection (shell, SQL, HTML); untrusted URLs and paths; least privilege; CI safe for pull requests from forks.",
"ux": "UX review, for whoever uses this change: names, defaults and error messages that say what to do next; docs and examples a first-time user can follow."
}
}
149 changes: 149 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# AGENTS.md

bugphyzz is a Bioconductor R package. It gives access to a harmonized database of microbial
physiologies (curated and imputed annotations) and makes taxon signatures from them for bug set
enrichment analysis. Users mostly call `importBugphyzz()` and `makeSignatures()`; the other exports
are `getTaxonSignatures()`, `physiologies()` and `showPhys()`.

## Stack and setup

- R (>= 4.4), Bioconductor devel. The default branch is `devel`; `RELEASE_3_*` branches are
Bioconductor releases and only take bug fixes.
- Imports: dplyr, tidyr, purrr, stringr, rlang, tidyselect, httr2, BiocFileCache, S4Vectors (plus
base utils, tools). Ask before adding a hard dependency; prefer `Suggests` for anything used only
in vignettes or tests.
- roxygen2 (markdown, version 8.0.0 per `Config/roxygen2/version`), testthat edition 3, knitr
vignettes.
- Install the dependencies (network) from the repo root:
`Rscript -e 'BiocManager::install(remotes::local_package_deps(dependencies = TRUE))'`,
plus `devtools` and `BiocCheck` for the commands below.
- If `Rscript` is not found, R's bin directory is not on `PATH` (on macOS it is usually
`/usr/local/bin`).

## Layout

- `R/bugphyzz.R`: `importBugphyzz()` (downloads a released export from Zenodo, or from bugphyzzExports
on GitHub for `version = "devel"` or a commit hash), its ASR filters (`kappaThreshold`,
`r2Threshold`, `asrScoreThreshold`), `makeSignatures()` and `getTaxonSignatures()`.
- `R/physiologies.R`: `physiologies()` and `showPhys()`. These read the source data (curation sheets
and scripted sources) from bugphyzzExports `sources/`, map source terms to attributes with
`inst/extdata/attribute_synonyms.tsv`, and add source information. The export pipeline calls
`physiologies()`, so changes here change the next data release.
- `R/cache.R`: BiocFileCache helpers. Every download goes through `.getResource()`.
- `R/bacdive.R`, `R/fattyAcidComposition.R`: source-specific import code.
- `R/sysdata.rda` (`bacdivePhysNames`, `ranksParents`): generated by `inst/scripts/sysdata.R` (needs
taxizedb and network). Don't edit it by hand or regenerate it unless the issue asks.
- `inst/extdata/`: the controlled vocabulary and source tables (`attributes.tsv`,
`attribute_synonyms.tsv`, `attribute_sources.tsv`, `spreadsheet_links.tsv`, `thresholds.tsv`, ...).
`inst/scripts/README.md` documents every file and its columns; update it when a column changes.
- `inst/backup/`: old scripts, excluded from the build (`.Rbuildignore`). Don't extend it.
- `tests/testthat/`: unit tests.
- `vignettes/`: `bugphyzz.Rmd` (main), `sources.Rmd`; `vignettes/articles/` is pkgdown-only.
`_pkgdown.yml` builds the site at https://waldronlab.io/bugphyzz/.
- `README.md` is edited by hand (there is no `README.Rmd`).

**Generated, never hand-edit:** `man/*.Rd` and `NAMESPACE` (roxygen; edit the `#'` comments, run
`devtools::document()`, commit the result), `R/sysdata.rda`, and the three `validation_*.tsv` files
(below).

## Related repositories

The table under "How the data are produced" in `README.md` maps every repository to its pipeline step;
read it first. Runs here can't change the other repositories, but many issues touch them. If a change
belongs in one of them, say so in the spec or PR and label it `needs:human` rather than working around
it in bugphyzz. The ones that matter most for a change here:

- [waldronlab/bugphyzzExports](https://github.com/waldronlab/bugphyzzExports): the curation data
(`sources/sheets/`, the scripted sources listed in `sources/manifest.tsv`, corrections in
`sources/sheet_overrides.tsv`), the weekly export that builds the released data
(`inst/scripts/export_bugphyzz.R`), and the design decisions (`docs/adr/`). Data corrections go
there, not here.
- [waldronlab/taxPPro](https://github.com/waldronlab/taxPPro): conflict resolution between sources
(highest `Confidence_in_curation`, then `Priority` in `attribute_sources.tsv`) and ancestral state
reconstruction (ASR), used by the export.
- [waldronlab/taxPProValidation](https://github.com/waldronlab/taxPProValidation): validation of the
ASR. `inst/extdata/validation_attributes.tsv`, `validation_states.tsv` and `validation_summary.tsv`
are copied from it by hand; never regenerate or edit them here.
- [waldronlab/bugphyzzAnalyses](https://github.com/waldronlab/bugphyzzAnalyses): articles that call
`importBugphyzz()` and `makeSignatures()`. A change to their arguments or output breaks them; say so
in the PR.

Data releases follow bugphyzzExports `RELEASING.md` and are tracked in one checklist issue here (v1.3.0
is #313). Work that gates a release goes on that checklist.
- waldronlab/bugphyzzAnalyses and the private bugphyzz-manuscript only use the package.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bullet is orphaned: it follows a prose paragraph, so it renders as a one-item list. It also duplicates the bugphyzzAnalyses bullet above, and it calls bugphyzzAnalyses "only use the package" while the earlier text says changes to importBugphyzz() or makeSignatures() break it. Fold the private bugphyzz-manuscript mention into the earlier bullet and delete this line.


## Commands

Run from the repo root.

```sh
Rscript -e 'devtools::document()' # after any roxygen change; commit the regenerated man/ and NAMESPACE
Rscript -e 'devtools::test()' # all tests; network for the download tests (see below)
Rscript -e 'devtools::test(filter = "attributeSynonyms|importBugphyzz-filters|importSources|makeSignatures-names|readZenodoZip")'
# offline tests only, about 3 s
Rscript -e 'devtools::check()' # R CMD check; CI treats warnings as errors
Rscript -e 'BiocCheck::BiocCheck(".")'
```

`devtools::check()` needs the network and takes minutes: the vignettes and the `importBugphyzz()`
and `makeSignatures()` examples download the data release. Test files that start with
`testthat::skip_if_offline()` (`test-importBugphyzz.R`, `test-physiologies.R`,
`test-makeSignatures.R`, `test-makeSignatures-DataFrame.R`, `test-getTaxonSignatures.R`) download
from Zenodo and GitHub and are skipped without a connection. Downloads are cached under
`tools::R_user_dir("bugphyzz", "cache")`.

CI (`.github/workflows/ci.yml`) runs R CMD check (`error_on: warning`), BiocCheck, coverage and
pkgdown in the Bioconductor container on pushes and PRs to `devel` and `RELEASE_*`.
`.github/workflows/claude.yml` adds an automatic Claude review on each PR.

## Rules

- **Branches and PRs.** Work on a short kebab-case branch (`source-priority`) and open a PR to
`devel`. Never commit to `devel` directly and never force-push. Commit subjects say what changed
and cite the issue and the new version, e.g.
`ProTraits: confidence medium to low (waldronlab/bugphyzzExports#66, 1.9.1)`.
- **Version and NEWS.** Bump the patch version in `DESCRIPTION` (1.9.2 to 1.9.3) for every change to
code, data tables or documentation that users see, and add a bullet for it at the top of `NEWS.md`
under a matching `# bugphyzz x.y.z` heading and `## SIGNIFICANT USER-VISIBLE CHANGES`,
`## NEW FEATURES` or `## BUG FIXES AND MINOR IMPROVEMENTS`, with `+ ` bullets. Follow the
existing entries: say what changed for the user and cite the issue (`#306`, or
`waldronlab/bugphyzzExports#66` for another repo). Never change x or y: devel has an odd y and
Bioconductor makes the y bumps around releases.
- **Deprecation.** Arguments and functions that have been in a Bioconductor release first warn
(`.Deprecated()` for functions; a `warning()` for arguments, as `importBugphyzz()` does for `v` and
`excludeRarely`), then go `.Defunct()`. Ones added since the last release can be changed or removed
outright.
- **Tests.** New behaviour needs a testthat test. New tests must not use the network or credentials:
build small data frames in the test and use `testthat::local_mocked_bindings()` for downloads (see
`test-importBugphyzz-filters.R`), or point `options(bugphyzz.sourcesBaseUrl = ...)` at files in a
`withr::local_tempdir()` with `withr::local_envvar(R_USER_CACHE_DIR = withr::local_tempdir())` (see
`test-importSources.R`). Older tests that download start with `testthat::skip_if_offline()`; don't
add more of those.
- **Code style.** Bioconductor style: 4-space indents, lines under 80 characters, `pkg::fun()` for
imported functions. Internal helpers start with a dot. Don't restyle code you aren't changing.
- **Data.** Don't change what a source says (a curated value, a mapping of a source term) without an
issue that asks for it. Vocabulary changes go in `attributes.tsv` and `attribute_synonyms.tsv`
together, and the export stops on unmapped values; `test-attributeSynonyms.R` checks that every
synonym target is a valid attribute.
- **Writing.** Plain, direct prose in docs, NEWS and comments. No em-dashes.

## Gotchas

- `importBugphyzz()` defaults to a Zenodo DOI (`version = "10.5281/zenodo.24166279"`, data release
v1.2.0). Changing the default is a user-visible change with its own NEWS entry.
- `.exportThresholds` in `R/bugphyzz.R` (kappa 0.7, R2 0.5, Score 0.5) must match what the export
applies (bugphyzzExports ADR 0006). Imputed values are kept or dropped per attribute, using
`score_lcb` at `rank == "all"` in `validation_attributes.tsv`; thresholds below the export's make
`importBugphyzz()` also read `bugphyzz_asr_dropped.csv.gz`.
- Source files are cached by name: `.getSourceResource()` keys entries on a hash of
`.sourcesBaseUrl()`, so a changed sheet shows up only with `forceDownload = TRUE`.
- `spreadsheet_links.tsv` `link` is a path under bugphyzzExports `sources/` (`sheets/x.csv`);
`source_link` is the frozen Google Sheet and is kept for provenance.
- `physiologies()` returns `NCBI_ID` as character. Signature names are
`bugphyzz:<attribute>|<value>` for discrete and numeric signatures alike (#256, `test-makeSignatures-names.R`).
- `.appendLinks()` is dead code kept for `source_link`, and `.fattyAcidComposition()` isn't reached
by `physiologies()`. Leave them unless the issue is about them.

**Review checklist:** version bumped and NEWS entry added; `man/` and `NAMESPACE` regenerated if
roxygen changed; new tests offline; `inst/scripts/README.md` updated if a table column changed; no
hand edits to generated or `validation_*.tsv` files; data or vocabulary changes backed by an issue.
Loading