Skip to content

FeatureTrack Class

FeatureTrack

FeatureTrack(
    name: str,
    seg_name2range: Mapping[str, tuple[int, int]],
    *,
    ratio: float = 1.0,
    space: float | list[float] = 0.01,
    offset: int | TrackAlignType = "left",
    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
)

Bases: Track

Feature Track Class

PARAMETER DESCRIPTION
name

Track name

TYPE: str

seg_name2range

Segment name & range dict

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

ratio

Track size ratio

TYPE: float DEFAULT: 1.0

space

Space ratio between segments

TYPE: float | list[float] DEFAULT: 0.01

offset

Offset int value or TrackAlignType (left|center|right)

TYPE: int | TrackAlignType DEFAULT: 'left'

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

label property

label: str

Track label (By default, track.label = track.name)

offset property

offset: int

Track offset

segments property

segments: list[FeatureSegment]

Segments

subtracks property

subtracks: list[FeatureSubTrack]

Subtracks

total_seg_size property

total_seg_size: int

Total segment size

spaces property

spaces: list[int]

Spaces between segments

max_track_total_seg_size property

max_track_total_seg_size: int

Max track total segment size (Use space calculation)

plot_size property

plot_size: int

Plot x size (total_seg_size + sum(spaces))

set_max_track_total_seg_size

set_max_track_total_seg_size(max_track_total_seg_size: int) -> None

Set max track total segment size

This method is expected to be called within the GenomeViz instance to update track status. General users should not use this method.

PARAMETER DESCRIPTION
max_track_total_seg_size

Max track total segment size

TYPE: int

set_label

set_label(label: str) -> None

Set track label (By default, track.label = track.name)

PARAMETER DESCRIPTION
label

Track label

TYPE: str

set_segment_sep

set_segment_sep(
    sep: bool | list[bool] = True,
    *,
    symbol: str = "//",
    size: float = 20,
    color: str = "grey",
    **kwargs
) -> None

Set segment separator symbol text

PARAMETER DESCRIPTION
sep

If True, insert separator text between all segments. If list[bool], insert separator text between segments where True.

TYPE: bool | list[bool] DEFAULT: True

symbol

Separator symbol text

TYPE: str DEFAULT: '//'

size

Separator symbol size

TYPE: float DEFAULT: 20

color

Separator symbol color

TYPE: str DEFAULT: 'grey'

**kwargs

TYPE: dict DEFAULT: {}

add_subtrack

add_subtrack(
    name: str | None = None, *, ratio: float = 1.0, ylim: tuple[int, int] = (0, 100)
) -> FeatureSubTrack

Add subtrack for user-defined plot axes

PARAMETER DESCRIPTION
name

Track name

TYPE: str DEFAULT: None

ratio

Subtrack size ratio to feature track

TYPE: float DEFAULT: 1.0

ylim

Axes ylim

TYPE: tuple[int, int] DEFAULT: (0, 100)

RETURNS DESCRIPTION
subtrack

Subtrack

TYPE: FeatureSubTrack

get_subtrack

get_subtrack(name: str | None = None) -> FeatureSubTrack

Get subtrack by name

If no subtrack found, raise error.

PARAMETER DESCRIPTION
name

Target subtrack name. If None, first subtrack is returned.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
subtrack

Target subtrack

TYPE: FeatureSubTrack

get_segment

get_segment(name: str | None = None) -> FeatureSegment

Get segment by name

PARAMETER DESCRIPTION
name

Target segment name. If None, first segment is returned.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
segment

Target segment

TYPE: FeatureSegment

add_text

add_text(
    x: float,
    text: str,
    *,
    target_seg: str | None = None,
    size: float = 15,
    vpos: VPos = "top",
    hpos: HPos = "left",
    ymargin: float = 0.2,
    rotation: float = 45,
    **kwargs
) -> None

Add text to track segment

PARAMETER DESCRIPTION
x

Text x coordinate

TYPE: float

text

Text content

TYPE: str

target_seg

Target segment name. If None, first segment is selected.

TYPE: str | None DEFAULT: None

size

Text size

TYPE: float DEFAULT: 15

vpos

