rapids_singlecell.ptg.GuideAssignment#

class rapids_singlecell.ptg.GuideAssignment[source]#

GPU-accelerated guide RNA assignment.

Provides the threshold-based and mixture-model-based methods of pertpy’s GuideAssignment with the same parameters and results.

Methods table#

assign_by_threshold(adata, *, ...[, layer, ...])

Assign cells to gRNAs exceeding a count threshold.

assign_mixture_model(adata, *[, model, ...])

Assign gRNAs to cells using a Poisson-Gaussian mixture model.

assign_to_max_guide(adata, *, ...[, layer, ...])

Assign each cell to its most expressed gRNA.

Methods#

assign_by_threshold(adata, *, assignment_threshold, layer=None, output_layer='assigned_guides')[source]#

Assign cells to gRNAs exceeding a count threshold.

Each cell is assigned to every gRNA with at least assignment_threshold counts. Expects unnormalized count data.

Parameters:
adata AnnData

Annotated data matrix of shape n_obs x n_vars.

assignment_threshold float

Minimum count for a viable assignment.

layer str | None (default: None)

Layer with raw counts. Uses adata.X if None.

output_layer str (default: 'assigned_guides')

Key under which the binary assignment matrix is stored in adata.layers.

Return type:

None

assign_mixture_model(adata, *, model='poisson_gauss_mixture', layer=None, assigned_guides_key='assigned_guide', output_layer='assigned_guides', no_grna_assigned_key='negative', max_assignments_per_cell=5, multiple_grna_assigned_key='multiple', multiple_grna_assignment_string='+', only_return_results=False, show_progress=False, n_iter=1000, learning_rate=0.01, n_init_seeds=10, seed=2024)[source]#

Assign gRNAs to cells using a Poisson-Gaussian mixture model.

The model, priors and per-guide thresholding rule are those of crispat.ga_poisson_gauss and of pertpy’s assign_mixture_model. For each guide, the log2 of its non-zero UMI counts is modelled as a mixture of a continuous Poisson background and a Gaussian on-target component with priors weights ~ Dirichlet([0.9, 0.1]), mu ~ Normal(3, 2), scale ~ LogNormal(2, 1) and lam ~ LogNormal(0, 1). A cell is assigned to a guide if its UMI count is at least the smallest integer t for which P(Normal | log2(t)) > 0.5.

The MAP estimate is found by multi-start EM on the distinct count values of every guide, for all guides in parallel on the GPU. The lowest-loss solution is kept after discarding label-switched optima and degenerate optima in which the Gaussian weight vanishes or the Gaussian collapses onto a single count value.

Parameters:
adata AnnData

Annotated data matrix with guide RNA counts.

model Literal['poisson_gauss_mixture'] (default: 'poisson_gauss_mixture')

The mixture model to use. Only "poisson_gauss_mixture" is supported.

layer str | None (default: None)

Layer with raw counts. Uses adata.X if None.

assigned_guides_key str (default: 'assigned_guide')

Per-cell assignment is saved on adata.obs[assigned_guides_key].

output_layer str | None (default: 'assigned_guides')

The binary cell-by-guide assignment matrix is saved on adata.layers[output_layer], or not at all if None. Unlike the per-cell assignment it is not capped by max_assignments_per_cell.

no_grna_assigned_key str (default: 'negative')

Key to use when a cell is negative for all gRNAs.

max_assignments_per_cell int (default: 5)

Maximum number of gRNAs that can be assigned to a cell.

multiple_grna_assigned_key str (default: 'multiple')

Key to use when more than max_assignments_per_cell gRNAs are assigned.

multiple_grna_assignment_string str (default: '+')

Separator used to join multiple gRNAs assigned to one cell.

only_return_results bool (default: False)

If True, do not modify adata and return the assignment array.

show_progress bool (default: False)

Whether to print a progress line.

n_iter int (default: 1000)

Maximum number of EM iterations per start.

learning_rate float (default: 0.01)

Deprecated since version 0.19.0: The mixture model is fit by EM, which has no learning rate. The argument is ignored.

Deprecated and ignored.

n_init_seeds int (default: 10)

Number of prior-median initialisations per guide.

seed int (default: 2024)

Random seed used for the prior-median initialisations.

Return type:

ndarray | None

Returns:

The per-cell assignments if only_return_results is True, else None.

assign_to_max_guide(adata, *, assignment_threshold, layer=None, obs_key='assigned_guide', no_grna_assigned_key='Negative')[source]#

Assign each cell to its most expressed gRNA.

Each cell is assigned to the gRNA with the highest count, provided that count is at least assignment_threshold. Ties are resolved in favour of the first of the tied gRNAs. For sparse input, as in pertpy, only stored counts are considered. Expects unnormalized count data.

Parameters:
adata AnnData

Annotated data matrix of shape n_obs x n_vars.

assignment_threshold float

Minimum count for a viable assignment.

layer str | None (default: None)

Layer with raw counts. Uses adata.X if None.

obs_key str (default: 'assigned_guide')

Column in adata.obs where the assignment is stored.

no_grna_assigned_key str (default: 'Negative')

Label for cells with no guide above threshold.

Return type:

None