1616
1717from .analysis_request import AnalysisRequest
1818from .normalization import QuantileNormalizer
19- from .variant_report import TrackScore , VariantReport , build_variant_report , _describe_normalizer
19+ from .variant_report import (
20+ TrackScore , VariantReport , build_variant_report ,
21+ _describe_normalizer , _fmt_percentile ,
22+ )
2023
2124logger = logging .getLogger (__name__ )
2225
@@ -1007,11 +1010,21 @@ def _build_causal_igv(result: CausalResult) -> str:
10071010 if igv_raw :
10081011 normalizer = None
10091012
1013+ # Build a mapping assay_id → enriched display name so IGV
1014+ # track labels match the table rows ("CHIP:CEBPA:HepG2"
1015+ # instead of "CHIP_TF/EFO:0001187 TF ChIP-seq CEBPA…").
1016+ track_display : dict [str , str ] = {}
1017+ for allele_scores in top_s ._variant_report .allele_scores .values ():
1018+ for ts_disp in allele_scores :
1019+ if ts_disp .description and ts_disp .assay_id :
1020+ track_display [ts_disp .assay_id ] = ts_disp .description
1021+
10101022 for aid in assay_ids :
10111023 ref_t = ref_pred [aid ]
10121024 alt_t = alt_pred [aid ]
10131025 t_start = ref_t .prediction_interval .reference .start
10141026 t_res = ref_t .resolution
1027+ display = track_display .get (aid , aid )
10151028
10161029 layer = classify_track_layer (ref_t )
10171030 floor_ok , ref_vals , alt_vals = apply_floor_rescale (
@@ -1036,20 +1049,20 @@ def _build_causal_igv(result: CausalResult) -> str:
10361049
10371050 rank_label = _TOP_VARIANT_COLORS [vi ]["label" ] if vi < len (_TOP_VARIANT_COLORS ) else f"#{ vi + 1 } "
10381051 tracks .append ({
1039- "name" : f"{ aid } ({ rank_label } { top_s .variant_id } )" ,
1052+ "name" : f"{ display } ({ rank_label } { top_s .variant_id } )" ,
10401053 "type" : "merged" ,
10411054 "height" : 60 ,
10421055 "tracks" : [
10431056 {
10441057 "type" : "wig" ,
1045- "name" : f"{ aid } ref" ,
1058+ "name" : f"{ display } ref" ,
10461059 "color" : f"rgb({ _REF_COLOR } )" ,
10471060 ** scale_cfg ,
10481061 "features" : ref_feats ,
10491062 },
10501063 {
10511064 "type" : "wig" ,
1052- "name" : f"{ aid } alt" ,
1065+ "name" : f"{ display } alt" ,
10531066 "color" : f"rgb({ alt_rgb } )" ,
10541067 ** scale_cfg ,
10551068 "features" : alt_feats ,
@@ -1295,11 +1308,18 @@ def _build_causal_html(result: CausalResult) -> str:
12951308 ct_str = top_info .get ("cell_type" ) or "—"
12961309 desc = top_info .get ("description" ) or ""
12971310 asm = top_info .get ("assay_id" ) or ""
1311+ # Show enriched description (e.g. "CHIP:CEBPA:HepG2") as the
1312+ # primary track label; keep the raw assay_id in a secondary
1313+ # <code> tag for traceability. Matches the variant-report
1314+ # convention and avoids showing the raw AlphaGenome catalog
1315+ # ID as the user-facing track name.
1316+ primary_label = desc if desc else asm
12981317 p .append ('<p class="top-track-line">'
12991318 f'<b>Strongest track:</b> { html_mod .escape (layer_label )} '
1300- f'· <code >{ html_mod .escape (asm )} </code > '
1319+ f'· <b >{ html_mod .escape (primary_label )} </b > '
13011320 f'· cell type: <b>{ html_mod .escape (ct_str )} </b>'
1302- + (f' · { html_mod .escape (desc )} ' if desc else '' )
1321+ + (f' · <code>{ html_mod .escape (asm )} </code>'
1322+ if desc and asm and asm != desc else '' )
13031323 + (f' · <span class="formula-chip">{ formula } </span>' if formula else '' )
13041324 + '</p>' )
13051325
@@ -1327,17 +1347,23 @@ def _build_causal_html(result: CausalResult) -> str:
13271347 else ("#dc3545" if score < 0 else "#6c757d" ))
13281348 info = s .per_layer_top_track .get (layer , {}) or {}
13291349 assay = info .get ("assay_id" ) or "—"
1350+ desc = info .get ("description" ) or ""
1351+ # Prefer enriched description ("CHIP:CEBPA:HepG2") over
1352+ # raw assay_id so the table matches the variant-report
1353+ # convention. Fall back to the raw id when description
1354+ # is absent (older snapshots).
1355+ assay_display = desc if desc else assay
13301356 ct_val = info .get ("cell_type" ) or "—"
13311357 ref_v = info .get ("ref_value" )
13321358 alt_v = info .get ("alt_value" )
13331359 ref_str = f"{ ref_v :.3g} " if ref_v is not None else "—"
13341360 alt_str = f"{ alt_v :.3g} " if alt_v is not None else "—"
13351361 q = info .get ("quantile_score" )
1336- q_str = f" { q * 100 :+.1f } %" if q is not None else "—"
1362+ q_str = _fmt_percentile ( q ) if q is not None else "—"
13371363 p .append (f'<tr>'
13381364 f'<td>{ html_mod .escape (name )} </td>'
13391365 f'<td><span class="formula-chip">{ formula } </span></td>'
1340- f'<td><code> { html_mod .escape (str (assay ))} </code> </td>'
1366+ f'<td>{ html_mod .escape (str (assay_display ))} </td>'
13411367 f'<td>{ html_mod .escape (str (ct_val ))} </td>'
13421368 f'<td>{ ref_str } </td>'
13431369 f'<td>{ alt_str } </td>'
0 commit comments