Package 'bustalab'

Title: Busta Lab Tools Built on 'phylochemistry'
Description: Lab tools for the Busta lab: the full-featured GC-MS / GC-TCD peak integration app, a GenomeScope genome-size estimator, a client for the lab's 'dgx' language-model servers, and cached download helpers for lab reference datasets. Attaching this package also attaches 'phylochemistry'.
Authors: Lucas Busta [aut, cre]
Maintainer: Lucas Busta <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-11-23 18:26:07 UTC
Source: https://github.com/thebustalab/phylochemistry

Help Index


Retired GC-MS apps (versions 2 to 6)

Description

These versions have been retired. Each one stops with a message pointing at analyzeGCMSdata7(), the current app.

Usage

analyzeGCMSdata2(...)

analyzeGCMSdata3(...)

analyzeGCMSdata4(...)

analyzeGCMSdata5(...)

analyzeGCMSdata6(...)

Arguments

...

Ignored.

Value

Nothing; always signals an error.

Examples

try(analyzeGCMSdata6("/path/to/your/CDF/folder"))

Interactive GC-MS / GC-TCD peak integration app (version 7)

Description

Opens a folder of ANDI-MS or ANDI-Chrom .CDF files, builds the chromatograms, and serves a Shiny app for baseline correction, peak detection and integration, all-ion views, co-elution splits and peak labelling. The app sets the working directory to CDF_directory_path and writes its state there (⁠<file>.CDF.csv⁠, chromatograms.csv, samples_monolist.csv, peaks_monolist.csv, caches and stamps).

Usage

analyzeGCMSdata7(
  CDF_directory_path = getwd(),
  zoom_and_scroll_rate = 100,
  baseline_window = 400,
  samples_per_page = 20,
  compact = FALSE,
  x_axis_start_default = NULL,
  x_axis_end_default = NULL,
  path_to_reference_library = busta_spectral_library,
  samples_monolist_subset = NULL,
  ions = 0,
  all_ion_view = FALSE,
  all_ion_threshold = 0.02,
  all_ion_scaling = "sqrt",
  all_ion_max_points = 1200,
  integrate_peak_ions = TRUE,
  score_peak_confidence = TRUE,
  confidence_thresholds = c(0.75, 0.9),
  coelution_crosstalk = c(0, 0),
  facet_label_size = 12,
  facet_label_wrap = 14,
  n_cores = NULL,
  ms_classifier_path = "/project_data/shared/mass_spectral_library/ms_classifier.py",
  jupyter = FALSE
)

Arguments

CDF_directory_path

Folder holding the .CDF files.

zoom_and_scroll_rate

Ignored; kept so old calls still run.

baseline_window

Baseline window, in scans, for new samples.

samples_per_page

Samples drawn per page.

compact

Ignored (Overview mode was removed); kept so old calls still run.

x_axis_start_default, x_axis_end_default

Initial x window (retention time).

path_to_reference_library

Unused; kept so old calls still run.

samples_monolist_subset

Optional subset of samples to load.

ions

Extra ions to extract; the TIC (ion 0) is always extracted.

all_ion_view

Start in the all-ion display.

all_ion_threshold

Ion-inclusion threshold for the all-ion views.

all_ion_scaling

Initial y scaling for the all-ion views.

all_ion_max_points

Maximum x points drawn per trace in the all-ion views.

integrate_peak_ions

Compute area_peak_ions alongside area.

score_peak_confidence

Compute spectrum-agreement confidence squares.

confidence_thresholds

Agreement thresholds for the confidence squares.

coelution_crosstalk

Supplied cross-talk for two-compound co-elution splits.

facet_label_size, facet_label_wrap

Sample-name strip size and wrap width.

n_cores

Cores for parallel prefetch (NULL = min(8, cores - 2); 1 = serial).

ms_classifier_path

Path to the Python peak classifier used by Shift+4; NULL or a missing file skips classification.

jupyter

If TRUE, serve the app on a free port from the lab's proxied pool and print its URL; if FALSE, return the shinyApp object.

Value

With jupyter = FALSE, a shiny.appobj; otherwise the app is run.


Generate text on the lab's dgx server

Description

