MSAViewer

class visualife.widget.MSAViewer(element_id, msa_header='', msa=None, **kwargs)

Bases: object

Displays a Multiple Sequence Alignment (MSA)

A basic example of the widget is given below:

It has been created by the following code:

from visualife.widget import MSAViewer

msa = [ {"description" : "Crambin", "sequence": "TTCCPSIVARSNFNVCRLPGTPEALCATYTGCIIIPGATCPGDYAN"},
{"description" : "Thionin", "sequence": "-SCCPTTAARNTYNVCRLPGTPRPVCASLSGCIIISGTRCPPNYPR"},
{"description" : "Viscotoxin", "sequence": "-SCCPNTTGRNIYNTCRFGGGSREVCASLSGCKIISASTCP-SYPD"}]

msa = MSAViewer("show_msa","crambin homologs", msa=msa)
msa.add_to_region("sel1", 1, first_pos=4, last_pos=8)
msa.region_tooltip("sel1","first region")
Parameters:
  • element_id – id of div element where you want to display your MSA
  • msa_header – header text will be display on top of MSA
  • msa – list of dictionaries; each dictionary is another sequence; eg. {“description”:”2gb1”,”sequence”:”AGTPTACAGA”}
Keyword Arguments:
 
  • if_bars (bool) – if True bars will appeare under every part of MSA
  • bars_function (string) – name of a function that bars shows
  • n_columns_of_ten (int) – when the widget displays sequence, it puts a space after every 10 residues; by default there are 50 residues in every line, divided in five 10-residues blocks; say n_columns_of_ten=4 to display only 40 residues per line or to n_columns_of_ten=8 if you like to have 80 residues per line
  • show_blockwise (bool) – if True, a sequence will be displayed in blocks of 10 residues, separated by a space (True by default); otherwise, each row of this widget will be a contiguous line of amino acid or nucleotide symbols

Attributes Summary

msa_header Header line for this MSA
secondary_structure Protein / nucleotide secondary structure - for coloring purposes only

Methods Summary

aa_composition(i_column) Returns amino acid composition of a given column of this alignment.
add_to_region(region_name, which_sequence[, …]) Add a block of amino acids/nucleotides to a sequence region
async_viewer(res)
change_bars(what)
color_background(color_scheme, **kwargs) Color letter background of this MSA
color_sequences(color_scheme, **kwargs) Color letters of this MSA
colors_by_scheme(color_scheme[, which_sequence]) Returns a vector of colors to color this MSA.
hydrophobicity(i_column) Computes average hydrophobicity at a given position for the most probable residue
identity_fraction(i_column) Computes sequence identity fraction at a given position for the most probable residue :param i_column: index of an alignment column (from 0) :return: a two-tuple of the most probable residue code and the fraction of sequences it has been observed in that column
load_msa(msa_as_json[, msa_header, …]) Loads MSA data into this widget.
region_tooltip(region_name, tooltip) Sets a text that will show up in a tooltip
shannon_entropy(i_column) Computes Shannon entropy for a given column of this alignment.

Attributes Documentation

msa_header

Header line for this MSA

Getter:returns the header line displayed by the widget
Setter:sets the new header line string
Type:string
secondary_structure

Protein / nucleotide secondary structure - for coloring purposes only

Getter:returns the secondary structure
Setter:sets secondary structure string for this sequence
Type:string

Methods Documentation

aa_composition(i_column)

Returns amino acid composition of a given column of this alignment.

Parameters:i_column – index of an alignment column (from 0)
Returns:a dictionary with single-letter characters as keys and integer counts as avalues
add_to_region(region_name, which_sequence, if_show_region=True, **kwargs)

Add a block of amino acids/nucleotides to a sequence region

This method calls SequenceViewer.add_to_region() method of an appropriate SequenceViewer panel of this widget. :param region_name: name of this sequence region :param which_sequence: (integer) index of a sequence to mark a region; use 0 (the default)

to mark a region on all sequences shown by this widget
Parameters:
async_viewer(res)
change_bars(what)
color_background(color_scheme, **kwargs)

Color letter background of this MSA

Parameters:
  • color_scheme

    either a color scheme name or a list of colors separately for each sequence: - (string) – a color scheme name the available color schemes are listed in colors_by_scheme()

    method documentation
    • (list[float]) – list of values to be converted to colors with a given palette; the same color will be used for a given column
    • (list[list[float]]) – list of values to be converted to colors with a given palette
    • (list[list[string]]) – list of colors to be used directly to color this MSA
  • kwargs – see below
Keyword Arguments:
 
  • palette_name (string) – name of a color palette used to convert values into colors
  • neutral_color (string) – a color to be used when no color can be assigned; white is used by default
color_sequences(color_scheme, **kwargs)

Color letters of this MSA

Parameters:
  • color_scheme

    either a color scheme name or a list of colors separately for each sequence: - (string) – a color scheme name the available color schemes are listed in colors_by_scheme()

    method documentation
    • (list[list[float]]) – list of values to be converted to colors with a given palette
    • (list[list[string]]) – list of colors to be used directly to color this MSA
  • kwargs – see below
Keyword Arguments:
 
  • palette_name (string) – name of a color palette used to convert values into colors
  • neutral_color (string) – a color to be used when no color can be assigned; black is used by default
colors_by_scheme(color_scheme, which_sequence=0, **kwargs)

Returns a vector of colors to color this MSA.

This method calculates color schemes based on MSA composition rather than on a single amino acid type. To color residues by chemical type, use method from SequenceViewer class

Parameters:
  • color_scheme – a color scheme name; known schemes are listed below
  • which_sequence – a sequence to be used as a reference;
  • kwargs – see below
Known color schemes:
 
  • secondary – color by secondary structure which must be provided by a secondary_structure() setter
  • identity – color scale based on the sequence identity (conservation) of a given MSA column
  • entropy – color scale based on the Shanon entropy of a given MSA column
  • hydrophobicity – color scale based on the average hydrophobicity of a given MSA column
  • mutations – color amino acids that are very unlikely in a given MSA column
Keyword Arguments:
 
  • palette_name (string) – name of a color palette used to convert values into colors
  • neutral_color (string) – a color to be used when no color can be assigned; a typical choice is "black" to color letters and "white" for background
Returns:

list[str] list of n_res colors, where n_res is the length of the selected sequence if a given color_scheme is incorrect, an emtpy list is returned

hydrophobicity(i_column)

Computes average hydrophobicity at a given position for the most probable residue

Parameters:i_column – index of an alignment column (from 0)
Returns:average hydrophobicity according to Kyte & Doolittle scale
identity_fraction(i_column)

Computes sequence identity fraction at a given position for the most probable residue :param i_column: index of an alignment column (from 0) :return: a two-tuple of the most probable residue code and the fraction of sequences it has been observed

in that column
load_msa(msa_as_json, msa_header='', fix_terminal_gaps=True, **kwargs)

Loads MSA data into this widget.

Input sequences should be provided in JSON data structure, see read_fasta() method for details :param msa_as_json: input sequences :param msa_header: a string displayed at the top of the MSA widget to describe it

region_tooltip(region_name, tooltip)

Sets a text that will show up in a tooltip

The given text will be displayed in a tooltip box when a user hoovers the given sequence region with a mouse pointer. Use empty string to clear a tooltip

Parameters:
  • region_name – name of a sequence region that needs a tooltip
  • tooltip – tooltip text
shannon_entropy(i_column)

Computes Shannon entropy for a given column of this alignment.

Parameters:i_column – index of an alignment column (from 0)
Returns:information entropy value in the range of [0,1]