Network Strategy¶
network_strategy ¶
Network Strategy - Interaction Network Visualizations.
This module implements the NetworkStrategy for creating network (graph) diagrams that visualize relationships between entities such as genes, compounds, samples, and pathways.
Classes:
| Name | Description |
|---|---|
NetworkStrategy | Strategy for network diagram generation using Plotly and NetworkX. |
Notes
- Supports bipartite networks (two node types)
- Supports similarity networks (weighted edges based on shared attributes)
- Multiple layout algorithms available (spring, circular, kamada_kawai)
For supported use cases, refer to the official documentation.
Classes¶
NetworkStrategy ¶
Bases: BasePlotStrategy
Strategy for network diagram interaction visualizations.
This strategy creates network graphs showing relationships between entities where nodes represent entities and edges represent connections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | Dict[str, Any] | Complete configuration from YAML file. | required |
Attributes:
| Name | Type | Description |
|---|---|---|
data_config | Dict[str, Any] | Data processing configuration. |
plotly_config | Dict[str, Any] | Plotly-specific configuration. |
mode | str | Processing mode: 'bipartite' or 'similarity'. |
source_column | str | Column name for source/primary entities. |
target_column | str | Column name for target/secondary entities. |
node_type_column | Optional[str] | Column indicating node type (for bipartite mode). |
shared_column | Optional[str] | Column for computing similarity (for similarity mode). |
Methods:
| Name | Description |
|---|---|
validate_data | Validate input data for network diagram requirements |
process_data | Process data and create graph structure |
create_figure | Create network diagram figure from processed graph data |
Notes
- Supports bipartite and similarity network modes
- Multiple layout algorithms available
- Visual encoding: node size/color by degree, edge width by weight
Initialize strategy with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | Dict[str, Any] | Complete configuration from YAML file. | required |
Source code in src/domain/plot_strategies/charts/network_strategy.py
Functions¶
validate_data ¶
Validate input data for network diagram requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Input data to validate. | required |
Raises:
| Type | Description |
|---|---|
ValueError | If DataFrame is empty, required columns missing, or mode configuration invalid. |
Source code in src/domain/plot_strategies/charts/network_strategy.py
process_data ¶
Process data and create graph structure for network visualization.
Creates edge list based on configured mode (bipartite or similarity).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Input data with required columns. | required |
Returns:
| Type | Description |
|---|---|
DataFrame | Graph data as DataFrame with source, target, and weight columns. |
Source code in src/domain/plot_strategies/charts/network_strategy.py
create_figure ¶
Create network diagram figure from processed graph data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processed_df | DataFrame | Processed edge list data. | required |
Returns:
| Type | Description |
|---|---|
Figure | Configured Plotly figure with network diagram. |
Source code in src/domain/plot_strategies/charts/network_strategy.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
apply_filters ¶
Apply filters to data.
This is a common implementation that can be overridden by subclasses if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Data to filter. | required |
filters | Optional[Dict[str, Any]] | Filter specifications. | None |
Returns:
| Type | Description |
|---|---|
DataFrame | Filtered data. |
Source code in src/domain/plot_strategies/base/base_plot_strategy.py
apply_customizations ¶
Apply custom styling to figure.
This is a hook for future customization features (FLEXIVEL and FLEXIVEL2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig | Figure | Base figure. | required |
customizations | Optional[Any] | Customization specifications. | None |
Returns:
| Type | Description |
|---|---|
Figure | Customized figure. |
Source code in src/domain/plot_strategies/base/base_plot_strategy.py
generate_plot ¶
generate_plot(data: DataFrame, filters: Optional[Dict[str, Any]] = None, customizations: Optional[Any] = None) -> go.Figure
Generate complete plot (Template Method).
This method orchestrates the entire plot generation process: 1. Validate input data 2. Process data 3. Apply filters 4. Create figure 5. Apply customizations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | DataFrame | Input data. | required |
filters | Optional[Dict[str, Any]] | Filters to apply. | None |
customizations | Optional[Any] | Customizations to apply. | None |
Returns:
| Type | Description |
|---|---|
Figure | Complete Plotly figure. |
Raises:
| Type | Description |
|---|---|
ValueError | If validation fails. |