Skip to content

GenomeViz Class

GenomeViz

GenomeViz(
    *,
    fig_width: float = 15,
    fig_track_height: float = 1.0,
    track_align_type: TrackAlignType = "left",
    feature_track_ratio: float = 0.25,
    link_track_ratio: float = 1.0,
    theme: Theme = "light",
    show_axis: bool = False
)

Genome Visualization Class

PARAMETER DESCRIPTION
fig_width

Figure width

TYPE: float DEFAULT: 15

fig_track_height

Figure height = fig_track_height * track number

TYPE: float DEFAULT: 1.0

track_align_type

Figure track alignment type (left|center|right)

TYPE: TrackAlignType DEFAULT: 'left'

feature_track_ratio

Feature track size ratio

TYPE: float DEFAULT: 0.25

link_track_ratio

Link track size ratio

TYPE: float DEFAULT: 1.0

theme

light: white background + black text, edge dark: black background + white text, edge

TYPE: Theme DEFAULT: 'light'

show_axis

Show axis for debug purpose

TYPE: bool DEFAULT: False

figsize property

figsize: tuple[float, float]

Figure size (Width, Height)

feature_tracks property

feature_tracks: list[FeatureTrack]

Feature tracks

link_tracks: list[LinkTrack]

Link tracks

get_tracks

get_tracks(*, subtrack: bool = True) -> list[Track]

Get tracks

PARAMETER DESCRIPTION
subtrack

If True, include subtracks in FeatureTrack

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
tracks

Tracks [FeatureTrack|FeatureSubTrack|LinkTrack]

TYPE: list[Track]

add_feature_track

add_feature_track(
    name: str,
    segments: (
        int
        | tuple[int, int]
        | Sequence[int | tuple[int, int]]
        | Mapping[str, int | tuple[int, int]]
    ),
    *,
    space: float | list[float] = 0.02,
    offset: int | TrackAlignType | None = None,
    labelsize: float = 20,
    labelmargin: float = 0.01,
    align_label: bool = True,
    label_kws: dict[str, Any] | None = None,
    line_kws: dict[str, Any] | None = None
) -> FeatureTrack

Add feature track

Add feature track, and also add link track between feature tracks if other feature tracks already exist.

PARAMETER DESCRIPTION
name

Track name

TYPE: str

segments

Track segments definition. Segment sizes or ranges can be specified.

TYPE: int | tuple[int, int] | Sequence[int | tuple[int, int]] | Mapping[str, int | tuple[int, int]]

space

Space ratio between segments. If float, all spaces are set to the same value. If list[float], each space is set to the corresponding value (list size must be len(segments) - 1)

TYPE: float | list[float] DEFAULT: 0.02

offset

Offset int value or TrackAlignType (left|center|right) If None, offset is defined by GenomeViz track_align_type argument at initialization.

TYPE: int | TrackAlignType | None DEFAULT: None

labelsize

Track label size

TYPE: float DEFAULT: 20

labelmargin

Track label margin

TYPE: float DEFAULT: 0.01

align_label

If True, align track label to the most left position. If False, set track label to first segment start position.

TYPE: bool DEFAULT: True

label_kws

