API

We advise to import scCODA in a python session via:

import sccoda
dat = sccoda.util.cell_composition_data
ana = sccoda.util.compositional_analysis
viz = sccoda.util.data_visualization

The workflow in scCODA starts with reading in cell count data (dat) and visualizing them (viz) or synthetically generating cell count data (util.data_generation).

Data acquisition

Integrating data sources (dat) (scanpy or pandas)

sccoda.util.cell_composition_data.from_pandas(df, …)

Converts a Pandas DataFrame into a compositional analysis data set.

sccoda.util.cell_composition_data.from_scanpy(…)

Creates a compositional analysis dataset from a single anndata object, as it is produced by e.g.

sccoda.util.cell_composition_data.from_scanpy_dir(…)

Creates a compositional analysis data set from all scanpy data sets in a directory.

sccoda.util.cell_composition_data.from_scanpy_list(…)

Creates a compositional analysis data set from a list of scanpy data sets.

sccoda.util.cell_composition_data.read_anndata_one_sample(…)

Converts a single scRNA-seq data set from scanpy (anndata format) to a row of a cell count matrix.

Synthetic data generation

sccoda.util.data_generation.generate_case_control([…])

Generates compositional data with binary covariates.

sccoda.util.data_generation.b_w_from_abs_change([…])

Calculates intercepts and slopes from a starting count and an absolute change for the first cell type

sccoda.util.data_generation.counts_from_first([…])

Calculates a count vector from a given first entry, length and sum.

sccoda.util.data_generation.sparse_effect_matrix(D, …)

Generates a sparse effect matrix

Compositional data visualization

Compositional datasets can be plotted via the methods in util.data_visualization.

sccoda.util.data_visualization.stacked_barplot(…)

Plots a stacked barplot for all levels of a covariate or all samples (if feature_name==”samples”).

sccoda.util.data_visualization.boxplots(…)

Grouped boxplot visualization.

sccoda.util.data_visualization.stackbar(y, …)

Plots a stacked barplot for one (discrete) covariate Typical use (only inside stacked_barplot): plot_one_stackbar(data.X, data.var.index, “xyz”, data.obs.index)

Model setup and inference

Using the scCODA model is easiest by generating an instance of ana.CompositionalAnalysis. By specifying the formula via the patsy syntax, many combinations and transformations of the covariates can be performed without redefining the covariate matrix. Also, the reference cell type needs to be specified in this step.

The scCODA model

sccoda.util.comp_ana.CompositionalAnalysis(…)

Initializer class for scCODA models.

sccoda.model.scCODA_model.CompositionalModel(…)

Dynamical framework for formulation and inference of Bayesian models for compositional data analysis.

sccoda.model.scCODA_model.scCODAModel(…)

Statistical model for single-cell differential composition analysis with specification of a reference cell type.

Utility functions

sccoda.util.helper_functions.sample_size_estimate(…)

calculates the estimated number of required samples for fixed MCC, absolute increase and log2-fold change using the fitted linear model from Büttner, Ostner et al., 2020

Result evaluation

Executing an inference method on a compositional model produces a sccoda.util.result_classes.CAResult object. This class extends the InferenceData class of arviz and supports all its diagnostic and plotting functionality.

sccoda.util.result_classes.CAResult(…)

Result class for scCODA, extends the arviz framework for inference data.

Model comparison

sccoda.models.other_models contains implementations of several compositional methods frm microbiome analysis and non-compositional tests that can be used for comparison.

sccoda.model.other_models.SimpleModel(…)

Simple Dirichlet-Multinomial model with normal priors.

sccoda.model.other_models.scdney_model(data)

wrapper for using the scdney package for R (Cao et al., 2019) with scCODA data

sccoda.model.other_models.HaberModel(data[, …])

Implements the Poisson regression model from Haber et al.

sccoda.model.other_models.CLRModel(data[, …])

Implements a CLR transform and subsequent linear model on each cell type.

sccoda.model.other_models.TTest(data[, …])

Implements a t-test on each cell type.

sccoda.model.other_models.CLRModel_ttest(data)

Implements a CLR transform and subsequent t-test on each cell type.

sccoda.model.other_models.ALDEx2Model(data)

Wrapper for using the ALDEx2 package for R (Fernandes et al., 2014)

sccoda.model.other_models.ALRModel_ttest(data)

Implements a ALR transform and subsequent t-test on each cell type.

sccoda.model.other_models.ALRModel_wilcoxon(data)

Implements a ALR transform and subsequent Wilcoxon rank-sum test on each cell type.

sccoda.model.other_models.AncomModel(data[, …])

Wrapper for the ancom model for compositional differentiation analysis (Mandal et al., 2015)

sccoda.model.other_models.DirichRegModel(data)

Wrapper for using the DirichReg package in R (Maier, 2014) with scCODA’s infrastructure

sccoda.model.other_models.BetaBinomialModel(data)

Wrapper for using the corncob package for R (Martin et al., 2020)

sccoda.model.other_models.ANCOMBCModel(data)

Wrapper for using the ANCOMBC package for R (Lin and Peddada, 2020)