count_occurrence_subset

besca.tl.count_occurrence_subset(adata, subset_variable, count_variable='celltype', return_percentage=False)[source]

count occurrence of a label in adata.obs after subseting adata object

This function subsets the supplied AnnData object into datasubsets according to the lables contained in the subset_variable. For each of the datasubsets, it counts the occurrence of each label within the specified column (count_variable) of the adata subset.

If return percentage = True then the percentage of each label occurrence within a subset is returned.

Parameters:
  • adata (AnnData) – the AnnData object

  • subset_variable (str) – string identifying the column in adata.obs along which the data should be subsetted

  • count_variable (str | default = ‘celltype’) – string identifying the column in which the unique labels should be counted

  • add_percentage (bool | default = False) – boolian indicator if the occurrence of each label as a percentage should be added to the dataframe

Returns:

Dataframe containing the counts of each label, if add_percentage = True, then the DataFrame contains the occurrence of each label as a percentage within the datasubset

Return type:

pandas.DataFrame