@@ -373,7 +373,10 @@ def build_background(args: argparse.Namespace) -> int:
373373
374374
375375def rows_for_plot (
376- args : argparse .Namespace , region : Interval , background_summary : BackgroundSummary
376+ args : argparse .Namespace ,
377+ region : Interval ,
378+ background_summary : BackgroundSummary ,
379+ transcript : TranscriptAnnotation | None = None ,
377380) -> list [dict [str , object ]]:
378381 """Join one sample with the background for plotting."""
379382 counts = parse_read_counts (args .read_counts )
@@ -413,6 +416,9 @@ def rows_for_plot(
413416 "bg_upper_norm" : bg_upper ,
414417 "background_n" : int (bg ["N" ]),
415418 }
419+ row ["overlaps_exon" ] = transcript is None or any (
420+ overlaps (interval [1 ], interval [2 ], exon .start , exon .end ) for exon in transcript .exons
421+ )
416422 row ["signal" ] = log2_ratio (sample_value , bg_median , 0.01 )
417423 row ["signal_lower" ] = log2_ratio (bg_lower , bg_median , 0.01 )
418424 row ["signal_upper" ] = log2_ratio (bg_upper , bg_median , 0.01 )
@@ -505,7 +511,9 @@ def y_for(value: float) -> float:
505511 ".grid { stroke: #d8dee4; stroke-width: 1; }" ,
506512 ".ribbon { fill: #c8d2df; opacity: 0.85; }" ,
507513 ".sample { fill: none; stroke: #127c78; stroke-width: 2.2; }" ,
508- ".point { fill: #127c78; stroke: white; stroke-width: 1.2; }" ,
514+ ".point { stroke-width: 1.6; }" ,
515+ ".point-filled { fill: #127c78; stroke: white; }" ,
516+ ".point-open { fill: white; stroke: #127c78; }" ,
509517 ".baseline { stroke: #5b6472; stroke-width: 2; stroke-dasharray: 6 5; }" ,
510518 ".highlight-band { fill: #f59e0b; opacity: 0.28; stroke: #b45309; stroke-width: 1.1; }" ,
511519 ".panel { fill: #ffffff; stroke: #d8dee4; stroke-width: 1.2; }" ,
@@ -564,8 +572,9 @@ def y_for(value: float) -> float:
564572 f"SIGNAL={ fmt (float (row ['signal' ]))} \n "
565573 f"BACKGROUND_N={ row ['background_n' ]} "
566574 )
575+ point_class = "point point-filled" if bool (row ["overlaps_exon" ]) else "point point-open"
567576 elements .append (
568- f'<circle class="point " cx="{ x :.2f} " cy="{ y :.2f} " r="4.8">'
577+ f'<circle class="{ point_class } " cx="{ x :.2f} " cy="{ y :.2f} " r="4.8">'
569578 f"<title>{ html .escape (title_text )} </title></circle>"
570579 )
571580
@@ -770,12 +779,10 @@ def add_arrow(x_pos: float) -> None:
770779 elements [3 ] = f'<rect class="panel" x="{ panel_x } " y="{ panel_y } " width="{ panel_width } " height="{ panel_h } "/>'
771780 elements .extend (
772781 [
773- f'<rect x="{ panel_x + 16 } " y="{ legend_y - 13 } " width="15" height="15" fill="#c8d2df" opacity="0.85"/>' ,
774- f'<text class="panel-text" x="{ panel_x + 40 } " y="{ legend_y } ">background</text>' ,
775- f'<line x1="{ panel_x + 16 } " y1="{ legend_y + 23 } " x2="{ panel_x + 34 } " y2="{ legend_y + 23 } " stroke="#5b6472" stroke-width="2" stroke-dasharray="6 5"/>' ,
776- f'<text class="panel-text" x="{ panel_x + 40 } " y="{ legend_y + 27 } ">expected baseline</text>' ,
777- f'<circle class="point" cx="{ panel_x + 24 } " cy="{ legend_y + 48 } " r="5"/>' ,
778- f'<text class="panel-text" x="{ panel_x + 40 } " y="{ legend_y + 52 } ">sample signal</text>' ,
782+ f'<circle class="point point-filled" cx="{ panel_x + 24 } " cy="{ legend_y } " r="5"/>' ,
783+ f'<text class="panel-text" x="{ panel_x + 40 } " y="{ legend_y + 4 } ">Overlaps exon</text>' ,
784+ f'<circle class="point point-open" cx="{ panel_x + 24 } " cy="{ legend_y + 24 } " r="5"/>' ,
785+ f'<text class="panel-text" x="{ panel_x + 40 } " y="{ legend_y + 28 } ">Outside exon</text>' ,
779786 "</svg>" ,
780787 ]
781788 )
@@ -793,7 +800,7 @@ def plot_sample(args: argparse.Namespace) -> int:
793800 region = (transcript .contig , transcript .start , transcript .end )
794801
795802 background_summary = parse_background (args .background )
796- rows = rows_for_plot (args , region , background_summary )
803+ rows = rows_for_plot (args , region , background_summary , transcript = transcript )
797804 if not rows :
798805 raise SystemExit ("No intervals with background statistics overlap the selected region." )
799806
0 commit comments