Getting started

MiTo infers clones and their phylogeny from mitochondrial DNA variants (MT-SNVs) in single cells. The whole pipeline is four calls on an Allele Frequency Matrix (AFM), a cell x variant AnnData of alternative-allele and coverage counts:

mt.pp.filter_cells(afm)          # cells with enough MT coverage
mt.pp.filter_afm(afm)            # informative MT-SNVs, per-cell genotypes, distances
tree = mt.tl.build_tree(afm)     # cell phylogeny (UPGMA)
mt.tl.annotate_clones(tree, afm) # clones, with the support of their clades

Here we run it on two simulated datasets whose true clones are known: one where all clones branch from the root (a polytomy), and one where clones are nested in sub-clones. Loading data shows how to build an AFM from real pre-processing output, and the Benchmark runs MiTo on real data with ground truth.

[1]:
import logging
import matplotlib.pyplot as plt
import mito as mt

logging.getLogger().setLevel(logging.WARNING)   # MiTo logs every stage at INFO level
mt.__version__
[1]:
'2.0.0'

Two simulated datasets

mt.ut.simulate_afm draws a clonal tree, MT-SNVs marking its clades, and per-cell molecule counts at MAESTER-like depth, including sequencing noise and germline-like variants. The true clone of each cell is in afm.obs['clone'].

[2]:
maester_like = dict(
    n_cells=500, frac_double_variants=.3, frac_noisy_variants=.2,
    af_beta=(3, 57), af_beta_min=.04, af_depth_decay=.85, af_beta_noise=(2, 1500),
    af_negative_frac=.002, mean_coverage=200, coverage_cell_cv=.2, coverage_site_cv=.8,
    mean_molecules=40, molecule_cv=.5, molecule_coverage_exponent=0.,
    overdispersion_background=1.2, overdispersion_noise_frac=.5, noise_prevalence=(.05, .2),
)
flat = mt.ut.simulate_afm(n_clones=8, n_root_clones=8, max_depth=1, random_seed=0, **maester_like)
nested = mt.ut.simulate_afm(n_clones=12, n_root_clones=3, max_depth=3, random_seed=1, **maester_like)
flat
[2]:
AnnData object with n_obs × n_vars = 500 × 12
    obs: 'clone', 'mean_site_coverage', 'median_target_site_coverage', 'frac_target_site_covered', 'nUMIs'
    var: 'pos', 'ref', 'alt', 'clone_of_origin', 'clade', 'n_clones_carrying', 'depth', 'is_noise', 'quality'
    uns: 'scLT_system', 'pp_method', 'simulation'
    layers: 'AD', 'DP', 'genotype', None (.X)

The pipeline

The same four calls, with their defaults, on both datasets. filter_cells uses the coverage of the MAESTER target sites (cell_filter='filter2'); for ReDeeM and mtscATAC the default ('filter1', genome-wide coverage) applies.

[3]:
trees = {}
for name, afm in (('flat', flat), ('nested', nested)):
    mt.pp.filter_cells(afm, cell_filter='filter2')
    mt.pp.filter_afm(afm)
    trees[name] = mt.tl.build_tree(afm)
    mt.tl.annotate_clones(trees[name], afm)

filter_afm records what each stage kept: here, of the simulated variants, those whose counts look like clonal MT-SNVs rather than sequencing noise.

[4]:
flat.uns['mito']['filter_afm']['flow']
[4]:
stage n_vars_in n_vars_out
0 over-dispersion filter 11 11
1 quality filter 11 11
2 known artefacts 11 10
3 candidate cap 10 10
4 clonality filter 10 9
5 prevalence and call-count filters 9 9
6 compatibility filter 9 9

Each cell gets a clone label (MiTo_clone), or unassigned when its own variants are not corroborated by its neighbours. Against the true clones:

[5]:
for name, afm in (('flat', flat), ('nested', nested)):
    lab = afm.obs['MiTo_clone'].astype(str)
    ok = lab != 'unassigned'
    ari = mt.ut.custom_ARI(afm.obs['clone'].astype(str)[ok], lab[ok])
    print(f'{name:7s} {lab[ok].nunique():2d} clones ({afm.obs["clone"].nunique()} true), '
          f'{ok.mean():.0%} of cells assigned, ARI {ari:.2f}')
flat     7 clones (7 true), 100% of cells assigned, ARI 0.99
nested   9 clones (10 true), 100% of cells assigned, ARI 0.73

Nested clones are harder: a sub-clone shares its parent’s variants, and its own markers are carried by fewer cells. The Benchmark gives averages over many simulations.

Genotypes and clones

Left: allele frequencies of the variants (colour scale up to 0.1), cells in tree order and variants in the order of the clades they mark. Middle: the tree with every clade that MiTo calls one clone drawn as a fan, in the clone’s colour, with a gap between neighbouring clones. Right: the clone tree, one tip per clone, a circle whose area is its number of cells, on the same branch lengths.

[6]:
def make_axes(nrows, height=4.5):
    """Rows of (heatmap, cell tree, clone tree) axes; a thin spacer evens the gaps despite the colorbar."""
    fig = plt.figure(figsize=(13.5, height * nrows))
    gs = fig.add_gridspec(nrows, 4, width_ratios=[2, .1, 2, 2])
    return fig, [[fig.add_subplot(gs[i, j]) for j in (0, 2, 3)] for i in range(nrows)]


def show_trees(tree, axs, lw=.6):
    """Collapsed clones (fans, with gaps) and the clone tree (circle = cells)."""
    labels = tree.cell_meta['MiTo_clone'].astype(str)
    mt.pl.plot_tree(tree, ax=axs[0], collapse_clones='MiTo_clone', clone_style='full', gap_by='MiTo_clone',
                    branches=dict(annot='MiTo_clone', linewidth=lw))
    mt.pl.plot_clone_tree(tree, ax=axs[1])
    axs[0].set_title(f'Cell tree (n={len(tree.leaves)})')
    axs[1].set_title(f'Clone tree (n={labels[labels != "unassigned"].nunique()})')
    for ax in axs:
        ax.set_aspect('equal')


fig, rows = make_axes(2)
for row, name, afm in zip(rows, ('flat', 'nested'), (flat, nested)):
    mt.pl.heatmap_variants(afm, tree=trees[name], ax=row[0])
    row[0].set_title(f'{name}: cells x variants')
    show_trees(trees[name], row[1:])
fig.tight_layout()
_images/getting_started_12_0.png

Each clone also comes with the support of its clade: how often it is rebuilt when the molecule counts are drawn again (mt.tl.clade_support, run by annotate_clones). annotate_clones(tree, afm, min_support=0.5) keeps only well-supported clones.

[7]:
nested.uns['mito']['annotate_clones']['clones'][['n_cells', 'support']]
[7]:
n_cells support
clone
MT-1 73 0.953333
MT-2 58 0.932456
MT-3 51 0.842400
MT-4 30 0.882069
MT-5 27 0.903462
MT-6 22 0.808571
MT-7 21 0.888500
MT-8 10 0.657778
MT-9 5 0.722500