Skip to content
Merged
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
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions R/fattyAcidComposition.R
Original file line number Diff line number Diff line change
@@ -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){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

forceDownload is added here, but nothing in R/ calls .fattyAcidComposition(). physiologies(forceDownload = TRUE) therefore never refreshes this sheet, although the docs say it re-downloads "the curation sheets". Either pass it through from the caller or drop the argument and adjust the docs. The new caching code is also duplicated from .importSpreadsheets() (tag + .getResource + cache-key construction); a small shared helper would keep the two in step.

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`,
Expand Down
54 changes: 39 additions & 15 deletions R/physiologies.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)) {
Expand All @@ -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()
}
Expand Down Expand Up @@ -206,20 +217,33 @@ 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'
)
links <- utils::read.table(fname, header = TRUE, sep = '\t')
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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. |
Expand All @@ -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.
2 changes: 1 addition & 1 deletion inst/extdata/spreadsheet_customlinks.tsv
Original file line number Diff line number Diff line change
@@ -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
Loading