scmagnify.tools.RegDecomp#
- class scmagnify.tools.RegDecomp(data, net_key='network', tensor_mode='multiscale', modes=None, filter=['quantile', 0.0, False], backend='numpy')#
A class for performing tensor decomposition on gene regulatory networks to identify regulatory factors (RegFactors).
- Parameters:
data (
AnnData|MuData|GRNMuData) – Single cell data object. Can be ananndata.AnnData,mudata.MuData,scmagnify.GRNMuDatanet_key (
str(default:'network')) – net_key indata.unswhere the network is stored.tensor_mode (
str(default:'multiscale')) – The mode of the tensor to be constructed. Options are ‘multiscale’ or ‘ensemble’.modes (
Optional[list[str]] (default:None)) – List of mode names for the tensor. Default is [‘Lag’, ‘TF’, ‘TG’] for ‘multiscale’ and [‘TF’, ‘TG’] for ‘ensemble’.filter (
list[str] (default:['quantile', 0.0, False])) – A list specifying the filtering method, parameter, and whether to binarize the network.backend (
str(default:'numpy')) – The backend to use for tensor operations. Options are ‘numpy’, ‘pytorch’, ‘tensorflow’, or ‘jax’.
Attributes table#
Get the current tensor. |
Methods table#
|
Compute the activity of RegFactors in the dataset. |
|
Perform CP decomposition on the tensor. |
|
Normalize the tensor along a specified mode. |
|
Rename RegFactors and optionally sort them. |
|
Perform Tucker decomposition on the tensor. |
Attributes#
- RegDecomp.get_tensor#
Get the current tensor.
- Returns:
np.ndarray The current tensor.
Methods#
- RegDecomp.compute_activity(modal='RNA', layer='log1p_norm', mode='TG', method='mlm', thres=0.0, mod_key='RegFactor', n_top=None)#
Compute the activity of RegFactors in the dataset.
- Parameters:
modal (
Literal['RNA','ATAC','GRN'] (default:'RNA')) – Modality key (e.g., ‘RNA’, ‘ATAC’) when using multi-modal data.mudata.MuDataorscmagnify.GRNMuDatamust be provided.layer (
str(default:'log1p_norm')) – Layer inlayers. IfNone, defaults toX.mode (
str(default:'TG')) – The mode (‘TF’ or ‘TG’) to use for defining the RegFactors.method (
Literal['mlm','aucell'] (default:'mlm')) – Method to compute activity.thres (
float(default:0.0)) – Threshold for filtering weights.mod_key (
str(default:'RegFactor')) – The key to store the activity matrix indata.mod.n_top (
Optional[int] (default:None)) – Number of top genes to consider for each RegFactor.
- Return type:
- Returns:
None
- RegDecomp.cp_decomposition(rank, non_negative=False, **kwargs)#
Perform CP decomposition on the tensor.
- Parameters:
- Returns:
tuple A tuple containing weights, factors, and normalized root mean squared error (NRE).
- RegDecomp.normalization(mode_name, method='proportion')#
Normalize the tensor along a specified mode.
- RegDecomp.rename_regfactors(rename_map, sort=False, mod_key='RegFactor')#
Rename RegFactors and optionally sort them.
- Parameters:
rename_map (
dict[str,str]) – A dictionary mapping old RegFactor names to new names. Example: {‘RegFactor_1’: ‘Proliferation’, ‘RegFactor_2’: ‘Apoptosis’}sort (
Union[bool,list[str],Literal['alphabetical']] (default:False)) –False: Only rename, do not change the order.Trueor'alphabetical': Sort the newly named factors alphabetically.List[str]: Sort the factors according to the provided list of new names.
mod_key (
str(default:'RegFactor')) – The key where the activity AnnData object is stored indata.mod.
- Return type:
- RegDecomp.tucker_decomposition(rank=None, non_negative=False, regfactor_key='regfactors', **kwargs)#
Perform Tucker decomposition on the tensor.
- Parameters:
rank (
Union[int,tuple,list,None] (default:None)) – The rank of the decomposition for each mode.non_negative (
bool(default:False)) – Whether to use non-negative decomposition.regfactor_key (
str(default:'regfactors')) – The key to store the resulting regulatory factors (RegFactors).**kwargs – additional keyword arguments for the tensorly.decomposition algorithm.
- Returns:
tuple A tuple containing core tensor, factors, and normalized root mean squared error (NRE).