Text properties (e.g. dict(size=25, color="red", ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html

TYPE: dict[str, Any] | None DEFAULT: None

line_kws

Axes.plot properties (e.g. dict(color="grey", lw=0.5, ls="--", ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html

TYPE: dict[str, Any] | None DEFAULT: None

RETURNS DESCRIPTION
feature_track

Feature track

TYPE: FeatureTrack

add_link(
    target1: tuple[str, int, int] | tuple[str, str | None, int, int],
    target2: tuple[str, int, int] | tuple[str, str | None, int, int],
    color: str = "grey",
    inverted_color: str | None = None,
    alpha: float = 0.8,
    v: float | None = None,
    vmin: float = 0,
    vmax: float = 100,
    size: float = 1.0,
    curve: bool = False,
    filter_length: int = 0,
    ignore_outside_range: bool = False,
    v_tooltip: float | None = None,
    **kwargs
) -> None

Add link patch to link track between adjacent feature tracks

PARAMETER DESCRIPTION
target1

Target link1 (track_name, start, end) or (track_name, target_segment, start, end)

TYPE: tuple[str, int, int] | tuple[str, int | str | None, int, int]

target2

Target link2 (track_name, start, end) or (track_name, target_segment, start, end)

TYPE: tuple[str, int, int] | tuple[str, int | str | None, int, int]

color

Link color

TYPE: str DEFAULT: 'grey'

inverted_color

Inverted link color. If None, color is set.

TYPE: str | None DEFAULT: None

alpha

Color transparency

TYPE: float DEFAULT: 0.8

v

Identity value for color interpolation. If None, no color interpolation is done.

TYPE: float | None DEFAULT: None

vmin

Min value for color interpolation

TYPE: float DEFAULT: 0

vmax

Max value for color interpolation

TYPE: float DEFAULT: 100

size

Link vertical size ratio for track

TYPE: float DEFAULT: 1.0

curve

If True, bezier curve link is plotted

TYPE: bool DEFAULT: False

filter_length

If link length is shorter than filter_length, ignore it.

TYPE: int DEFAULT: 0

ignore_outside_range

If True and the link position is outside the range of the target track, ignore it without raising an error.

TYPE: bool DEFAULT: False

v_tooltip

Identity value for only tooltip display. If no color interpolation is required, use this option instead of v.

TYPE: float | None DEFAULT: None

**kwargs

Patch properties (e.g. ec="black", lw=0.5, hatch="//", ...) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

DEFAULT: {}

set_scale_bar

set_scale_bar(
    *,
    ymargin: float = 1.0,
    labelsize: float = 15,
    scale_size_label: tuple[int, str] | None = None
) -> None

Set scale bar

PARAMETER DESCRIPTION
ymargin

Scale bar y margin

TYPE: float DEFAULT: 1.0

labelsize

Label size

TYPE: float DEFAULT: 15

scale_size_label

Scale bar size & label tuple (e.g. (1000, "1.0 kb")) If None, scale bar size & label are automatically set.

TYPE: tuple[int, str] | None DEFAULT: None

set_scale_xticks

set_scale_xticks(
    *,
    ymargin: float = 1.0,
    labelsize: float = 15,
    start: int = 0,
    unit: Unit | None = None
) -> None

Set scale xticks

PARAMETER DESCRIPTION
ymargin

X ticks y margin

TYPE: float DEFAULT: 1.0

labelsize

Label size

TYPE: float DEFAULT: 15

start

X ticks start position

TYPE: int DEFAULT: 0

unit

Display unit (Gb|Mb|Kb|bp)

TYPE: Unit | None DEFAULT: None

set_colorbar

set_colorbar(
    colors: list[str] | None = None,
    *,
    alpha: float = 0.8,
    vmin: float = 0,
    vmax: float = 100,
    bar_height: float = 0.2,
    bar_width: float = 0.01,
    bar_left: float = 1.02,
    bar_bottom: float = 0,
    bar_label: str = "",
    bar_labelsize: float = 15,
    tick_labelsize: float = 10
) -> None

Set colorbar

PARAMETER DESCRIPTION
colors

Colors for bar

TYPE: list[str] | None DEFAULT: None

alpha

Color transparency

TYPE: float DEFAULT: 0.8

vmin

Colorbar min value

TYPE: float DEFAULT: 0

vmax

Colorbar max value

TYPE: float DEFAULT: 100

bar_height

Colorbar height ratio

TYPE: float DEFAULT: 0.2

bar_width

Colorbar width ratio

TYPE: float DEFAULT: 0.01

bar_left

Colorbar left position

TYPE: float DEFAULT: 1.02

bar_bottom

Colorbar bottom position

TYPE: float DEFAULT: 0

bar_label

Colorbar label

TYPE: str DEFAULT: ''

bar_labelsize

Colorbar label size

TYPE: float DEFAULT: 15

tick_labelsize

Colorbar tick label size

TYPE: float DEFAULT: 10

plotfig

plotfig(*, dpi: int = 100, fast_render: bool = True) -> Figure

Plot figure

PARAMETER DESCRIPTION
dpi

DPI

TYPE: int DEFAULT: 100

fast_render

Enable fast rendering mode using PatchCollection. Set fast_render=True by default, and set it to False when used in the savefig_html() method. Fast rendering mode cannot generate tooltips for html display.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
fig

Plot figure result

TYPE: Figure

savefig

savefig(savefile: str | Path, *, dpi: int = 100, pad_inches: float = 0.5) -> None

Save figure to file

PARAMETER DESCRIPTION
savefile

Save file

TYPE: str | Path

dpi

DPI

TYPE: int DEFAULT: 100

pad_inches

Padding inches

TYPE: float DEFAULT: 0.5

Warnings

To plot a figure that settings a user-defined legend, subtracks, or annotations, call fig.savefig() instead of gv.savefig().

savefig_html

savefig_html(
    html_outfile: str | Path | io.StringIO | io.BytesIO, figure: Figure | None = None
) -> None

Save figure in html format

PARAMETER DESCRIPTION
html_outfile

Output HTML file (*.html)

TYPE: str | Path | StringIO | BytesIO

figure

Save HTML viewer file using user customized figure. Set to output figure including user-specified legend, subtracks, etc. Target figure must be generated by gv.plotfig(fast_render=False).

TYPE: Figure | None DEFAULT: None