count_occurrence¶
- besca.tl.count_occurrence(adata, count_variable='celltype', add_percentage=False)[source]¶
Generate dataframe containing the label counts/percentages of a specific column in adata.obs
This function counts the occurrence of each label within the specified column (count_variable) of an AnnData object and outputs the results to a pandas DataFrame. If add_percentage is true it also calculates the occurrence of each label as a percentage. Note, percentages have been rounded to the second decimal place after the comma.
One of the most common use-cases for this function will be to count the occurrence of specific celltypes within the dataset.
- Parameters:
adata (AnnData) – the AnnData object
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 also contains the occurrence of each label as a percentage
- Return type:
pandas.DataFrame