Transcript plots
TranscriptPlots
TranscriptPlots
def TranscriptPlots(
transcript_data, intron_scale:float=0.12, intron_scale_mode:str='relative', # 'relative' | 'fixed'
intron_fixed_length:float=5.0, exon_scale_mode:str='none', # 'none' | 'relative' | 'fixed'
exon_scale:float=1.0, exon_fixed_length:float=8.0, exon_min_length:float=1.5, intron_min_length:float=1.0,
label_drop:float=0.1, show_length:bool=False, length_mode:str='exonic', # 'exonic' | 'span'
palette:str='wong', # 'wong' | 'tab10' | list
exon_edge_style:str='soft', # 'soft' | 'rounded' | 'sharp'
intron_style:str='line', # 'line' | 'chevron'
color_offset:int=0, # rotate palette by this many steps
):
Visualize transcript structures (intron-compressed, optional exon scaling) and provide a right-hand panel (heatmap or dotplot).
TranscriptPlots.draw_transcripts_list
def draw_transcripts_list(
transcripts_ids:List[str], # List of transcript IDs to draw
colors:Optional[List[str]]=None, # Custom colors for each transcript
draw_cds:bool=False, # Whether to draw CDS/UTR distinction
show_ticks:bool=True, # Whether to show top ruler with coordinates
show_row_bounds:bool=False, # Whether to show row boundary markers
title_gene:Optional[str]=None, # Custom gene label for the title
fig_width:float | None=None, # Figure width
reference_tx:Optional[str]=None, # Splicing event visualization options
highlight_style:Optional[str]=None, # How to highlight splicing events:
- "box": Draw bounding boxes around affected regions
- "color": Color affected exons differently
- None: No highlighting
highlight_color:Optional[str]=None, # Color for highlighting (default: red-ish color)
show_event_labels:bool=False, # Whether to show event type labels (MXE, SE, etc.) below transcript ID.
Only shown for non-reference transcripts.
event_label_fontsize:int=8, # Font size for event labels
):
Draw a list of transcripts with optional splicing event highlighting.
add_quant_band_to_layout
def add_quant_band_to_layout(
layout:PanelLayout, values:np.ndarray, cmap:str='viridis', slot:int=0, n_slots:int=1, which:str='top',
ax_panel:Optional[plt.Axes]=None, # when set, draw on panel axis for perfect alignment
)->Tuple[mpl.colors.Normalize, mpl.colors.Colormap]:
Draw a quantitative strip. When ax_panel is provided, patches are drawn directly on the panel axis using get_xaxis_transform() which guarantees pixel-perfect x-alignment with the heatmap. Returns (norm, cmap_obj).
add_categorical_band_to_layout
def add_categorical_band_to_layout(
layout:PanelLayout, groups:List[str], color_map:Dict[str, str], slot:int=0, n_slots:int=1,
which:str='top', # "top" or "bottom"
ax_panel:Optional[plt.Axes]=None
):
Draw a categorical strip using imshow on ax_band_top/ax_band_bottom. Uses the same imshow+extent approach as the heatmap so column widths are pixel-identical — guaranteed alignment.
add_dotpanel_to_layout
def add_dotpanel_to_layout(
tp:TranscriptPlots, layout:PanelLayout, dot_color:np.ndarray, dot_size:np.ndarray, cmap:str='magma',
vmin:float | None=None, vmax:float | None=None, colorbar_label:str='PSI', col_labels:Optional[List[str]]=None,
label_wrap:int=14, label_rot:int=35, show_panel_colorbar:bool=True, # toggle PSI bar next to panel
):
Fill an existing transcript+panel layout with a dotplot.
dot_color: isoform × group (same shape as dot_size) dot_size: isoform × group in [0,1] (prevalence, coverage, etc.)
Returns a metadata dict: {“artist”, “colorbar”, “vmin”, “vmax”, “cmap”} so callers can reuse vmin/vmax/cmap for legends.
add_heatmap_to_layout
def add_heatmap_to_layout(
tp:TranscriptPlots, layout:PanelLayout, values:np.ndarray, cmap:str='magma', vmin:float | None=None,
vmax:float | None=None, colorbar_label:str='PSI', col_labels:Optional[List[str]]=None, label_wrap:int=14,
label_rot:int=35, show_panel_colorbar:bool=True, # toggle PSI bar next to panel
):
Fill an existing transcript+panel layout with a heatmap whose look matches isoform_dashboard_by_manip_fixedtitle.
values: [n_iso x n_groups] matrix (rows must match layout.tids order).
Returns a metadata dict: {“artist”, “colorbar”, “vmin”, “vmax”, “cmap”} so callers can reuse vmin/vmax/cmap for legends.
PanelLayout
def PanelLayout(
fig:plt.Figure, ax_main:plt.Axes, ax_panel:plt.Axes, ax_cbar:plt.Axes, tids:List[str], y_centers:List[float],
mapper:Callable[[int | float], float], g0:int, g1:int, n_cols:int=0, ax_band_top:Optional[plt.Axes]=None,
ax_band_bottom:Optional[plt.Axes]=None, ax_legend:Optional[plt.Axes]=None
)->None:
LegendConfig
def LegendConfig(
psi_cbar_location:str='panel', show_group_legend:bool=False, show_gex_colorbar:bool=True,
show_prevalence_legend:bool=True
)->None:
Panel layout
Compose transcript diagrams with quantification panels.
make_transcript_panel_layout
def make_transcript_panel_layout(
tp:TranscriptPlots, transcripts_ids:List[str], n_panel_cols:int, fig_width:float | None=None, draw_cds:bool=True,
show_ruler:bool=True, bands_frac_top:float=0.0, # fraction above panel
bands_frac_bottom:float=0.0, # fraction below panel
)->PanelLayout:
Generic builder: draws transcripts on the left and reserves a right-hand panel + colorbar axis + far-right legend axis.
bands_frac_top / bands_frac_bottom are fractions of the panel height used for strips above and below the panel, respectively.