tracks

Prebuilt track configurations for genome view plotting.

This module provides ready-to-use tracks built on top of the primitives in mutopia.plot.track_plot and the helpers in .transforms.

mutopia.plot.track_plot.tracks.order_components(dataset)[source]

Compute an ordering of components based on hierarchical clustering.

Parameters:

dataset (GTensorDataset) – Input dataset with component_distributions_locus.

Returns:

Ordered component identifiers.

Return type:

ndarray

mutopia.plot.track_plot.tracks.plot_component_rates(view, *components, smooth=30, height=0.5, label=None, color='#427aa1ff', linewidth=0.5)[source]

Plot per-component mutation rates as filled line tracks.

Parameters:
  • view (GenomeView) – Genome view used for smoothing and renormalization.

  • *components (Any) – Component identifiers to plot.

  • smooth (int, default 30) – Smoothing window (in regions).

  • height (float, default 0.5) – Track height per component.

  • label (str, optional) – Label to use (defaults to the component identifier).

  • color (str, default categorical_palette[0]) – Fill/line color.

  • linewidth (float, default 0.5) – Line width.

Returns:

One line_plot callable per component.

Return type:

list of callable

mutopia.plot.track_plot.tracks.plot_empirical_topography(transformer, palette='Greys', label='Empirical\ntopography', height=1.5, quantile_cutoff=0.999, s=0.01, alpha=0.5, topography_kw={'alpha': 0.15, 'cbar': False, 'vmax': 3, 'vmin': -3}, **scatter_kw)[source]

Overlay empirical topography points on a predicted topography heatmap.

Parameters:
  • transformer (TopographyTransformer) – Fitted transformer.

  • palette (str, default "Greys") – Colormap for the background heatmap.

  • label (str, default "Empiricalntopography") – Track label.

  • height (float, default 1.5) – Track height.

  • quantile_cutoff (float, default 0.999) – Upper quantile for clipping empirical intensities.

  • s (float, default 0.01) – Scatter point size.

  • alpha (float, default 0.5) – Scatter alpha.

  • topography_kw (dict) – Extra kwargs passed to the background heatmap.

  • **scatter_kw – Extra kwargs passed to ax.scatter.

Returns:

Stacked scatter + heatmap track.

Return type:

callable

mutopia.plot.track_plot.tracks.plot_gene_annotation(gtf, label='Genes', all_labels_inside=False, style='flybase', label_genes=True, fontsize=5, ax_fn=<function <lambda>>, **kw)[source]

Create a gene annotation track from GTF file.

Parameters:
  • gtf (str) – Path to GTF file

  • label (str, default "Genes") – Track label

  • all_labels_inside (bool, default False) – Whether to show all gene labels inside

  • style (str, default "flybase") – Gene track style

  • fontsize (int, default 5) – Font size for labels

  • ax_fn (callable) – Function to customize axes appearance

  • **kw – Additional keyword arguments

Returns:

Track plotting function

Return type:

callable

Examples

>>> import mutopia.plot.track_plot as tr
>>> cfg = lambda v: tr.tracks.gene_annotation_track("/path/genes.gtf")
>>> _ = tr.plot_view(cfg, tr.make_view(ds, region="chr1:1-2_000_000"))
mutopia.plot.track_plot.tracks.plot_gene_expression_strip(feature_name='GeneExpression', label=None)[source]
mutopia.plot.track_plot.tracks.plot_gene_expression_track(expression_key='GeneExpression', strand_key='GeneStrand', linewidth=0.5, label='Gene\nexpression', color='lightgrey', height=1, log1p=True)[source]

Strand-aware gene expression bar track (optionally symlog1p-transformed).

Parameters:
  • expression_key (str, default "GeneExpression") – Dataset feature key for expression magnitude.

  • strand_key (str, default "GeneStrand") – Dataset feature key for strand (+1 / -1 / 0).

  • linewidth (float, default 0.5) – Horizontal zero-line width.

  • label (str, default "Genenexpression") – Track label.

  • color (str, default "lightgrey") – Bar color.

  • height (float, default 1) – Track height.

  • log1p (bool, default True) – If True, applies symmetric log1p to signed expression.

Returns:

Bar plot callable.

Return type:

callable

mutopia.plot.track_plot.tracks.plot_marginal_observed_vs_expected(view, smooth=20, pred_smooth=10, label='Mutation rate', legend=True, height=1, empirical_kw={'alpha': 0.5, 'color': 'lightgrey', 's': 0.1}, predicted_kw={'alpha': 0.8, 'color': '#e07a5fff', 'dashes': (1, 1), 'linewidth': 0.75}, ax_fn=<function <lambda>>)[source]

Compare empirical vs. predicted marginal mutation rates.

Parameters:
  • view (GenomeView) – Genome view that supplies smoothing and locus metadata.

  • smooth (int, default 20) – Window size for smoothing empirical rates.

  • pred_smooth (int, default 10) – Window size for smoothing predicted rates.

  • label (str, default "Mutation rate") – Track label.

  • legend (bool, default True) – Whether to show a legend.

  • height (float, default 1) – Track height.

  • empirical_kw (dict) – Keyword args passed to the empirical scatterplot.

  • predicted_kw (dict) – Keyword args passed to the predicted line plot.

  • ax_fn (callable) – Optional axes customization function.

Returns:

A stacked track containing empirical scatter and predicted line.

Return type:

callable

Examples

>>> import mutopia.plot.track_plot as tr
>>> view = tr.make_view(ds, region="chr1:1_000_000-1_200_000")
>>> cfg = lambda v: tr.tracks.marginal_observed_vs_expected(view)
>>> _ = tr.plot_view(cfg, view)
mutopia.plot.track_plot.tracks.plot_topography(transformer, palette='Greys', yticks=False, label='Predicted\ntopography', vmin=-3, vmax=3, height=1.5, **heatmap_kw)[source]

Heatmap of predicted topography with hierarchical row order.

Parameters:
  • transformer (TopographyTransformer) – Fitted transformer that supplies transform, ordering, and labels.

  • palette (str, default "Greys") – Matplotlib colormap name.

  • yticks (bool, default False) – Whether to render y tick labels.

  • label (str, default "Predictedntopography") – Track label.

  • vmin (float) – Color scale limits.

  • vmax (float) – Color scale limits.

  • height (float, default 1.5) – Track height.

  • **heatmap_kw – Extra kwargs forwarded to heatmap_plot.

Returns:

Heatmap plotting callable.

Return type:

callable