|
325 | 325 | " return plot_df"
|
326 | 326 | ]
|
327 | 327 | },
|
| 328 | + { |
| 329 | + "cell_type": "code", |
| 330 | + "execution_count": null, |
| 331 | + "id": "6d1433dd-c829-470a-82d5-1eb21cb8b568", |
| 332 | + "metadata": {}, |
| 333 | + "outputs": [], |
| 334 | + "source": [ |
| 335 | + "class SubsetConfig:\n", |
| 336 | + " def __init__(self, df):\n", |
| 337 | + " self.strat = df['Interval'].iloc[0] if len(df) > 0 and 'Interval' in df.columns else None\n", |
| 338 | + " self.type_ = df['Type'].iloc[0] if len(df) > 0 else None\n", |
| 339 | + " self.color = None if (len(df) > 0) and (df['Experiment'].iloc[0] == 'No_ExpGroups_Provided') else 'Experiment'\n", |
| 340 | + "\n", |
| 341 | + " def make_title(self, prefix):\n", |
| 342 | + " title = prefix\n", |
| 343 | + " if self.strat is not None:\n", |
| 344 | + " title += f' over {self.strat}'\n", |
| 345 | + " if self.type_ is not None:\n", |
| 346 | + " title += f' for {self.type_}'\n", |
| 347 | + " return title" |
| 348 | + ] |
| 349 | + }, |
328 | 350 | {
|
329 | 351 | "cell_type": "code",
|
330 | 352 | "execution_count": null,
|
|
349 | 371 | "outputs": [],
|
350 | 372 | "source": [
|
351 | 373 | "def make_prec_recall_plot(df, marginal, axes_mode):\n",
|
352 |
| - " strat = df['Interval'].iloc[0]\n", |
353 |
| - " type_ = df['Type'].iloc[0]\n", |
354 |
| - " color = None if df['Experiment'].iloc[0] == 'No_ExpGroups_Provided' else 'Experiment'\n", |
| 374 | + " cfg = SubsetConfig(df)\n", |
| 375 | + " \n", |
355 | 376 | " if not SINGLE_SAMPLE_MODE:\n",
|
356 | 377 | " marginal = marginal.lower() if marginal != 'None' else None\n",
|
357 |
| - " fig = px.scatter(df, x='Recall', y='Precision', color=color, marginal_x=marginal, marginal_y=marginal,\n", |
358 |
| - " hover_data=['Query_Name'], title=f'Precision vs Recall Plot over {strat} for {type_}', \n", |
| 378 | + " fig = px.scatter(df, x='Recall', y='Precision', color=cfg.color, marginal_x=marginal, marginal_y=marginal,\n", |
| 379 | + " hover_data=['Query_Name'], title=cfg.make_title(prefix=f'Precision vs Recall Plot'), \n", |
359 | 380 | " category_orders=CATEGORY_ORDERS, color_discrete_map=EXPERIMENT_COLOR_MAP)\n",
|
360 | 381 | " if axes_mode == 'Fixed':\n",
|
361 | 382 | " fig.update_layout(xaxis_range=[0, 1.1], yaxis_range=[0, 1.1])\n",
|
362 | 383 | " else:\n",
|
363 | 384 | " melted_df = df.melt(id_vars=['Experiment', 'Query_Name', 'Base_Name', 'Interval', 'Type'], value_vars=['Precision', 'Recall', 'F1_Score'])\n",
|
364 | 385 | " melted_df = melted_df.rename(columns={'variable': 'Stat', 'value': 'Value'})\n",
|
365 |
| - " fig = px.bar(melted_df, x='Stat', y='Value', title=f'Performance Stats over {strat} for {type_}', \n", |
| 386 | + " fig = px.bar(melted_df, x='Stat', y='Value', title=cfg.make_title(prefix=f'Performance Stats'), \n", |
366 | 387 | " category_orders=CATEGORY_ORDERS, color_discrete_map=EXPERIMENT_COLOR_MAP)\n",
|
367 | 388 | " fig.update_layout(yaxis_range=[0, 1.1])\n",
|
368 | 389 | " \n",
|
369 | 390 | " return fig\n",
|
370 | 391 | "\n",
|
371 | 392 | "\n",
|
372 | 393 | "def make_stat_covariate_plot(df, covaraite, stat, axes_mode):\n",
|
373 |
| - " strat = df['Interval'].iloc[0]\n", |
374 |
| - " type_ = df['Type'].iloc[0]\n", |
375 |
| - " color = None if df['Experiment'].iloc[0] == 'No_ExpGroups_Provided' else 'Experiment'\n", |
376 |
| - " fig = px.scatter(df, x=stat_corr, y=stat, color=color, hover_data=['Query_Name', 'TP_Base', 'TP_Query', 'FP', 'FN'],\n", |
377 |
| - " title=f'Plot of {stat} by {covariate} over {strat} for {type_}', \n", |
| 394 | + " cfg = SubsetConfig(df)\n", |
| 395 | + " \n", |
| 396 | + " fig = px.scatter(df, x=stat_corr, y=stat, color=cfg.color, hover_data=['Query_Name', 'TP_Base', 'TP_Query', 'FP', 'FN'],\n", |
| 397 | + " title=cfg.make_title(prefix=f'Plot of {stat} by {covariate}'), \n", |
378 | 398 | " category_orders=CATEGORY_ORDERS, color_discrete_map=EXPERIMENT_COLOR_MAP)\n",
|
379 | 399 | " if axes_mode == 'Fixed':\n",
|
380 | 400 | " fig.update_layout(yaxis_range=[0, 1.1])\n",
|
|
492 | 512 | "outputs": [],
|
493 | 513 | "source": [
|
494 | 514 | "def make_roc_plot(df, roc_mode, error_bars, axes_mode):\n",
|
495 |
| - " type_ = df['Type'].iloc[0]\n", |
| 515 | + " cfg = SubsetConfig(df)\n", |
| 516 | + "\n", |
496 | 517 | " if roc_mode in ['Precision', 'Recall']:\n",
|
497 | 518 | " error_y = None\n",
|
498 | 519 | " if not SINGLE_SAMPLE_MODE:\n",
|
|
503 | 524 | " \n",
|
504 | 525 | " fig = px.line(plot_df, x='Score', y=f'{roc_mode}_mean', error_y=error_y, \n",
|
505 | 526 | " hover_data=['Score', 'TP_Base_mean', 'TP_Query_mean', 'FP_mean', 'FN_mean'],\n",
|
506 |
| - " title=f'{roc_mode} Plot for {type_} stratified by Score', color='Experiment',\n", |
| 527 | + " title=cfg.make_title(f'{roc_mode} Plot') + ' stratified by Score', color=cfg.color,\n", |
507 | 528 | " category_orders=CATEGORY_ORDERS, color_discrete_map=EXPERIMENT_COLOR_MAP)\n",
|
508 | 529 | " else:\n",
|
509 |
| - " fig = px.line(df, x='Recall', y='Precision', color='Experiment', line_group='Query_Name', hover_data=['Score'],\n", |
510 |
| - " title=f'ROC Plot for {type_} stratified by Score')\n", |
| 530 | + " fig = px.line(df, x='Recall', y='Precision', color=cfg.color, line_group='Query_Name', hover_data=['Score'],\n", |
| 531 | + " title=cfg.make_title(f'ROC Plot') + ' stratified by Score')\n", |
511 | 532 | " fig.update_layout(xaxis_range=[0, 1.1])\n",
|
512 | 533 | "\n",
|
513 | 534 | " if axes_mode == 'Fixed':\n",
|
|
605 | 626 | "outputs": [],
|
606 | 627 | "source": [
|
607 | 628 | "def make_titv_plot(df, stat, axes_mode):\n",
|
608 |
| - " color = None if df['Experiment'].iloc[0] == 'No_ExpGroups_Provided' else 'Experiment'\n", |
609 |
| - " strat = df['Interval'].iloc[0]\n", |
610 |
| - " type_ = df['Type'].iloc[0]\n", |
| 629 | + " cfg = SubsetConfig(df)\n", |
611 | 630 | "\n",
|
612 | 631 | " error_y = None\n",
|
613 | 632 | " if not SINGLE_SAMPLE_MODE:\n",
|
|
619 | 638 | " plot_df = plot_df.replace('Ti', 'Transitions').replace('Tv', 'Transversions')\n",
|
620 | 639 | "\n",
|
621 | 640 | " fig = px.bar(plot_df, x='Substitution_Type', y=f'{stat}_mean', error_y=error_y, \n",
|
622 |
| - " title=f'Plot of {stat} mean by Substitution Type on {strat} for {type_}', \n", |
623 |
| - " hover_data=['TP_Base_mean', 'TP_Query_mean', 'FP_mean', 'FN_mean', 'IGN_mean', 'OUT_mean'], color=color, barmode='group',\n", |
| 641 | + " title=cfg.make_title(f'Plot of {stat} mean by Substitution Type'), \n", |
| 642 | + " hover_data=['TP_Base_mean', 'TP_Query_mean', 'FP_mean', 'FN_mean', 'IGN_mean', 'OUT_mean'], color=cfg.color, barmode='group',\n", |
624 | 643 | " category_orders=CATEGORY_ORDERS, color_discrete_map=EXPERIMENT_COLOR_MAP)\n",
|
625 | 644 | " if axes_mode == 'Fixed' and stat in ['Precision', 'Recall', 'F1_Score']:\n",
|
626 | 645 | " fig.update_layout(yaxis_range=[0, 1.1])\n",
|
627 | 646 | " return fig\n",
|
628 | 647 | "\n",
|
629 | 648 | "def make_snp_substitution_plot(df, stat, axes_mode):\n",
|
630 |
| - " color = None if df['Experiment'].iloc[0] == 'No_ExpGroups_Provided' else 'Experiment'\n", |
631 |
| - " strat = df['Interval'].iloc[0]\n", |
632 |
| - " type_ = df['Type'].iloc[0]\n", |
| 649 | + " cfg = SubsetConfig(df)\n", |
| 650 | + "\n", |
633 | 651 | " df_means = df.groupby(['Experiment', 'Type', 'Substitution_Type', \n",
|
634 | 652 | " 'Ref_Nucleotide', 'Var_Nucleotide'])[['TP_Base', 'TP_Query', \n",
|
635 | 653 | " 'FP', 'FN', 'F1_Score', 'Precision', 'Recall', 'IGN', 'OUT']].mean().reset_index()\n",
|
|
647 | 665 | " if EXPERIMENT_ORDER is not None:\n",
|
648 | 666 | " category_orders = {**category_orders, **{'Experiment': EXPERIMENT_ORDER}}\n",
|
649 | 667 | "\n",
|
650 |
| - " fig = px.scatter_3d(plot_df, x='Ref_Nucleotide', y='Var_Nucleotide', z=f'{stat}_mean', error_z=f'{stat}_conf', color=color, \n", |
| 668 | + " fig = px.scatter_3d(plot_df, x='Ref_Nucleotide', y='Var_Nucleotide', z=f'{stat}_mean', error_z=f'{stat}_conf', color=cfg.color, \n", |
651 | 669 | " hover_data=['TP_Base_mean', 'TP_Query_mean', 'FP_mean', 'FN_mean', 'IGN_mean', 'OUT_mean'],\n",
|
652 |
| - " title=f'Plot of {stat} per Substitution Type on {strat} for {type_}', \n", |
| 670 | + " title=cfg.make_title(f'Plot of {stat} per Substitution Type'), \n", |
653 | 671 | " category_orders=category_orders, symbol='Substitution_Type_mean', color_discrete_map=EXPERIMENT_COLOR_MAP,\n",
|
654 | 672 | " height=700, width=1000,\n",
|
655 | 673 | " )\n",
|
|
745 | 763 | "outputs": [],
|
746 | 764 | "source": [
|
747 | 765 | "def make_idd_plot(df, stat, axes_mode):\n",
|
748 |
| - " color = None if df['Experiment'].iloc[0] == 'No_ExpGroups_Provided' else 'Experiment'\n", |
749 |
| - " strat = df['Interval'].iloc[0]\n", |
750 |
| - " type_ = df['Type'].iloc[0]\n", |
| 766 | + " cfg = SubsetConfig(df)\n", |
751 | 767 | "\n",
|
752 | 768 | " error_y = None\n",
|
753 | 769 | " if not SINGLE_SAMPLE_MODE:\n",
|
|
756 | 772 | " else:\n",
|
757 | 773 | " plot_df = df\n",
|
758 | 774 | " \n",
|
759 |
| - " fig = px.line(plot_df, x='INDEL_Length', y=f'{stat}_mean', error_y=error_y, title=f'Plot of {stat} mean by INDEL Length on {strat} for {type_}', \n", |
760 |
| - " hover_data=['TP_Base_mean', 'TP_Query_mean', 'FP_mean', 'FN_mean', 'IGN_mean', 'OUT_mean'], color=color, line_group=color, \n", |
| 775 | + " fig = px.line(plot_df, x='INDEL_Length', y=f'{stat}_mean', error_y=error_y, title=cfg.make_title(f'Plot of {stat} mean by INDEL Length'), \n", |
| 776 | + " hover_data=['TP_Base_mean', 'TP_Query_mean', 'FP_mean', 'FN_mean', 'IGN_mean', 'OUT_mean'], color=cfg.color, line_group=cfg.color, \n", |
761 | 777 | " category_orders=CATEGORY_ORDERS, color_discrete_map=EXPERIMENT_COLOR_MAP)\n",
|
762 | 778 | " if axes_mode == 'Fixed' and stat in ['Precision', 'Recall', 'F1_Score']:\n",
|
763 | 779 | " fig.update_layout(yaxis_range=[0, 1.1])\n",
|
|
859 | 875 | "metadata": {},
|
860 | 876 | "outputs": [],
|
861 | 877 | "source": [
|
862 |
| - "start_app(board, app_title='BenchmarkBoard', mode='external', port=8055)" |
| 878 | + "start_app(board, app_title='BenchmarkBoard', jupyter_mode='external', port=8050)" |
863 | 879 | ]
|
864 | 880 | },
|
865 | 881 | {
|
|
881 | 897 | ],
|
882 | 898 | "metadata": {
|
883 | 899 | "kernelspec": {
|
884 |
| - "display_name": "quickboard_venv", |
| 900 | + "display_name": "Python 3 (ipykernel)", |
885 | 901 | "language": "python",
|
886 |
| - "name": "quickboard_venv" |
| 902 | + "name": "python3" |
887 | 903 | },
|
888 | 904 | "language_info": {
|
889 | 905 | "codemirror_mode": {
|
|
895 | 911 | "name": "python",
|
896 | 912 | "nbconvert_exporter": "python",
|
897 | 913 | "pygments_lexer": "ipython3",
|
898 |
| - "version": "3.9.6" |
| 914 | + "version": "3.10.9" |
899 | 915 | }
|
900 | 916 | },
|
901 | 917 | "nbformat": 4,
|
|
0 commit comments