Skip to content

glycontact.visualize module

glycontact.visualize

add_snfg_symbol(view, center, mono_name, alpha=1.0)

Adds a 3D Symbol Nomenclature for Glycans (SNFG) representation to a py3Dmol view. Args: view (py3Dmol.view): The py3Dmol view object. center (numpy.ndarray): 3D coordinates for the center of the symbol. mono_name (str): Name of the monosaccharide (e.g., 'Neu5Ac', 'Gal', 'GlcNAc'). alpha (float, optional): Transparency level (0.0-1.0). Defaults to 1.0. Returns: None: Modifies the view object in-place.

calculate_average_metric(graph, pattern_in, metric)

Calculate average of the specified metric across all nodes in the graph. Excludes nodes related to the pattern to ensure fair comparison. Args: graph: NetworkX DiGraph of glycan structure pattern: Pattern to exclude from calculation metric: Metric to average Returns: Average value of metric across non-pattern nodes

draw_contact_map(act, filepath='', size=0.5, return_plot=False)

Visualizes an atom contact map as a heatmap. Args: act (pd.DataFrame): The atom contact table from make_atom_contact_table() filepath (str, optional): Path to save the figure. If empty, no file is saved. size (float, optional): Text size for the plot. Defaults to 0.5. return_plot (bool, optional): If True, returns the plot object. Defaults to False. Returns: matplotlib.axes.Axes or None: Heatmap object if return_plot is True, None otherwise.

extract_torsion_angles(disaccharide: str, structure_graphs: Dict[str, nx.DiGraph] = structure_graphs) -> Tuple[List[float], List[float]]

Extract phi and psi torsion angles for a specific disaccharide linkage across all glycan structures. Args: disaccharide: String representing the disaccharide (e.g., "Fuc(a1-2)Gal") structure_graphs: Dictionary of glycan structure graphs Returns: Tuple of (phi_angles, psi_angles) lists

find_difference(glycans, pattern=None, alternative=None, metric='SASA', struc_dict=structure_graphs, plot=False)

Analyze differences in glycan properties between twin pairs based on pattern presence/absence or pattern substitution. Args: glycans: List of glycan structures to analyze pattern: String pattern to analyze (e.g., "[Fuc(a1-6)]") for presence/absence comparison alternative: String pattern to compare against the first pattern (e.g., "a2-6" vs "a2-3") When provided, function compares substitution rather than presence/absence metric: Property to compare (default: "SASA") struc_dict: Dictionary of glycan structure graphs plot: Whether to generate and return a visualization (default: False) Returns: Dictionary with statistical analysis results

make_gif(prefix, tables)

Creates an animated GIF from a series of contact map visualizations. Args: prefix (str): Prefix for the output filename. tables (list): List of contact tables to animate, one per frame. Returns: None: Displays the resulting GIF animation.

plot_glycan_3D(glycan, filepath=None, stereo=None, view=None, show_volume=False, volume_params={}, **plot_kwargs)

Creates a 3D visualization of a glycan structure from its IUPAC sequence. Args: glycan (str): IUPAC glycan sequence. stereo (str, optional): Stereochemistry specification ('alpha' or 'beta'). If None, inferred from sequence. filepath (str, optional): Path to PDB file to use. view (py3Dmol.view, optional): Existing py3Dmol view object. If None, creates new. show_volume (bool, optional): Whether to show volume surface. Defaults to False. volume_params (dict, optional): Parameters for volume rendering. **plot_kwargs: Additional arguments passed to _do_3d_plotting. Returns: py3Dmol.view: The configured view object with rendered glycan.

plot_glycan_score(glycan, score_list=[], attribute='SASA', filepath='')

Displays a glycan structure with monosaccharides highlighted according to a score. Args: glycan (str): IUPAC glycan sequence. score_list (list, optional): List of values for highlighting monosaccharides. If empty, uses values from the structure graph. attribute (str, optional): Attribute to use from structure graph if score_list is empty. Defaults to "SASA". filepath (str, optional): Path prefix for output file. If empty, no file is saved. Returns: GlycoDraw: The rendered glycan drawing object.

plot_monosaccharide_instability(glycan, filepath='', mode='sum')

Plots monosaccharide variability across different clusters of a glycan. Args: glycan (str): IUPAC glycan sequence. filepath (str, optional): Path prefix for output file. If empty, no file is saved. mode (str, optional): Method for aggregating variability ('sum' or 'mean'). Defaults to 'sum'. Returns: None: Displays the plot and optionally saves to file.

plot_superimposed_glycans(superposition_result, filepath='', animate=True, rotation_speed=1, show_labels=False, show_snfg=True)

Creates a 3D visualization of superimposed glycan structures. Args: superposition_result (dict): Output from superimpose_glycans() function. filepath (str, optional): Path to save the visualization image. If empty, no file is saved. animate (bool, optional): Whether to animate the visualization. Defaults to True. rotation_speed (int, optional): Speed of rotation if animated. Defaults to 1. show_labels (bool, optional): Whether to show monosaccharide labels. Defaults to False. show_snfg (bool, optional): Whether to show SNFG symbols. Defaults to True. Returns: py3Dmol.view: The configured view object with rendered superimposed glycans.

ramachandran_plot(disaccharide: str, structure_graphs: Dict[str, nx.DiGraph] = structure_graphs, density: bool = True, filepath: Optional[str] = None) -> plt.Figure

Generate a Ramachandran plot for a specific disaccharide linkage. Args: disaccharide: String representing the disaccharide (e.g., "Fuc(a1-2)Gal") structure_graphs: Dictionary of glycan structure graphs density: Whether to show density contours (default: True) filepath: Path to save the figure (optional) Returns: Matplotlib figure object

show_correlation_dendrogram(corr_df, font_size=1)

Creates a hierarchical clustering dendrogram from a correlation matrix. Args: corr_df (pd.DataFrame): Correlation matrix as a DataFrame. font_size (float, optional): Font size for the plot. Defaults to 1. Returns: dict: Dictionary mapping cluster colors to lists of monosaccharides in each cluster.

show_correlations(corr_df, font_size=1)

Visualizes a correlation matrix as a heatmap. Args: corr_df (pd.DataFrame): Correlation matrix as a DataFrame. font_size (float, optional): Font size for the plot. Defaults to 1. Returns: None: Displays the heatmap.

show_monosaccharide_preference_structure(df, monosaccharide, threshold, mode='default')

Visualizes preference statistics for a specific monosaccharide type. Args: df (pd.DataFrame): Monosaccharide distance table. monosaccharide (str): Target monosaccharide type. threshold (float): Distance threshold for interactions. mode (str, optional): Analysis mode ('default', 'monolink', or 'monosaccharide'). Defaults to 'default'. Returns: None: Displays a histogram of monosaccharide preferences.