rapids_singlecell.ptg.GuideAssignment#

class rapids_singlecell.ptg.GuideAssignment[source]#

GPU-accelerated guide RNA assignment.

Provides threshold-based and mixture-model-based methods for assigning cells to guide RNAs, compatible with pertpy’s GuideAssignment API. The mixture model fits a Poisson-Gaussian mixture per guide with batched EM on GPU, yielding orders-of-magnitude speedup.

Methods table#

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

Assign cells to gRNAs exceeding a count threshold.

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

Assign gRNAs using a GPU-accelerated Poisson–Gaussian mixture model.

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

Assign each cell to its most expressed gRNA.

Methods#

assign_by_threshold#

GuideAssignment.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#

GuideAssignment.assign_mixture_model(adata, *, layer=None, assigned_guides_key='assigned_guide', no_grna_assigned_key='negative', max_assignments_per_cell=5, multiple_grna_assigned_key='multiple', multiple_grna_assignment_string='+', only_return_results=False, max_iter=90, tol=0.0001, posterior_threshold=0.5)[source]#

Assign gRNAs using a GPU-accelerated Poisson–Gaussian mixture model.

Fits a two-component mixture (Poisson background + Gaussian signal) to the log₂-transformed non-zero counts of each guide simultaneously using batched Expectation-Maximization on GPU. The fitted model is converted to an integer raw-count threshold; the default posterior cutoff matches pertpy’s threshold rule.

Parameters:
adata AnnData

Annotated data matrix with guide RNA counts.

layer str | None (default: None)

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

assigned_guides_key str (default: 'assigned_guide')

Key in adata.obs for storing the assignment result.

no_grna_assigned_key str (default: 'negative')

Label for cells negative for all gRNAs.

max_assignments_per_cell int (default: 5)

Maximum number of gRNAs a cell can be assigned to.

multiple_grna_assigned_key str (default: 'multiple')

Label for cells exceeding max_assignments_per_cell.

multiple_grna_assignment_string str (default: '+')

Delimiter for joining multiple guide names.

only_return_results bool (default: False)

If True, return assignments without modifying adata.

max_iter int (default: 90)

Maximum number of EM iterations.

tol float (default: 0.0001)

Convergence tolerance on parameter changes.

posterior_threshold float (default: 0.5)

Minimum posterior probability of the Gaussian component required for a raw UMI count to define the assignment threshold.

Return type:

ndarray | None

Returns:

If only_return_results is True, returns an array of assignments. Otherwise modifies adata in-place and returns None.

assign_to_max_guide#

GuideAssignment.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. 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