mmcontext.pl.plotting.plot_query_scores_with_labels_umap#
- mmcontext.pl.plotting.plot_query_scores_with_labels_umap(adata, queries, labels, label_key, embedding_key='X_umap', emb_key='mmcontext_emb', save_plot=True, save_dir=None, nametag=None, figsize=(6, 6), dpi=300, point_size=5, frameon=False, legend_fontsize=10, font_weight='normal', font_style='normal', font_size=12, axis_label_size=12, axis_tick_size=10, save_format='png', umap_n_neighbors=15, umap_min_dist=0.1, umap_random_state=42, **kwargs)#
Plot UMAPs colored by query similarity scores with label highlighting.
This function creates UMAP plots where: 1. Points are colored by similarity scores for each query 2. Points corresponding to specific labels are highlighted with borders 3. Query strings are saved as titles in separate plots 4. Verification is performed to ensure labels match queries and exist in adata.obs
- Parameters:
adata (anndata.AnnData) – AnnData object containing query_scores in .obs and embeddings in .obsm
queries (list[str]) – List of query strings to plot. Must match keys in adata.obs[“query_scores”]
labels (list[str]) – List of label names, one per query (same length as queries)
label_key (str) – Key in adata.obs containing the label information
embedding_key (str, optional) – Key in adata.obsm containing UMAP coordinates. If not present, UMAP will be computed. Defaults to “X_umap”
emb_key (str, optional) – Key in adata.obsm containing embeddings for UMAP computation. Defaults to “mmcontext_emb”
save_plot (bool, optional) – Whether to save plots. Defaults to True
save_dir (str, optional) – Directory to save plots. Defaults to None
nametag (str, optional) – Additional tag for saved files. Defaults to None
figsize (tuple, optional) – Figure size (width, height). Defaults to (6, 6)
dpi (int, optional) – DPI for saved plots. Defaults to 300
point_size (int, optional) – Size of scatter plot points. Defaults to 5
frameon (bool, optional) – Whether to show plot frame. Defaults to False
legend_fontsize (int, optional) – Font size for legends. Defaults to 10
font_weight (str, optional) – Font weight. Defaults to “normal”
font_style (str, optional) – Font style. Defaults to “normal”
font_size (int, optional) – General font size. Defaults to 12
axis_label_size (int, optional) – Axis label font size. Defaults to 12
axis_tick_size (int, optional) – Axis tick font size. Defaults to 10
save_format (str, optional) – Format for saved plots. Defaults to “png”
umap_n_neighbors (int, optional) – Number of neighbors for UMAP computation. Defaults to 15
umap_min_dist (float, optional) – Minimum distance for UMAP computation. Defaults to 0.1
umap_random_state (int, optional) – Random state for UMAP computation. Defaults to 42
**kwargs – Additional keyword arguments
- Returns:
None Saves or displays UMAP plots
- Raises:
ValueError – If validation checks fail
Examples
>>> plot_query_scores_with_labels_umap( ... adata=adata, ... queries=["T cell", "B cell"], ... labels=["T_cell", "B_cell"], ... label_key="cell_type", ... save_dir="plots/query_analysis", ... )