Skip to content

MsaViz Class

MsaViz

MsaViz(
    msa: str | Path | MSA,
    *,
    format: str = "fasta",
    color_scheme: str | None = None,
    start: int = 1,
    end: int | None = None,
    wrap_length: int | None = None,
    wrap_space_size: float = 3.0,
    show_label: bool = True,
    label_type: str = "id",
    show_seq_char: bool = True,
    show_grid: bool = False,
    show_count: bool = False,
    show_consensus: bool = False,
    consensus_color: str = "#1f77b4",
    consensus_size: float = 2.0,
    sort: bool = False
)

Multiple Sequence Alignment Visualization

PARAMETER DESCRIPTION
msa

MSA file, URL MSA file, MSA object

TYPE: str | Path | MultipleSeqAlignment

format

Alignment file format (e.g. fasta, phylip, clustal, emboss, etc...)

TYPE: str DEFAULT: 'fasta'

color_scheme

Color scheme. If None, Zappo(AA) or Nucleotide(NT) is set. [Clustal|Zappo|Taylor|Flower|Blossom|Sunset|Ocean| Hydrophobicity|HelixPropensity|StrandPropensity|TurnPropensity| BuriedIndex|Nucleotide|Purine/Pyrimidine|Identity|None]

TYPE: str | None DEFAULT: None

start

Start position of visualization (one-based coordinates)

TYPE: int DEFAULT: 1

end

End position of visualization (one-based coordinates)

TYPE: int | None DEFAULT: None

wrap_length

Wrap sequence length. If None, no wrapping sequence.

TYPE: int | None DEFAULT: None

wrap_space_size

Space size between wrap MSA plot area

TYPE: float DEFAULT: 3.0

show_label

If True, show label

TYPE: bool DEFAULT: True

label_type

Label type (id|description) to be shown when show_label=True. If label_type="id", show omitted id label. If label_type="description", show full description label.

TYPE: str DEFAULT: 'id'

show_seq_char

If True, show sequence character

TYPE: bool DEFAULT: True

show_grid

If True, show grid

TYPE: bool DEFAULT: False

show_count

If True, show seq char count without gap on right side

TYPE: bool DEFAULT: False

show_consensus

If True, show consensus sequence

TYPE: bool DEFAULT: False

consensus_color

Consensus identity bar color

TYPE: str DEFAULT: '#1f77b4'

consensus_size

Consensus identity bar height size

TYPE: float DEFAULT: 2.0

sort

Sort MSA order by NJ tree constructed from MSA distance matrix

TYPE: bool DEFAULT: False

available_color_schemes staticmethod

available_color_schemes() -> list[str]

Get available color schemes

RETURNS DESCRIPTION
color_scheme_names

Available color schemes

TYPE: list[str]

set_plot_params

set_plot_params(
    *,
    ticks_interval: int | None = 10,
    x_unit_size: float = 0.14,
    y_unit_size: float = 0.2,
    grid_color: str = "lightgrey",
    show_consensus_char: bool = True,
    identity_color: str = "#A3A5FF",
    identity_color_min_thr: float = 30
) -> None

Set plot parameters to adjust figure appearence in detail

PARAMETER DESCRIPTION
ticks_interval

Ticks interval. If None, ticks interval is not displayed.

TYPE: int | None DEFAULT: 10

x_unit_size

X-axis unit size of seq char rectangle

TYPE: float DEFAULT: 0.14

y_unit_size

Y-axis unit size of seq char rectangle

TYPE: float DEFAULT: 0.2

grid_color

Grid color

TYPE: str DEFAULT: 'lightgrey'

show_consensus_char

If True, show consensus character

TYPE: bool DEFAULT: True

identity_color

Base color for Identity color scheme

TYPE: str DEFAULT: '#A3A5FF'

identity_color_min_thr

Min identity color threshold for Identity color scheme

TYPE: float DEFAULT: 30

set_custom_color_scheme

set_custom_color_scheme(color_scheme: dict[str, str]) -> None

Set user-defined custom color scheme (Overwrite color scheme setting)

PARAMETER DESCRIPTION
color_scheme

Custom color scheme dict (e.g. {"A": "red", "R": "#F01505", ...})

TYPE: dict[str, str]

set_custom_color_func

set_custom_color_func(custom_color_func: Callable[[int, int, str, MSA], str | None])

Set user-defined custom color func (Overwrite all other color setting)

User can change the color of each residue specified by the row and column position of the MSA.

PARAMETER DESCRIPTION
custom_color_func

Custom color function. Callable[[int, int, str, MSA], str | None] means Callable[[row_pos, col_pos, seq_char, msa], hexcolor | None]

TYPE: Callable[[int, int, str, MultipleSeqAlignment], str | None]

set_highlight_pos

set_highlight_pos(positions: list[tuple[int, int] | int]) -> None

Set user-defined highlight MSA positions

PARAMETER DESCRIPTION
positions

Highlight positions. int and tuple range mixture positions can be specified. (e.g. If [1, 5, (10, 13), 18] is set, 1, 5, 10, 11, 12, 13, 18 positions are highlighted)

TYPE: list[tuple[int, int] | int]

set_highlight_pos_by_ident_thr

set_highlight_pos_by_ident_thr(min_thr: float = 0, max_thr: float = 100) -> None

Set highlight MSA positions by consensus identity threshold

PARAMETER DESCRIPTION
min_thr

Min identity threshold for highlight position selection

TYPE: float DEFAULT: 0

max_thr

Max identity threshold for highlight position selection

TYPE: float DEFAULT: 100

add_markers

add_markers(
    positions: list[tuple[int, int] | int],
    marker: str = "v",
    color: str = "black",
    size: float = 6,
) -> None

Add markers on specified positions

PARAMETER DESCRIPTION
positions

Marker positions. int and tuple range mixture positions can be specified. (e.g. If [1, 5, (10, 13), 18] is set, markers are plotted on 1, 5, 10, 11, 12, 13, 18 positions)

TYPE: list[tuple[int, int] | int]

marker

Marker type of matplotlib. See https://matplotlib.org/stable/api/markers_api.html for details.

TYPE: str DEFAULT: 'v'

color

Marker color

TYPE: str DEFAULT: 'black'

size

Marker size

TYPE: float DEFAULT: 6

add_text_annotation

add_text_annotation(
    range: tuple[int, int],
    text: str,
    *,
    text_color: str = "black",
    text_size: float = 10,
    range_color: str = "black"
) -> None

Add text annotation in specified range

PARAMETER DESCRIPTION
range

Annotation start-end range tuple

TYPE: tuple[int, int]

text

Annotation text

TYPE: str

text_color

Text color

TYPE: str DEFAULT: 'black'

text_size

Text size

TYPE: float DEFAULT: 10

range_color

Annotation range line color

TYPE: str DEFAULT: 'black'

plotfig

plotfig(dpi: int = 100) -> Figure

Plot figure

PARAMETER DESCRIPTION
dpi

Figure DPI

TYPE: int DEFAULT: 100

RETURNS DESCRIPTION
fig

Figure

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