ocelli.tl.scale_weights#
- ocelli.tl.scale_weights(adata: AnnData, obs: list, modalities: list, weights: str = 'weights', kappa: float = 1.0, verbose: bool = False, copy: bool = False)#
Scale multimodal weights for selected cells and modalities
This function scales the weights of specific cells (obs) and modalities by a factor of kappa. It is useful for adjusting the influence of certain modalities for selected cells in downstream analyses.
When selecting observations and modalities, ensure that their types match the adata.obsm[weights].index and adata.obsm[weights].columns, respectively.
- Parameters:
adata (anndata.AnnData) – The annotated data matrix.
obs (list) – List of elements from adata.obsm[weights].index specifying the cells to scale.
modalities (list) – List of elements from adata.obsm[weights].columns specifying the modalities to scale.
weights (str) – Key in adata.obsm where the weights are stored. (default: ‘weights’)
kappa (float) – The scaling factor applied to the selected weights. (default: 1.0)
verbose (bool) – Whether to print progress notifications. (default: False)
copy (bool) – Whether to return a copy of adata. If False, updates are made in-place. (default: False)
- Returns:
If copy=False: Updates adata with the scaled weights in adata.obsm[weights].
If copy=True: Returns a modified copy of adata with the scaled weights.
- Return type:
anndata.AnnData or None
- Example:
import ocelli as oci from anndata import AnnData import numpy as np import pandas as pd # Example data adata = AnnData(X=np.random.rand(100, 50)) adata.obsm["weights"] = pd.DataFrame( np.random.rand(100, 3), index=["cell{}".format(i) for i in range(100)], columns=["modality1", "modality2", "modality3"] ) # Scale weights for specific cells and modalities oci.tl.scale_weights( adata, obs=["cell1", "cell2"], modalities=["modality1", "modality2"], kappa=2.0, verbose=True )