Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions alldata/bblab_site/tools/isoforms_plot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,14 @@
}

.results-section {
background: white;
background: #fafafa;
padding: 30px;
margin: 40px auto 30px auto;
box-shadow: 0 4px 20px rgba(86, 171, 47, 0.15);
border: 2px solid #56ab2f;
border-radius: 12px;
/* Wider than normal sections but scales with zoom */
width: calc(80% - 40px);
max-width: 1800px;
width: calc(min(1800px, max(80% - 40px, 900px)));
}

.results-section h2 {
Expand All @@ -226,12 +225,11 @@
}

.results-content-wrapper {
max-width: 900px;
margin: 0 auto;
}

.plot-container {
background: #fafafa;
background: white;
padding: 15px;
margin: 20px;
text-align: center;
Expand Down
16 changes: 10 additions & 6 deletions alldata/bblab_site/tools/isoforms_plot/isoforms_plot/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- resolve "end" (None) to END_POS
"""

from collections import Counter
from collections import Counter, defaultdict
from dataclasses import dataclass
from typing import Literal, Optional, Sequence, Tuple

Expand Down Expand Up @@ -164,14 +164,18 @@ def compile_transcripts(
# Build groups structure
# Preserve order of first appearance
groups_order = []
seen = set()
group_counts = defaultdict(int)
last_group = None
last_group_count = 0
for transcript in parsed_transcripts:
if transcript.group not in seen:
if transcript.group != last_group:
group_counts[last_group] = last_group_count
last_group = transcript.group
groups_order.append(transcript.group)
seen.add(transcript.group)
last_group_count = 0
last_group_count += 1

# Count transcripts per group
group_counts = Counter(t.group for t in parsed_transcripts)
group_counts[last_group] = last_group_count # for the final group

# Build groups list
compiled_groups = [
Expand Down
94 changes: 44 additions & 50 deletions alldata/bblab_site/tools/isoforms_plot/isoforms_plot/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,54 +624,7 @@ def plot(transcripts, groups, splicing_sites, title=None) -> draw.Drawing:
if lineheight > 5:
lineheight = 5

# Calculate total height of all groups for dotted lines
# First, we need to determine the height of each group
total_groups_height = 0.0
transcript_index = 0
for group in groups:
group_size = group.size

# Calculate height for this group
group_height = 0.0
for i in range(group_size):
if transcript_index >= len(transcripts):
break
transcript = transcripts[transcript_index]
label = transcript.label

if i > 0:
group_height += 3 # gap between transcripts
if label:
group_height += lineheight + 9 + 6 # 9 is font_size from GroupWithTranscripts
else:
group_height += lineheight

transcript_index += 1

# Add group height
total_groups_height += group_height

# Add initial gap and extra padding
total_groups_height += 30 + 25 + 50 # 25 is initial gap, 50 is extra padding

# Add title at the top if title is not None
if title is not None:
figure.add(Title(title), gap=10)

# add genome overview at the top of the figure so it appears above sample tracks
add_genome_overview(figure, LANDMARKS)
# add splicing sites display below the genome overview with calculated height
figure.add(SplicingSites(splicing_sites, total_samples=total_samples, lineheight=lineheight,
total_height=total_groups_height), gap=5)
# add a small blank multitrack to create vertical separation between the splicing sites
# and the sample tracks (gap value tuned to avoid overlap with multi-level labels)
try:
figure.add(Multitrack([Track(START_POS + XOFFSET, START_POS + XOFFSET, color='#ffffff', h=2)]), gap=25)
except TypeError:
# fallback if Track signature differs; attempt without named color
figure.add(Multitrack([Track(START_POS + XOFFSET, START_POS + XOFFSET, color='#ffffff', h=2)]), gap=25)

# Draw each transcript from transcripts variable, organized by groups
# Build all group components first to get their exact heights
default_color = 'grey'
max_comment_width = 0.0
comment_font_size = 8
Expand All @@ -680,7 +633,8 @@ def plot(transcripts, groups, splicing_sites, title=None) -> draw.Drawing:
if aggregate_group_size != len(transcripts):
raise RuntimeError(f"Bad group sizes: {aggregate_group_size} != {len(transcripts)}")

transcript_index = 0 # Track position in transcripts list
transcript_index = 0
group_components = []

for group in groups:
group_name = group.name
Expand All @@ -706,8 +660,48 @@ def plot(transcripts, groups, splicing_sites, title=None) -> draw.Drawing:
transcripts_data.insert(0, (parts, color, label, comment))
transcript_index += 1

# Create and add the group component (contains vertical line and all transcripts)
# Create the group component
group_component = GroupWithTranscripts(group_name, transcripts_data, lineheight=lineheight)
group_components.append(group_component)

# Calculate total height for dotted lines using actual component heights
# Dotted lines start at the baseline (line_y) within SplicingSites component
# and extend downward through all components that come after
total_dotted_height = 0.0

# Gap after SplicingSites
total_dotted_height += 5

# Multitrack spacer (gap + height)
total_dotted_height += 25 # gap before multitrack
total_dotted_height += 2 # multitrack height

# Add all group heights and their gaps
for i, group_comp in enumerate(group_components):
total_dotted_height += 30 # gap before each group
total_dotted_height += group_comp.h # actual height of the group

total_dotted_height += 1 # extra padding at the bottom to ensure lines extend beyond last group

# Add title at the top if title is not None
if title is not None:
figure.add(Title(title), gap=10)

# add genome overview at the top of the figure so it appears above sample tracks
add_genome_overview(figure, LANDMARKS)
# add splicing sites display below the genome overview with calculated height
figure.add(SplicingSites(splicing_sites, total_samples=total_samples, lineheight=lineheight,
total_height=total_dotted_height), gap=5)
# add a small blank multitrack to create vertical separation between the splicing sites
# and the sample tracks (gap value tuned to avoid overlap with multi-level labels)
try:
figure.add(Multitrack([Track(START_POS + XOFFSET, START_POS + XOFFSET, color='#ffffff', h=2)]), gap=25)
except TypeError:
# fallback if Track signature differs; attempt without named color
figure.add(Multitrack([Track(START_POS + XOFFSET, START_POS + XOFFSET, color='#ffffff', h=2)]), gap=25)

# Add all pre-created group components to the figure
for group_component in group_components:
figure.add(group_component, gap=30)

# Calculate figure width to accommodate comments
Expand Down
14 changes: 7 additions & 7 deletions alldata/bblab_site/tools/isoforms_plot/test_isoforms.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ My Isoforms Plot Title

[transcripts]
fragments,label,comment,group
1-743; 4913-end,vif,(3),My Group 1
1-743; 5390-end,vpr,(15),My Group 1
1-743; 4913-4962; 5390-end,vpr,(4),My Group 1
1-743; 5390-5463; 5976-end,vpu/env,(4),My Group 1
1-743; 5976-end,vpu/env,(1),My Group 1
1-743; 4913-4962; 5390-5463; 5976-end,vpu/env,(1),My Group 1
1-743; 5390-5463; 5976-6046; 8369-end,nef,(14),My Group 1
1-743; 4913-end,vif,(3),My First Group
1-743; 5390-end,vpr,(15),My First Group
1-743; 4913-4962; 5390-end,vpr,(4),My First Group
1-743; 5390-5463; 5976-end,vpu/env,(4),My First Group
1-743; 5976-end,vpu/env,(1),My First Group
1-743; 4913-4962; 5390-5463; 5976-end,vpu/env,(1),My First Group
1-743; 5390-5463; 5976-6046; 8369-end,nef,(14),My First Group
1-743; 4913-4962; 5390-5463; 5976-6046; 8369-end,nef,(7)
1-743; 5976-6046; 8369-end,nef,(6)
1-710; 5976-6046; 8369-end,nef,(2)
Expand Down