Vertical position (top|center|bottom)

TYPE: str DEFAULT: 'top'

hpos

Horizontal position (left|center|right)

TYPE: str DEFAULT: 'left'

ymargin

Y margin

TYPE: float DEFAULT: 0.2

rotation

Text rotation

TYPE: float DEFAULT: 45

**kwargs

segment.add_text() method keyword arguments (e.g. color="red", ...)

TYPE: dict DEFAULT: {}

add_sublabel

add_sublabel(
    text: str | None = None,
    *,
    target_seg: str | None = None,
    size: float = 12,
    pos: str = "bottom-left",
    ymargin: float = 0.2,
    rotation: float = 0,
    **kwargs
) -> None

Add sublabel to corners of the track segment

PARAMETER DESCRIPTION
text

Text content

TYPE: str | None DEFAULT: None

target_seg

Target segment name. If None, first segment is selected.

TYPE: str | None DEFAULT: None

size

Text size

TYPE: float DEFAULT: 12

pos

Label position ([top|bottom]-[left|center|right])

TYPE: str DEFAULT: 'bottom-left'

ymargin

Y margin

TYPE: float DEFAULT: 0.2

rotation

Text rotation

TYPE: float DEFAULT: 0

**kwargs

segment.add_text() method keyword arguments (e.g. color="red", ...)

TYPE: dict DEFAULT: {}

add_feature

add_feature(
    start: int,
    end: int,
    strand: int = 1,
    *,
    target_seg: str | None = None,
    plotstyle: PlotStyle = "arrow",
    arrow_shaft_ratio: float = 0.5,
    extra_tooltip: dict[str, str] | None = None,
    label: str = "",
    text_kws: dict[str, Any] | None = None,
    **kwargs
) -> None

Add feature

PARAMETER DESCRIPTION
start

Start position

TYPE: int

end

End position

TYPE: int

strand

Feature strand

TYPE: int DEFAULT: 1

target_seg

Target segment name. If None, first segment is selected.

TYPE: str | None DEFAULT: None

plotstyle

Feature plot style (bigarrow|arrow|bigbox|box|bigrbox|rbox)

TYPE: PlotStyle DEFAULT: 'arrow'

arrow_shaft_ratio

Arrow shaft size ratio

TYPE: float DEFAULT: 0.5

extra_tooltip

Extra tooltip dict for html figure

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

label

Feature label

TYPE: str DEFAULT: ''

text_kws

segment.add_text() method keyword arguments (e.g. dict(size=12, color="red", ...))

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

**kwargs

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

TYPE: dict DEFAULT: {}

add_features

add_features(
    features: SeqFeature | list[SeqFeature],
    *,
    target_seg: str | None = None,
    plotstyle: PlotStyle = "arrow",
    arrow_shaft_ratio: float = 0.5,
    label_type: str | None = None,
    label_handler: Callable[[str], str] | None = None,
    extra_tooltip: dict[str, str] | None = None,
    ignore_outside_range: bool = False,
    text_kws: dict[str, Any] | None = None,
    **kwargs
) -> None

Add features (BioPython SeqFeature)

PARAMETER DESCRIPTION
features

BioPython SeqFeature or SeqFeature list

TYPE: SeqFeature | list[SeqFeature]

target_seg

Target segment name. If None, first segment is selected.

TYPE: str | None DEFAULT: None

plotstyle

Feature plot style (bigarrow|arrow|bigbox|box|bigrbox|rbox)

TYPE: PlotStyle DEFAULT: 'arrow'

arrow_shaft_ratio

Arrow shaft size ratio

TYPE: float DEFAULT: 0.5

label_type

Label type (e.g. gene,protein_id,product,etc...)

TYPE: str | None DEFAULT: None

label_handler

Label handler function to customize label display. If None, set label handler to exclude labels containing hypothetical.

TYPE: Callable[[str], str] | None DEFAULT: None

extra_tooltip

Extra tooltip dict for html figure

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

ignore_outside_range

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

TYPE: bool DEFAULT: False

text_kws

segment.add_text() method keyword arguments (e.g. dict(size=12, color="red", ...))

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

**kwargs

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

