From 6f9c595b7c77d976c19f8a7455362196987f4477 Mon Sep 17 00:00:00 2001 From: Levi Waldron Date: Wed, 25 Nov 2026 10:10:10 -0500 Subject: [PATCH 1/2] Read curation sheets from bugphyzzExports sources/sheets/ (#306, 1.9.1) physiologies() read all 24 curation sheets and the fatty acid sheet live from Google on every call. It now reads the snapshots in bugphyzzExports sources/sheets/ (bugphyzzExports ADR 0007, #113) through BiocFileCache, like the programmatic sources. - spreadsheet_links.tsv / spreadsheet_customlinks.tsv: link now holds the path under sources/ (sheets/aerophilicity.csv); source_link kept. - .importSpreadsheets() and .fattyAcidComposition() resolve link against .sourcesBaseUrl() and read via .getResource(), so a sheet is cached and a change shows up only after forceDownload = TRUE. forceDownload added to .importSpreadsheets() and passed through from physiologies(). - An unreachable base URL when reading the sheets is a hard error; the programmatic-sources read stays a warning, with corrected text. - Tests: give the base-URL tests a sheet file, add an offline sheet read. - Docs: README, inst/scripts/README (and the custmolinks typo), physiologies() @details/@param and .Rd, NEWS. Verified old-vs-new, run back to back: .importSpreadsheets (24), .fattyAcidComposition (138,496 rows) and physiologies("all") (45) are identical on rows and column types, and bugphyzzExports apply_sheet_overrides() matches all 5 override rows on the new output. Co-authored-by: Claude Code --- NEWS.md | 8 ++++ R/fattyAcidComposition.R | 17 ++++++-- R/physiologies.R | 54 +++++++++++++++++------- README.md | 6 +-- inst/extdata/spreadsheet_customlinks.tsv | 2 +- inst/extdata/spreadsheet_links.tsv | 48 ++++++++++----------- inst/scripts/README.md | 16 +++---- man/physiologies.Rd | 21 +++++---- tests/testthat/test-importSources.R | 30 +++++++++++-- 9 files changed, 136 insertions(+), 66 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9b4cf640..9e4eb7b7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,14 @@ ## SIGNIFICANT USER-VISIBLE CHANGES ++ `physiologies()` reads the curation sheets from the snapshot in + bugphyzzExports `sources/sheets/` instead of live from Google Sheets + (bugphyzzExports ADR 0007, #306, @lwaldron). The sheet data is now cached + with BiocFileCache like the other sources, so a change to a sheet shows up + only after `forceDownload = TRUE`. `physiologies()` and + `.importSpreadsheets()` gain the pass-through `forceDownload`, and the + location can be pointed at a local checkout with + `options(bugphyzz.sourcesBaseUrl = ...)`. + ProTraits goes from confidence `medium` to `low`: its values are predictions from text mining and comparative genomics (Brbić et al. 2016), and the resource is no longer maintained diff --git a/R/fattyAcidComposition.R b/R/fattyAcidComposition.R index 082a8c28..e84d4e1b 100644 --- a/R/fattyAcidComposition.R +++ b/R/fattyAcidComposition.R @@ -1,9 +1,18 @@ -## Function for importing fatty acid compositions -.fattyAcidComposition <- function(){ - link <- .customLinks() |> +## Function for importing fatty acid compositions. The sheet is snapshotted as +## CSV in waldronlab/bugphyzzExports, sources/sheets/ (ADR 0007); the `link` +## column of spreadsheet_customlinks.tsv holds the path there, resolved against +## .sourcesBaseUrl() and read through the cache like .importSpreadsheets(). +.fattyAcidComposition <- function(forceDownload = FALSE){ + relPath <- .customLinks() |> dplyr::filter(functionname == "fattyAcidComposition") |> dplyr::pull(link) - fac_wide <- utils::read.csv(link, check.names = FALSE) + base <- .sourcesBaseUrl() + tag <- substr(rlang::hash(base), 1, 8) + fpath <- .getResource( + paste0("sources_", tag, "_", gsub("/", "_", relPath)), + paste0(base, relPath), force = forceDownload, verbose = FALSE + ) + fac_wide <- utils::read.csv(fpath, check.names = FALSE) fac_long <- fac_wide |> tidyr::pivot_longer( cols = `Br-C10:1`:`Oxo-C19:1`, diff --git a/R/physiologies.R b/R/physiologies.R index 7bbb4087..b9f9bb06 100644 --- a/R/physiologies.R +++ b/R/physiologies.R @@ -14,16 +14,21 @@ #' @param sources Logical. Also read the programmatic sources (Bergey's #' Manual extraction, Madin et al. 2020, ...) kept under `sources/` in #' \url{https://github.com/waldronlab/bugphyzzExports}. Default is `TRUE`. -#' @param forceDownload Logical. Re-download the programmatic sources instead -#' of using the cached copy. Default is `FALSE`. The location can be changed -#' with `options(bugphyzz.sourcesBaseUrl = ...)`, e.g. to a local checkout. +#' @param forceDownload Logical. Re-download the curation sheets and the +#' programmatic sources instead of using the cached copy. Default is `FALSE`. +#' The location can be changed with `options(bugphyzz.sourcesBaseUrl = ...)`, +#' e.g. to a local checkout. #' #' @details -#' Rows come from three places: the curation Google Sheets listed in -#' `inst/extdata/spreadsheet_links.tsv`, the BacDive strain table (built from -#' the BacDive API, `sources/bacdive` in bugphyzzExports), and the other -#' programmatic sources above. The last are produced by scripts, never edited -#' by hand, and are cached with BiocFileCache like the exports. +#' Rows come from three places, all read from `sources/` in +#' \url{https://github.com/waldronlab/bugphyzzExports} and cached with +#' BiocFileCache: the curation sheets snapshotted in `sources/sheets/` (one +#' CSV per physiology, listed by the `link` column of +#' `inst/extdata/spreadsheet_links.tsv`, bugphyzzExports ADR 0007), the BacDive +#' strain table (built from the BacDive API, `sources/bacdive`), and the other +#' programmatic sources above (produced by scripts, never edited by hand). +#' Because the sheets are now cached, a change to a sheet shows up only after +#' `forceDownload = TRUE`. #' #' Attribute values from all three are mapped to the controlled vocabulary #' in `inst/extdata/attributes.tsv` with the synonym table @@ -52,7 +57,9 @@ physiologies <- function( cond2 <- any(keyword %in% showPhys('bacdive')) if (cond1 && cond2) { - spreadsheets <- .importSpreadsheets(keyword = keyword) + spreadsheets <- .importSpreadsheets( + keyword = keyword, forceDownload = forceDownload + ) spreadsheets <- spreadsheets[names(spreadsheets) %in% keyword] bacdive <- .reshapeBacDive( .getBacDive(verbose = FALSE, forceDownload = forceDownload) @@ -67,7 +74,9 @@ physiologies <- function( }) names(physiologies) <- keyword } else if (cond1 && !cond2) { - spreadsheets <- .importSpreadsheets(keyword = keyword) + spreadsheets <- .importSpreadsheets( + keyword = keyword, forceDownload = forceDownload + ) physiologies <- spreadsheets[names(spreadsheets) %in% keyword] ## Not creating a vector. Only usin the side effect of the for loop. for (i in seq_along(keyword)) { @@ -91,7 +100,9 @@ physiologies <- function( error = function(e) { warning( "Programmatic sources could not be read (", - conditionMessage(e), "). Using sheets only.", call. = FALSE + conditionMessage(e), + "). Continuing with the curation sheet data only.", + call. = FALSE ) list() } @@ -206,8 +217,13 @@ showPhys <- function(whichNames = 'all') { return(keyword) } -## Helper function for physiologies -.importSpreadsheets <- function(keyword) { +## Helper function for physiologies. The curation sheets are snapshotted as +## CSV in waldronlab/bugphyzzExports, sources/sheets/ (ADR 0007). The `link` +## column of spreadsheet_links.tsv holds the path there (e.g. +## "sheets/aerophilicity.csv"), resolved against .sourcesBaseUrl() and read +## through the cache like the programmatic sources, so an unreachable base URL +## is a hard error: without the sheets there is no curation data to return. +.importSpreadsheets <- function(keyword, forceDownload = FALSE) { fname <- system.file( 'extdata', 'spreadsheet_links.tsv', package = 'bugphyzz' ) @@ -215,11 +231,19 @@ showPhys <- function(whichNames = 'all') { links <- links[links[['physiology']] %in% keyword,] ## a physiology with no sheet link comes only from programmatic sources links <- links[!is.na(links[['link']]) & nzchar(links[['link']]),] + base <- .sourcesBaseUrl() + ## cache entries are keyed on the base URL so a local checkout or another + ## branch never shadows the default location + tag <- substr(rlang::hash(base), 1, 8) spreadsheets <- lapply(seq_len(nrow(links)), function(i) { physName <- links[i, 'physiology', drop = FALSE][[1]] attrType <- links[i, 'attribute_type', drop = FALSE][[1]] - url <- links[i, 'link', drop = FALSE][[1]] - df <- dplyr::distinct(utils::read.csv(url)) + relPath <- links[i, 'link', drop = FALSE][[1]] + fpath <- .getResource( + paste0("sources_", tag, "_", gsub("/", "_", relPath)), + paste0(base, relPath), force = forceDownload, verbose = FALSE + ) + df <- dplyr::distinct(utils::read.csv(fpath)) .processSheet(df, physName = physName, attrType = attrType) }) names(spreadsheets) <- links$physiology diff --git a/README.md b/README.md index af50ea22..6b6aea83 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The package is the user-facing end of a pipeline spread over several repositorie | Step | Where | What | |---|---|---| -| 1. Curation | Google Sheets listed in [`inst/extdata/spreadsheet_links.tsv`](inst/extdata/spreadsheet_links.tsv) | Hand-curated annotations, one sheet per physiology, with the controlled vocabulary in [`inst/extdata/attributes.tsv`](inst/extdata/attributes.tsv) and the sources in [`inst/extdata/attribute_sources.tsv`](inst/extdata/attribute_sources.tsv). | +| 1. Curation | [bugphyzzExports](https://github.com/waldronlab/bugphyzzExports), `sources/sheets/`, listed in [`inst/extdata/spreadsheet_links.tsv`](inst/extdata/spreadsheet_links.tsv) | Hand-curated annotations, one CSV per physiology (a snapshot of the former curation Google Sheets, bugphyzzExports ADR 0007), with the controlled vocabulary in [`inst/extdata/attributes.tsv`](inst/extdata/attributes.tsv) and the sources in [`inst/extdata/attribute_sources.tsv`](inst/extdata/attribute_sources.tsv). | | 2. Programmatic sources | [bugphyzzExports](https://github.com/waldronlab/bugphyzzExports), `sources/` | Scripted imports kept under version control with the script and pinned upstream version: Bergey's Manual genus abstracts (LLM extraction), Madin et al. 2020, BacDive (API), NCBI RefSeq assemblies (genome size, G+C, coding genes). Corrections go in each source's `overrides.tsv`, never in the output. | | 3. Raw import | this package, `physiologies()` | Reads steps 1 and 2 into one tidy table per physiology; for curators and the export, not for users. | | 4. Harmonization, conflict resolution, propagation | [taxPPro](https://github.com/waldronlab/taxPPro) (R package) and [bugphyzzExports](https://github.com/waldronlab/bugphyzzExports) `inst/scripts/export_bugphyzz.R` | Resolves conflicting annotations by source confidence, propagates strain annotations to species, runs ancestral state reconstruction on the LTP tree (phytools for discrete, castor for numeric), applies the validation thresholds, writes CSV and GMT files. A GitHub Action runs it weekly and commits to `devel`. | @@ -43,7 +43,7 @@ Other related repositories: [taxoniq](https://github.com/lwaldron/taxoniq) (date ## Contributing -- **Data corrections**: open an issue here with the `curation` label, naming the taxon, attribute, source and the sheet or `sources/` file; or edit the sheet directly if you have access. Corrections to programmatic sources go in that source's `overrides.tsv` in bugphyzzExports. +- **Data corrections**: open an issue here with the `curation` label, naming the taxon, attribute, source and the `sources/sheets/` or `sources/` file. A row copied from a cited source is corrected by a drop in `sources/sheet_overrides.tsv` in bugphyzzExports, not by editing the copy (ADR 0005, 0007); other curation rows are corrected by a pull request editing the file. Corrections to programmatic sources go in that source's `overrides.tsv`. - **New sources**: add a directory under `sources/` in bugphyzzExports following its README (script, pinned version, README, manifest row), then a row in `attribute_sources.tsv` here. -- **New attributes**: add the values to `attributes.tsv`, the physiology to `spreadsheet_links.tsv` (a sheet link, or none for a source-only attribute), signature bins to `thresholds.tsv` for numeric attributes, and the attribute to the list in `export_bugphyzz.R`. +- **New attributes**: add the values to `attributes.tsv`, the physiology to `spreadsheet_links.tsv` (with a `link` path to a CSV under `sources/sheets/` in bugphyzzExports, or none for a source-only attribute), signature bins to `thresholds.tsv` for numeric attributes, and the attribute to the list in `export_bugphyzz.R`. - **Code**: pull requests get an automatic review; `R CMD check` and `BiocCheck` run in CI. Keep `NEWS.md` current with user-facing changes. diff --git a/inst/extdata/spreadsheet_customlinks.tsv b/inst/extdata/spreadsheet_customlinks.tsv index 41c87d93..f370f526 100644 --- a/inst/extdata/spreadsheet_customlinks.tsv +++ b/inst/extdata/spreadsheet_customlinks.tsv @@ -1,2 +1,2 @@ physiology ontology link functionname source_link -fatty acid composition NA https://docs.google.com/spreadsheets/d/e/2PACX-1vQJh0AzSYWeYO1zOs4GSZIOde3zV_O71HGixPoN_F8gEY2KhxkZoj1XeSj0HcpCSz2Xu2dxBVyrm0GH/pub?output=csv fattyAcidComposition https://docs.google.com/spreadsheets/d/1u_zgX9dDuk2hIUMlfHqC2pDAmc3ktGf6Vj2EbzRiV8M +fatty acid composition NA sheets/fatty_acid_composition.csv fattyAcidComposition https://docs.google.com/spreadsheets/d/1u_zgX9dDuk2hIUMlfHqC2pDAmc3ktGf6Vj2EbzRiV8M diff --git a/inst/extdata/spreadsheet_links.tsv b/inst/extdata/spreadsheet_links.tsv index 00075954..95a92a3e 100644 --- a/inst/extdata/spreadsheet_links.tsv +++ b/inst/extdata/spreadsheet_links.tsv @@ -1,35 +1,35 @@ physiology ontology trait_type attribute_type link source_link -acetate producing NA discrete binary https://docs.google.com/spreadsheets/d/e/2PACX-1vQb6gDQdhCMWHLQdkzMM4bgTPPosYCZvjzJu4NyOYaSBGOCaOPoQh0OiUr4btnJ8EAWn7NiF-T9JaCE/pub?gid=0&single=true&output=csv https://docs.google.com/spreadsheets/d/1PGW4C8fkyZYUJKA8yAW7ZjWEB6QXYdoTb6wrNxatK2c -aerophilicity MICRO_0000491 discrete multistate-intersection https://docs.google.com/spreadsheets/d/e/2PACX-1vQDC8VfkkOfN6MKGxrzMEoJjfgYIfpsJO-SxVr3pkUUChBNkMQ3YKaxSvDSSjjrPRf51nU3wbk-WWJp/pub?output=csv https://docs.google.com/spreadsheets/d/1JgUzttAZf5Qu2obZ_2xXqsnEr_I1XKn_ZzNvrE6ssO4 +acetate producing NA discrete binary sheets/acetate_producing.csv https://docs.google.com/spreadsheets/d/1PGW4C8fkyZYUJKA8yAW7ZjWEB6QXYdoTb6wrNxatK2c +aerophilicity MICRO_0000491 discrete multistate-intersection sheets/aerophilicity.csv https://docs.google.com/spreadsheets/d/1JgUzttAZf5Qu2obZ_2xXqsnEr_I1XKn_ZzNvrE6ssO4 animal pathogen NA discrete binary -antimicrobial resistance NA discrete multistate-union https://docs.google.com/spreadsheets/d/e/2PACX-1vQmtXGNF7n8mGZKow2Kj2m5JPXsisau9T4TF_u53ovqeELiIVxrDUjaNbdGi-qiKanTKoO5xfba5LTq/pub?gid=0&single=true&output=csv https://docs.google.com/spreadsheets/d/1ldVVQr6zT9g_Bf6WsJtAjke8yyP-gLp8llMYh6bipag +antimicrobial resistance NA discrete multistate-union sheets/antimicrobial_resistance.csv https://docs.google.com/spreadsheets/d/1ldVVQr6zT9g_Bf6WsJtAjke8yyP-gLp8llMYh6bipag antimicrobial sensitivity NA discrete binary -arrangement NA discrete multistate-intersection https://docs.google.com/spreadsheets/d/e/2PACX-1vSgNXC-VPLmG8dUN8VAun_pbT0Y4-qJo6u9ozHGO8j7Weq6ymPaPw9kJUPl-RpHSYvtUgACo-SVHyk5/pub?output=csv https://docs.google.com/spreadsheets/d/1qkNPdVDjpkdvZ-UtWeIrmWA3aYCInIQrseDDYqXiH-w +arrangement NA discrete multistate-intersection sheets/arrangement.csv https://docs.google.com/spreadsheets/d/1qkNPdVDjpkdvZ-UtWeIrmWA3aYCInIQrseDDYqXiH-w biofilm formation NA discrete binary -butyrate producing NA discrete binary https://docs.google.com/spreadsheets/d/e/2PACX-1vQPnLOpbFbfLvOb8fvC6A-WfzVNMDYRWOUsT4hIseDNgI7nwZGjVwg3KBkWeFtOBBLK0j-DRiZ-jtqG/pub?output=csv https://docs.google.com/spreadsheets/d/1uPOIyeFD5ClPR2W2XyT6jAdD8FkgGuNBSl_8F2CT_uI +butyrate producing NA discrete binary sheets/butyrate_producing.csv https://docs.google.com/spreadsheets/d/1uPOIyeFD5ClPR2W2XyT6jAdD8FkgGuNBSl_8F2CT_uI COGEM pathogenicity rating NA discrete multistate-intersection -disease association NA discrete multistate-union https://docs.google.com/spreadsheets/d/e/2PACX-1vQvmmfCe2iXNNR3oC73wXTgukNGNj6_i9qU_20kwpBITtrjn_zgNBK_w9-cfJYKsvXmgXWF_2P8ZMZF/pub?gid=546928968&single=true&output=csv https://docs.google.com/spreadsheets/d/1MAtkI-UEc7T33BYvLBAkw4PDmEmNBroMVUi4KwN8cCc +disease association NA discrete multistate-union sheets/disease_association.csv https://docs.google.com/spreadsheets/d/1MAtkI-UEc7T33BYvLBAkw4PDmEmNBroMVUi4KwN8cCc extreme environment NA discrete binary -gram stain NA discrete multistate-intersection https://docs.google.com/spreadsheets/d/e/2PACX-1vRxQOO7O7oJDJrFbY3s1Y_rbouUSR3rM_a3kGlXgcVMys5pFLqmd00VjJh1adJBmh3xA3aM8r3Am2oC/pub?output=csv https://docs.google.com/spreadsheets/d/1ygWBlBczB24fyL0DTPmTModCuEDi-1j1_rsYBZ5JEOc -growth medium NA discrete multistate-union https://docs.google.com/spreadsheets/d/e/2PACX-1vTLNLWfdNxo7NGNuJ4Pq6nji-7jQhO1glTHh1cQVS3j147WxbwhbWqhyI3FJR0I578o1hzeGbHwMOmY/pub?output=csv https://docs.google.com/spreadsheets/d/1r7GIZWjBbmC-rRZYbHUwM31LGJ6YGexdZozYOvFZXVs -growth temperature NA numeric numeric https://docs.google.com/spreadsheets/d/e/2PACX-1vTWXUnR0_jkpZEE06C0GAypTGjOa2RnOPiLSmPiwAnaf2qS33hd-6GKG95CYDgKeSk6t4BFVjIAB_sh/pub?output=csv https://docs.google.com/spreadsheets/d/1yJjKSd59tjpq1Oaifd7S3jFBWFe2ZU-kmxV4HtYJznc -habitat NA discrete multistate-union https://docs.google.com/spreadsheets/d/e/2PACX-1vQrR6R5nhANAU-CweaEp_X9P13eXiyq2A16_hOOREDYZuOqFS_4jAnI4JjihFmy3jAWtUW2V-4kZYPN/pub?gid=0&single=true&output=csv https://docs.google.com/spreadsheets/d/16WVR910o0p_CyiqYxSa1hkDTdtsAM4Oy8TlbZNIr7ys -health associated NA discrete binary https://docs.google.com/spreadsheets/d/e/2PACX-1vQm5WlnrHECspbrKkrXpo7nAYD4YEllr2GYoc1rcxuchbXk26H2y_Foyx9kXefVFRU239982aCCb0Xv/pub?output=csv https://docs.google.com/spreadsheets/d/1oKvcKub-2NnbwYsIyXPETt7nUl89RwTk5Vwzk1WX0j0 -host-associated NA discrete binary https://docs.google.com/spreadsheets/d/e/2PACX-1vTtPP7Ecv27M7DmcgC_AgotEeT0iIAx9SpvibyZUQREiIOEa1PPWXRhlXL0klq18SC-eYCp289VB05g/pub?gid=0&single=true&output=csv https://docs.google.com/spreadsheets/d/1SHk5e6ASkTDTg5CGKVEryBeHRPawXdtOoH_3Kge9Z48 -hydrogen gas producing NA discrete binary https://docs.google.com/spreadsheets/d/e/2PACX-1vSpucXiYrMe_iYvnZDuNSNkRVnEWRQhykCCXoIvtmTiKAVUdkVnRYvl17nbwGqZDg2xVDwaUXccGYsF/pub?output=csv https://docs.google.com/spreadsheets/d/14CNe6W0OmR5iY9lQU2IPFtYZsLd8a77ehR3lVJkx1A8 -isolation site NA discrete multistate-union https://docs.google.com/spreadsheets/d/e/2PACX-1vR5qKaSI_iXovASXA2U8figFKFBRNOuuFcnr-wSedtGuxAu2m8IjHp1uD23NGTWK9NmnKcO0m7FfkIx/pub?output=csv https://docs.google.com/spreadsheets/d/1QmwZcfoXhBdWPxTt6qa7hhMckHGV7c0lU2pTPpcSVfI -lactate producing NA discrete binary https://docs.google.com/spreadsheets/d/e/2PACX-1vSDYef_4xX2-RVfxhz7XrHIglvHjB5a9bagpApN_zHNhnswhFXN7CRsaQr3pKW6bAyrh8b26tndxCFi/pub?output=csv https://docs.google.com/spreadsheets/d/1Am4XPHK9zyEuPV1h1je2TmsSHLitJJOLPcuhN6-v_hk -length NA range range https://docs.google.com/spreadsheets/d/e/2PACX-1vQkcQ7CJ0LjgE0928maxcVEiqq7QHl6vuosL7qdWaCMVuqHCDwsPJA7yNSeXm9FIip-mDRaU6pMk4Ww/pub?output=csv https://docs.google.com/spreadsheets/d/1gtD-kPb3XEQF0HAFcMMx3Deunj5GxVchPHXWHF-ZK9w -mutation rate per site per generation NA numeric numeric https://docs.google.com/spreadsheets/d/e/2PACX-1vQxiU_sfIyCEcwua8vuCjbSCeZkUBsL1pnNxEK-985NAsCgy0sNbaSKuFMaU5ytPCQ86h9x2NEJsX-t/pub?output=csv https://docs.google.com/spreadsheets/d/1YIlMJCwqtzU1v2hTrPOPbjhxjmj_t-ol6WvMLkkz1bs -mutation rate per site per year NA numeric numeric https://docs.google.com/spreadsheets/d/e/2PACX-1vQGJBifwNIYz6znmGAFgGtzaSNPhxU8qagDgl4BWLHKDcjs_gm11pEaLV7X01qdyeacmwYxalTrx0um/pub?output=csv https://docs.google.com/spreadsheets/d/1K9KUScp1VeEkeXjJmKft_Rdr4xqlyD9Cx7eQpijzWMQ +gram stain NA discrete multistate-intersection sheets/gram_stain.csv https://docs.google.com/spreadsheets/d/1ygWBlBczB24fyL0DTPmTModCuEDi-1j1_rsYBZ5JEOc +growth medium NA discrete multistate-union sheets/growth_medium.csv https://docs.google.com/spreadsheets/d/1r7GIZWjBbmC-rRZYbHUwM31LGJ6YGexdZozYOvFZXVs +growth temperature NA numeric numeric sheets/growth_temperature.csv https://docs.google.com/spreadsheets/d/1yJjKSd59tjpq1Oaifd7S3jFBWFe2ZU-kmxV4HtYJznc +habitat NA discrete multistate-union sheets/habitat.csv https://docs.google.com/spreadsheets/d/16WVR910o0p_CyiqYxSa1hkDTdtsAM4Oy8TlbZNIr7ys +health associated NA discrete binary sheets/health_associated.csv https://docs.google.com/spreadsheets/d/1oKvcKub-2NnbwYsIyXPETt7nUl89RwTk5Vwzk1WX0j0 +host-associated NA discrete binary sheets/host-associated.csv https://docs.google.com/spreadsheets/d/1SHk5e6ASkTDTg5CGKVEryBeHRPawXdtOoH_3Kge9Z48 +hydrogen gas producing NA discrete binary sheets/hydrogen_gas_producing.csv https://docs.google.com/spreadsheets/d/14CNe6W0OmR5iY9lQU2IPFtYZsLd8a77ehR3lVJkx1A8 +isolation site NA discrete multistate-union sheets/isolation_site.csv https://docs.google.com/spreadsheets/d/1QmwZcfoXhBdWPxTt6qa7hhMckHGV7c0lU2pTPpcSVfI +lactate producing NA discrete binary sheets/lactate_producing.csv https://docs.google.com/spreadsheets/d/1Am4XPHK9zyEuPV1h1je2TmsSHLitJJOLPcuhN6-v_hk +length NA range range sheets/length.csv https://docs.google.com/spreadsheets/d/1gtD-kPb3XEQF0HAFcMMx3Deunj5GxVchPHXWHF-ZK9w +mutation rate per site per generation NA numeric numeric sheets/mutation_rate_per_site_per_generation.csv https://docs.google.com/spreadsheets/d/1YIlMJCwqtzU1v2hTrPOPbjhxjmj_t-ol6WvMLkkz1bs +mutation rate per site per year NA numeric numeric sheets/mutation_rate_per_site_per_year.csv https://docs.google.com/spreadsheets/d/1K9KUScp1VeEkeXjJmKft_Rdr4xqlyD9Cx7eQpijzWMQ optimal ph NA numeric numeric plant pathogenicity NA discrete binary -shape NA discrete multistate-intersection https://docs.google.com/spreadsheets/d/e/2PACX-1vSSBfC2jfuqioMyj891v-hYM-uL61-amoDNl0bufw5RwVOmjp5m2uNOKTeJsAsZVHFdujgjEAencl5E/pub?output=csv https://docs.google.com/spreadsheets/d/1OpjfL-EIosX9iUg8nRxv03qpAx8iKo0FpcK_ZQokr-k -spore shape OMP_0008000 discrete multistate-intersection https://docs.google.com/spreadsheets/d/e/2PACX-1vQSMzIaqrE8gCV20sDu_8VBmu1WkpQ_vngaWzLCK2qe5E8IJL7-sOF8qEY0sHeUEavvLHpKVp-vmUxh/pub?output=csv https://docs.google.com/spreadsheets/d/1XPtnoqeSfJFwDC3QHsXuNrTSJpgIZgUpv4ZmSFtT38g -width NA range range https://docs.google.com/spreadsheets/d/e/2PACX-1vR45vzAobXMOH1SCECpkBkIvxTsG5d8jAweSHaUst-gFKQcS0tTYUjivmLVByOLbFZgF59miCyF11TC/pub?output=csv https://docs.google.com/spreadsheets/d/1Wc14Gp4nygdR6XNnZEJ5mZMJtCP6pniqa9GQOwzriNo -genome size NA numeric numeric https://docs.google.com/spreadsheets/d/e/2PACX-1vT3FGe5zB0y6l3x1s0Xlc41xHVdlCg2ddllxOrHcYabYmDtemwBCYa5ar86UCZaGJRdQomYihwN1niX/pub?output=csv https://docs.google.com/spreadsheets/d/1LR0WnLf-trrGHLObcr4t2rs_4W4MHS21SZ8KoujF1k4 -coding genes NA numeric numeric https://docs.google.com/spreadsheets/d/e/2PACX-1vTnz-m2zfMkOiPOEjZgq6Q04TNP44qsC1DUYcGnSuDT37k_jyIP9HavVw8qNgGcQU-H4mO8_zobnqTE/pub?output=csv https://docs.google.com/spreadsheets/d/1MVQ3o4fRYA4EOjp9mNAF0AvyQ0SzzdTMoZXruAIHmb4 -sphingolipid producing NA discrete binary https://docs.google.com/spreadsheets/d/e/2PACX-1vQsNoXw2Noa29eSM0kbn_MCMFGC40nTQffmBHqiqY0Aalax0tHVVjNZBg83t9p0vyLpoSxwkfoWwySL/pub?gid=0&single=true&output=csv https://docs.google.com/spreadsheets/d/1mVeLtc94SykCBBHhxxPhrbUgFopZ4OMWHrM_c5-grjU +shape NA discrete multistate-intersection sheets/shape.csv https://docs.google.com/spreadsheets/d/1OpjfL-EIosX9iUg8nRxv03qpAx8iKo0FpcK_ZQokr-k +spore shape OMP_0008000 discrete multistate-intersection sheets/spore_shape.csv https://docs.google.com/spreadsheets/d/1XPtnoqeSfJFwDC3QHsXuNrTSJpgIZgUpv4ZmSFtT38g +width NA range range sheets/width.csv https://docs.google.com/spreadsheets/d/1Wc14Gp4nygdR6XNnZEJ5mZMJtCP6pniqa9GQOwzriNo +genome size NA numeric numeric sheets/genome_size.csv https://docs.google.com/spreadsheets/d/1LR0WnLf-trrGHLObcr4t2rs_4W4MHS21SZ8KoujF1k4 +coding genes NA numeric numeric sheets/coding_genes.csv https://docs.google.com/spreadsheets/d/1MVQ3o4fRYA4EOjp9mNAF0AvyQ0SzzdTMoZXruAIHmb4 +sphingolipid producing NA discrete binary sheets/sphingolipid_producing.csv https://docs.google.com/spreadsheets/d/1mVeLtc94SykCBBHhxxPhrbUgFopZ4OMWHrM_c5-grjU gc content NA range range halophily class NA discrete multistate-intersection temperature class NA discrete multistate-intersection diff --git a/inst/scripts/README.md b/inst/scripts/README.md index 30adebd6..e5831d9f 100644 --- a/inst/scripts/README.md +++ b/inst/scripts/README.md @@ -47,10 +47,10 @@ Columns: | description | The meaning of the attribute described in the 'attribute' column. | | ordinal_position | Position of the state on an ordered scale (1 = lowest), used for linearly weighted kappa in the cross-validation; NA for states without an order. Set for aerophilicity (aerobic, facultatively anaerobic, anaerobic), gram stain (negative, variable, positive), biosafety level and COGEM pathogenicity rating (bugphyzzExports ADR 0006). | -## spreadsheet_custmolinks.tsv +## spreadsheet_customlinks.tsv -Links for datasets in google spreadsheets that are not in tidy format and -need to be converted to tidy format. +Links for datasets that are not in tidy format and need to be converted to +tidy format. Columns: @@ -58,13 +58,13 @@ Columns: | --- | --- | | physiology | Name of the physiology or attribute group. | | ontology | If applicably, mapping to an ontology term. | -| link | Link to the csv export. | +| link | Path to the snapshotted CSV under `sources/sheets/` in bugphyzzExports (e.g. `sheets/fatty_acid_composition.csv`), resolved against `options(bugphyzz.sourcesBaseUrl)` (bugphyzzExports ADR 0007). | | functionname | The name of the function (unexported) in bugphyzz. | -| source_link | Link to the source spreadsheet on Google Docs. | +| source_link | Link to the historical source spreadsheet on Google Docs. | ## spreadsheet_links.tsv -Links for datasets in spreadsheets that are already in tidy format. +Links for datasets that are already in tidy format. Columns: @@ -73,8 +73,8 @@ Columns: | physiology | Name of the dataset. Equivalent to attribute group. | | ontolgy | Mapping to an ontology term if applicable. | | sig_type | The type of the signature. Either range for numeric or logical for categorical and binary values. | -| link | Link to the csv export. | -| source_link | Link to the source spreadsheet. | +| link | Path to the snapshotted CSV under `sources/sheets/` in bugphyzzExports (e.g. `sheets/aerophilicity.csv`), resolved against `options(bugphyzz.sourcesBaseUrl)` (bugphyzzExports ADR 0007). Empty for a source-only attribute. | +| source_link | Link to the historical source spreadsheet on Google Docs. | ## curation_template.tsv diff --git a/man/physiologies.Rd b/man/physiologies.Rd index c2482c70..2805f283 100644 --- a/man/physiologies.Rd +++ b/man/physiologies.Rd @@ -24,9 +24,10 @@ will contain shortened versions of the sources. Default is \code{FALSE}.} Manual extraction, Madin et al. 2020, ...) kept under \verb{sources/} in \url{https://github.com/waldronlab/bugphyzzExports}. Default is \code{TRUE}.} -\item{forceDownload}{Logical. Re-download the programmatic sources instead -of using the cached copy. Default is \code{FALSE}. The location can be changed -with \code{options(bugphyzz.sourcesBaseUrl = ...)}, e.g. to a local checkout.} +\item{forceDownload}{Logical. Re-download the curation sheets and the +programmatic sources instead of using the cached copy. Default is \code{FALSE}. +The location can be changed with \code{options(bugphyzz.sourcesBaseUrl = ...)}, +e.g. to a local checkout.} } \value{ A list of data.frames in tidy format. @@ -37,11 +38,15 @@ state before cleaning and going through the data imputation steps. It should be used by developers/curators of the package. } \details{ -Rows come from three places: the curation Google Sheets listed in -\code{inst/extdata/spreadsheet_links.tsv}, the BacDive strain table (built from -the BacDive API, \code{sources/bacdive} in bugphyzzExports), and the other -programmatic sources above. The last are produced by scripts, never edited -by hand, and are cached with BiocFileCache like the exports. +Rows come from three places, all read from \verb{sources/} in +\url{https://github.com/waldronlab/bugphyzzExports} and cached with +BiocFileCache: the curation sheets snapshotted in \verb{sources/sheets/} (one +CSV per physiology, listed by the \code{link} column of +\code{inst/extdata/spreadsheet_links.tsv}, bugphyzzExports ADR 0007), the BacDive +strain table (built from the BacDive API, \code{sources/bacdive}), and the other +programmatic sources above (produced by scripts, never edited by hand). +Because the sheets are now cached, a change to a sheet shows up only after +\code{forceDownload = TRUE}. Attribute values from all three are mapped to the controlled vocabulary in \code{inst/extdata/attributes.tsv} with the synonym table diff --git a/tests/testthat/test-importSources.R b/tests/testthat/test-importSources.R index ef1fac37..71e7b969 100644 --- a/tests/testthat/test-importSources.R +++ b/tests/testthat/test-importSources.R @@ -25,10 +25,32 @@ test_that(".importSources reads a manifest and processes files like sheets", { expect_equal(length(bugphyzz:::.importSources("habitat")), 0) }) +## The curation sheets are read from /sheets/.csv, so these +## tests give the temp base URL a tiny sheet file (ADR 0007, #306). +.writeSheet <- function(dir) { + dir.create(file.path(dir, "sheets"), showWarnings = FALSE) + writeLines(c("NCBI_ID,Genome_ID,Accession_ID,Taxon_name,Attribute,Attribute_value,Attribute_source,Frequency,Note", + "561,,,Escherichia,sphingolipid producing,TRUE,BacMap,always,"), + file.path(dir, "sheets", "sphingolipid_producing.csv")) +} + +test_that(".importSpreadsheets reads a sheet from the base URL, offline", { + withr::local_envvar(R_USER_CACHE_DIR = withr::local_tempdir()) + d <- withr::local_tempdir() + .writeSheet(d) + withr::local_options(bugphyzz.sourcesBaseUrl = paste0(d, "/")) + out <- bugphyzz:::.importSpreadsheets("sphingolipid producing", forceDownload = TRUE) + expect_equal(names(out), "sphingolipid producing") + sp <- out[["sphingolipid producing"]] + expect_equal(nrow(sp), 1) + expect_true(all(sp$Attribute_value)) + expect_equal(unique(sp$Attribute_group), "sphingolipid producing") +}) + test_that("physiologies() merges sources and sources = FALSE skips them", { - testthat::skip_if_offline() withr::local_envvar(R_USER_CACHE_DIR = withr::local_tempdir()) d <- withr::local_tempdir() + .writeSheet(d) writeLines(c("source\tphysiology\tattribute_type\tfile", "Test\tsphingolipid producing\tbinary\tsp.tsv"), file.path(d, "manifest.tsv")) writeLines(c("NCBI_ID\tGenome_ID\tAccession_ID\tTaxon_name\tAttribute\tAttribute_value\tAttribute_source\tFrequency\tNote", "562\t\t\tEscherichia coli\tsphingolipid producing\tTRUE\tBergeys_2026\talways\tdoi"), file.path(d, "sp.tsv")) @@ -42,9 +64,11 @@ test_that("physiologies() merges sources and sources = FALSE skips them", { }) test_that("physiologies() warns and continues when sources are unreachable", { - testthat::skip_if_offline() + ## sheets reachable, programmatic sources (no manifest.tsv) are not withr::local_envvar(R_USER_CACHE_DIR = withr::local_tempdir()) - withr::local_options(bugphyzz.sourcesBaseUrl = paste0(withr::local_tempdir(), "/nowhere/")) + d <- withr::local_tempdir() + .writeSheet(d) + withr::local_options(bugphyzz.sourcesBaseUrl = paste0(d, "/")) expect_warning(suppressMessages(physiologies("sphingolipid producing")), "Programmatic sources") }) From b4e5d6e7265d63af5d5416f867f63dcea522a2fe Mon Sep 17 00:00:00 2001 From: Levi Waldron Date: Wed, 25 Nov 2026 10:28:42 -0500 Subject: [PATCH 2/2] Extract .getSourceResource() for the shared cached-read pattern .importSources(), .importSpreadsheets() and .fattyAcidComposition() repeated the base-URL hash cache key and the .getResource() call. Pull it into one helper so the keying cannot drift between them. No behaviour change: physiologies("all") and the sheet/fatty-acid imports are identical to before (addresses the PR #311 review). Co-authored-by: Claude Code --- R/fattyAcidComposition.R | 7 +------ R/physiologies.R | 31 +++++++++++++------------------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/R/fattyAcidComposition.R b/R/fattyAcidComposition.R index e84d4e1b..4145e9f5 100644 --- a/R/fattyAcidComposition.R +++ b/R/fattyAcidComposition.R @@ -6,12 +6,7 @@ relPath <- .customLinks() |> dplyr::filter(functionname == "fattyAcidComposition") |> dplyr::pull(link) - base <- .sourcesBaseUrl() - tag <- substr(rlang::hash(base), 1, 8) - fpath <- .getResource( - paste0("sources_", tag, "_", gsub("/", "_", relPath)), - paste0(base, relPath), force = forceDownload, verbose = FALSE - ) + fpath <- .getSourceResource(relPath, force = forceDownload) fac_wide <- utils::read.csv(fpath, check.names = FALSE) fac_long <- fac_wide |> tidyr::pivot_longer( diff --git a/R/physiologies.R b/R/physiologies.R index b9f9bb06..f1236169 100644 --- a/R/physiologies.R +++ b/R/physiologies.R @@ -231,18 +231,11 @@ showPhys <- function(whichNames = 'all') { links <- links[links[['physiology']] %in% keyword,] ## a physiology with no sheet link comes only from programmatic sources links <- links[!is.na(links[['link']]) & nzchar(links[['link']]),] - base <- .sourcesBaseUrl() - ## cache entries are keyed on the base URL so a local checkout or another - ## branch never shadows the default location - tag <- substr(rlang::hash(base), 1, 8) spreadsheets <- lapply(seq_len(nrow(links)), function(i) { physName <- links[i, 'physiology', drop = FALSE][[1]] attrType <- links[i, 'attribute_type', drop = FALSE][[1]] relPath <- links[i, 'link', drop = FALSE][[1]] - fpath <- .getResource( - paste0("sources_", tag, "_", gsub("/", "_", relPath)), - paste0(base, relPath), force = forceDownload, verbose = FALSE - ) + fpath <- .getSourceResource(relPath, force = forceDownload) df <- dplyr::distinct(utils::read.csv(fpath)) .processSheet(df, physName = physName, attrType = attrType) }) @@ -512,15 +505,20 @@ showPhys <- function(whichNames = 'all') { ) } -.importSources <- function(keyword, forceDownload = FALSE) { +## Resolve a path under sources/ (e.g. "sheets/aerophilicity.csv") against the +## base URL and read it through the cache. Cache entries are keyed on the base +## URL so a local checkout or another branch never shadows the default. +.getSourceResource <- function(relPath, force = FALSE) { base <- .sourcesBaseUrl() - ## cache entries are keyed on the base URL so a local checkout or another - ## branch never shadows the default location tag <- substr(rlang::hash(base), 1, 8) - mpath <- .getResource( - paste0("sources_", tag, "_manifest.tsv"), paste0(base, "manifest.tsv"), - force = forceDownload, verbose = FALSE + .getResource( + paste0("sources_", tag, "_", gsub("/", "_", relPath)), + paste0(base, relPath), force = force, verbose = FALSE ) +} + +.importSources <- function(keyword, forceDownload = FALSE) { + mpath <- .getSourceResource("manifest.tsv", force = forceDownload) manifest <- utils::read.table( mpath, header = TRUE, sep = "\t", quote = "", stringsAsFactors = FALSE ) @@ -528,10 +526,7 @@ showPhys <- function(whichNames = 'all') { if (!nrow(manifest)) return(list()) out <- lapply(split(manifest, manifest$physiology), function(m) { dplyr::bind_rows(lapply(seq_len(nrow(m)), function(i) { - fpath <- .getResource( - paste0("sources_", tag, "_", gsub("/", "_", m$file[i])), - paste0(base, m$file[i]), force = forceDownload, verbose = FALSE - ) + fpath <- .getSourceResource(m$file[i], force = forceDownload) df <- utils::read.table( fpath, header = TRUE, sep = "\t", quote = "", comment.char = "", stringsAsFactors = FALSE, colClasses = "character"