ReportGenerator¶
- class visual.ReportGenerator.ReportGenerator(base_file_html_path: str = './visual/web/base.html')[source]¶
Bases:
objectGenerate interactive HTML reports for protein-protein interaction (PPI) networks.
This class creates standalone HTML reports with embedded Cytoscape.js visualizations and analysis plots. Reports include interactive controls for selecting which node/edge attributes determine visual properties (color, size, width).
- html_template¶
The base HTML template with placeholders for dynamic content.
- Type:
str
- add_cytoscape_html_report(network: PPINetwork, title: str = 'Protein Network Report', node_color_attr: str = 'pagerank', node_size_attr: str = 'degree', edge_width_attr: str = 'combined_score', cmap_name: str = 'viridis', min_node_size: float = 35, max_node_size: float = 100, min_edge_width: float = 1, max_edge_width: float = 10) ReportGenerator[source]¶
Add an interactive Cytoscape.js network visualization to the report.
The visualization includes dropdown menus for dynamically selecting which node/edge attributes control color, size, and width, allowing interactive exploration of different network properties.
- Parameters:
network – The PPINetwork object to visualize.
title – Title for the network report. Defaults to “Protein Network Report”.
node_color_attr – Node attribute to control node color. Defaults to “pagerank”.
node_size_attr – Node attribute to control node size. Defaults to “degree”.
edge_width_attr – Edge attribute to control edge width. Defaults to “combined_score”.
cmap_name – Name of the matplotlib colormap. Defaults to “viridis”.
min_node_size – Minimum node size in pixels. Defaults to 35.
max_node_size – Maximum node size in pixels. Defaults to 100.
min_edge_width – Minimum edge width in pixels. Defaults to 1.
max_edge_width – Maximum edge width in pixels. Defaults to 10.
- Returns:
Self for method chaining.
- Return type:
Note
The generated HTML tries to load cytoscape.min.js locally first. If not found, it loads Cytoscape.js from the online CDN.
- add_section(html_to_add: str) ReportGenerator[source]¶
Add a new section to the HTML report.
Adds the provided HTML content by replacing the placeholder string.
- Parameters:
html_to_add – HTML string to insert into the report.
- Returns:
Self for method chaining.
- Return type:
Note
The placeholder string is defined as __ADD_MORE_SECTIONS__ and should be present in the base HTML template.
- add_section_from_file(file: str, replacements: Dict[str, str] | None = None) ReportGenerator[source]¶
Add a new section to the HTML report by reading from an HTML file.
Optionally performs string replacements before inserting the content.
- Parameters:
file – Path to an HTML file to read and insert.
replacements – Optional dictionary mapping strings to replace in the file content. Defaults to None.
- Returns:
Self for method chaining.
- Return type:
- Raises:
FileNotFoundError – If the specified file does not exist.
IOError – If the file cannot be read.
Example
>>> gen = ReportGenerator() >>> gen.add_section_from_file( ... file="./plots.html", ... replacements={"__PLOT_1__": encoded_image_1, "__PLOT_2__": encoded_image_2} ... )
- generate_report_file(output_file: str = 'protein_network_report.html') str[source]¶
Generate and save the final HTML report file.
- Parameters:
output_file – Output file path for the HTML report. Defaults to “protein_network_report.html”.
- Returns:
The absolute path to the generated report file.
- Return type:
str
- Raises:
IOError – If the report file cannot be written.