mtopic.pp.scale_counts

Contents

mtopic.pp.scale_counts#

mtopic.pp.scale_counts(mdata, counts_per_cell=10000, copy=False)#

Scale count matrices to normalize the total sum of counts across modalities.

This function normalizes the total sum of counts in the .X matrix of each modality within the provided MuData object. Each modality’s counts are scaled so that their total sum matches a specified target value (counts_per_cell * n_obs). This ensures consistency in total counts across different modalities, which is crucial for comparative analyses in single-cell multimodal datasets.

Parameters:
  • mdata (mu.MuData) – A MuData object containing multiple modalities, each with an .X attribute representing counts data.

  • counts_per_cell (int, optional) – The target average counts per cell. The total sum of counts in each modality is scaled to counts_per_cell * n_obs, where n_obs is the number of cells. Default is 10,000.

  • copy (bool, optional) – If True, a copy of the MuData object is created, and the scaling is applied to the copy. If False, the scaling is performed in-place on the original object. Default is False.

Returns:

If copy is True, returns a new MuData object with scaled counts data. If copy is False, returns None and applies scaling directly to the input MuData object.

Return type:

mu.MuData or None

Example:
import mtopic

# Load MuData object
mdata = mtopic.read.h5mu("path/to/file.h5mu")

# Scale counts in-place
mtopic.pp.scale_counts(mdata)

# Scale counts and return a copy
scaled_mdata = mtopic.pp.scale_counts(mdata, copy=True)
Notes:
  • This function is especially useful when working with multimodal datasets where each modality may have different total counts, making comparisons challenging.