tfmindi.pl.tsne_logos#
- tfmindi.pl.tsne_logos(adata, patterns=None, color_by='cluster_dbd', logo_width=1.0, logo_height=0.8, alpha=0.2, s=2, ic_threshold=0.2, min_nucleotides=4, min_seqlets=10, show_cluster_labels=True, show_legend=True, gray_background=True, cmap='tab20', **kwargs)#
Visualize seqlet clusters in t-SNE space with optional sequence logos at centroids.
This function can display both basic t-SNE scatter plots and enhanced plots with sequence logos. When show_logos=False, it delegates to the basic tsne() function for fast exploration. When show_logos=True, it renders sequence logos at cluster centroids for publication-quality visualization.
- Parameters:
adata (
AnnData) – AnnData object with t-SNE coordinates and cluster assignments. Must contain adata.obsm[“X_tsne”] and adata.obs[“leiden”].patterns (
dict[str,Pattern] |None(default:None)) – Dictionary mapping cluster IDs to Pattern objects with PWMs. Required when show_logos=True, optional when show_logos=False.color_by (
str(default:'cluster_dbd')) – Column in adata.obs to use for coloring points.logo_width (
float(default:1.0)) – Width of sequence logos relative to plot coordinates.logo_height (
float(default:0.8)) – Height of sequence logos relative to plot coordinates.alpha (
float(default:0.2)) – Transparency of scatter points.s (
float(default:2)) – Size of scatter points.ic_threshold (
float(default:0.2)) – Information content threshold for logo trimming.min_nucleotides (
int(default:4)) – Minimum number of nucleotides required after trimming to show logo. Patterns with fewer nucleotides will be skipped to avoid showing noisy logos.min_seqlets (
int(default:10)) – Minimum number of seqlets required in a cluster to display its logo. Clusters with fewer seqlets will be skipped to avoid showing weak motifs from small clusters.show_cluster_labels (
bool(default:True)) – Whether to show cluster ID labels.show_legend (
bool(default:True)) – Whether to show the legend (default: True).gray_background (
bool(default:True)) – Whether to use gray background for all scatter points to improve logo readability. When True, all points are colored gray and no legend is shown.cmap (
str(default:'tab20')) – Colormap name for categorical data (default: “tab20”). Any valid matplotlib colormap name (e.g., “viridis”, “plasma”, “Set1”).**kwargs – Additional arguments passed to render_plot() for styling and display options. Common options include width, height, title, xlabel, ylabel, show, save_path.
- Return type:
- Returns:
matplotlib.Figure or None Figure with t-SNE plot and optional sequence logos, or None if show=True.
Examples
>>> import tfmindi as tm >>> # After clustering and pattern creation - full plot with logos >>> tm.pl.tsne_logos(adata, patterns, color_by="cluster_dbd", width=12, height=10) >>> >>> # Publication plot with custom styling >>> tm.pl.tsne_logos(adata, patterns, width=30, height=30, title="My Plot", show=False, save_path="plot.png")