| Title: | Strain Level Microbiome Wide Association Studies |
|---|---|
| Description: | Fits statistical models to detect microbial strains associated with a phenotype. For small sample sizes, models can be fitted using empirical Bayes maximum a posteriori (MAP) priors to improve detection power. Supports various experimental design scenarios, including repeated measures. |
| Authors: | Gerry Tonkin-Hill [aut], Sudaraka Mallawarachchi [aut, cre] (ORCID: <https://orcid.org/0000-0001-8899-3323>) |
| Maintainer: | Sudaraka Mallawarachchi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.2 |
| Built: | 2026-09-16 17:49:29 UTC |
| Source: | https://github.com/gtonkinhill/strainspy |
This function fits a linear regression model using stats::lm() or lmerTest::lmer(). The latter is used for models with random effects.
It takes a SummarizedExperiment object as input, along with a user-defined formula, and fits a linear model on the assay data.
abundanceFit( se, design, nthreads = 1, scale_continuous = TRUE, transform = NULL, BPPARAM = NULL, progress = TRUE )abundanceFit( se, design, nthreads = 1, scale_continuous = TRUE, transform = NULL, BPPARAM = NULL, progress = TRUE )
se |
SummarizedExperiment. A |
design |
Formula. A formula to specify the fixed and random effects, e.g., |
nthreads |
An integer specifying the number of (CPUs or workers) to use. Defaults to one 1. |
scale_continuous |
Logical. If |
transform |
If data is already transformed, set to |
BPPARAM |
Optional |
progress |
Logical. If |
Generally, these linear models are useful to model compositional abundance data (e.g. Taxonomic_abundance in Sylph Profile) with appropriate transforms.
A strainspy_fit object with the following components:
row_data |
A DFrame with 6 slots with feature details |
coefficients |
A DFrame with coefficients for each feature |
std_errors |
A DFrame of standard errors for each feature |
p_values |
A DFrame of p-values for each feature |
residuals |
A DFrame of residual vectors for each feature |
convergence |
A named logical vector indicating convergence for each feature |
design |
Formula used in the call to |
call |
Call to |
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta, 'Taxonomic_abundance') se <- filter_by_presence(se, 20) design <- as.formula(" ~ Case_status + Age_at_collection") fit <- abundanceFit(se[1:10,], design, nthreads=2, transform='CLR') top_hits(fit, alpha = 0.5)library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta, 'Taxonomic_abundance') se <- filter_by_presence(se, 20) design <- as.formula(" ~ Case_status + Age_at_collection") fit <- abundanceFit(se[1:10,], design, nthreads=2, transform='CLR') top_hits(fit, alpha = 0.5)
This function calculates the distance between samples in a SummarizedExperiment object representing strain level ANI data.
ani_distance( se, taxonomy = NULL, tax_level = "Species", collapse_method = "representative" )ani_distance( se, taxonomy = NULL, tax_level = "Species", collapse_method = "representative" )
se |
A |
taxonomy |
An optional |
tax_level |
A character string specifying the taxonomic level at which to collapse the ANI values. (default="Species") |
collapse_method |
A character string specifying the method to use to collapse the ANI values. Must be one of 'representative', 'mean' or 'max'. (default='representative') |
A distance matrix.
example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") tax_path <- system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy") se <- read_sylph(example_path) tax <- read_taxonomy(tax_path) distance_matrix <- ani_distance(se)example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") tax_path <- system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy") se <- read_sylph(example_path) tax <- read_taxonomy(tax_path) distance_matrix <- ani_distance(se)
This function fits a logistic regression model similar to that published in the original Sylph paper.
It takes a SummarizedExperiment object as input, along with a user-defined formula.
caseControlFit( se, design, min_identity = 0.98, nthreads = 1, scale_continuous = TRUE, BPPARAM = NULL, progress = TRUE )caseControlFit( se, design, min_identity = 0.98, nthreads = 1, scale_continuous = TRUE, BPPARAM = NULL, progress = TRUE )
se |
SummarizedExperiment. A |
design |
Formula. A formula to specify the fixed and random effects, e.g., |
min_identity |
A numeric value specifying the minimum identity threshold to consider (default=0.98). |
nthreads |
An integer specifying the number of (CPUs or workers) to use. Defaults to one 1. |
scale_continuous |
Logical. If |
BPPARAM |
Optional |
progress |
Logical. If |
A strainspy_fit object with the following components:
row_data |
A DFrame with 6 slots with feature details |
coefficients |
A DFrame with coefficients for each feature |
std_errors |
A DFrame of standard errors for each feature |
p_values |
A DFrame of p-values for each feature |
residuals |
A DFrame of residual vectors for each feature |
convergence |
A named logical vector indicating convergence for each feature |
design |
Formula used in the call to |
call |
Call to |
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_meta$Case_status <- factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula("Case_status ~ Value + Age_at_collection") fit <- caseControlFit(se[1:10,], design, nthreads=2)library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_meta$Case_status <- factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula("Case_status ~ Value + Age_at_collection") fit <- caseControlFit(se[1:10,], design, nthreads=2)
progress argumentInternal helper used by the fitting functions to check that progress is a
single, non-missing logical value.
check_progress(progress)check_progress(progress)
progress |
The value supplied to a |
progress, invisibly.
read_sylph(), read_metaphlan() and read_sourmash() all reduce
Sample_file to a bare basename when clean_names = TRUE. Two input paths
that differ only by directory (runA/S1.fastq.gz and runB/S1.fastq.gz)
therefore collapse to the same name. Duplicated names are not rejected by
SummarizedExperiment, and every downstream match() on sample or feature
names would then silently attach the wrong metadata to the wrong column, so
fail here instead.
check_unique_names(x, what, clean_names = FALSE)check_unique_names(x, what, clean_names = FALSE)
x |
Character vector of names to check. |
what |
Character. What the names identify, used in the error message
(for example |
clean_names |
Logical. Whether the caller applied basename cleaning; used only to tailor the suggested remedy. |
x, invisibly, if every name is unique.
Automatically clean contig names for plots
clean_contig_names(contig_names, max_length = 50, return_map = FALSE)clean_contig_names(contig_names, max_length = 50, return_map = FALSE)
contig_names |
Vector of contig names. These will be cleaned up. This function usually works with long sylph contigs, such as those given by |
max_length |
Numeric. Number of characters to keep (default 50) |
return_map |
bool. Return data.frame of original and shortened contig names for mapping |
A data.frame or original and shortened names, or a vector of shortened name in the same order
In the zero-inflated beta model, beta effects represent changes in strain identity and are modeled on the logit scale. While this scale is effective for distinguishing phenotype groups statistically, the resulting effect sizes are not directly interpretable as differences in mean ANI. Same applies for effect sizes from the ordinal beta model.
comp_ani_diff_and_posthoc_test( se, fit, th = NULL, simplified_formula = NULL, beta_min_nz = 0.1, beta_min_ani_diff = 0.015, nthreads = 1L, reorder_hits = FALSE, BPPARAM = NULL, progress = TRUE )comp_ani_diff_and_posthoc_test( se, fit, th = NULL, simplified_formula = NULL, beta_min_nz = 0.1, beta_min_ani_diff = 0.015, nthreads = 1L, reorder_hits = FALSE, BPPARAM = NULL, progress = TRUE )
se |
SummarizedExperiment. A |
fit |
A fitted |
th |
|
simplified_formula |
A formula to use instead of |
beta_min_nz |
Minimum non-zero proportion per phenotype group required
to consider a beta hit is well supported. Hits driven by a proportion
of non zero values below this threshold at least in one phenotype group are
flagged |
beta_min_ani_diff |
Minimum absolute mean ANI difference required for
a beta hit to be considered meaningful. Effect sizes small than this are
flagged: |
nthreads |
Number of threads for parallel processing. Default |
reorder_hits |
Logical. Return |
BPPARAM |
Optional BiocParallelParam object. |
progress |
Logical. If |
This function converts logit-scale beta effects into response-scale
mean ANI differences using marginal means and pairwise contrasts
(requires emmeans). It therefore provides an interpretable estimate of the
magnitude of strain-level differences between phenotype groups, along
with post hoc quality checks for poorly supported beta signals.
Posthoc testing uses two approaches. First, it counts the number of non-zero observations supporting each beta effect. Second, it compares the estimated mean ANI difference against a preset threshold. A comment is added to each hit depending on the outcome.
By default, this function uses the formula from fit@design. However, if the
formula contains multiple covariates, this can cause emmeans to behave
unexpectedly. For example, if fit@design = ~ disease + age + sex + country + (1|study),
this can cause this function to throw errors or warnings. Using a simplified_formula = ~ disease
to override can be a useful approach.
This function is designed to directly work on the tibble returned from
top_hits().
A tibble similar to th, with added columns giving details on:
Component (Beta, ZI or both), Mean ANI_Difference, Contrast, Non-Zero Counts
of contrast components, and a general Comment on each hit. The commetn will
be NA if the hit passes all posthoc tests.
if (requireNamespace("emmeans", quietly = TRUE)) { meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30)[1:10, ] fit <- glmZiBFit(se, ~ Case_status + Age_at_collection, nthreads = 1) th <- top_hits(fit, coef = 2, alpha = 1) posthoc <- comp_ani_diff_and_posthoc_test(se, fit, th, nthreads = 1) head(posthoc$ANI_Difference) }if (requireNamespace("emmeans", quietly = TRUE)) { meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30)[1:10, ] fit <- glmZiBFit(se, ~ Case_status + Age_at_collection, nthreads = 1) th <- top_hits(fit, coef = 2, alpha = 1) posthoc <- comp_ani_diff_and_posthoc_test(se, fit, th, nthreads = 1) head(posthoc$ANI_Difference) }
Fits fast binomial and beta models to estimate MAP prior SDs for use in
zero-inflated and ordinal beta models fitted using GLMMTMB.
compute_eb_priors( se, design, nthreads = 1L, BPPARAM = NULL, low_cutoff = 0.1, high_cutoff = 10, est_disperion_prior = FALSE, progress = TRUE )compute_eb_priors( se, design, nthreads = 1L, BPPARAM = NULL, low_cutoff = 0.1, high_cutoff = 10, est_disperion_prior = FALSE, progress = TRUE )
se |
A |
design |
A fixed-effects-only formula (e.g., ~ group + age + sex). |
nthreads |
An integer specifying the number of (CPUs or workers) to use. Defaults to one 1. |
BPPARAM |
Optional |
low_cutoff |
Ceiling for small SD estimates. Default 0.1 |
high_cutoff |
Floor for large SD estimates. Default 10 |
est_disperion_prior |
Estimate a prior for disperion (default = FALSE) |
progress |
Logical. If |
An object of class strainspy_priors.
if (requireNamespace("fastglm", quietly = TRUE) && requireNamespace("betareg", quietly = TRUE)) { meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) pri <- compute_eb_priors(se[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1) class(pri) }if (requireNamespace("fastglm", quietly = TRUE) && requireNamespace("betareg", quietly = TRUE)) { meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) pri <- compute_eb_priors(se[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1) class(pri) }
Constructor for strainspy_priors using preset or user defined priors
define_priors( se, design, method = "preset_weak", add_dispersion_prior = FALSE, priors_df = NULL )define_priors( se, design, method = "preset_weak", add_dispersion_prior = FALSE, priors_df = NULL )
se |
A |
design |
A fixed-effects-only formula (e.g., ~ group + age + sex). |
method |
Prior type ("preset_weak", "preset_strong", "manual"). To compute
empirical priors, use |
add_dispersion_prior |
Add a prior of normal(0,1) to the dispersion parameter. Default False |
priors_df |
NULL if |
An object of class strainspy_priors.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) pri <- suppressWarnings(define_priors(se[1:10, ], ~ Case_status + Age_at_collection, method = "preset_weak")) class(pri)meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) pri <- suppressWarnings(define_priors(se[1:10, ], ~ Case_status + Age_at_collection, method = "preset_weak")) class(pri)
Estimate beta diversity from ANI
estimate_beta_diversity( se, method = "manhattan", distance_only = FALSE, ani_threshold = 95, phenotype = NULL, show_plots = FALSE, return_plots = FALSE )estimate_beta_diversity( se, method = "manhattan", distance_only = FALSE, ani_threshold = 95, phenotype = NULL, show_plots = FALSE, return_plots = FALSE )
se |
SummarizedExperiment. A |
method |
Distance method: |
distance_only |
Logical. If TRUE, stop after computing distance matrix |
ani_threshold |
Numeric. Threshold for presence/absence determination if |
phenotype |
Any factor variable in |
show_plots |
Logical. If TRUE, shows the plots (default = FALSE) |
return_plots |
Logical. If TRUE, returns ggplot2 objects (default = FALSE) |
If distance_only = TRUE, returns distance object. Otherwise a list with:
distance — distance matrix
nmds — NMDS object
ordination — NMDS coordinates with group
permanova — PERMANOVA results
betadisper — betadisper object
plots — list of ggplot2 objects (if return_plots = TRUE)
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) d <- estimate_beta_diversity(se[1:15, ], distance_only = TRUE)meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) d <- estimate_beta_diversity(se[1:15, ], distance_only = TRUE)
This function estimates sample-level species richness and
strain coverage using ANI-based presence/absence. A strain is
considered present if ANI > ani_threshold.
estimate_sample_richness( se, taxonomy, ani_threshold = 95, report_strain_richness = FALSE )estimate_sample_richness( se, taxonomy, ani_threshold = 95, report_strain_richness = FALSE )
se |
SummarizedExperiment. A |
taxonomy |
An optional taxonomy file read using |
ani_threshold |
Numeric ANI threshold used to define presence (default: 95). |
report_strain_richness |
Return the estimated strain_richness count. See description (default: FALSE) |
Species richness is defined as the number of species with at least
one strain exceeding the ANI threshold. This requires taxonomy data, which
can be read in using read_taxonomy().
Experimental Strain coverage is a database-dependent, normalised score that increases with the number of reference strains detected within a species. When only one strain is present for a species, it contributes 1 towards strain coverage. Asmore strains are detected, the contribution increases toward 2, reaching 2 when all reference strains are detected. Although this is designed to prevent inflation for species with many reference strains, this measures the coverage of reference strain space in the database, not true biological strain richness. Therefore, this value is not returned by default.
The strain coverage metric is computed as:
where is the number of reference strains detected for a species
and is the total number of reference strains for that species
in the database.
This approach does not resolve true strain multiplicity and may overestimate coverage when a single biological strain matches many highly similar reference genomes. Alternative approaches are being investigated.
A named list with:
Integer vector giving the number of species detected per sample.
NA or Numeric vector giving the database-normalised strain coverage per sample.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) rich <- estimate_sample_richness(se[1:20, ], tax)meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) rich <- estimate_sample_richness(se[1:20, ], tax)
Access fixef priors needed for ordinal beta regression
extract_fixef_priors(object) ## S4 method for signature 'strainspy_priors' extract_fixef_priors(object)extract_fixef_priors(object) ## S4 method for signature 'strainspy_priors' extract_fixef_priors(object)
object |
A |
A data frame of prior parameters for fixed effects.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) pri <- suppressWarnings(define_priors(se[1:10, ], ~ Case_status + Age_at_collection, method = "preset_weak")) head(extract_fixef_priors(pri))meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) pri <- suppressWarnings(define_priors(se[1:10, ], ~ Case_status + Age_at_collection, method = "preset_weak")) head(extract_fixef_priors(pri))
SummarizedExperiment object in long formatExtract data from a StrainSpy SummarizedExperiment object in long format
extract_strainspy( se, variables = NULL, contigs = NULL, taxonomy = NULL, drop_zeros = FALSE )extract_strainspy( se, variables = NULL, contigs = NULL, taxonomy = NULL, drop_zeros = FALSE )
se |
SummarizedExperiment. A |
variables |
One or multiple variables in |
contigs |
A vector of contigs to generate violin plots |
taxonomy |
An optional taxonomy file read using strainspy::read_taxonomy (default=NULL). |
drop_zeros |
Bool. If TRUE, ANI or Abundance 0 values will not be included in the violin plot. Default FALSE. |
A long-format data.frame with sample metadata, contig identity columns,
ANI values, row-level annotations, and optional taxonomy columns.
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) # Change variable from character to factor example_meta$Case_status = factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) tax_path <- system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy") tax <- read_taxonomy(tax_path) extract_strainspy(se, variables = c("Case_status", "Age_at_collection"), contigs = rownames(se)[1:5], taxonomy=tax)library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) # Change variable from character to factor example_meta$Case_status = factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) tax_path <- system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy") tax <- read_taxonomy(tax_path) extract_strainspy(se, variables = c("Case_status", "Age_at_collection"), contigs = rownames(se)[1:5], taxonomy=tax)
The fitting backends signal failure in two different ways. glmObFit(),
glmQBFit() and abundanceFit() return NULL for a feature that could not
be fitted, so the failure shows up as a zero-length entry. Both glmZiBFit()
backends instead return a fully-populated list whose coefficient matrices are
NA and whose log_likelihood is NA, so the zero-length test never fires
there and the NA log-likelihood is the only signal.
failed_fit_index(results)failed_fit_index(results)
results |
A list of per-feature fit results, one element per feature,
in the same order as |
Detecting only one of the two leaves failed fits in the results, and applying
the log_likelihood test blindly is worse: glmQBFit() does not report a
log-likelihood at all, so every successful fit would look like a failure.
This helper handles both protocols by treating a log-likelihood that is
absent from every result as "not reported" rather than "all failed".
It deliberately uses vapply() rather than unlist(). unlist() silently
drops the NULL log-likelihood of a zero-length entry, which shortens the
vector and shifts every later index, so the returned positions would no
longer line up with results or with rowData().
An increasing integer vector of positions in results that should be
dropped, or integer(0) if every fit succeeded.
This function filters a SummarizedExperiment object to keep only rows (features/strains) that are present in a specified number of samples. The same rows are filtered from all assays in the SummarizedExperiment.
filter_by_presence(se, min_nonzero = 10)filter_by_presence(se, min_nonzero = 10)
se |
A |
min_nonzero |
Integer. The minimum number of non-zero entries required to retain a row. Default is 10. |
A filtered SummarizedExperiment object with only the rows that meet the criteria.
example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path) # Filter to keep only rows with >20 non-zero entries filtered_se <- filter_by_presence(se, min_nonzero = 20)example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path) # Filter to keep only rows with >20 non-zero entries filtered_se <- filter_by_presence(se, min_nonzero = 20)
This function is copied from filter_by_presence(). Additionally, it rescales abundances such that each sample sums back to 100. Since this behaviour is not useful for association testing, this function is not exported.
filter_by_presence_and_rescale(se, min_nonzero = 10, rescale_abundance = FALSE)filter_by_presence_and_rescale(se, min_nonzero = 10, rescale_abundance = FALSE)
se |
A |
min_nonzero |
Integer. The minimum number of non-zero entries required to retain a row. Default is 10. |
rescale_abundance |
bool. Instead of containment ANI (e.g. sylph), if |
A filtered SummarizedExperiment object with only the rows that meet the criteria.
example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path) # Filter to keep only rows with at least 10 non-zero entries in the assay filtered_se <- filter_by_presence(se) # View the filtered object filtered_seexample_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path) # Filter to keep only rows with at least 10 non-zero entries in the assay filtered_se <- filter_by_presence(se) # View the filtered object filtered_se
FThis function filters a SummarizedExperiment object to keep only rows (features/strains)
present in at least min_subjects individuals and at least min_timepoints timepoints
per subject.
filter_by_presence_longitudinal( se, min_subjects = 3, min_timepoints = 2, subject_col = "subject", time_col = "time" )filter_by_presence_longitudinal( se, min_subjects = 3, min_timepoints = 2, subject_col = "subject", time_col = "time" )
se |
A |
min_subjects |
Integer. Minimum number of subjects that must have the strain. |
min_timepoints |
Integer. Minimum number of non-zero timepoints per subject.Default is 3. |
subject_col |
Character. Column name in |
time_col |
Character. Column name in |
A filtered SummarizedExperiment object with only the rows that meet the criteria.
Fits a simple linear model for functions without random effects using stats::lm()
fit_lm(se_subset, col_data, combined_formula)fit_lm(se_subset, col_data, combined_formula)
se_subset |
A |
col_data |
A data frame containing the design matrix and additional covariates. |
combined_formula |
The formula for the conditional mean model. |
A list with model coefficients, zero-inflation coefficients, residuals, log-likelihood, and convergence status.
Fits a linear model for a single feature in an assay using lmerTest::lmer()
fit_lmer(se_subset, col_data, combined_formula)fit_lmer(se_subset, col_data, combined_formula)
se_subset |
A |
col_data |
A data frame containing the design matrix and additional covariates. |
combined_formula |
The formula for the conditional mean model. |
A list with model coefficients, zero-inflation coefficients, residuals, log-likelihood, and convergence status.
Fits a logistic regression for a single feature in an assay
using glmmTMB.
fit_logit_model(se_subset, col_data, design, fixed_priors, min_identity)fit_logit_model(se_subset, col_data, design, fixed_priors, min_identity)
se_subset |
A |
col_data |
A data frame containing the design matrix and additional covariates. |
design |
Formula. A formula to specify the fixed and random effects, e.g., |
fixed_priors |
Optional priors for the model. |
min_identity |
A numeric value specifying the minimum identity threshold to consider (default=0.98). |
A list with model coefficients, zero-inflation coefficients, residuals, log-likelihood, and convergence status.
Fits a zero-inflated beta regression for a single feature in an assay
using glmmTMB.
fit_ob_model(se_subset, col_data, combined_formula, fixed_priors, family)fit_ob_model(se_subset, col_data, combined_formula, fixed_priors, family)
se_subset |
A |
col_data |
A data frame containing the design matrix and additional covariates. |
combined_formula |
The formula for the conditional mean model. |
fixed_priors |
Optional priors for the model. |
family |
A |
A list where each element contains per-feature fitted coefficients, residuals, and convergence status.
Fits a quasibinomial regression for a single feature in an assay
using stats::glm().
fit_qb_model(se_subset, col_data, combined_formula)fit_qb_model(se_subset, col_data, combined_formula)
se_subset |
A |
col_data |
A data frame containing the design matrix and additional covariates. |
combined_formula |
The formula for the conditional mean model. |
A list where each element contains per-feature fitted coefficients, residuals, and convergence status.
Fits a zero-inflated beta regression for a single feature in an assay
using glmmTMB.
fit_zero_inflated_beta( se_subset, col_data, combined_formula, design, fixed_priors )fit_zero_inflated_beta( se_subset, col_data, combined_formula, design, fixed_priors )
se_subset |
A |
col_data |
A data frame containing the design matrix and additional covariates. |
combined_formula |
The formula for the conditional mean model. |
design |
The formula for the zero-inflation model. |
fixed_priors |
Optional priors for the model. |
A list with model coefficients, zero-inflation coefficients, residuals, log-likelihood, and convergence status.
Fits a zero-inflated beta regression for a single feature in an assay
using gamlss.
fit_zero_inflated_beta_gamlss( se_subset, col_data, combined_formula, design, fixed_priors, progress = TRUE )fit_zero_inflated_beta_gamlss( se_subset, col_data, combined_formula, design, fixed_priors, progress = TRUE )
se_subset |
A |
col_data |
A data frame containing the design matrix and additional covariates. |
combined_formula |
The formula for the conditional mean model. |
design |
The formula for the zero-inflation model. |
fixed_priors |
Optional priors for the model. |
progress |
Logical. If |
A list with model coefficients, zero-inflation coefficients, residuals, log-likelihood, and convergence status.
This function generates a vector of colours for plotting, prioritising a fixed palette of 21 distinct colours.
If more than 21 colours are required, additional colours are generated using grDevices::rainbow().
get_colors(n)get_colors(n)
n |
Integer. The number of colours needed. |
A character vector of n colour hex codes.
Generate a confusion matrix for a fitted model
get_confusion_mx(top_hits, gt_contigs, all_contigs, print_cm = TRUE)get_confusion_mx(top_hits, gt_contigs, all_contigs, print_cm = TRUE)
top_hits |
Output from |
gt_contigs |
Vector of ground truth contigs |
all_contigs |
Vector of all contigs |
print_cm |
logical. Print the confusion matrix (default = TRUE) |
Confusion Matrix.
Gets the ordered list of fitted contig names in a strainspy_fit
getContigNames(object) ## S4 method for signature 'strainspy_fit' getContigNames(object)getContigNames(object) ## S4 method for signature 'strainspy_fit' getContigNames(object)
object |
An object of class |
A vector of contig names
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) head(getContigNames(fit))meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) head(getContigNames(fit))
Gets the ordered list of fitted genomes in a strainspy_fit
getGenomes(object) ## S4 method for signature 'strainspy_fit' getGenomes(object)getGenomes(object) ## S4 method for signature 'strainspy_fit' getGenomes(object)
object |
An object of class |
A vector of fitted genomes
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) head(getGenomes(fit))meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) head(getGenomes(fit))
Returns the residuals from a strainspy_fit object.
getResiduals(object) ## S4 method for signature 'strainspy_fit' getResiduals(object)getResiduals(object) ## S4 method for signature 'strainspy_fit' getResiduals(object)
object |
An object of class |
A DataFrame containing residuals.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) class(getResiduals(fit))meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) class(getResiduals(fit))
Gets the ordered list of samples used in strainspy_fit
getSamples(object) ## S4 method for signature 'strainspy_fit' getSamples(object)getSamples(object) ## S4 method for signature 'strainspy_fit' getSamples(object)
object |
An object of class |
A vector of fitted sample names
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) head(getSamples(fit))meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) head(getSamples(fit))
Returns the zero-inflation coefficients from a strainspy_fit object.
getZICoefficients(object) ## S4 method for signature 'strainspy_fit' getZICoefficients(object)getZICoefficients(object) ## S4 method for signature 'strainspy_fit' getZICoefficients(object)
object |
An object of class |
A DataFrame containing zero-inflation coefficients.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) class(getZICoefficients(fit))meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) class(getZICoefficients(fit))
TODO: Implement return of vcov info. Patched for compatibility (returns NULL)
glmObFit( se, design, nthreads = 1L, scale_continuous = TRUE, MAP_prior = "preset_weak", family = glmmTMB::ordbeta(), BPPARAM = NULL, progress = TRUE )glmObFit( se, design, nthreads = 1L, scale_continuous = TRUE, MAP_prior = "preset_weak", family = glmmTMB::ordbeta(), BPPARAM = NULL, progress = TRUE )
se |
SummarizedExperiment. A |
design |
Formula. A formula to specify the fixed and random effects, e.g., |
nthreads |
An integer specifying the number of (CPUs or workers) to use. Defaults to one 1. |
scale_continuous |
Logical. If |
MAP_prior |
One of |
family |
A |
BPPARAM |
Optional |
progress |
Logical. If |
This function fits a ordinalbeta regression model using the glmmTMB package.
It takes a SummarizedExperiment object as input, along with a user-defined formula,
and fits an ordinal beta regression model on the assay data.
For robust model fitting, it is recommended to use maximum a posteriori (MAP)
estimation. Emprical Bayes MAP priors can be computed using strainspy::compute_eb_priors().
They can also be manually defined using strainspy::define_priors(). The resulting
strainspy_priors object can be passed to the MAP_prior argument.
Alternatively, a character string ("preset_weak" or "preset_strong") or a
valid prior data.frame (see ?glmmTMB::priors) can be provided instead.
This will result in a call to strainspy::define_priors() to generate priors.
To disable MAP estimation and perform standard REML fitting, set MAP_prior = NULL.
A strainspy_fit object with the following components:
row_data |
A DFrame with 6 slots with feature details |
coefficients |
A DFrame with coefficients for each feature |
std_errors |
A DFrame of standard errors for each feature |
p_values |
A DFrame of p-values for each feature |
residuals |
A DFrame of residual vectors for each feature |
convergence |
A named logical vector indicating convergence for each feature |
design |
Formula used in the call to |
call |
Call to |
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status + Age_at_collection") fit <- glmObFit(se[1:10,], design, family=glmmTMB::ordbeta())library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status + Age_at_collection") fit <- glmObFit(se[1:10,], design, family=glmmTMB::ordbeta())
This function fits a quasibinomial regression model using stats::glm().
glmQBFit( se, design, nthreads = 1L, scale_continous = TRUE, BPPARAM = NULL, progress = TRUE )glmQBFit( se, design, nthreads = 1L, scale_continous = TRUE, BPPARAM = NULL, progress = TRUE )
se |
SummarizedExperiment. A |
design |
Formula. A formula to specify fixed effects, e.g.,
|
nthreads |
An integer specifying the number of (CPUs or workers) to use. Defaults to one 1. |
scale_continous |
Logical. If |
BPPARAM |
Optional |
progress |
Logical. If |
It takes a SummarizedExperiment object as input, along with a user-defined
formula containing only fixed effect parameters, and fits a quasibinomial
regression model on the assay data.
A strainspy_fit object with the following components:
row_data |
A DFrame with 6 slots with feature details |
coefficients |
A DFrame with coefficients for each feature |
std_errors |
A DFrame of standard errors for each feature |
p_values |
A DFrame of p-values for each feature |
residuals |
A DFrame of residual vectors for each feature |
convergence |
A named logical vector indicating convergence for each feature |
design |
Formula used in the call to |
call |
Call to |
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status") fit <- glmQBFit(se[1:10,], design, nthreads=2)library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status") fit <- glmQBFit(se[1:10,], design, nthreads=2)
This function fits a zero-inflated beta regression model using either glmmTMB or gamlss packages.
It takes a SummarizedExperiment object as input, along with a user-defined formula,
and fits a zero-inflated beta regression model on the assay data.
glmZiBFit( se, design, nthreads = 1, scale_continuous = TRUE, MAP_prior = "preset_weak", BPPARAM = NULL, method = "glmmTMB", return_vcov = TRUE, progress = TRUE )glmZiBFit( se, design, nthreads = 1, scale_continuous = TRUE, MAP_prior = "preset_weak", BPPARAM = NULL, method = "glmmTMB", return_vcov = TRUE, progress = TRUE )
se |
SummarizedExperiment. A |
design |
Formula. A formula to specify the fixed and random effects, e.g., |
nthreads |
An integer specifying the number of (CPUs or workers) to use. Defaults to one 1. |
scale_continuous |
Logical. If |
MAP_prior |
One of |
BPPARAM |
Optional |
method |
Character. The method to use for fitting the model. Either 'glmmTMB' (default) or 'gamlss'. |
return_vcov |
Logical. Return variance-covariance matrices for each model, required for |
progress |
Logical. If |
A strainspy_fit object with the following components:
row_data |
A DFrame with 6 slots with feature details |
coefficients |
A DFrame with coefficients for each feature |
std_errors |
A DFrame of standard errors for each feature |
p_values |
A DFrame of p-values for each feature |
zi_coefficients |
A DFrame of zero inflated coefficients for each feature |
zi_std_errors |
A DFrame of zero inflated standard errors for each feature |
zi_p_values |
A DFrame of zero inflated p-values for each feature |
residuals |
A DFrame of residual vectors for each feature |
convergence |
A named logical vector indicating convergence for each feature |
design |
Formula used in the call to |
call |
Call to |
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status") fit <- glmZiBFit(se[1:10,], design, nthreads=2)library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status") fit <- glmZiBFit(se[1:10,], design, nthreads=2)
This function performs multiple testing adjustment on the results of a betaGLM object integrating taxonomic information. Various correction methods are available, including Harmonic Mean P-value (HMP), Bonferroni and Benjamini-Hochberg (BH).
hadjust(object, coef = 2, method = "HMP", taxonomy = NULL, index_range = FALSE)hadjust(object, coef = 2, method = "HMP", taxonomy = NULL, index_range = FALSE)
object |
A |
coef |
The coefficient to use for p-value adjustment. Defaults to 2. |
method |
The method for p-value adjustment. Options include "bonferroni" and Harmonic Mean P-value (HMP). |
taxonomy |
A taxonomy data.table object. If provided, the p-values will be adjusted at each taxonomic level. |
index_range |
This option is only used to generate Manhattan plot segments for higher taxonomic levels |
A tibble with original and adjusted p-values.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) fit <- glmZiBFit(se[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) out <- hadjust(fit, coef = 2, taxonomy = tax) head(out)meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) fit <- glmZiBFit(se[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) out <- hadjust(fit, coef = 2, taxonomy = tax) head(out)
Merge MetaPhlAn >=4.0 profiles into a single file to use with read_metaphlan() and generate the taxonomy file required for downstream analysis.
merge_metaphlan_files( metaphlan_files, output_folder, output_filename = "metaphlan", sgb_database = TRUE )merge_metaphlan_files( metaphlan_files, output_folder, output_filename = "metaphlan", sgb_database = TRUE )
metaphlan_files |
A character vector of file paths to merge. Optionally, if the input is named, |
output_folder |
Folder path to save outputs. |
output_filename |
File name for the two outputs. By default, the two files will be saved as metaphlan_merged.tsv.gz and metaphlan_taxonomy.tsv.gz |
sgb_database |
bool. Specify whether the default sgb database was used for profiling. Set to FALSE if |
Invisibly returns NULL. The function writes two files to output_folder:
a merged profile table (*_merged.tsv.gz) and a taxonomy table (*_taxonomy.tsv.gz).
files <- character(0) is.character(files)files <- character(0) is.character(files)
Merge the outputs of sourmash search or sourmash gather into a single file.
The output of this function is suitable to use in read_sourmash()
merge_sourmash_files( sourmash_files, manifest_file = NULL, output, strip_unusable = TRUE )merge_sourmash_files( sourmash_files, manifest_file = NULL, output, strip_unusable = TRUE )
sourmash_files |
A character vector of file paths to merge. |
manifest_file |
If one or several indexed databases were used for searching or gathering, required genome column can be missing.
The path to the output of |
output |
Save path for the output file. Internally, data.table::fwrite is used, provide the extension |
strip_unusable |
Remove columns containing data not useful for further analysis. Default TRUE. |
Refer to sourmash documentation for more information.
Invisibly returns NULL. The merged sourmash table is written to output.
# Split the bundled sourmash output into two per-query files, then merge them. hits <- data.table::fread( system.file("extdata", "example_sourmash.csv.gz", package = "strainspy") ) queries <- head(unique(hits$query_name), 2) parts <- vapply(queries, function(q) { f <- tempfile(fileext = ".csv") data.table::fwrite(hits[hits$query_name == q, ], f) f }, character(1)) merged <- tempfile(fileext = ".csv.gz") merge_sourmash_files(parts, output = merged) sm <- read_sourmash(merged) dim(sm)# Split the bundled sourmash output into two per-query files, then merge them. hits <- data.table::fread( system.file("extdata", "example_sourmash.csv.gz", package = "strainspy") ) queries <- head(unique(hits$query_name), 2) parts <- vapply(queries, function(q) { f <- tempfile(fileext = ".csv") data.table::fwrite(hits[hits$query_name == q, ], f) f }, character(1)) merged <- tempfile(fileext = ".csv.gz") merge_sourmash_files(parts, output = merged) sm <- read_sourmash(merged) dim(sm)
Merge the outputs of sylph query or sylph profile into a single file.
The output of this function is suitable to use in read_sylph()
merge_sylph_files(sylph_files, output)merge_sylph_files(sylph_files, output)
sylph_files |
A character vector of sylph output file paths to merge. |
output |
Save path for the output file. Internally, data.table::fwrite is used, provide the extension |
Invisibly returns NULL. The merged sylph table is written to output.
# Split the bundled profile into two per-sample files, then merge them back. profile <- data.table::fread( system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") ) samples <- head(unique(profile$Sample_file), 2) parts <- vapply(samples, function(s) { f <- tempfile(fileext = ".tsv") data.table::fwrite(profile[profile$Sample_file == s, ], f, sep = "\t") f }, character(1)) merged <- tempfile(fileext = ".tsv.gz") merge_sylph_files(parts, merged) # The merged file carries one header and both samples se <- read_sylph(merged) dim(se)# Split the bundled profile into two per-sample files, then merge them back. profile <- data.table::fread( system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") ) samples <- head(unique(profile$Sample_file), 2) parts <- vapply(samples, function(s) { f <- tempfile(fileext = ".tsv") data.table::fwrite(profile[profile$Sample_file == s, ], f, sep = "\t") f }, character(1)) merged <- tempfile(fileext = ".tsv.gz") merge_sylph_files(parts, merged) # The merged file carries one header and both samples se <- read_sylph(merged) dim(se)
SummarizedExperiment objectThis function adds or modifies metadata in a SummarizedExperiment object.
modify_metadata(se, meta_data, replace = FALSE, convert = TRUE)modify_metadata(se, meta_data, replace = FALSE, convert = TRUE)
se |
A SummarizedExperiment object. |
meta_data |
A data.frame with sample metadata. The first column must contain all samples returned by |
replace |
Logical. If TRUE, replaces existing colData. Default FALSE. |
convert |
Logical. If TRUE, attempts to auto-convert types as suited for model fitting (int to numeric, char to factor). Disable if meta_data is fully configured for model fitting. Default TRUE. See Details. |
If convert = TRUE, character columns with less than 5 unique (non-NA) values will be automatically
converted to factors, with levels ordered alphabetically. For meaningful association testing,
however, factor levels should reflect the intended reference level. It is recommended to
manually convert such variables to factors with explicitly set levels before calling modify_metadata().
Updated SummarizedExperiment object.
# Add or modify metadata subsequently example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path) se <- modify_metadata(se, example_meta)# Add or modify metadata subsequently example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path) se <- modify_metadata(se, example_meta)
nobars_ copied from https://github.com/bbolker/reformulas This function can work with formulas like ~cohort + timepoint + (1 + timepoint | patientID), above fails We can either use it like this, or add reformulas (or lme4) as a dependency
nobars_(term)nobars_(term)
term |
Formula object |
A formula without mixed components
This function reduces all non-zero ANI values by eps
offset_ANI(x, eps = 0.01)offset_ANI(x, eps = 0.01)
x |
Vector of ANI values in (0,1) |
eps |
offset value (default 1e-2) |
Adjusted ANI vector
Generate a violin or box plot for a subset of contigs for a categorical phenotype.
plot_ani_dist( se, phenotype, contigs, facet_phenotype = NULL, contig_names = NULL, show_zero_plot = TRUE, show_points = TRUE, plot = TRUE, plot_type = "box" )plot_ani_dist( se, phenotype, contigs, facet_phenotype = NULL, contig_names = NULL, show_zero_plot = TRUE, show_points = TRUE, plot = TRUE, plot_type = "box" )
se |
SummarizedExperiment. A |
phenotype |
Any factor variable in |
contigs |
A vector of contigs to generate distribution plots |
facet_phenotype |
Any factor variable in |
contig_names |
Optional character vector to replace long contig names in the plot.
Must match the length and order of |
show_zero_plot |
Bool. If TRUE, distribution of the proportion of zeros will also be plotted. Default TRUE |
show_points |
Bool. If TRUE, points will be overlaid with jitter using ggforce::geom_sina(). Default TRUE |
plot |
If set to false, the function will return a tibble with data used to generate the plot. |
plot_type |
Specify whether |
If plot = TRUE, returns a ggplot object (or a combined patchwork plot
when show_zero_plot = TRUE). If plot = FALSE, returns a long-format table
used to generate the ANI distribution plot.
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) # Change variable from character to factor example_meta$Case_status = factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_ani_dist(se, phenotype = "Case_status", contigs = rownames(se)[1:5])library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) # Change variable from character to factor example_meta$Case_status = factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_ani_dist(se, phenotype = "Case_status", contigs = rownames(se)[1:5])
Generate a histogram for a single contig for a categorical phenotype.
plot_histogram( se, phenotype, contig, bins = 250, drop_zeros = FALSE, show_quantiles = TRUE, fit_spline = FALSE, fit_control = 100, separate_facets = TRUE )plot_histogram( se, phenotype, contig, bins = 250, drop_zeros = FALSE, show_quantiles = TRUE, fit_spline = FALSE, fit_control = 100, separate_facets = TRUE )
se |
SummarizedExperiment. A |
phenotype |
One variable in |
contig |
Contig name to visualise |
bins |
Numeric. Number of bins to plot the histogram. This parameter should be adjusted to properly visualise the ANI differences. Default 250 |
drop_zeros |
Bool. If TRUE, ANI or Abundance 0 values will not be included in the violin plot. Default FALSE |
show_quantiles |
Bool. If TRUE, min, max, etc. will be shown as vertical lines. Default TRUE |
fit_spline |
Bool. If TRUE, a spline will be fitted to each histogram. Default FALSE |
fit_control |
Numeric. Smaller values increase the smoothness of the fitted spline. Default 100 |
separate_facets |
Bool. If TRUE, each category of the phenotype will be plotted in a separate facet. Default TRUE |
A ggplot histogram object. A summary table of per-group statistics is
attached as attr(plot, "summary_table").
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) # Change variable from character to factor example_meta$Case_status = factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_histogram(se, phenotype = "Case_status", contig = rownames(se)[1])library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) # Change variable from character to factor example_meta$Case_status = factor(example_meta$Case_status) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_histogram(se, phenotype = "Case_status", contig = rownames(se)[1])
This function can generate multiple Manhattan plots from a strainspy_fit object.
plot_manhattan( object, coef = 2, taxonomy = NULL, aggregate_by_taxa = NULL, method = "holm", alpha = 0.05, tax_levels = c("Phylum", "Genus", "Species", "Strain"), plot = TRUE )plot_manhattan( object, coef = 2, taxonomy = NULL, aggregate_by_taxa = NULL, method = "holm", alpha = 0.05, tax_levels = c("Phylum", "Genus", "Species", "Strain"), plot = TRUE )
object |
A |
coef |
The number of the coefficient from which to generate the plot (default=2). |
taxonomy |
An optional taxonomy file read using strainspy::read_taxonomy (default=NULL). |
aggregate_by_taxa |
Logical. If TRUE, aggregate p-values across |
method |
Character. Multiple testing correction method for p-values (e.g., "holm"). Defaults to "holm". Only applicable if |
alpha |
Numeric. Significance threshold for adjusted p-values. Defaults to 0.05. |
tax_levels |
Character vector. Subset of taxonomic levels: c("Domain", "Phylum", "Class", "Order", "Family", "Genus", "Species", "Strain") to include in the plot.
Defaults to c("Phylum", "Genus", "Species", "Strain"). Provided levels will be reordered by the standard hierarchy and the highest level is used for colouring. If it has >30 categories,
the legend is replaced by a named vector. Only applicable with |
plot |
If set to false, the function will return a tibble with data used to generate the plot. NOTE: Will be disregarded if taxonomy is provided with the option |
The generated plot will be more informative if taxonomic information is provided. Two types of plots can be generated with taxonomic information.
Set aggregate_by_taxa = TRUE to aggregate p-values across taxonomic levels
specified by tax_levels. This generates a stacked segment Manhattan plot.
In this plot, -log10 p-values adjusted using method will be plotted in
taxonomic ordering. Significance threshold will be alpha.
Set aggregate_by_taxa = FALSE to generate a traditional Manhattan plot for
all strains coloured by phylum. Unadjusted p-values will be plotted and
Bonferroni significance thresholds (0.05, 0.01) will be shown. Strains will
be in taxonomic ordering and a tree showing the taxonomic relationship between
strains will be plotted below the Manhattan plot.
If taxonomic information is not provided (taxonomy = NULL), a plot with
-log10 p-values adjusted using method will be generated. Strains will be
plotted in alphabetical order. Significance threshold will be alpha.
If Zero-Inflated Beta regression was used to model object, separate
facets will be used for zero-inflated and beta components of the model.
A ggplot object showing the Manhattan plot if plot = TRUE, else a data.frame with plot data.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) fit <- glmZiBFit(se[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) mh_data <- plot_manhattan(fit, taxonomy = tax, plot = FALSE) head(mh_data)meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) se <- filter_by_presence(se, min_nonzero = 30) tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) fit <- glmZiBFit(se[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) mh_data <- plot_manhattan(fit, taxonomy = tax, plot = FALSE) head(mh_data)
This function is copied from plot_manhattan()
plot_manhattan_gt( object, coef = 2, taxonomy = NULL, method = "HMP", alpha = 0.05, levels = c("Phylum", "Genus", "Species", "Strain"), colour_level = "Phylum", plot = TRUE, ground_truth = NULL )plot_manhattan_gt( object, coef = 2, taxonomy = NULL, method = "HMP", alpha = 0.05, levels = c("Phylum", "Genus", "Species", "Strain"), colour_level = "Phylum", plot = TRUE, ground_truth = NULL )
object |
A |
coef |
The number of the coefficient from which to generate the plot (default=2). |
taxonomy |
An optional taxonomy file read using strainspy::read_taxonomy (default=NULL). |
method |
Character. Multiple testing correction method for p-values (e.g., "holm"). Defaults to "holm". |
alpha |
Numeric. Significance threshold for adjusted p-values. Defaults to 0.05. |
levels |
Character vector. Taxonomic levels to include in the plot when |
colour_level |
Character. Taxonomic level used for coloring the plot segments. Defaults to "Phylum". |
plot |
If set to false, the function will return a tibble with data used to generate the plot. |
ground_truth |
A vector of ground truth contigs |
A ggplot object showing the Manhattan plot.
conventional Manhattan plot for the strain all strains.Generate a conventional Manhattan plot for the strain all strains.
plot_manhattan_tree(object, taxonomy, coef = 2)plot_manhattan_tree(object, taxonomy, coef = 2)
object |
A |
taxonomy |
Taxonomy file read using strainspy::read_taxonomy (default=NULL). |
coef |
The number of the coefficient from which to generate the plot (default=2). |
A ggplot object showing the Manhattan plot combined with the taxonomic tree
Performs classical multidimensional scaling (MDS) on a SummarizedExperiment object
and plots the result, optionally colored by a phenotype.
plot_mds( se, coef = 2, taxonomy = NULL, palette = c("#DAA520", "#3CB371", "#483D8B"), plot = TRUE )plot_mds( se, coef = 2, taxonomy = NULL, palette = c("#DAA520", "#3CB371", "#483D8B"), plot = TRUE )
se |
A |
coef |
Integer. Index of the column in |
taxonomy |
Optional taxonomy table to use in distance calculation. |
palette |
A vector of color hex codes for numeric phenotype gradients. Defaults to viridis palette. |
plot |
Logical. If |
A ggplot object showing the MDS plot, or a tibble of MDS coordinates if plot = FALSE.
example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_mds(se, coef = 2)example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_mds(se, coef = 2)
Perform PCA and Generate a Biplot
plot_pca_biplot(se, phenotype, plot = TRUE)plot_pca_biplot(se, phenotype, plot = TRUE)
se |
A |
phenotype |
A character string specifying the name of a phenotype or an integer specifying the column number in colData(se) |
plot |
A logical value indicating whether to return the PCA plot ( |
This function performs Principal Component Analysis (PCA) on a SummarizedExperiment object and generates a PCA biplot colored by a specified phenotype.
If plot = TRUE, returns a ggplot2 PCA plot. If plot = FALSE, returns a tibble with PCA results.
example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_pca_biplot(se, phenotype = 3)example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) plot_pca_biplot(se, phenotype = 3)
Plot method for strainspy_priors objects
plot_prior_bootstrap(object, prior) ## S4 method for signature 'strainspy_priors' plot_prior_bootstrap(object, prior)plot_prior_bootstrap(object, prior) ## S4 method for signature 'strainspy_priors' plot_prior_bootstrap(object, prior)
object |
An object of class |
prior |
Prior to be plotted |
Invisibly returns the object
methods::hasMethod("plot_prior_bootstrap", "strainspy_priors")methods::hasMethod("plot_prior_bootstrap", "strainspy_priors")
This function creates a volcano plot from the results of a betaGLM analysis, highlighting the relationship between effect size (coefficients) and statistical significance (-log10 p-values).
plot_volcano( object, coef = 2, alpha = 0.05, method = "holm", palette = rev(viridis::viridis(3)), label = FALSE, contig_names = NULL, plot = TRUE )plot_volcano( object, coef = 2, alpha = 0.05, method = "holm", palette = rev(viridis::viridis(3)), label = FALSE, contig_names = NULL, plot = TRUE )
object |
A strainspy_fit object containing model results. |
coef |
Integer, specifying the phenotype index of the betaGLM to extract p values and effect size for plotting. Default is 2. |
alpha |
Float indicating signficance level. Default is 0.05 |
method |
The method for p-value adjustment. For available options, see |
palette |
A vector of user defined palette to colour plot. Default is the viridis palette. |
label |
Logical, whether to label most signifcant points of the plot with Species name. |
contig_names |
Optional character vector to replace long contig names in the plot.
Must match the length and order of |
plot |
Logical, whether to return a ggplot object (default: TRUE). If FALSE, returns the processed data. |
A ggplot2 object if plot = TRUE, otherwise a dataframe containing the relevant statistics.
example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status + Sex") fit <- glmZiBFit(se[1:10,], design, nthreads=2) plot_volcano(fit, coef = 2, label = TRUE)example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") se <- read_sylph(example_path, example_meta) se <- filter_by_presence(se) design <- as.formula(" ~ Case_status + Sex") fit <- glmZiBFit(se[1:10,], design, nthreads=2) plot_volcano(fit, coef = 2, label = TRUE)
Formats strain-level data and optional covariates into a data.frame object
ready for modeling with caret. The function extracts selected contigs
from the sy assay matrix, combines them with the specified outcome and
optional covariates from the metadata, and performs basic validation
and cleaning. Metadata is pulled from SummarizedExperiement::colData(sy),
and generally assumes strainspy::modify_metadata() was used upstream.
prep_for_prediction( sy, outcome, contigs, covariates = NULL, use_genome_names = TRUE )prep_for_prediction( sy, outcome, contigs, covariates = NULL, use_genome_names = TRUE )
sy |
A SummarizedExperiment A
|
outcome |
Character string giving the name of the outcome variable
present in |
contigs |
Character vector of contigs (feature) to include as
predictors. Must be present in |
covariates |
Optional character vector of additional metadata variables
to include as covariates. Default |
use_genome_names |
Bool. Use |
Character variables are automatically converted to factors.
Numeric variables are returned unchanged. For pre processing, refer to
caret::train().
A data.frame containing the specified outcome variable, optional
covariates, and selected contig features. The object is ready for direct
use in caret functions such as caret::train().
library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") sy <- read_sylph(example_path, example_meta) contigs <- rownames(sy)[1:10] df <- prep_for_prediction( sy = sy, outcome = "Case_status", contigs = contigs, covariates = c("Sex", "BMI") )library(strainspy) example_meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") example_meta <- read.csv(example_meta_path) example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") sy <- read_sylph(example_path, example_meta) contigs <- rownames(sy)[1:10] df <- prep_for_prediction( sy = sy, outcome = "Case_status", contigs = contigs, covariates = c("Sex", "BMI") )
This function reads a merged MetaPhlAn profile output and create a SummarizedExperiment object.
An optional metadata table can be provided and added directly to colData via an internal call to modify_metadata().
read_metaphlan( file_path, meta_data = NULL, variable = "relative_abundance", clean_names = TRUE )read_metaphlan( file_path, meta_data = NULL, variable = "relative_abundance", clean_names = TRUE )
file_path |
Character. Path to the merged metaphlan output file. |
meta_data |
data.frame. An optional tibble or data frame containing sample metadata. See Details |
variable |
Character. Name of the input variable to import. Defaults to |
clean_names |
Logical. If |
A SummarizedExperiment object with the following components:
assays |
A matrix containing numeric features such as |
rowData |
DataFrame containing metadata for each sequence, such as |
colData |
DataFrame containing information for each sample (derived from the |
Since MetaPhlAn profiles are usually generated per sample, first use merge_metaphlan_files() to merge and generate the input for this function.
#' If metadata is provided, it must meet the input requirements described in
modify_metadata(). If appending metadata fails due to pre processing requirements,
this function will issue a detailed warning and still return the SummarizedExperiment
object without metadata. In that case, apply necessary fixes and subsequently
call modify_metadata().
# Read a merged metaphlan profile file into a SummarizedExperiment object example_path <- system.file("extdata", "metaphlan_merged.tsv.gz", package = "strainspy") mp <- read_metaphlan(example_path)# Read a merged metaphlan profile file into a SummarizedExperiment object example_path <- system.file("extdata", "metaphlan_merged.tsv.gz", package = "strainspy") mp <- read_metaphlan(example_path)
This function reads a sourmash gather or sourmash search -like output CSV file and create a SummarizedExperiment object.
An optional metadata table can be provided and added directly to colData via an internal call to modify_metadata().
read_sourmash( file_path, meta_data = NULL, variable = "match_containment_ani", clean_names = TRUE )read_sourmash( file_path, meta_data = NULL, variable = "match_containment_ani", clean_names = TRUE )
file_path |
Character. Path to the sourmash gather file (CSV format). |
meta_data |
data.frame. A tibble or data frame containing sample metadata. Metadata requirements are identical to |
variable |
Character. Name of the input variable to import. Defaults to |
clean_names |
Logical. If |
A SummarizedExperiment object with the following components:
assays |
A matrix containing numeric features such as |
rowData |
DataFrame containing metadata for each sequence, such as |
colData |
DataFrame containing information for each sample (derived from the |
Some of sourmash subcommands like gather are designed to take exactly one query file.
To merge and save a CSV file suitable to use with this function, use merge_sourmash_files()
#' If metadata is provided, it must meet the input requirements described in
modify_metadata(). If appending metadata fails due to pre processing requirements,
this function will issue a detailed warning and still return the SummarizedExperiment
object without metadata. In that case, apply necessary fixes and subsequently
call modify_metadata().
# Read a merged sourmash file into a SummarizedExperiment object example_path <- system.file("extdata", "example_sourmash.csv.gz", package = "strainspy") sm <- read_sourmash(example_path)# Read a merged sourmash file into a SummarizedExperiment object example_path <- system.file("extdata", "example_sourmash.csv.gz", package = "strainspy") sm <- read_sourmash(example_path)
This function reads a Sylph output file (either query or profile), parses the data, and returns a SummarizedExperiment object.
An optional metadata table can be provided and added directly to colData via an internal call to modify_metadata().
read_sylph( file_path, meta_data = NULL, variable = "Adjusted_ANI", min_identity = 95, clean_names = TRUE )read_sylph( file_path, meta_data = NULL, variable = "Adjusted_ANI", min_identity = 95, clean_names = TRUE )
file_path |
Character. Path to the Sylph query or profile output file(s) in |
meta_data |
data.frame. An optional tibble or data frame containing sample metadata. See Details |
variable |
Character. Name of the input variable to import. Defaults to |
min_identity |
Numeric. Minimum identity threshold for filtering ANI values. Defaults to |
clean_names |
Logical. If |
If metadata is provided, it must meet the input requirements described in
modify_metadata(). If appending metadata fails due to pre processing requirements,
this function will issue a detailed warning and still return the SummarizedExperiment
object without metadata. In that case, apply necessary fixes and subsequently
call modify_metadata().
A SummarizedExperiment object with the following components:
assays |
A matrix containing numeric features such as |
rowData |
DataFrame containing metadata for each sequence, such as |
colData |
DataFrame containing information for each sample (derived from the |
# Read a Sylph file example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") sy <- read_sylph(example_path)# Read a Sylph file example_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") sy <- read_sylph(example_path)
This function reads a taxonomy file in Sylph format.
read_taxonomy(file_path)read_taxonomy(file_path)
file_path |
Path to the taxonomy file. |
A data.table containing parsed taxonomy information.
tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) head(tax)tax <- read_taxonomy(system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy")) head(tax)
This function applies a simple linear transformation to simulate a treatment effect.
rescale_beta(x, beta = 0.98, zi = 0.1)rescale_beta(x, beta = 0.98, zi = 0.1)
x |
a vector of sequence identity values to transform |
beta |
simulate a decreased in identiy by factor of beta (default=0.95) |
zi |
simulate an increased shift in the proportion of zeros by zi (default=0.1) |
a vector of transformed values
Ensures MAP_prior is interpreted correctly and returns a valid
strainspy_priors object or NULL (for unpenalised ML fits).
resolve_priors(MAP_prior, se, design)resolve_priors(MAP_prior, se, design)
MAP_prior |
One of: NULL, a character string ("preset_weak", "preset_strong"),
a prior |
se |
A |
design |
A fixed-effects-only formula. |
A strainspy_priors object or NULL.
Displays a summary of a strainspy_fit object, including model design,
convergence, and coefficient matrix dimensions.
## S4 method for signature 'strainspy_fit' show(object)## S4 method for signature 'strainspy_fit' show(object)
object |
An object of class |
Invisibly returns NULL after printing a compact summary.
Show method for strainspy_priors objects
## S4 method for signature 'strainspy_priors' show(object)## S4 method for signature 'strainspy_priors' show(object)
object |
An object of class |
Invisibly returns the object
A wrapper to run a full strainspy workflow with explicit input validation.
strainspy( meta_path, sylph_path, design_formula, coef, min_nonzero = NULL, taxonomy_path = NULL, output_path = NULL, alpha = 0.05, p_adjust_method = "holm", model_method = "glmmTMB", scale_continuous = TRUE, nthreads = 2, return_vcov = FALSE, attach_taxonomy = TRUE, overwrite = TRUE, progress = TRUE )strainspy( meta_path, sylph_path, design_formula, coef, min_nonzero = NULL, taxonomy_path = NULL, output_path = NULL, alpha = 0.05, p_adjust_method = "holm", model_method = "glmmTMB", scale_continuous = TRUE, nthreads = 2, return_vcov = FALSE, attach_taxonomy = TRUE, overwrite = TRUE, progress = TRUE )
meta_path |
Path to the metadata file (CSV format). |
sylph_path |
Path to the sylph output file (TSV format). |
design_formula |
One-sided formula (or string coercible to formula) for
the design matrix, e.g. |
coef |
Coefficient index to report in |
min_nonzero |
Minimum number of samples for strain presence filtering.
If |
taxonomy_path |
Optional path to a taxonomy file (TSV format). If provided, taxonomy columns are appended to top hits. |
output_path |
Optional path to save top hits as CSV. If |
alpha |
Significance threshold used by |
p_adjust_method |
Multiple-testing correction method for |
model_method |
Backend used by |
scale_continuous |
If |
nthreads |
Number of threads for parallel processing (default: all available cores). |
return_vcov |
If |
attach_taxonomy |
If |
overwrite |
If |
progress |
Logical. If |
A data frame of top hits. If taxonomy_path is supplied and
attach_taxonomy = TRUE, taxonomy columns are appended.
meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") sylph_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") taxonomy_path <- system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy") # Decision 1: choose predictors for the design formula # Decision 2: choose which coefficient index to report in top_hits() # For ~ Case_status + Age_at_collection, coef = 2 corresponds to Case_status out <- strainspy( meta_path = meta_path, sylph_path = sylph_path, design_formula = "~ Case_status + Age_at_collection", coef = 2, taxonomy_path = taxonomy_path, output_path = tempfile(fileext = ".csv"), nthreads = 2, alpha = 1 ) head(out)meta_path <- system.file("extdata", "example_metadata.csv.gz", package = "strainspy") sylph_path <- system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy") taxonomy_path <- system.file("extdata", "example_taxonomy.tsv.gz", package = "strainspy") # Decision 1: choose predictors for the design formula # Decision 2: choose which coefficient index to report in top_hits() # For ~ Case_status + Age_at_collection, coef = 2 corresponds to Case_status out <- strainspy( meta_path = meta_path, sylph_path = sylph_path, design_formula = "~ Case_status + Age_at_collection", coef = 2, taxonomy_path = taxonomy_path, output_path = tempfile(fileext = ".csv"), nthreads = 2, alpha = 1 ) head(out)
The strainspy_fit class is designed to store the results of strainspy
row_dataA DataFrame containing row data.
priorsA strainspy_priors object or NULL for REML.
scale_continuousA logical indicating whether all numeric columns were z-score standardized
coefficientsA DataFrame containing model coefficients.
std_errorsA DataFrame containing standard errors of the coefficients.
p_valuesA DataFrame containing p-values for the coefficients.
vcovA DataFrame containing the variance-covariance matrix.
zi_coefficientsA DataFrame containing zero-inflation coefficients.
zi_std_errorsA DataFrame containing zero-inflation standard errors.
zi_p_valuesA DataFrame containing zero-inflation p-values.
zi_vcovA DataFrame containing the zero-inflated variance-covariance matrix.
residualsA DataFrame containing residuals from the model.
convergenceA logical indicating whether model fitting converged.
designA matrix representing the design matrix of the model.
callThe matched call of the model.
familyThe family of the fit.
The strainspy_priors class is designed to store MAP priors used for ordinal
and zero-inflated beta model fitting using glmmTMB.
methodCharacter. Prior estimation method used ("preset_weak", "preset_strong", "empirical", "manual").
priors_dfData frame. Data frame containing prior parameters.
boot_fixefNumeric matrix. Bootstrap SD values for fixed effect priors
boot_fixef_ZINumeric matrix. Bootstrap SD values for zero inflated fixed effect priors
boot_dispNumeric matrix. Bootstrap mean and SD values for the dispersion term of beta component.
designThe formula with with effect terms used
callThe matched call of the model.
Provides a high-level summary of a strainspy_fit object, including its call,
coefficients, zero-inflation coefficients, dispersion, and the availability
of FDR and residuals.
## S4 method for signature 'strainspy_fit' summary(object)## S4 method for signature 'strainspy_fit' summary(object)
object |
An object of class |
A list summarizing the strainspy_fit object.
This function performs multiple testing adjustment on the results of a strainspy_fit object integrating taxonomic information. Various correction methods are available, including Harmonic Mean P-value (HMP), Bonferroni and Benjamini-Hochberg (BH).
top_hits(fit, coef = 2, method = "holm", alpha = 0.05)top_hits(fit, coef = 2, method = "holm", alpha = 0.05)
fit |
A |
coef |
The coefficient to report and use for p-value adjustment. Defaults to 2. |
method |
The method for p-value adjustment. Available methods are a subset of those in |
alpha |
Numeric. Significance threshold for adjusted p-values. Defaults to 0.05. |
A tibble with the top hits, sorted by adjusted p-value.
meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) top_hits(fit, coef = 2, alpha = 1)meta <- read.csv(system.file("extdata", "example_metadata.csv.gz", package = "strainspy")) meta$Case_status <- factor(meta$Case_status) se <- read_sylph(system.file("extdata", "example_sylph_profile.tsv.gz", package = "strainspy"), meta_data = meta) fit <- glmZiBFit(filter_by_presence(se, min_nonzero = 30)[1:10, ], ~ Case_status + Age_at_collection, nthreads = 1, return_vcov = FALSE) top_hits(fit, coef = 2, alpha = 1)
Update the model fit by calling the specified fit function only a subset of features. Same design will be fitted.
update_fit( fit, update_idx, se, scale_continuous = TRUE, min_identity = 0.98, method = "glmmTMB", family = glmmTMB::ordbeta(), nthreads = 1, BPPARAM = NULL, progress = TRUE )update_fit( fit, update_idx, se, scale_continuous = TRUE, min_identity = 0.98, method = "glmmTMB", family = glmmTMB::ordbeta(), nthreads = 1, BPPARAM = NULL, progress = TRUE )
fit |
A |
update_idx |
Vector of indices that need to be updated |
se |
SummarizedExperiment. A |
scale_continuous |
Binary specifying whether to rescale numeric values. Default T |
min_identity |
Only for |
method |
Character. The method to use for fitting the model. Either 'glmmTMB' (default) or 'gamlss'. Only applicable for |
family |
A |
nthreads |
An integer specifying the number of (CPUs or workers) to use. Defaults to 1. |
BPPARAM |
Optional |
progress |
Logical. If |
Updated version of the fit object