vampire.anno.pl.tracksplot

Contents

vampire.anno.pl.tracksplot#

vampire.anno.pl.tracksplot(tracks, region, title='', x_title='Position (bp)', vertical_spacing=0.02, base_width=600, track_name_dx=-0.07, figsize=(None, None), save=None, **kwargs)[source]#

Create a multi-track genomic plot with shared x-axis.

Each track gets its own subplot with independent y-axis, but all tracks share the same x-axis (genomic position). Supported track types include bedgraph, bed, and heatmap.

Parameters:
  • tracks (list) –

    list of track configuration dictionaries. Each dictionary should contain:

    Common fields for all track types:

    • name (str) - Track name displayed on the left side

    • type (str) - Track type, one of “bedgraph”, “bed”, or “heatmap”

    • data (pl.DataFrame | pl.LazyFrame) - Polars DataFrame with track data

    • height (float, optional) - Relative height of the track. Default is 1.0

    • showlegend (bool, optional) - Whether to show the legend. Default is False

    Additional options for “bedgraph” tracks:

    • plot_type (str, optional) - “line”, “bar” or “density”. Default is “line”

    • max_value (float, optional) - Maximum value. Default is the maximum in the data

    • min_value (float, optional) - Minimum value. Default is the minimum in the data

    • linewidth (float, optional) - Line width. Default is 1

    • color (str, optional) - Line or bar color. Default is “#212529”

    • colorscale (list[str] or list[tuple[float, str]], optional) - Colorscale for density plot

    Additional options for “bed” tracks:

    • stranded (bool, optional) - Whether to show stranded arrows. Default is False

    • arrowhead_length (float, optional) - Arrowhead length compared with the region length for stranded arrows. Default is 0.03

    • color (str, optional) - color. Default is “#212529”

    • draw_baseline (bool, optional) - When True, draws a thin black horizontal line across the full region before the rectangles, so gaps appear as breaks. Default is False.

    Additional options for “heatmap” tracks:

    • max_value (float, optional) - Maximum value. Default is the maximum in the data

    • min_value (float, optional) - Minimum value. Default is the minimum in the data

    • colorscale (list[str] or list[tuple[float, str]], optional) - Colorscale for heatmap

    • flip_y (bool, optional) - Whether to flip the y-axis. Default is False

  • region (str) – Genomic region in the format “chrom:start-end” (e.g., “chr1:1000-2000”).

  • title (str) – Title of the figure. Default is an empty string.

  • x_title (str) – Title of the x axis. Default is “Position (bp)”.

  • vertical_spacing (float) – Vertical spacing between subplots as a fraction of total height. Default is 0.02.

  • base_width (int) – The plotting width of the whole figure.

  • track_name_dx (float) – Horizontal offset applied to track name position along the x-axis,expressed as a fraction of the total width. Default is -0.07.

  • figsize (tuple[int | None, int | None] | None) – Figure size in pixels. Default is (None, None).

  • save (str | bool | None) – If True or a str, save the figure. A string is appended to the default filename. Infer the filetype if ending on {‘.pdf’, ‘.png’, ‘.svg’}.

  • **kwargs – Additional keyword arguments passed to Plotly update_layout. Used to control figure-level styling (e.g. template, margin, background color, legend settings).

Returns:

A Plotly figure object with all tracks plotted as subplots.

Return type:

Figure

Examples

>>> import vampire as vp
>>> vp.anno.pl.set_default_plotstyle()
>>> tracks = vp.datasets.chm13_cen1_tracks()
>>> vp.anno.pl.tracksplot(
...     tracks,
...     region = "chm13_chr1:121119216-127324115",
...     title = "chm13_chr1:121119216-127324115",
...     vertical_spacing = 0.02,
...     track_name_dx = -0.08,
...     base_width = 400, # optional; adjust figure width to fit within the manual page width
... )