tfmindi.pl.region_contributions

tfmindi.pl.region_contributions#

tfmindi.pl.region_contributions(adata, annotation_col=None, example_idx=None, region_name=None, zoom_start=None, zoom_end=None, min_attribution=None, overlap_threshold=25, show_unannotated=False, annotations_to_show=None, cmap='tab20', **kwargs)#

Visualize contribution scores for a full genomic region with annotated seqlet regions.

Creates a two-panel plot showing contribution scores as sequence logos for the entire region on top, and DNA-binding domain annotations for detected seqlets overlaid below.

Parameters:
  • adata (AnnData) – AnnData object with seqlet data and region information. Must contain adata.uns[‘unique_examples’] with ‘oh’ and ‘contrib’ arrays, and adata.obs with ‘example_oh_idx’ and ‘example_contrib_idx’ columns.

  • example_idx (int | None (default: None)) – Index of the example/region to visualize. Mutually exclusive with region_name.

  • region_name (str | None (default: None)) – Name of the region to visualize (e.g., ‘chr1:1000-2000’). Mutually exclusive with example_idx. Requires ‘region_name’ column in adata.obs.

  • zoom_start (int | None (default: None)) – Start position for zooming into a specific subregion (0-based indexing). Must be used together with zoom_end.

  • zoom_end (int | None (default: None)) – End position for zooming into a specific subregion (0-based indexing, exclusive). Must be used together with zoom_start.

  • min_attribution (float | None (default: None)) – Minimum absolute attribution score for seqlets to be highlighted with colored boxes. Seqlets with an absolute attribution below this threshold will not show colored rectangles. If None, all seqlets are highlighted regardless of attribution score.

  • overlap_threshold (default: 25) – Minimum distance (in base pairs) between seqlet labels to avoid overlap. Labels will be stacked vertically if they are too close together.

  • show_unannotated (bool (default: False)) – Whether to show rectangles for seqlets without annotations (default: False). When True, unannotated seqlets are shown in gray.

  • annotation_col (str | None (default: None)) – Column in adata.obs holding the per-seqlet TF-family annotation, e.g. the predicted_<resolution>_predicted_family column written by tfmindi.tl.predict_tf_family_seqlets().

  • annotations_to_show (str | list[str] | None (default: None)) – Annotation name(s) to display. Can be a single annotation (string) or a list of annotations. If None (default), all annotations are shown. Only seqlets with these specific annotations will be highlighted and labeled.

  • cmap (str (default: 'tab20')) – Colormap name for annotation coloring (default: “tab20”).

  • **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:

Figure | None

Returns:

Figure with contribution score visualization, or None if show=True.

Examples

>>> import tfmindi as tm
>>> # Plot saliency for example 0
>>> fig = tm.pl.region_contributions(adata, example_idx=0)
>>> # Plot saliency by region name
>>> fig = tm.pl.region_contributions(adata, region_name="chr1:1000-2000")
>>> # Zoom into a specific subregion (positions 50-150)
>>> fig = tm.pl.region_contributions(adata, example_idx=0, zoom_start=50, zoom_end=150)
>>> # Only show seqlets with high contribution scores
>>> fig = tm.pl.region_contributions(adata, example_idx=0, min_attribution=0.5)
>>> # Show only specific annotations
>>> fig = tm.pl.region_contributions(adata, example_idx=0, annotations_to_show="bZIP")
>>> fig = tm.pl.region_contributions(adata, example_idx=0, annotations_to_show=["bZIP", "HLH"])
>>> # Custom styling
>>> tm.pl.region_contributions(adata, example_idx=0, width=15, height=6)