Sends one prompt to the dgx generate endpoint (an SSH tunnel on the lab's JupyterHub) and returns the parsed JSON reply. If the server answers 503 "memory_admission" the call waits and retries for up to max_wait_sec.

Usage

dgxGenerate(
  prompt,
  model = NULL,
  quant = NULL,
  max_tokens = 256,
  system = NULL,
  logprobs = NULL,
  server_url = Sys.getenv("DGX_GENERATE_URL", "http://127.0.0.1:9002"),
  timeout_sec = 900,
  max_wait_sec = as.numeric(Sys.getenv("DGX_MEMORY_WAIT_SEC", 4 * 3600)),
  on_wait = NULL
)

Arguments

prompt

Prompt text.

model

Model id, e.g. "google/gemma-4-12B-it"; NULL uses the server default.

quant

Quantisation: 4 = nf4, 8 = int8, 16 = bf16.

max_tokens

Maximum tokens to generate.

system

Optional system prompt.

logprobs

Optional 1-3: return token log-probabilities (needs max_tokens <= 512).

server_url

Base URL of the generate server (env DGX_GENERATE_URL).

timeout_sec

Request timeout in seconds; a cold model load takes about 180 s.

max_wait_sec

Longest total wait for memory admission, in seconds; 0 fails at once.

on_wait

Internal: a function called before and after each memory wait.

Value

A list parsed from the server's JSON reply (completion, duration_sec, ...).


Report whether the dgx generate server is reachable and busy

Description

Report whether the dgx generate server is reachable and busy

Usage

dgxGridStatus()

Value

NULL, invisibly; the status is printed as a message.


Check the dgx endpoints (generate, ESM2, ESMC)

Description

Check the dgx endpoints (generate, ESM2, ESMC)

Usage

dgxHealth()

Value

NULL, invisibly; one status line per endpoint is printed as a message.


Largest grid runModelGrid() will start

Description

Largest grid runModelGrid() will start

Usage

dgxMaxGridCells()

Value

The cell limit (env DGX_MAX_GRID_CELLS, default 5000).


Estimate genome size and heterozygosity from a k-mer histogram (GenomeScope 2.0)

Description

A port of GenomeScope 2.0: fits the k-mer spectrum with a negative-binomial mixture model by nonlinear least squares (minpack.lm::nlsLM()) and writes the summary, model and progress files into output_dir.

Usage

genomeScope(input_histogram_file, output_dir, ploidy, kmer_length)

Arguments

input_histogram_file

Path to a two-column k-mer histogram (coverage, count), whitespace separated, no header.

output_dir

Output directory (created if needed).

ploidy

Ploidy of the model, 1 to 6.

kmer_length

k-mer length used to build the histogram.

Value

Called for its side effects (files in output_dir).


Lab reference datasets (downloaded once, then cached)

Description

Fetches one of the lab's reference datasets from the lab website on first use, caches the file under tools::R_user_dir("bustalab", "cache") and reads it with the same reader and column types the old bustalab <- TRUE loader used.

Usage

getLabDataset(
  name,
  refresh = FALSE,
  cache_dir = tools::R_user_dir("bustalab", "cache")
)

Arguments

name

Dataset name; omit it to list the available names.

refresh

If TRUE, download again even when a cached copy exists.

cache_dir

Where cached files are kept.

Details

  • "busta_spectral_library": the lab mass-spectral library (CSV, about 40 MB).

  • "plant_phylogeny": a plant phylogeny (ape::read.tree() of a Newick file).

  • "plant_species": the plant species table (CSV).

Value

The dataset (a tibble, or a phylo tree for "plant_phylogeny"); with name missing, a character vector of dataset names.

Examples

getLabDataset()
## Not run: 
busta_spectral_library <- getLabDataset("busta_spectral_library")

## End(Not run)

Run every prompt against every (model, quantisation) on the dgx

Description

Batched by cell, resumable (re-running skips rows that succeeded and retries failed ones) and refuses to start against an unreachable server or a grid larger than dgxMaxGridCells() unless force = TRUE.

Usage

runModelGrid(
  prompts,
  models = c("google/gemma-4-E2B-it", "google/gemma-4-E4B-it", "google/gemma-4-12B-it",
    "google/gemma-4-26B-A4B-it", "google/gemma-4-31B-it"),
  quants = c(4),
  out_csv = "grid_results.csv",
  max_tokens = 16,
  system = NULL,
  labels = NULL,
  verbose = TRUE,
  force = FALSE,
  max_consecutive_errors = as.numeric(Sys.getenv("DGX_MAX_CONSECUTIVE_ERRORS", "10")),
  logprobs = NULL
)

Arguments

prompts

Character vector of prompts.

models

Model ids.

quants

Quantisations (4, 8, 16).

out_csv

Results CSV, appended after every prompt.

max_tokens

Maximum tokens per generation.

system

Optional system prompt.

labels

Prompt ids; defaults to seq_along(prompts).

verbose

Print progress.

force

Start even if the pre-flight check fails.

max_consecutive_errors

Stop after this many failures in a row.

logprobs

Optional 1-3, as in dgxGenerate(); adds two columns.

Value

out_csv, invisibly.