calour.manipulation.aggregate_by_metadata

calour.manipulation.aggregate_by_metadata(exp: calour.experiment.Experiment, field, agg='mean', axis=0, inplace=False)[source]

aggregate all samples/features that have the same value in the given field.

Group the samples (axis=0) or features (axis=1) that have the same value in the column of given field and then aggregate the data table of the group with the given method.

The number of samples/features in each group and their IDs are stored in new metadata columns ‘_calour_merge_number’ and ‘_calour_merge_ids’, respectively

Warning

It will convert the Experiment.data from the sparse matrix to dense array.

Note

This function is also available as a class method Experiment.aggregate_by_metadata()

Parameters:
  • exp (Experiment) – Input experiment object.
  • field (str) – The sample/feature metadata field to group samples/features
  • agg (str, optional) –

    aggregate method. Choice includes:

    • ’mean’ : the mean of the group
    • ’median’ : the median of the group
    • ’random’ : a random selection from the group
    • ’sum’ : the sum of of the group
  • axis (0, 1, 's', or 'f', optional) – 0 or ‘s’ (default) to aggregate samples; 1 or ‘f’ to aggregate features
  • inplace (bool, optional) – False (default) to create new Experiment, True to perform inplace
Returns:

Return type:

Experiment