mtopic.pp.permute#
- mtopic.pp.permute(mdata, subset: int = None, seed=2291, copy=False)#
Randomly permute the count matrices in a MuData object.
This function permutes each modality’s .X matrix along the observation (cell/spot) axis, independently per modality. It is used to generate a control dataset for detecting pervasive features — features that dominate feature–topic distributions despite randomized input. Basic filtering is applied to retain only non-empty cells and features.
- Parameters:
mdata (muon.MuData) – A MuData object containing multiple modalities, each with an .X attribute representing the counts to be permuted.
subset (int, optional) – The number of cells (observations) to randomly subset before performing permutation. If None, all cells are used. Default is None.
seed (int, optional) – Seed for the random number generator to ensure reproducibility of the permutation. Default is 2291.
copy (bool, optional) – If True, creates a copy of the MuData object and performs permutation on the copy. If False, the operation is performed in-place. Default is False.
- Returns:
If copy is True, returns a new MuData object with permuted data. If copy is False, returns None and applies permutation directly to the input MuData object.
- Return type:
muon.MuData or None
- Example:
import mtopic # Load MuData object mdata = mtopic.read.h5mu("path/to/file.h5mu") # Permute data in-place mtopic.pp.permute(mdata) # Permute data and return a copy permuted_mdata = mtopic.pp.permute(mdata, copy=True)