Skip to content

Commit 5b57939

Browse files
Minor polish
- (minor) transform_coordinate now returns a tuple instead of a list, preventing potential silent mutation of cached results via @lru_cache - minor code quality fixes — corrected `Optional` return type annotation, replaced `raise e` with bare `raise`, fixed some docstrings, and replaced hardcoded plate dimension magic numbers with constants
1 parent 438cfb9 commit 5b57939

22 files changed

Lines changed: 68 additions & 64 deletions

config/loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# Description: Various supplementary utilities related to reading the config file
1717
#
1818
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
19-
# Version: 1.3.4
20-
# Last Revision: March 2026
19+
# Version: 1.3.5
20+
# Last Revision: April 2026
2121
#
2222

2323

controllers/csv_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# Coordinates file selection and writing through native dialog interfaces.
2121
#
2222
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
23-
# Version: 1.3.4
24-
# Last Revision: March 2026
23+
# Version: 1.3.5
24+
# Last Revision: April 2026
2525
#
2626

2727
import logging

controllers/dzn_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# Handles validation and generation of DZN files.
1818
#
1919
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
20-
# Version: 1.3.4
21-
# Last Revision: March 2026
20+
# Version: 1.3.5
21+
# Last Revision: April 2026
2222
#
2323

2424
import logging

controllers/main_controller.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# Orchestrates main window operations and coordinates other controllers.
1818
#
1919
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
20-
# Version: 1.3.4
21-
# Last Revision: March 2026
20+
# Version: 1.3.5
21+
# Last Revision: April 2026
2222
#
2323

2424
import logging
@@ -78,7 +78,7 @@ def parse_dzn_file(self, path: str) -> Tuple[str, str, str]:
7878
path: Path to DZN file
7979
8080
Returns:
81-
Tuple of (num_cols, num_rows, control_names) as strings
81+
Tuple of (num_rows, num_cols, control_names) as strings (in this specific order)
8282
8383
Raises:
8484
FileNotFoundError: If DZN file doesn't exist
@@ -91,15 +91,15 @@ def parse_dzn_file(self, path: str) -> Tuple[str, str, str]:
9191
self.state.num_cols = cols
9292
self.state.control_names = controls
9393
self.state.dzn_file_path = path
94-
return (cols, rows, controls)
94+
return (rows, cols, controls)
9595
except FileNotFoundError as e:
9696
logger.error(f"DZN file not found: {path}")
9797
raise
9898
except Exception as e:
9999
logger.error(f"Failed to parse DZN file: {e}")
100100
raise ValueError(f"Invalid DZN file format: {e}") from e
101101

102-
def load_csv_file(self, path: str) -> CsvDiagnostics:
102+
def load_csv_file(self, path: str) -> Optional[CsvDiagnostics]:
103103
"""
104104
Load CSV file and update application state, and return consistency diagnostics.
105105
@@ -109,6 +109,9 @@ def load_csv_file(self, path: str) -> CsvDiagnostics:
109109
110110
Args:
111111
path: Path to CSV file to load
112+
113+
Returns:
114+
CsvDiagnostics or None
112115
113116
Raises:
114117
FileNotFoundError: If CSV file doesn't exist

controllers/minizinc_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# Handles running constraint programming models and processing output.
1818
#
1919
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
20-
# Version: 1.3.4
21-
# Last Revision: March 2026
20+
# Version: 1.3.5
21+
# Last Revision: April 2026
2222
#
2323

2424
import logging

controllers/viz_controller.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# Orchestrates data preparation and figure generation for plate layouts.
1818
#
1919
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
20-
# Version: 1.3.4
21-
# Last Revision: March 2026
20+
# Version: 1.3.5
21+
# Last Revision: April 2026
2222
#
2323

2424
import logging
@@ -32,7 +32,7 @@
3232
from core.io_utils import read_csv_file
3333
from core.layout_utils import find_all_plates_concentrations
3434
from core.layout_utils import transform_concentrations_to_alphas
35-
from models.constants import Visualization, Performance, FigureProperties
35+
from models.constants import PlateDefaults, Visualization, Performance, FigureProperties
3636

3737
logger = logging.getLogger(__name__)
3838

@@ -228,9 +228,9 @@ def plot_plate_wells(self, ax, plate_data: List, viz_state: VisualizationState)
228228

229229
for well in materials[material]:
230230
if is_switched:
231-
[y_coord, x_coord] = transform_coordinate(well[0])
231+
y_coord, x_coord = transform_coordinate(well[0])
232232
else:
233-
[x_coord, y_coord] = transform_coordinate(well[0])
233+
x_coord, y_coord = transform_coordinate(well[0])
234234

235235
x_coords.append(x_coord + Visualization.WELL_COORDINATE_OFFSET)
236236
y_coords.append(y_coord + Visualization.WELL_COORDINATE_OFFSET)
@@ -361,10 +361,11 @@ def _concentration_to_size(
361361
"""
362362
from core.layout_utils import to_number_if_possible
363363

