Skip to content

biocore/BIRDMAn

Repository files navigation

BIRDMAn

GitHub Actions CI Documentation Status PyPI DOI

Overview

Bayesian Inferential Regression for Differential Microbiome Analysis (BIRDMAn) is a framework for differential abundance analysis of microbiome count data using Bayesian inference.

Quantifying differential abundance (DA) in microbiome studies is challenging due to data characteristics (e.g., compositionality, sparsity) and study designs (e.g., repeated measures, meta-analysis, cross-over). BIRDMAn is a flexible DA method that accounts for these data characteristics and diverse experimental designs by fitting hierarchical Bayesian models in Stan via CmdStanPy, returning full posterior distributions over per-feature effects so that uncertainty is quantified alongside every estimate.

BIRDMAn ships with default negative-binomial models (fixed-effects and linear-mixed-effects variants, in both whole-table and per-feature forms) and exposes the underlying Stan templates so users can write their own custom models against the same fitting and post-processing machinery. Fits are returned as ArviZ InferenceData objects.

See the documentation for details on usage, including a walkthrough of the default models and a guide to writing custom Stan code.

For a runnable example, see this Google Colab notebook.

Installation

BIRDMAn requires Python 3.8 or higher.

We recommend using mamba for installation of dependencies.

mamba install -c conda-forge biom-format patsy xarray arviz cmdstanpy
pip install birdman

Quick example

The snippet below uses the macaque gut microbiome table bundled with the repo at tests/data/ (clone the repo, or substitute your own BIOM table and metadata):

import biom
import pandas as pd
from birdman import NegativeBinomial

table = biom.load_table("tests/data/macaque_tbl.biom")
metadata = pd.read_csv("tests/data/macaque_metadata.tsv", sep="\t", index_col=0)
metadata.index = metadata.index.astype(str)  # match BIOM sample IDs

nb = NegativeBinomial(
    table=table,
    formula="host_common_name",
    metadata=metadata,
)
nb.compile_model()
nb.fit_model(method="vi", num_draws=500)

inference = nb.to_inference()
inference.posterior["beta_var"]  # per-covariate, per-feature effects

Citation

If you use BIRDMAn, please cite our manuscript:

Rahman G, Morton JT, Martino C, Sepich-Poore GD, Allaband C, Guccione C, Chen Y, Hakim D, Estaki M, Knight R. BIRDMAn: A Bayesian differential abundance framework that enables robust inference of host-microbe associations. bioRxiv. 2023. doi:10.1101/2023.01.30.526328.

Contributing

Issues and pull requests are welcome.

License

BIRDMAn is released under the BSD 3-Clause License, see LICENSE.