Chord Diagram Strategy¶
chord_strategy ¶
Chord Diagram Strategy.
This module implements the ChordStrategy class following the Strategy Pattern, providing logic for generating chord diagrams that visualize relationships between categorical entities as arcs connecting nodes arranged in a circle.
Classes:
| Name | Description |
|---|---|
ChordStrategy | Concrete strategy for chord diagram generation using Plotly |
Notes
Chord diagrams are ideal for: - Visualizing relationships between entities (source-target pairs) - Showing interaction strength between categories - Displaying sample similarity networks - Mapping set intersections and overlaps
Processing Modes: 1. Direct Aggregation Mode (mode='aggregation'): - Groups by source and target columns - Aggregates count of interactions
- Pairwise Similarity Mode (mode='pairwise'):
- Computes shared entities between pairs
-
Creates links based on intersection size
-
Set Intersection Mode (mode='set_intersection'):
- Computes pairwise intersections between named sets
- Links represent overlap size between sets
For supported use cases, refer to the official documentation.
Version: 1.0.0
Classes¶
ChordStrategy ¶
Bases: BasePlotStrategy
Chord diagram strategy for network relationship visualizations.
This strategy creates chord diagrams showing relationships between categorical entities where: - Nodes: Categories arranged in a circle - Arcs: Connections between nodes weighted by interaction strength - Colors: Node/arc coloring based on category
Attributes:
| Name | Type | Description |
|---|---|---|
data_config | Dict[str, Any] | Data processing configuration |
plotly_config | Dict[str, Any] | Plotly-specific configuration |
mode | str | Processing mode: 'aggregation', 'pairwise', or 'set_intersection' |
source_column | str | Column name for source entities |
target_column | str | Column name for target entities |
value_column | Optional[str] | Column for pre-aggregated values (if any) |
group_by_column | Optional[str] | Column for grouping in pairwise mode |
shared_column | Optional[str] | Column for computing shared entities in pairwise mode |
Notes
Required YAML configuration structure:
visualization:
strategy: "ChordStrategy"
plotly:
mode: "aggregation" # or "pairwise", "set_intersection"
source_column: "sample"
target_column: "compoundclass"
# For pairwise mode:
# group_by_column: "sample"
# shared_column: "compoundname"
chart:
title:
text: "Sample-Compound Interactions"
colorscale: "Category20"
layout:
height: 800
width: 800
Refer to the official documentation for supported use cases and detailed configuration examples.
Initialize chord diagram strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | Dict[str, Any] | Complete configuration from YAML file | required |
Source code in src/domain/plot_strategies/charts/chord_strategy.py
Functions¶
validate_data ¶
Validate input data for chord diagram requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Input data to validate | required |
Raises:
| Type | Description |
|---|---|
ValueError | If any validation rule fails |
Source code in src/domain/plot_strategies/charts/chord_strategy.py
process_data ¶
Process data and create links DataFrame for chord diagram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df | DataFrame | Input data with required columns | required |
Returns:
| Type | Description |
|---|---|
DataFrame | Links DataFrame with columns: source, target, value |
Source code in src/domain/plot_strategies/charts/chord_strategy.py
create_figure ¶
Create chord diagram figure from processed links data.
This implementation uses Plotly's graph_objects to create a custom chord diagram since Plotly Express doesn't have native chord support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processed_df | DataFrame | Processed links data with source, target, value columns | required |
Returns:
| Type | Description |
|---|---|
Figure | Configured Plotly figure with chord diagram |
Source code in src/domain/plot_strategies/charts/chord_strategy.py
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 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
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. |