Skip to content

Commit c54ee95

Browse files
committed
updated
1 parent 65800e3 commit c54ee95

4 files changed

Lines changed: 173 additions & 161 deletions

File tree

fishplotpy/data.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,15 @@ def _validate_inputs(self):
327327
current_time_fracs = self.frac_table.iloc[:, time_idx].values
328328

329329
calculated_nest_levels = self.nest_level # Get the calculated levels
330-
# print(f"DEBUG: Time {time_idx}, Nest Levels: {calculated_nest_levels}") # Add this
330+
# print(f"DEBUG: Time {time_idx}, Nest Levels: {calculated_nest_levels}"
331331
for level in np.unique(calculated_nest_levels):
332332
level_mask = calculated_nest_levels == level
333333
level_clones_indices = np.where(level_mask)[0] # 0-based indices
334334
level_sum = current_time_fracs[level_mask].sum()
335-
# print(f"DEBUG: Time {time_idx}, Level {level}, Clones(0-based): {level_clones_indices}, Sum: {level_sum}") # Add this
335+
# print(f"DEBUG: Time {time_idx}, Level {level}, Clones(0-based): {level_clones_indices}, Sum: {level_sum}")
336336
if level_sum > 100.0 + tolerance:
337337
level_clones_one_based = level_clones_indices + 1
338-
# print(f"ERROR Triggered: Clones {level_clones_one_based}, Level {level}, Sum {level_sum}") # Add this
338+
# print(f"ERROR Triggered: Clones {level_clones_one_based}, Level {level}, Sum {level_sum}")
339339
raise ValueError(
340340
f"Clones {list(level_clones_one_based)} with nest level {level} sum to "
341341
f"{level_sum:.2f} (> 100) at timepoint {time_idx} (value {self.timepoints[time_idx]})."
@@ -524,8 +524,6 @@ def layout_clones(self, separate_independent_clones: bool = False):
524524
else: # Handling subclones (parent_1based > 0)
525525
parent_0based = parent_1based - 1
526526
# Start at the bottom coordinate of the parent
527-
# If parent fraction is 0, parent ybtm is NaN - need fallback?
528-
# If parent absent, start from 0? R seems to imply start from ybtm[parent]
529527
# If parent ybtm[parent_0based, time_idx] is NaN, this will propagate NaN.
530528
current_y = ybtm_matrix[parent_0based, time_idx]
531529

@@ -575,7 +573,7 @@ def layout_clones(self, separate_independent_clones: bool = False):
575573
# Deferring this precise logic for now to get core layout working.
576574
# It might be better handled during shape generation (spline/polygon).
577575

578-
# --- Finalize Coordinates (Convert to lists, remove NaNs) ---
576+
# --- Finalize Coordinates ---
579577
final_xpos = []
580578
final_ytop = []
581579
final_ybtm = []

fishplotpy/plot.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ def _annot_clone(ax: plt.Axes, x: float, y: float, annot: str,
4242
# Let's assume cex is a multiplier for a default reasonable size e.g., 8
4343
fontsize = plt.rcParams['font.size'] * cex # Scale default font size
4444

45-
# Basic offset implementation:
46-
# Calculate offset in display coordinates (pixels) and convert back? Simpler:
47-
# Approximate offset in data coordinates based on position.
48-
# This is a rough heuristic. A fixed pixel offset would be more robust but complex.
49-
# Let's use a fraction of axis range as offset unit.
45+
# Basic offset implementation (use a fraction of axis range as offset unit)
5046
x_range = ax.get_xlim()[1] - ax.get_xlim()[0]
5147
y_range = ax.get_ylim()[1] - ax.get_ylim()[0]
5248
offset_scale_x = x_range * 0.01 # Scale offset relative to x-axis range
@@ -68,15 +64,16 @@ def _annot_clone(ax: plt.Axes, x: float, y: float, annot: str,
6864
# Outline with white, adjust linewidth as needed
6965
path_effects = [pe.withStroke(linewidth=1.5, foreground='white')]
7066

71-
ax.text(x + x_off, y + y_off, annot, # Apply offset
72-
ha=ha, va=va,
73-
rotation=angle,
74-
color=col,
75-
fontsize=fontsize,
76-
rotation_mode='anchor', # Rotate around the anchor point (ha/va)
77-
transform=ax.transData,
78-
path_effects=path_effects # Add path effects
79-
)
67+
ax.text(
68+
x + x_off, y + y_off, annot, # Apply offset
69+
ha=ha, va=va,
70+
rotation=angle,
71+
color=col,
72+
fontsize=fontsize,
73+
rotation_mode='anchor', # Rotate around the anchor point (ha/va)
74+
transform=ax.transData,
75+
path_effects=path_effects # Add path effects
76+
)
8077

8178

8279
def _draw_clust_polygon(ax: plt.Axes, xpos: np.ndarray, ytop: np.ndarray, ybtm: np.ndarray,
@@ -197,9 +194,7 @@ def _draw_clust_spline(ax: plt.Axes, xpos: np.ndarray, ytop: np.ndarray, ybtm: n
197194
print("Skipping drawing for clone with no timepoints.") # Mimic R warning
198195
return
199196
if len(xpos) < 2:
200-
# Cannot draw spline with < 2 points, draw as polygon?
201-
# Or just skip/draw a point? R's spline might handle this.
202-
# For now, draw simple polygon if only 1 point.
197+
# draw simple polygon if only 1 point
203198
if len(xpos) == 1:
204199
_draw_clust_polygon(ax, xpos, ytop, ybtm, color, nest_level, pad_left,
205200
border, col_border, ramp_angle=0.5, # Use default ramp

tests/test_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ def test_init_valid_data(valid_input_data):
3939
# Check defaults
4040
assert fp_data.clone_labels == ['1', '2', '3']
4141
assert fp_data.clone_annots == ['', '', '']
42-
assert len(fp_data.colors) == 3 # Should have assigned default colors
42+
assert len(fp_data.colors) == 3 # Should have assigned default colors
4343

4444

4545
def test_init_mismatched_parents_length():
4646
"""Test error if len(parents) != num_clones."""
4747
with pytest.raises(ValueError, match="Length of parents must equal"):
48-
FishPlotData(frac_table=VALID_FRACS, parents=[0, 1]) # Too short
48+
FishPlotData(frac_table=VALID_FRACS, parents=[0, 1])
4949

5050

5151
def test_init_mismatched_timepoints_length():
5252
"""Test error if len(timepoints) != num_timepoints."""
5353
with pytest.raises(ValueError, match="Length of timepoints must equal"):
54-
FishPlotData(frac_table=VALID_FRACS, parents=VALID_PARENTS, timepoints=[0, 50]) # Too short
54+
FishPlotData(frac_table=VALID_FRACS, parents=VALID_PARENTS, timepoints=[0, 50])
5555

5656

5757
def test_init_invalid_parent_index_negative():
@@ -63,7 +63,7 @@ def test_init_invalid_parent_index_negative():
6363
def test_init_invalid_parent_index_too_large():
6464
"""Test error if parents index > num_clones."""
6565
with pytest.raises(ValueError, match="greater than the number of clones"):
66-
FishPlotData(frac_table=VALID_FRACS, parents=[0, 1, 4]) # Parent 4 invalid
66+
FishPlotData(frac_table=VALID_FRACS, parents=[0, 1, 4]) # Parent 4 invalid
6767

6868

6969
def test_init_non_numeric_fracs():
@@ -79,7 +79,7 @@ def test_init_non_numeric_fracs():
7979
def test_validation_clone_reappearance_error():
8080
"""Test error when a clone reappears after being zero."""
8181
fracs = pd.DataFrame([
82-
[10, 0, 10], # Clone 1 reappears
82+
[10, 0, 10], # Clone 1 reappears
8383
[90, 100, 90]
8484
])
8585
parents = [0, 0]

0 commit comments

Comments
 (0)