mtopic.pl.filter_var_knee#
- mtopic.pl.filter_var_knee(model, mod, knee_sensitivities=[1, 2, 5, 10], s=20, figsize=(8, 6), fontsize=10, annotate_features=False, show_frac=1, log_scale=True, transparent=False, save=None)#
Detect and visualize overrepresented features using a knee detection algorithm.
This function identifies and visualizes features (e.g., genes) that are overrepresented across all topics in a specified modality of a topic model. By plotting the cumulative feature scores across topics, it applies a knee detection algorithm to find points of significant activity drop, which can be used to filter out less informative features in downstream analysis.
Multiple knee points are calculated using varying sensitivities, providing insight into how the detection threshold affects the selection of overrepresented features.
- Parameters:
model (mtopic.tl.MTM or mtopic.tl.sMTM) – An instance of a topic model (e.g., mtopic.tl.MTM or mtopic.tl.sMTM) containing the topic-feature distributions.
mod (str) – The modality to analyze (e.g., ‘rna’, ‘protein’).
knee_sensitivities (list of int, optional) – List of sensitivities for the knee detection algorithm. Higher values make the algorithm more conservative in identifying overrepresented features. Default is [1, 2, 5, 10].
s (int, optional) – Marker size for the scatter plot. Default is 20.
figsize (tuple, optional) – Tuple specifying the size of the figure (width, height) in inches. Default is (8, 6).
fontsize (int, optional) – Font size for plot labels, annotations, and ticks. Default is 10.
annotate_features (bool, optional) – Whether to annotate feature names on the plot. If True, feature names will be displayed near their points. Default is False.
show_frac (float, optional) – Fraction of the top features to display based on their cumulative activity. Default is 1 (all features).
log_scale (bool, optional) – Whether to apply a log scale to the y-axis for feature activity. Default is True.
transparent (bool, optional) – If True, saves the figure with a transparent background. Default is False.
save (str, optional) – Path to save the figure. If None, the figure is displayed but not saved. Default is None.
- Returns:
None
- Example:
import mtopic # Assume `model` is an instance of mtopic.tl.MTM or mtopic.tl.sMTM mtopic.pl.filter_var_knee( model, mod='rna', knee_sensitivities=[1, 2, 5], annotate_features=True, save='knee_plot.pdf' )