Skip to content

Commit 8cbaf78

Browse files
committed
improve html report
1 parent a652abe commit 8cbaf78

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

tpcav/cavs.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from sklearn.linear_model import LinearRegression
2626
import logomaker
2727

28-
from . import helper, utils
28+
from . import helper, utils, report
2929
from .concepts import ConceptBuilder
3030
from .tpcav_model import TPCAV
3131
from matplotlib import gridspec
@@ -615,7 +615,7 @@ def load_custom_motif_info(key):
615615
cavs_fscores_df['AUC_fscores_residual'] = residuals
616616
plot_reg(data=cavs_fscores_df, x='avg_len', y='AUC_fscores', ax=axes[0])
617617
plot_reg(data=cavs_fscores_df, x='avg_gc', y='AUC_fscores', ax=axes[1])
618-
axes[2].set_axis('off')
618+
axes[2].axis('off')
619619

620620
cavs_fscores_df.sort_values("AUC_fscores_residual", ascending=False, inplace=True)
621621
else:
@@ -648,7 +648,9 @@ def run_tpcav(
648648
num_pc: Union[str,int]='full',
649649
p=1,
650650
max_pending_jobs=4,
651-
save_cav_trainer=True
651+
save_cav_trainer=True,
652+
generate_html_report=True,
653+
html_report_fscore_thresh=0.9,
652654
):
653655
"""
654656
One-stop function to compute CAVs on motif concepts and bed concepts, compute AUC of motif concept f-scores after correction
@@ -765,4 +767,9 @@ def run_tpcav(
765767
else:
766768
cavs_fscores_df = None
767769

770+
if generate_html_report:
771+
report.generate_tcav_html_report(str(output_path / f"report.html"), motif_cav_trainers,
772+
extra_cav_trainers = {'bed concepts': bed_cav_trainer},
773+
motif_file=motif_file, motif_file_fmt=motif_file_fmt, fscore_thresh=html_report_fscore_thresh)
774+
768775
return cavs_fscores_df, motif_cav_trainers, bed_cav_trainer

tpcav/report.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def generate_tpcav_html_report(
100100
fscore_thresh: float = 0.8,
101101
top_motif_concepts: int = 10,
102102
title: str = "TPCAV report",
103-
embed_images: bool = True,
103+
embed_images: bool = False,
104104
) -> Path:
105105
"""
106106
Generate a standalone HTML report from CavTrainer objects.
@@ -435,6 +435,14 @@ def _to_list(x: Any) -> Any:
435435
f"<div class='muted'>Images are stored in: {_html.escape(str(assets_dir))}</div>"
436436
)
437437

438+
param_rows = [
439+
("fscore_thresh", str(fscore_thresh)),
440+
("top_motif_concepts", str(top_motif_concepts)),
441+
("motif_file", str(motif_file) if motif_file is not None else ""),
442+
("motif_file_fmt", str(motif_file_fmt)),
443+
]
444+
params_html = _render_kv_table(param_rows)
445+
438446
all_concepts: list[str] = []
439447
seen = set()
440448
for c in ranked_motif_concepts:
@@ -739,12 +747,13 @@ def _png_html(path: Path, alt: str) -> str:
739747
</style>
740748
</head>
741749
<body>
742-
<div class="container">
743-
<header>
744-
<h1>{_html.escape(title)}</h1>
745-
<div class="meta">Generated: {now}</div>
746-
{assets_note}
747-
</header>
750+
<div class="container">
751+
<header>
752+
<h1>{_html.escape(title)}</h1>
753+
<div class="meta">Generated: {now}</div>
754+
{params_html}
755+
{assets_note}
756+
</header>
748757
749758
<section>
750759
<h2>Concepts</h2>

0 commit comments

Comments
 (0)