count_occurrence_subset_conditions

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

count occurrence of a label for each condition 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 for each condition identified in the column condition_identifier.

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

  • condition_identifier (str) – string identifying the coloumn in which the conditions are annotated

  • 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