inference/plot API¶
dnallm.inference.plot ¶
DNA Language Model Visualization and Plotting Module.
This module provides comprehensive plotting capabilities for DNA language model results, including metrics visualization, attention maps, embeddings, and mutation effects analysis.
Functions¶
plot_attention_map ¶
plot_attention_map(
attentions,
sequences,
tokenizer,
seq_idx=0,
layer=-1,
head=-1,
width=800,
height=800,
save_path=None,
)
Plot attention map visualization for transformer models.
This function creates a heatmap visualization of attention weights between tokens in a sequence, showing how the model attends to different parts of the input.
Args:
attentions: Tuple or
list containing attention weights from model layers
sequences: List of input sequences
tokenizer: Tokenizer object for converting tokens to readable text
seq_idx: Index of the sequence to plot, default 0
layer: Layer index to visualize, default -1 (last layer)
attention_head: Attention head index to visualize,
default -1 (last head)
width: Width of the plot
height: Height of the plot
save_path: Path to save the plot. If None,
plot will be shown interactively
Returns:
Altair chart object showing the attention heatmap
Source code in dnallm/inference/plot.py
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 |
|
plot_bars ¶
plot_bars(
data,
show_score=True,
ncols=3,
width=200,
height=50,
bar_width=30,
domain=(0.0, 1.0),
save_path=None,
separate=False,
)
Plot bar charts for model metrics comparison.
This function creates bar charts to compare different metrics across multiple models. It supports automatic layout with multiple columns and optional score labels on bars.
Args:
data: Dictionary containing metrics data with 'models' as the first
key
show_score: Whether to show the score values on the bars
ncols: Number of columns to arrange the plots
width: Width of each individual plot
height: Height of each individual plot
bar_width: Width of the bars in the plot
domain: Y-axis domain range for the plots, default (0.0, 1.0)
save_path: Path to save the plot. If None,
plot will be shown interactively
separate: Whether to return separate plots for each metric
Returns:
Altair chart object (combined or
separate plots based on separate parameter)
Source code in dnallm/inference/plot.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
plot_curve ¶
plot_curve(
data,
show_score=True,
width=400,
height=400,
save_path=None,
separate=False,
)
Plot ROC and PR curves for classification tasks.
This function creates ROC (Receiver Operating Characteristic) and
PR (Precision-Recall)
curves to evaluate model performance on classification tasks.
Args:
data: Dictionary containing ROC and PR curve data with 'ROC' and
'PR' keys
show_score: Whether to show the score values on the plot (currently not implemented) width: Width of each plot height: Height of each plot save_path: Path to save the plot. If None, plot will be shown interactively separate: Whether to return separate plots for ROC and PR curves
Returns:
Altair chart object (combined or
separate plots based on separate parameter)
Source code in dnallm/inference/plot.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 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 |
|
plot_embeddings ¶
plot_embeddings(
hidden_states,
attention_mask,
reducer="t-SNE",
labels=None,
label_names=None,
ncols=4,
width=300,
height=300,
save_path=None,
separate=False,
)
Visualize embeddings using dimensionality reduction techniques.
This function creates 2D visualizations of high-dimensional embeddings from different model layers using PCA, t-SNE, or UMAP dimensionality reduction methods.
Args:
hidden_states: Tuple or list containing hidden states from model
layers
attention_mask: Tuple or
list containing attention masks for sequence padding
reducer: Dimensionality reduction method. Options: 'PCA',
't-SNE', 'UMAP'
labels: List of labels for the data points
labels_names: List of label names for legend display
ncols: Number of columns to arrange the plots
width: Width of each plot
height: Height of each plot
save_path: Path to save the plot. If None,
plot will be shown interactively
separate: Whether to return separate plots for each layer
Returns:
Altair chart object (combined or
separate plots based on separate parameter)
Raises:
ValueError: If unsupported dimensionality reduction method is
specified
Source code in dnallm/inference/plot.py
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
|
plot_muts ¶
plot_muts(
data,
show_score=False,
width=None,
height=100,
save_path=None,
)
Visualize mutation effects on model predictions.
This function creates comprehensive visualizations of how different mutations affect model predictions, including: - Heatmap showing mutation effects at each position - Line plot showing gain/loss of function - Bar chart showing maximum effect mutations
Args:
data: Dictionary containing mutation data with 'raw' and mutation
keys
show_score: Whether to show the score values on the plot (currently not implemented) width: Width of the plot. If None, automatically calculated based on sequence length height: Height of the plot save_path: Path to save the plot. If None, plot will be shown interactively
Returns:
Altair chart object showing the combined mutation effects
visualization
Source code in dnallm/inference/plot.py
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
|
plot_scatter ¶
plot_scatter(
data,
show_score=True,
ncols=3,
width=400,
height=400,
save_path=None,
separate=False,
)
Plot scatter plots for regression task evaluation.
This function creates scatter plots to compare predicted vs. experimental values for regression tasks, with optional R² score display.
Args:
data: Dictionary containing scatter plot data for each model
show_score: Whether to show the R² score on the plot
ncols: Number of columns to arrange the plots
width: Width of each plot
height: Height of each plot
save_path: Path to save the plot. If None,
plot will be shown interactively
separate: Whether to return separate plots for each model
Returns:
Altair chart object (combined or
separate plots based on separate parameter)
Source code in dnallm/inference/plot.py
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 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
prepare_data ¶
prepare_data(metrics, task_type='binary')
Prepare data for plotting various types of visualizations.
This function organizes model metrics data into formats suitable for different plot types: - Bar charts for classification and regression metrics - ROC and PR curves for classification tasks - Scatter plots for regression tasks
Args:
metrics: Dictionary containing model metrics for different models
task_type: Type of task (
'binary',
'multiclass',
'multilabel',
'token',
'regression')
Returns:
Tuple containing:
- bars_data: Data formatted for bar chart visualization
- curves_data/scatter_data: Data formatted for curve or
scatter plot visualization
Raises:
ValueError: If task type is not supported for plotting
Source code in dnallm/inference/plot.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|