knitr::opts_chunk$set(echo = TRUE) library(tidyverse) library(phyloseq)
Phyloseq is a popular package for working with microbiome data. Here we show how to use the phy_to_floral_data
helper function to convert phyloseq data into a format accepted by FLORAL.
The following code downloads data described in this paper and turns it into a phyloseq object. The tax_glom step here takes some time, and can be replaced with speedyseq::tax_glom
for better performace.
samples <- get0("samples", envir = asNamespace("FLORAL")) counts <- get0("counts", envir = asNamespace("FLORAL")) taxonomy <- get0("taxonomy", envir = asNamespace("FLORAL")) phy <- phyloseq( sample_data(samples %>% column_to_rownames("SampleID")), tax_table(taxonomy %>% select(ASV, Kingdom:Genus) %>% column_to_rownames("ASV") %>% as.matrix()), otu_table(counts %>% pivot_wider(names_from = "SampleID", values_from = "Count", values_fill = 0) %>% column_to_rownames("ASV") %>% as.matrix(), taxa_are_rows = TRUE) ) %>% subset_samples(DayRelativeToNearestHCT > -30 & DayRelativeToNearestHCT < 0) %>% tax_glom("Genus")
Next, we convert that phyloseq object into a list of results to be used by FLORAL; we have to specify the main outcome of interest as y
, and any metadata columns (from sample_data(phy)
) to use as covariates. Note that the analysis described here is just an example for using the function; this
dat <- FLORAL::phy_to_floral_data(phy, covariates=c("Consistency"), y = "DayRelativeToNearestHCT")
The resulting list has named entities for the main arguments to FLORAL:
res <- FLORAL::FLORAL(y = dat$y, x = dat$xcount, ncov = dat$ncov, family = "gaussian", ncv=NULL, progress=FALSE)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.