364-
# if the plate differs from 16x24 then we need to readjust the size ranges
364+
# if the plate differs from 24x16 then we need to readjust the size ranges
365365
# We do not increase more than 1 / 0.7 to keep the marker size reasonable
366+
# NOTE: we use the reoriented grid, thus PlateDefaults.COLS and PlateDefaults.ROWS are swapped
366367
plate_num_rows, plate_num_cols, _ = self._resolve_orientation(plate_num_rows, plate_num_cols)
367-
ratio = max(0.7, plate_num_rows / 24, plate_num_cols / 16)
368+
ratio = max(0.7, plate_num_rows / int(PlateDefaults.COLS), plate_num_cols / int(PlateDefaults.ROWS))
368369

369370
# Get size range from constants
370371
size_min = math.floor(Visualization.CONCENTRATION_SIZE_MIN / ratio)
@@ -451,7 +452,7 @@ def _generate_colors(self, concentrations_list: Dict[str, List[Any]]) -> Dict[st
451452
return material_colors
452453

453454
def _resolve_orientation(self, num_rows: int, num_cols: int) -> Tuple[int, int, bool]:
454-
"""Return (effective_rows, effective_cols, is_switched).
455+
"""Return (num_rows, num_cols, is_switched).
455456
456457
MPLACE convention: wider dimension is always horizontal (x-axis).
457458
If num_cols > num_rows the axes are swapped for display.

core/csv_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# Description: Validation of CSV files on loading
1717
#
1818
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
19-
# Version: 1.3.4
20-
# Last Revision: March 2026
19+
# Version: 1.3.5
20+
# Last Revision: April 2026
2121
#
2222
import logging
2323
from typing import List, Optional

core/dzn_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# Description: Various supplementary utilities related to DZN parsing
1717
#
1818
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
19-
# Version: 1.3.4
20-
# Last Revision: March 2026
19+
# Version: 1.3.5
20+
# Last Revision: April 2026
2121
#
2222

2323
import re

core/dzn_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# Description: DZN text generation logic
1717
#
1818
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
19-
# Version: 1.3.4
20-
# Last Revision: March 2026
19+
# Version: 1.3.5
20+
# Last Revision: April 2026
2121
#
2222

2323
from models.dto import DznBuildParams, ValidationVerdict

core/io_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# Description: Various supplementary utilities related to I/O operations
1717
#
1818
# Authors: Ramiz GINDULLIN (ramiz.gindullin@it.uu.se)
19-
# Version: 1.3.4
20-
# Last Revision: March 2026
19+
# Version: 1.3.5
20+
# Last Revision: April 2026
2121
#
2222

2323

@@ -140,7 +140,7 @@ def read_csv_file(file_path: str) -> List[str]:
140140
return layout_text_array
141141
except (ValueError) as e:
142142
logger.error(f"Failed to read CSV file: {file_path}, error: {e}")
143-
raise e
143+
raise
144144
except (FileNotFoundError, IOError) as e:
145145
logger.error(f"Failed to read CSV file: {file_path}, error: {e}")
146146
raise FileNotFoundError(f"Could not read CSV file: {file_path}") from e
@@ -279,7 +279,7 @@ def scan_csv_plater_matrices(layout_text_array: List[str]) -> Tuple[int, int, Li
279279
logger.info('Concentrations:')
280280
for line in concentrations_matrix:
281281
logger.info(line)
282-
raise ValueError(f'Drug and concentration layouts of Plater file have mismatched number of rows: {rows} and {len(concentrations_matrix)}')
282+
raise ValueError(f'Drug and concentration layouts of Plater file have mismatched number of rows: {len(rows)} and {len(concentrations_matrix)}')
283283

284284
return rows, cols, drugs_matrix, concentrations_matrix
285285

@@ -361,7 +361,7 @@ def convert_pharmbio_to_plater_plate(input_data: CSVConversionRequest) -> str:
361361
input_data: CSVConversionRequest() object containing all input data
362362
363363
Returns:
364-
List of CSV lines compatible with Plater R-package
364+
CSV rows compatible with Plater R-package as a single string
365365
"""
366366
rows = int(input_data.rows)
367367
cols = int(input_data.cols)
@@ -382,7 +382,7 @@ def convert_pharmbio_to_plater_plate(input_data: CSVConversionRequest) -> str:
382382
concentration_matrix[0][i] = str(i)
383383

384384
for line in lines:
385-
x,y = transform_coordinate(line[0])
385+
x, y = transform_coordinate(line[0])
386386
drugs_matrix[x+1][y+1] = line[1]
387387
concentration_matrix[x+1][y+1] = line[2]
388388

0 commit comments

Comments
 (0)