mantispy.tl.project_cell_cycle#

mantispy.tl.project_cell_cycle(adata, model='cell_cycle', by=('Metadata_Plate', 'Metadata_Well'), checks=('irregular', 'small', 'dim'), key_added='cell_cycle', copy=False)[source]#

Place every cell on the cycle of a model from fit_cell_cycle(), with its uncertainty.

Each cell gets a posterior over its position: the age distribution of the reference as the prior, times how well the cell’s DNA content fits each position. From it come the probability of each phase, and of sitting below 2N or above 4N, off the cycle, and quantiles of the position. An S cell is placed tightly. A G1 or G2M cell spreads over its whole plateau, since DNA content does not order cells within it, so there its position is the prior. Perturbed cells are placed on the reference’s cycle, so an arrest shows up as cells piling up at one position.

Each by group, normally a well, is also checked against the reference. When its 2N and 4N peaks both sit off the reference’s by more than the 2N peak width, the well reads its DNA stain differently, every position in it is biased by that shift, and a warning names it. The positions are not corrected, since a well with only one of the two peaks, such as an arrested one, cannot tell a shifted stain from a shifted population. Groups that cannot be checked are named in a warning with the reason.

Parameters:
adata AnnData

Object-resolution object carrying the DNA content column the model was fitted on.

model str | Mapping (default: 'cell_cycle')

Key of the model in uns["mantispy"], or the model itself, such as one fitted on another object.

by Sequence[str] | str | None (default: ('Metadata_Plate', 'Metadata_Well'))

The obs columns of a well, to check each well’s peaks against the reference; None skips the check. The default uses whichever of Metadata_Plate and Metadata_Well the object has.

checks Sequence[str] (default: ('irregular', 'small', 'dim'))

The shape checks to flag, out of "irregular", "small" and "dim", when the model holds qc_features. Rounded mitotic cells can fail the solidity check as merged nuclei do, so whether to use "irregular" depends on the cell line and the question.

key_added str (default: 'cell_cycle')

Prefix of the outputs written.

copy bool (default: False)

Return a modified copy instead of mutating in place.

Return type:

AnnData | None

Returns:

None, or the modified copy. Writes obsm[key_added + "_probabilities"], a frame with the probability of each of CYCLE_PHASES per cell; obs[key_added + "_phase"], the most probable of them, for convenience; obs[key_added + "_position"], the posterior median in [0, 1), 0 being the start of G1; obsm[key_added + "_quantiles"], a frame with the 5%, 25%, 50%, 75% and 95% posterior quantiles; obs[key_added + "_qc"], when the model holds qc_features, the first of checks a nucleus fails: "irregular" for a solidity below the reference’s, as merged nuclei and mitotic figures have, "small" for an area below it, as fragments and debris have, "dim" for too little DNA per area, and "ok" otherwise; uns["mantispy"][key_added], the model used, so plots read its phase edges from there; and uns["mantispy"][key_added + "_wells"], one row per by group with its n_cells and the shift its 2N and 4N peaks share against the reference, in doublings, NaN when it could not be checked. A cell without a DNA content gets NaN positions and phases, as does every cell when the model failed its check. A cell off the cycle gets NaN positions. Columns of an earlier projection under key_added that this model does not write, and the orders of phase_order(), are removed.

Raises:
  • KeyError – uns["mantispy"] has no entry model, or obs lacks the DNA content column it was fitted on or a by column, or the object lacks a feature of the model’s qc_features.

  • ValueError – A by column holds missing values, or checks names an unknown check.

See also

Where cells sit in the cycle for a worked example, and How the cell-cycle model works for how the model works, step by step.