### Install PyMSAView with pip Source: https://moshi4.github.io/pyMSAviz/getting_started Installs the PyMSAView library using pip. This is the first step before using any of its functionalities. Ensure you have pip installed and updated. ```bash # %pip install pymsaviz ``` -------------------------------- ### Basic MSA Visualization with PyMSAView Source: https://moshi4.github.io/pyMSAviz/getting_started Demonstrates the basic usage of PyMSAView to create a visualization from an MSA file. It involves creating an MsaViz instance and calling the plotfig method. The example uses a test MSA file obtained via get_msa_testdata. ```python 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")] ``` -------------------------------- ### MSA Visualization with Range Limit and Character Hiding Source: https://moshi4.github.io/pyMSAviz/getting_started Demonstrates how to limit the displayed range of the MSA and hide the sequence characters. This example uses the 'start', 'end', and 'show_seq_char' parameters in the MsaViz constructor. ```python 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() ``` -------------------------------- ### Customizing MSA Visualization: Wrap Length and Color Scheme Source: https://moshi4.github.io/pyMSAviz/getting_started Shows how to customize the MSA visualization by setting the wrap length and changing the color scheme. This example utilizes the MsaViz class with specific parameters for 'wrap_length' and 'color_scheme'. ```python 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() ``` -------------------------------- ### MSA Visualization with Grid and Consensus Sequence Source: https://moshi4.github.io/pyMSAviz/getting_started Illustrates how to display a grid and the consensus sequence along with identity bars in the MSA visualization. The MsaViz class is used with 'show_grid' and 'show_consensus' set to True. ```python 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() ``` -------------------------------- ### Add Markers and Annotations in pymsaviz Source: https://moshi4.github.io/pyMSAviz/getting_started This code demonstrates adding markers to specific positions and adding text annotations. It uses extracted data to dynamically add markers based on consensus identity threshold. ```Python 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") ``` -------------------------------- ### Color Block MSA Display with Customizations (Python) Source: https://moshi4.github.io/pyMSAviz/getting_started Demonstrates how to create a color-blocked MSA display with specific coloring schemes and layout adjustments. It uses the `MsaViz` constructor with parameters like `color_scheme`, `show_seq_char`, `show_count`, `sort`, and `show_consensus`. Additionally, `set_plot_params` is used to fine-tune the display, such as tick intervals and consensus character visibility. ```python 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() ``` -------------------------------- ### Set Highlight Positions in pymsaviz Source: https://moshi4.github.io/pyMSAviz/getting_started This code snippet demonstrates how to highlight specific positions in the multiple sequence alignment using the `set_highlight_pos` method. The positions to be highlighted are specified as a list of integers and tuples. ```Python 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() ``` -------------------------------- ### Highlight by Identity Threshold in pymsaviz Source: https://moshi4.github.io/pyMSAviz/getting_started This code snippet shows how to highlight positions based on consensus identity using `set_highlight_pos_by_ident_thr`. It highlights positions based on a minimum and maximum threshold. ```Python 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() ``` -------------------------------- ### Visualize MSA with Different Color Schemes in pyMSAviz Source: https://moshi4.github.io/pyMSAviz/color_schemes This example demonstrates how to apply various color schemes to an MSA visualization using pyMSAviz. It first fetches a test MSA file, then iterates through all available color schemes, creating a plot for each. The `MsaViz` class is used for plotting, and `matplotlib` is implicitly used for figure manipulation. ```python from pymsaviz import MsaViz, get_msa_testdata msa_file = get_msa_testdata("MRGPRG.fa") for color_scheme in MsaViz.available_color_schemes(): mv = MsaViz(msa_file, start=100, end=160, color_scheme=color_scheme, show_label=False) fig = mv.plotfig() fig.suptitle(f"Color Scheme = {color_scheme}", x=0.5, y=1.15, va="bottom", size=15) ``` -------------------------------- ### Add Various Markers to MSA Visualization (Python) Source: https://moshi4.github.io/pyMSAviz/getting_started Illustrates how to add a variety of marker types and colors to an MSA visualization using the `add_markers` method. It iterates through a predefined list of markers and colors, applying them to different positions in the alignment. This is useful for visually distinguishing specific sites or sequences. ```python 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() ``` -------------------------------- ### Get Available Color Schemes Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Retrieves a list of all available color scheme names that can be used with the MsaViz visualization. This function is a static method of the MsaViz class and does not require an instance. ```python available_color_schemes() -> list[str] ``` -------------------------------- ### Customize MSA Plot Parameters (Python) Source: https://moshi4.github.io/pyMSAviz/getting_started Shows how to customize various plotting parameters for an MSA visualization using the `set_plot_params` method. This includes adjusting tick intervals, unit sizes, grid colors, and identity colors. Customization allows for tailoring the visualization to specific analytical needs. ```python 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() ``` -------------------------------- ### Set Custom Color Scheme in pymsaviz Source: https://moshi4.github.io/pyMSAviz/getting_started This code snippet demonstrates how to set a custom color scheme for the visualization of a multiple sequence alignment. It uses the `set_custom_color_scheme` method to define colors for specific amino acids. ```Python 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() ``` -------------------------------- ### Add Text Annotations to MSA Visualization (Python) Source: https://moshi4.github.io/pyMSAviz/getting_started Demonstrates how to add text annotations to specific regions of an MSA visualization. It utilizes the `add_text_annotation` method from the `MsaViz` class, allowing customization of text and range colors. This function is useful for highlighting specific features or regions within the alignment. ```python 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) # 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() ``` -------------------------------- ### Set Highlight Positions in MSA Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Configures specific positions within an MSA to be highlighted. It supports a mixed input of individual integer positions and tuple-based ranges. For example, providing `[1, 5, (10, 13), 18]` will highlight positions 1, 5, 10, 11, 12, 13, and 18. ```python def set_highlight_pos(positions: list[tuple[int, int] | int]) -> None: """Set user-defined highlight MSA positions""" pass ``` -------------------------------- ### Set Custom Color Function in pymsaviz Source: https://moshi4.github.io/pyMSAviz/getting_started This code snippet demonstrates how to use a custom color function in pymsaviz to define complex color mappings based on sequence position and characters. It utilizes the `set_custom_color_func` method to apply a user-defined function for color assignment. ```Python 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() ``` -------------------------------- ### Add Text Annotation to MSA Range Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Enables the addition of text annotations within a defined range in the MSA. Users can specify the annotation text, its color and size, as well as the color of the range indicator line. The range is defined by a start and end tuple. ```python def 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""" pass ``` -------------------------------- ### Initialize MsaViz Object Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Constructs an MsaViz object for visualizing a Multiple Sequence Alignment. It accepts the MSA data, format, and numerous optional parameters to control the appearance and content of the visualization, such as color schemes, sequence wrapping, and display of labels or consensus sequences. ```python 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 ) ``` -------------------------------- ### List Available Color Schemes in pyMSAviz Source: https://moshi4.github.io/pyMSAviz/color_schemes This snippet shows how to retrieve a list of all supported color schemes within the pyMSAviz library. It utilizes the `MsaViz.available_color_schemes()` static method. No external dependencies beyond the pyMSAviz library are required. ```python from pymsaviz import MsaViz print(MsaViz.available_color_schemes()) ``` -------------------------------- ### set_highlight_pos Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Sets user-defined highlight positions in the MSA. Supports individual integer positions and ranges specified as tuples. ```APIDOC ## set_highlight_pos ### Description Sets user-defined highlight MSA positions. Supports individual integer positions and ranges specified as tuples. ### Method POST ### Endpoint /websites/moshi4_github_io_pymsaviz/set_highlight_pos ### Parameters #### Request Body - **positions** (list[tuple[int, int] | int]) - Required - Highlight positions. Can be a mixture of integers and tuple ranges (e.g., `[1, 5, (10, 13), 18]`). ### Request Example ```json { "positions": [1, 5, [10, 13], 18] } ``` ### Response #### Success Response (200) - **status** (string) - Operation status message. #### Response Example ```json { "status": "Highlight positions set successfully." } ``` ``` -------------------------------- ### Set Plot Parameters Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Configures global plotting parameters for MsaViz visualizations to fine-tune the appearance of the generated plots. This includes adjustments for tick intervals, unit sizes, grid color, and specific settings for consensus sequences and identity coloring. ```python 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 Highlight Positions by Identity Threshold Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Highlights MSA positions based on a consensus identity threshold. Users can specify a minimum and maximum threshold to control which positions are selected for highlighting. The default range covers all possible identities (0 to 100). ```python def set_highlight_pos_by_ident_thr(min_thr: float = 0, max_thr: float = 100) -> None: """Set highlight MSA positions by consensus identity threshold""" pass ``` -------------------------------- ### set_highlight_pos_by_ident_thr Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Sets highlight positions in the MSA based on a consensus identity threshold. Allows specifying minimum and maximum thresholds. ```APIDOC ## set_highlight_pos_by_ident_thr ### Description Sets highlight MSA positions by consensus identity threshold. Allows specifying minimum and maximum thresholds. ### Method POST ### Endpoint /websites/moshi4_github_io_pymsaviz/set_highlight_pos_by_ident_thr ### Parameters #### Request Body - **min_thr** (float) - Optional - Minimum identity threshold for highlight position selection. Defaults to 0. - **max_thr** (float) - Optional - Maximum identity threshold for highlight position selection. Defaults to 100. ### Request Example ```json { "min_thr": 0.7, "max_thr": 0.9 } ``` ### Response #### Success Response (200) - **status** (string) - Operation status message. #### Response Example ```json { "status": "Highlight positions set by identity threshold successfully." } ``` ``` -------------------------------- ### plotfig Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Generates and returns the MSA plot figure. Allows specifying the DPI for the figure resolution. ```APIDOC ## plotfig ### Description Plots the MSA figure. Allows specifying the DPI for the figure resolution. ### Method GET ### Endpoint /websites/moshi4_github_io_pymsaviz/plotfig ### Parameters #### Query Parameters - **dpi** (int) - Optional - Figure DPI. Defaults to 100. ### Request Example ``` GET /websites/moshi4_github_io_pymsaviz/plotfig?dpi=150 ``` ### Response #### Success Response (200) - **fig** (Figure) - The generated Matplotlib Figure object representing the MSA plot. #### Response Example ```json { "fig": "" } ``` ``` -------------------------------- ### Save MSA Figure to File Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Saves the generated MSA figure to a specified file. Options include setting the DPI for resolution and adjusting padding around the figure. It supports saving to string paths or Path objects. ```python from pathlib import Path def savefig(savefile: str | Path, dpi: int = 100, pad_inches: float = 0.5) -> None: """Save figure to file""" pass ``` -------------------------------- ### add_markers Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Adds markers to specified positions in the MSA plot. Customizable marker type, color, and size. ```APIDOC ## add_markers ### Description Adds markers on specified positions in the MSA plot. Customizable marker type, color, and size. ### Method POST ### Endpoint /websites/moshi4_github_io_pymsaviz/add_markers ### Parameters #### Request Body - **positions** (list[tuple[int, int] | int]) - Required - Marker positions. Can be a mixture of integers and tuple ranges (e.g., `[1, 5, (10, 13), 18]`). - **marker** (str) - Optional - Marker type (e.g., 'v', 'o', '*'). Defaults to 'v'. See Matplotlib markers API for details. - **color** (str) - Optional - Marker color. Defaults to 'black'. - **size** (float) - Optional - Marker size. Defaults to 6. ### Request Example ```json { "positions": [2, 7, [15, 17]], "marker": "o", "color": "red", "size": 8 } ``` ### Response #### Success Response (200) - **status** (string) - Operation status message. #### Response Example ```json { "status": "Markers added successfully." } ``` ``` -------------------------------- ### Add Markers to MSA Positions Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Adds visual markers to specified positions in the MSA. This function allows customization of the marker type, color, and size. Similar to highlighting, it accepts a mixture of integer positions and tuple ranges for placement. ```python def add_markers(positions: list[tuple[int, int] | int], marker: str = "v", color: str = "black", size: float = 6) -> None: """Add markers on specified positions""" pass ``` -------------------------------- ### savefig Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Saves the current MSA plot figure to a specified file. Supports custom DPI and padding. ```APIDOC ## savefig ### Description Saves the current MSA plot figure to a specified file. Supports custom DPI and padding. ### Method POST ### Endpoint /websites/moshi4_github_io_pymsaviz/savefig ### Parameters #### Request Body - **savefile** (str | Path) - Required - The path or filename to save the figure to. - **dpi** (int) - Optional - DPI for the saved figure. Defaults to 100. - **pad_inches** (float) - Optional - Padding around the figure in inches. Defaults to 0.5. ### Request Example ```json { "savefile": "msa_plot.png", "dpi": 120, "pad_inches": 0.2 } ``` ### Response #### Success Response (200) - **status** (string) - Operation status message indicating successful save. #### Response Example ```json { "status": "Figure saved successfully to msa_plot.png." } ``` ``` -------------------------------- ### Set Custom Color Scheme Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Allows users to define and apply a custom color scheme for visualizing residues in the MSA. This function overwrites any previously set color schemes and accepts a dictionary mapping residue characters to their desired hexadecimal color codes. ```python set_custom_color_scheme(color_scheme: dict[str, str]) -> None ``` -------------------------------- ### Set Custom Color Function Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Enables the use of a user-defined function to determine the color of each residue based on its position and character within the MSA. This provides the most granular control over coloring and overrides all other color settings. ```python set_custom_color_func(custom_color_func: Callable[[int, int, str, MSA], str | None]) ``` -------------------------------- ### add_text_annotation Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Adds text annotations within a specified range on the MSA plot. Customizable text and range colors, and text size. ```APIDOC ## add_text_annotation ### Description Adds text annotation in the specified range on the MSA plot. Customizable text and range colors, and text size. ### Method POST ### Endpoint /websites/moshi4_github_io_pymsaviz/add_text_annotation ### Parameters #### Request Body - **range** (tuple[int, int]) - Required - Annotation start-end range tuple (e.g., `(10, 20)`). - **text** (str) - Required - The annotation text. - **text_color** (str) - Optional - Text color. Defaults to 'black'. - **text_size** (float) - Optional - Text size. Defaults to 10. - **range_color** (str) - Optional - Annotation range line color. Defaults to 'black'. ### Request Example ```json { "range": [5, 15], "text": "Important Region", "text_color": "blue", "range_color": "green" } ``` ### Response #### Success Response (200) - **status** (string) - Operation status message. #### Response Example ```json { "status": "Text annotation added successfully." } ``` ``` -------------------------------- ### Plot MSA Figure Source: https://moshi4.github.io/pyMSAviz/api-docs/msaviz Generates and returns the MSA figure object. This function allows control over the figure's resolution using the DPI parameter. The returned object can then be used for further manipulation or saving. ```python from matplotlib.figure import Figure def plotfig(dpi: int = 100) -> Figure: """Plot figure""" pass ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.