pertpy.preprocessing.GuideAssignment

class pertpy.preprocessing.GuideAssignment[source]

Offers simple guide assigment based on count thresholds.

Methods table

assign_by_threshold(adata, assignment_threshold)

Simple threshold based gRNA assignment function.

assign_to_max_guide(adata, assignment_threshold)

Simple threshold based max gRNA assignment function.

plot_heatmap(adata[, layer, order_by, ...])

Heatmap plotting of guide RNA expression matrix.

Methods

assign_by_threshold

GuideAssignment.assign_by_threshold(adata, assignment_threshold, layer=None, output_layer='assigned_guides', only_return_results=False)[source]

Simple threshold based gRNA assignment function.

Each cell is assigned to gRNA with at least assignment_threshold counts. This function expects unnormalized data as input.

Parameters:
  • adata (AnnData) – Annotated data matrix containing gRNA values

  • assignment_threshold (float) – The count threshold that is required for an assignment to be viable.

  • layer (str | None) – Key to the layer containing raw count values of the gRNAs. adata.X is used if layer is None. Expects count data.

  • output_layer (str) – Assigned guide will be saved on adata.layers[output_key]. Defaults to assigned_guides.

  • only_return_results (bool) – If True, input AnnData is not modified and the result is returned as an np.ndarray. Defaults to False.

Return type:

ndarray | None

Examples

Each cell is assigned to gRNA that occurs at least 5 times in the respective cell.

>>> import pertpy as pt
>>> mdata = pt.data.papalexi_2021()
>>> gdo = mdata.mod["gdo"]
>>> ga = pt.pp.GuideAssignment()
>>> ga.assign_by_threshold(gdo, assignment_threshold=5)

assign_to_max_guide

GuideAssignment.assign_to_max_guide(adata, assignment_threshold, layer=None, output_key='assigned_guide', no_grna_assigned_key='NT', only_return_results=False)[source]

Simple threshold based max gRNA assignment function.

Each cell is assigned to the most expressed gRNA if it has at least assignment_threshold counts. This function expects unnormalized data as input.

Parameters:
  • adata (AnnData) – Annotated data matrix containing gRNA values

  • assignment_threshold (float) – The count threshold that is required for an assignment to be viable.

  • layer (str | None) – Key to the layer containing raw count values of the gRNAs. adata.X is used if layer is None. Expects count data.

  • output_key (str) – Assigned guide will be saved on adata.obs[output_key]. default value is assigned_guide.

  • no_grna_assigned_key (str) – The key to return if no gRNA is expressed enough.

  • only_return_results (bool) – If True, input AnnData is not modified and the result is returned as an np.ndarray.

Return type:

ndarray | None

Examples

Each cell is assigned to the most expressed gRNA if it has at least 5 counts.

>>> import pertpy as pt
>>> mdata = pt.dt.papalexi_2021()
>>> gdo = mdata.mod["gdo"]
>>> ga = pt.pp.GuideAssignment()
>>> ga.assign_to_max_guide(gdo, assignment_threshold=5)

plot_heatmap

GuideAssignment.plot_heatmap(adata, layer=None, order_by=None, key_to_save_order=None, **kwargs)[source]

Heatmap plotting of guide RNA expression matrix.

Assuming guides have sparse expression, this function reorders cells and plots guide RNA expression so that a nice sparse representation is achieved. The cell ordering can be stored and reused in future plots to obtain consistent plots before and after analysis of the guide RNA expression. Note: This function expects a log-normalized or binary data.

Parameters:
  • adata (AnnData) – Annotated data matrix containing gRNA values

  • layer (str | None) – Key to the layer containing log normalized count values of the gRNAs. adata.X is used if layer is None.

  • order_by (ndarray | str | None) – The order of cells in y axis. Defaults to None. If None, cells will be reordered to have a nice sparse representation. If a string is provided, adata.obs[order_by] will be used as the order. If a numpy array is provided, the array will be used for ordering.

  • key_to_save_order (str) – The obs key to save cell orders in the current plot. Only saves if not None.

  • kwargs – Are passed to sc.pl.heatmap.

Return type:

list[Axes]

Returns:

List of Axes. Alternatively you can pass save or show parameters as they will be passed to sc.pl.heatmap. Order of cells in the y-axis will be saved on adata.obs[key_to_save_order] if provided.

Examples

Each cell is assigned to gRNA that occurs at least 5 times in the respective cell, which is then visualized using a heatmap.

>>> import pertpy as pt
>>> mdata = pt.dt.papalexi_2021()
>>> gdo = mdata.mod["gdo"]
>>> ga = pt.pp.GuideAssignment()
>>> ga.assign_by_threshold(gdo, assignment_threshold=5)
>>> ga.plot_heatmap(gdo)