Getting Started
InĀ [1]:
Copied!
# %pip install pymsaviz
# %pip install pymsaviz
1. Simple VisualizationĀ¶
- Create
MsaViz
class instance from MSA file - Plot figure by
plotfig
method
InĀ [2]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("HIGD2A.fa")
mv = MsaViz(msa_file)
fig = mv.plotfig() # If save figure, use savefig method [e.g. mv.savefig("result.png")]
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("HIGD2A.fa")
mv = MsaViz(msa_file)
fig = mv.plotfig() # If save figure, use savefig method [e.g. mv.savefig("result.png")]
- Wrap style MSA visualization (
wrap_length=60
) - Change color scheme (
color_scheme='Flower'
)
InĀ [3]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("HIGD2A.fa")
mv = MsaViz(msa_file, wrap_length=60, color_scheme="Flower", show_count=True)
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("HIGD2A.fa")
mv = MsaViz(msa_file, wrap_length=60, color_scheme="Flower", show_count=True)
fig = mv.plotfig()
- Show grid (
show_grid=True
) - Show consensus sequence & identity bar (
show_consensus=True
)
InĀ [4]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, wrap_length=60, show_grid=True, show_consensus=True)
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, wrap_length=60, show_grid=True, show_consensus=True)
fig = mv.plotfig()
- Limit MSA visualization start-end range (
start=100, end=160
) - No display MSA characters (
show_seq_char=False
)
InĀ [5]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160, show_seq_char=False, show_consensus=True, consensus_color="tomato")
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160, show_seq_char=False, show_consensus=True, consensus_color="tomato")
fig = mv.plotfig()
2. Customized VisualizationĀ¶
- Set user-defined custom color scheme by
set_custom_color_scheme
method
InĀ [6]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160)
mv.set_custom_color_scheme({"A": "red", "P": "skyblue", "C": "lime", "H": "orange", "L": "pink"})
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160)
mv.set_custom_color_scheme({"A": "red", "P": "skyblue", "C": "lime", "H": "orange", "L": "pink"})
fig = mv.plotfig()
- Set user-defined custom color handle function by
set_custom_color_func
method
InĀ [7]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
from Bio.Align import MultipleSeqAlignment
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160, show_grid=True)
def custom_color_func(
row_pos: int, col_pos: int, seq_char: str, msa: MultipleSeqAlignment
):
# Note: Both `row_pos` and `col_pos` are 0-index starts
if col_pos < 115 and seq_char != "-":
return "salmon"
if 115 <= col_pos < 130:
if seq_char in ("A", "V", "P"):
return "skyblue"
else:
return "lightyellow"
if 130 <= col_pos < 145:
if 1 <= row_pos <= 4:
return "lime"
else:
return "white"
# Use default color setting in other column (145 <= col_pos < 160)
return None
mv.set_custom_color_func(custom_color_func)
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
from Bio.Align import MultipleSeqAlignment
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160, show_grid=True)
def custom_color_func(
row_pos: int, col_pos: int, seq_char: str, msa: MultipleSeqAlignment
):
# Note: Both `row_pos` and `col_pos` are 0-index starts
if col_pos < 115 and seq_char != "-":
return "salmon"
if 115 <= col_pos < 130:
if seq_char in ("A", "V", "P"):
return "skyblue"
else:
return "lightyellow"
if 130 <= col_pos < 145:
if 1 <= row_pos <= 4:
return "lime"
else:
return "white"
# Use default color setting in other column (145 <= col_pos < 160)
return None
mv.set_custom_color_func(custom_color_func)
fig = mv.plotfig()
- Set user-defined highlight position by
set_highlight_pos
method
InĀ [8]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, wrap_length=60)
mv.set_highlight_pos([10, 20, 30, (40, 120), (150, 200), 220, 270])
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, wrap_length=60)
mv.set_highlight_pos([10, 20, 30, (40, 120), (150, 200), 220, 270])
fig = mv.plotfig()
- Set highlight position by consensus identity threshold using
set_highlight_pos_by_identity_thr
method
InĀ [9]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160, show_consensus=True)
# Only highlight 0 - 80 [%] consensus identity positions
mv.set_highlight_pos_by_ident_thr(min_thr=0, max_thr=80)
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100, end=160, show_consensus=True)
# Only highlight 0 - 80 [%] consensus identity positions
mv.set_highlight_pos_by_ident_thr(min_thr=0, max_thr=80)
fig = mv.plotfig()
- Add markers by
add_markers
method - Add text annotation by
add_text_annotation
method
InĀ [10]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=1, end=180, wrap_length=60, show_consensus=True)
# Extract MSA positions less than 50% consensus identity
pos_ident_less_than_50 = []
ident_list = mv._get_consensus_identity_list()
for pos, ident in enumerate(ident_list, 1):
if ident <= 50:
pos_ident_less_than_50.append(pos)
# Add markers
mv.add_markers([1])
mv.add_markers([10, 20], color="orange", marker="o")
mv.add_markers([30, (40, 50), 55], color="green", marker="+")
mv.add_markers(pos_ident_less_than_50, marker="x", color="blue")
# Add text annotations
mv.add_text_annotation((76, 102), "Gap Region", text_color="red", range_color="red")
mv.add_text_annotation((112, 123), "Gap Region", text_color="green", range_color="green")
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=1, end=180, wrap_length=60, show_consensus=True)
# Extract MSA positions less than 50% consensus identity
pos_ident_less_than_50 = []
ident_list = mv._get_consensus_identity_list()
for pos, ident in enumerate(ident_list, 1):
if ident <= 50:
pos_ident_less_than_50.append(pos)
# Add markers
mv.add_markers([1])
mv.add_markers([10, 20], color="orange", marker="o")
mv.add_markers([30, (40, 50), 55], color="green", marker="+")
mv.add_markers(pos_ident_less_than_50, marker="x", color="blue")
# Add text annotations
mv.add_text_annotation((76, 102), "Gap Region", text_color="red", range_color="red")
mv.add_text_annotation((112, 123), "Gap Region", text_color="green", range_color="green")
fig = mv.plotfig()
- Marker list (https://matplotlib.org/stable/api/markers_api.html)
InĀ [11]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, end=60, show_grid=True)
# Add various type markers
markers = [".", ",", "o", "v", "^", "<", ">", "1", "2", "3", "4", "8", "s", "p", "*", "h", "H", "+", "x", "D", "d", "|", "_"]
colors = ["red", "blue", "green", "chocolate", "magenta"]
for idx, marker in enumerate(markers, 1):
color = colors[idx % len(colors)]
mv.add_markers([idx * 2], marker=marker, color=color, size=8)
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, end=60, show_grid=True)
# Add various type markers
markers = [".", ",", "o", "v", "^", "<", ">", "1", "2", "3", "4", "8", "s", "p", "*", "h", "H", "+", "x", "D", "d", "|", "_"]
colors = ["red", "blue", "green", "chocolate", "magenta"]
for idx, marker in enumerate(markers, 1):
color = colors[idx % len(colors)]
mv.add_markers([idx * 2], marker=marker, color=color, size=8)
fig = mv.plotfig()
Change detail plot parameters by set_plot_params
method
ticks_interval=5
(Default: 10)x_unit_size=0.20
(Default: 0.14)grid_color="black"
(Default: "lightgrey")identity_color="tomato"
(Default: "#A3A5FF")
InĀ [12]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100 ,end=140, show_grid=True, show_count=True, color_scheme="Identity")
mv.set_plot_params(ticks_interval=5, x_unit_size=0.20, grid_color="black", identity_color="tomato")
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, start=100 ,end=140, show_grid=True, show_count=True, color_scheme="Identity")
mv.set_plot_params(ticks_interval=5, x_unit_size=0.20, grid_color="black", identity_color="tomato")
fig = mv.plotfig()
Color block MSA display
InĀ [13]:
Copied!
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, color_scheme="Clustal", show_seq_char=False, show_count=True, sort=True, show_consensus=True, consensus_color="grey")
mv.set_plot_params(ticks_interval=50, x_unit_size=0.04, show_consensus_char=False)
fig = mv.plotfig()
from pymsaviz import MsaViz, get_msa_testdata
msa_file = get_msa_testdata("MRGPRG.fa")
mv = MsaViz(msa_file, color_scheme="Clustal", show_seq_char=False, show_count=True, sort=True, show_consensus=True, consensus_color="grey")
mv.set_plot_params(ticks_interval=50, x_unit_size=0.04, show_consensus_char=False)
fig = mv.plotfig()