TYPE: dict DEFAULT: {}

add_exon_feature

add_exon_feature(
    locs: list[tuple[int, int]],
    strand: int = 1,
    *,
    target_seg: str | None = None,
    plotstyle: PlotStyle = "arrow",
    arrow_shaft_ratio: float = 0.5,
    label: str = "",
    patch_kws: dict[str, Any] | None = None,
    intron_patch_kws: dict[str, Any] | None = None,
    text_kws: dict[str, Any] | None = None
) -> None

Add exon feature

PARAMETER DESCRIPTION
locs

Exon locations (e.g. [(0, 100), (200, 300), (350, 400)])

TYPE: list[tuple[int, int]]

strand

Feature strand

TYPE: int DEFAULT: 1

target_seg

Target segment name. If None, first segment is selected.

TYPE: str | None DEFAULT: None

plotstyle

Feature plot style (bigarrow|arrow|bigbox|box|bigrbox|rbox)

TYPE: PlotStyle DEFAULT: 'arrow'

arrow_shaft_ratio

Arrow shaft size ratio

TYPE: float DEFAULT: 0.5

label

Feature label

TYPE: str DEFAULT: ''

patch_kws

Exon patch properties (e.g. dict(fc="red", lw=0.5, hatch="//", ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

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

intron_patch_kws

Intron patch properties (e.g. dict(color="red", lw=2.0, ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

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

text_kws

segment.add_text() method keyword arguments (e.g. dict(size=12, color="red", ...))

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

add_exon_features

add_exon_features(
    features: SeqFeature | list[SeqFeature],
    *,
    target_seg: str | None = None,
    plotstyle: PlotStyle = "arrow",
    arrow_shaft_ratio: float = 0.5,
    label_type: str | None = None,
    label_handler: Callable[[str], str] | None = None,
    extra_tooltip: dict[str, str] | None = None,
    ignore_outside_range: bool = False,
    patch_kws: dict[str, Any] | None = None,
    intron_patch_kws: dict[str, Any] | None = None,
    text_kws: dict[str, Any] | None = None
) -> None

Add exon features

PARAMETER DESCRIPTION
features

BioPython SeqFeature or SeqFeature list

TYPE: SeqFeature | list[SeqFeature]

target_seg

Target segment name. If None, first segment is selected.

TYPE: str | None DEFAULT: None

plotstyle

Feature plot style (bigarrow|arrow|bigbox|box|bigrbox|rbox)

TYPE: PlotStyle DEFAULT: 'arrow'

arrow_shaft_ratio

Arrow shaft size ratio

TYPE: float DEFAULT: 0.5

label_type

Label type (e.g. gene,protein_id,product, etc...)

TYPE: str | None DEFAULT: None

label_handler

Label handler function to customize label display. If None, set label handler to exclude labels containing hypothetical.

TYPE: Callable[[str], str] | None DEFAULT: None

extra_tooltip

Extra tooltip dict for html figure

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

ignore_outside_range

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

TYPE: bool DEFAULT: False

patch_kws

Exon patch properties (e.g. dict(fc="red", lw=0.5, hatch="//", ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

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

intron_patch_kws

Intron patch properties (e.g. dict(color="red", lw=2.0, ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

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

text_kws

segment.add_text() method keyword arguments (e.g. dict(size=12, color="red", ...))

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

transform_coord

transform_coord(
    x: int | float | NDArray, *, target_seg: str | None = None
) -> int | float | NDArray[np.float64]

Transform segment-level coordinate to track-level coordinate

PARAMETER DESCRIPTION
x

Segment-level coordinate(s)

TYPE: int | float | NDArray

target_seg

Target segment name. If None, first segment is selected.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
transform_x

Track-level coordinate(s)

TYPE: int | float | NDArray[float64]

plot_all

plot_all(fast_render: bool = True) -> None

Plot all objects (Expected to be called in gv.plotfig())

  1. Plot track label
  2. Plot segment lines
  3. Plot segment separator
  4. Plot features
  5. Plot texts
PARAMETER DESCRIPTION
fast_render

Enable fast rendering using PatchCollection plot style.

TYPE: bool DEFAULT: True