graph-visualization-interactive-rendering
Summary
Render a NetworkX graph object as an interactive force-directed network visualization using pyvis, or as a static matplotlib plot, optionally with node labels and HTML export. This skill is used to display structural relationships (isotopologue, adduct, and cross-assay links) between mass spectrometry features organized into clusters.
When to use
After constructing a NetworkX graph object from structural clusters (via MamsiStructSearch), when you need to interactively explore feature relationships or publish a static network diagram showing isotopologue links, adduct relationships, and cross-assay connections. Triggered when return_nx_object=True or when the graph structure is ready for human interpretation.
When NOT to use
- Graph structure is not yet constructed from structural clusters—use MamsiStructSearch first.
- You need to perform further graph analysis (centrality, clustering detection)—export the NetworkX object instead and use dedicated graph analysis libraries.
- Input is not a NetworkX graph object—validate the object type before rendering.
Inputs
- NetworkX graph object with features as nodes
- Node attributes: assay, cluster membership, compound name (optional)
- Weighted edges: isotopologue (weight=1), adduct (weight=5), cross-assay (weight=10)
Outputs
- Interactive HTML file with pyvis force-directed visualization
- Static matplotlib figure with optional node labels
- NetworkX graph object (if return_nx_object=True)
How to apply
Pass the NetworkX graph object (with nodes representing features and edges representing structural relationships weighted by link type: isotopologue=1, adduct=5, cross-assay=10) to either the pyvis renderer (for interactive HTML output with force-directed layout) or the NetworkX/matplotlib combination (for static rendering). The pyvis output uses a physics-based layout to spatially separate clusters, improving readability. Set include_all=True to render all features or False to show only features with at least one structural link. Optionally enable node labels (labels=True) to display feature identifiers. Save the output as an HTML file for interactive exploration in a web browser, or display statically using matplotlib.
Related tools
- pyvis (Interactive force-directed graph rendering and HTML export)
- networkx (Graph construction and manipulation; static rendering via matplotlib integration)
- matplotlib (Static 2D visualization of NetworkX graph with optional node labels)
- pandas (Loading structural cluster DataFrame with feature, cluster, and link attributes)
- MamsiStructSearch (Source tool that generates structural clusters and correlation clusters prior to graph construction) — https://github.com/kopeckylukas/py-mamsi
Examples
network = struct.get_structural_network(include_all=True, interactive=True, labels=True, return_nx_object=True)
Evaluation signals
- HTML file is generated and renders without errors in a web browser with interactive zoom, pan, and hover tooltips.
- Nodes are positioned spatially such that densely connected clusters (high edge weight) are grouped closer together.
- Node colors correspond to flattened hierarchical correlation clusters; edge types visually reflect link weight (isotopologue, adduct, cross-assay).
- All features specified by include_all parameter are present or only those with structural links are rendered, as configured.
- Node labels (if enabled) are readable and correspond to feature identifiers in the input DataFrame.
- Static matplotlib output can be saved as a publication-ready image with consistent layout across runs.
Limitations
- Large graphs (>500 features) may be visually cluttered or slow to render interactively; consider filtering or subgraph extraction first.
- pyvis force-directed layout is non-deterministic; repeated renders may produce different spatial arrangements unless a random seed is set.
- Node label density can obscure edges and node positions in dense subgraphs; toggling labels or zooming is necessary.
- HTML output is browser-specific; rendering performance varies with browser capabilities and available system memory.
- The skill does not perform graph layout optimization beyond pyvis default physics parameters; custom layout algorithms require external networkx plugins.
Evidence
- [methods] Construct a NetworkX graph with features as nodes, assigning node attributes (assay, cluster membership, compound name). Create edges between features based on structural relationships: isotopologue links (weight=1), adduct links (weight=5), and cross-assay links (weight=10).: "Construct a NetworkX graph with features as nodes, assigning node attributes (assay, cluster membership, compound name). 3. Create edges between features based on structural relationships:"
- [methods] Render the graph interactively using pyvis with force-directed layout and save as HTML output_file, or display statically using NetworkX and matplotlib with optional node labels.: "Render the graph interactively using pyvis with force-directed layout and save as HTML output_file, or display statically using NetworkX and matplotlib with optional node labels."
- [readme] the different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links.: "the different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links."
- [methods] Optionally include all features in the network or only those with structural links, controlled by the include_all parameter.: "Optionally include all features in the network or only those with structural links, controlled by the include_all parameter."
- [methods] If return_nx_object=True, return the NetworkX graph object for downstream curation.: "If return_nx_object=True, return the NetworkX graph object for downstream curation."
1---2name: graph-visualization-interactive-rendering3description: Use when after constructing a NetworkX graph object from structural clusters (via MamsiStructSearch), when you need to interactively explore feature relationships or publish a static network diagram showing isotopologue links, adduct relationships, and cross-assay connections.4license: CC-BY-4.05---67# graph-visualization-interactive-rendering89## Summary1011Render a NetworkX graph object as an interactive force-directed network visualization using pyvis, or as a static matplotlib plot, optionally with node labels and HTML export. This skill is used to display structural relationships (isotopologue, adduct, and cross-assay links) between mass spectrometry features organized into clusters.1213## When to use1415After constructing a NetworkX graph object from structural clusters (via MamsiStructSearch), when you need to interactively explore feature relationships or publish a static network diagram showing isotopologue links, adduct relationships, and cross-assay connections. Triggered when return_nx_object=True or when the graph structure is ready for human interpretation.1617## When NOT to use1819- Graph structure is not yet constructed from structural clusters—use MamsiStructSearch first.20- You need to perform further graph analysis (centrality, clustering detection)—export the NetworkX object instead and use dedicated graph analysis libraries.21- Input is not a NetworkX graph object—validate the object type before rendering.2223## Inputs2425- NetworkX graph object with features as nodes26- Node attributes: assay, cluster membership, compound name (optional)27- Weighted edges: isotopologue (weight=1), adduct (weight=5), cross-assay (weight=10)2829## Outputs3031- Interactive HTML file with pyvis force-directed visualization32- Static matplotlib figure with optional node labels33- NetworkX graph object (if return_nx_object=True)3435## How to apply3637Pass the NetworkX graph object (with nodes representing features and edges representing structural relationships weighted by link type: isotopologue=1, adduct=5, cross-assay=10) to either the pyvis renderer (for interactive HTML output with force-directed layout) or the NetworkX/matplotlib combination (for static rendering). The pyvis output uses a physics-based layout to spatially separate clusters, improving readability. Set include_all=True to render all features or False to show only features with at least one structural link. Optionally enable node labels (labels=True) to display feature identifiers. Save the output as an HTML file for interactive exploration in a web browser, or display statically using matplotlib.3839## Related tools4041- **pyvis** (Interactive force-directed graph rendering and HTML export)42- **networkx** (Graph construction and manipulation; static rendering via matplotlib integration)43- **matplotlib** (Static 2D visualization of NetworkX graph with optional node labels)44- **pandas** (Loading structural cluster DataFrame with feature, cluster, and link attributes)45- **MamsiStructSearch** (Source tool that generates structural clusters and correlation clusters prior to graph construction) — https://github.com/kopeckylukas/py-mamsi4647## Examples4849```50network = struct.get_structural_network(include_all=True, interactive=True, labels=True, return_nx_object=True)51```5253## Evaluation signals5455- HTML file is generated and renders without errors in a web browser with interactive zoom, pan, and hover tooltips.56- Nodes are positioned spatially such that densely connected clusters (high edge weight) are grouped closer together.57- Node colors correspond to flattened hierarchical correlation clusters; edge types visually reflect link weight (isotopologue, adduct, cross-assay).58- All features specified by include_all parameter are present or only those with structural links are rendered, as configured.59- Node labels (if enabled) are readable and correspond to feature identifiers in the input DataFrame.60- Static matplotlib output can be saved as a publication-ready image with consistent layout across runs.6162## Limitations6364- Large graphs (>500 features) may be visually cluttered or slow to render interactively; consider filtering or subgraph extraction first.65- pyvis force-directed layout is non-deterministic; repeated renders may produce different spatial arrangements unless a random seed is set.66- Node label density can obscure edges and node positions in dense subgraphs; toggling labels or zooming is necessary.67- HTML output is browser-specific; rendering performance varies with browser capabilities and available system memory.68- The skill does not perform graph layout optimization beyond pyvis default physics parameters; custom layout algorithms require external networkx plugins.6970## Evidence7172- [methods] Construct a NetworkX graph with features as nodes, assigning node attributes (assay, cluster membership, compound name). Create edges between features based on structural relationships: isotopologue links (weight=1), adduct links (weight=5), and cross-assay links (weight=10).: "Construct a NetworkX graph with features as nodes, assigning node attributes (assay, cluster membership, compound name). 3. Create edges between features based on structural relationships:"73- [methods] Render the graph interactively using pyvis with force-directed layout and save as HTML output_file, or display statically using NetworkX and matplotlib with optional node labels.: "Render the graph interactively using pyvis with force-directed layout and save as HTML output_file, or display statically using NetworkX and matplotlib with optional node labels."74- [readme] the different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links.: "the different node colours represent different flattened hierarchical correlation clusters, while the edges between nodes identify their structural links."75- [methods] Optionally include all features in the network or only those with structural links, controlled by the include_all parameter.: "Optionally include all features in the network or only those with structural links, controlled by the include_all parameter."76- [methods] If return_nx_object=True, return the NetworkX graph object for downstream curation.: "If return_nx_object=True, return the NetworkX graph object for downstream curation."