$ show theislab/scCODA
scCODA is a Python library for Bayesian compositional analysis of single-cell count data, specifically designed to identify differentially abundant cell types between conditions while respecting compositional constraints (e.g., cell type proportions sum to 1). The core implements a Dirichlet-Multinomial model with spike-and-slab priors, providing posterior inclusion probabilities and effect size estimates. It integrates with the scverse ecosystem (anndata, scanpy) for data handling and uses TensorFlow Probability for HMC/NUTS sampling. The package also includes wrappers for alternative methods (ALDEx2, ANCOM, etc.) and provides utilities for data conversion, visualization, and synthetic data generation. While the repository is well-architected with clear separation of concerns and includes tutorials and unit tests, it is explicitly marked as no longer maintained (successor in pertpy using JAX). The technical drift is high due to outdated TensorFlow/TPP dependencies and lack of active development.
The LLM identified 5 files worth highlighting for reuse:
Provides functions to convert count data from pandas DataFrames, scanpy AnnData objects, or lists of AnnData into the standardized AnnData format expected by scCODA. This is a reusable data adapter pattern that can be extracted for any compositional analysis tool needing to ingest heterogeneous input sources.
Implements stacked barplots, grouped boxplots, and a dispersion-presence plot for reference cell type selection, all tailored for compositional count data. These are general-purpose visualization utilities for exploratory analysis of sample-by-cell-type matrices and can be reused in other compositional data projects with minimal adaptation.
Offers functions to generate synthetic compositional count data with controlled covariates, effect sizes, and noise, useful for benchmarking and testing. The generation logic is parameterized and idempotent, making it a reusable pattern for creating simulated datasets in any compositional analysis context.
Defines CAResult, a subclass of arviz.InferenceData that adds methods for extracting credible effects, computing FDR, saving/loading results, and generating summary tables. This is a well-encapsulated pattern for handling MCMC posterior results in Bayesian compositional models and could be adapted for other Bayesian analysis packages.
Contains the core scCODA model: a Dirichlet-Multinomial with spike-and-slab priors on covariate effects, implemented in TensorFlow Probability with HMC/NUTS samplers. While tightly coupled to TensorFlow, the modular design (sampling, result construction, chain processing) demonstrates a clean separation of inference from data and is a reference implementation for Bayesian compositional models.