Skip to content

Result types

Frozen dataclasses over numpy arrays.

Frozen result records.

Plain dataclasses over numpy arrays. eq=False because elementwise == on arrays does not return a bool, so a generated __eq__ would raise.

Tree dataclass

Tree(parent: ndarray, branch: ndarray, n_leaves: int)

A rooted tree over the cells.

Leaves are 0..n_leaves in input order; internal nodes follow, ordered by height above the leaves. Every function in this package that takes a tree assumes that ordering, so build trees with this package (or read_newick) rather than by hand.

Attributes:

Name Type Description
parent ndarray

Parent of each node, -1 for the root. int64.

branch ndarray

Length of the branch above each node; the root's is ignored.

n_leaves int

Number of leaves.

n_nodes property

n_nodes: int

Leaves plus inferred ancestors.

BonsaiResult dataclass

BonsaiResult(
    tree: Tree,
    loglik: float,
    features: ndarray,
    dropped: ndarray,
    node_means: ndarray,
    node_sds: ndarray,
    steps: list[Step],
)

A finished reconstruction.

Attributes:

Name Type Description
tree Tree

The tree. Leaf i is input cell i.

loglik float

Final loglikelihood, meaningful only up to an additive constant.

features ndarray

Input column of each retained feature, ascending. For bonsai_from_counts these index the genes of the count matrix.

dropped ndarray

Genes the Sanity conversion dropped as ill-conditioned. Empty unless the run started from counts.

node_means ndarray

Posterior mean of every node, (n_nodes, n_retained), in the input's units. Rows n_leaves: are the ancestors.

node_sds ndarray

Posterior standard deviation, same layout.

steps list[Step]

The loglikelihood after each search step, in order.

Step dataclass

Step(step: str, loglik: float, gain: float)

What one step of the search bought.

Attributes:

Name Type Description
step str

Which step, "1 star" through "8 collapse".

loglik float

Tree loglikelihood after it, up to an additive constant.

gain float

Change from the previous step.

SanityResult dataclass

SanityResult(
    log_fold_changes: ndarray,
    error_bars: ndarray,
    mean_log_quotient: ndarray,
    mean_log_quotient_error: ndarray,
    variance: ndarray,
)

Sanity posteriors.

Attributes:

Name Type Description
log_fold_changes ndarray

Posterior log fold change d_c, (n_cells, n_genes). Zero-centred per gene. This, not log_transcription_quotients, is what from_sanity wants.

error_bars ndarray

Posterior SD on each log fold change, same layout.

mean_log_quotient ndarray

Per-gene mean log transcription quotient m.

mean_log_quotient_error ndarray

Error bar on m.

variance ndarray

Per-gene variance of the log fold changes v.

log_transcription_quotients property

log_transcription_quotients: ndarray

Normalised expression m + d_c, (n_cells, n_genes).

Likelihood dataclass

Likelihood(
    means: ndarray,
    sds: ndarray,
    variances: ndarray,
    features: ndarray,
    dropped: ndarray,
)

Likelihood means and SDs recovered from Sanity posteriors (S5).

Attributes:

Name Type Description
means ndarray

(n_cells, n_kept), ready for bonsai.

sds ndarray

Same layout.

variances ndarray

Sanity's v for the kept genes; pass it to bonsai.

features ndarray

Input column of each kept gene.

dropped ndarray

Input columns dropped as ill-conditioned.

Clustering dataclass

Clustering(
    leaf_cluster: ndarray, centres: ndarray, sizes: ndarray
)

A cut of the tree into clusters.

Attributes:

Name Type Description
leaf_cluster ndarray

Cluster of each leaf, numbered by decreasing size.

centres ndarray

Representative node of each cluster.

sizes ndarray

Leaves per cluster.

SimulatedData dataclass

SimulatedData(
    tree: Tree,
    truth: ndarray,
    means: ndarray,
    sds: ndarray,
    variances: ndarray,
)

Brownian motion on a known tree.

Attributes:

Name Type Description
tree Tree

The generating tree.

truth ndarray

Noise-free leaf positions, (n_leaves, n_features).

means ndarray

Observed means, truth plus noise.

sds ndarray

Error bars on the means.

variances ndarray

Per-feature variance the data was scaled by. truth, means and sds are already divided by its square root.

SimulatedCounts dataclass

SimulatedCounts(
    tree: Tree, counts: ndarray, cell_totals: ndarray
)

UMI counts drawn on a known tree.

Attributes:

Name Type Description
tree Tree

The generating tree.

counts ndarray

(n_cells, n_genes) integer counts.

cell_totals ndarray

The library size each cell was drawn with. Pass these, not the row sums: with a few hundred high-variance genes the row sums carry a per-cell compositional shift that costs the tree.