From 68b2ad3a4a6c5926b1051f65995427a47798cb58 Mon Sep 17 00:00:00 2001 From: TimMonko <47310455+TimMonko@users.noreply.github.com> Date: Sun, 22 Dec 2024 22:54:06 -0600 Subject: [PATCH] add leading zeroes to measure_props --- src/napari_ndev/_tests/test_measure.py | 2 +- src/napari_ndev/measure.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/napari_ndev/_tests/test_measure.py b/src/napari_ndev/_tests/test_measure.py index 5590b98..c7b472d 100644 --- a/src/napari_ndev/_tests/test_measure.py +++ b/src/napari_ndev/_tests/test_measure.py @@ -187,7 +187,7 @@ def test_map_tx_dict_to_df_id_col(): } ) id_column = 'well' - result = _map_tx_dict_to_df_id_col(tx, tx_n_well, target_df, id_column) + result = _map_tx_dict_to_df_id_col(tx, tx_n_well, False, target_df, id_column) assert isinstance(result, pd.DataFrame) assert 'Treatment1' in result.columns assert 'Treatment2' in result.columns diff --git a/src/napari_ndev/measure.py b/src/napari_ndev/measure.py index c751219..a207978 100644 --- a/src/napari_ndev/measure.py +++ b/src/napari_ndev/measure.py @@ -22,7 +22,7 @@ from napari_ndev._plate_mapper import PlateMapper -__all__ = ['measure_regionprops', 'group_and_agg_measurements'] +__all__ = ['group_and_agg_measurements', 'measure_regionprops'] def measure_regionprops( label_images: list[ArrayLike] | ArrayLike, @@ -36,6 +36,7 @@ def measure_regionprops( tx_id: str | None = None, tx_dict: dict | None = None, tx_n_well: int | None = None, + tx_leading_zeroes: bool = False, save_data_path: PathLike = None, ) -> pd.DataFrame: """ @@ -88,6 +89,8 @@ def measure_regionprops( The treatment dictionary. tx_n_well : int or None, optional The number of wells in the plate. + tx_leading_zeroes : bool, optional + Whether to use leading zeroes in the plate map. save_data_path : PathLike or None, optional The path to save the data. @@ -145,7 +148,7 @@ def measure_regionprops( measure_df.insert(2, key, value) if tx_id is not None and tx_dict is not None: - _map_tx_dict_to_df_id_col(tx_dict, tx_n_well, measure_df, tx_id) + _map_tx_dict_to_df_id_col(tx_dict, tx_n_well, tx_leading_zeroes, measure_df, tx_id) if save_data_path is not None: measure_df.to_csv(save_data_path, index=False) @@ -354,6 +357,7 @@ def _rename_intensity_columns(df: pd.DataFrame, intensity_names: list[str]): def _map_tx_dict_to_df_id_col( tx: dict | None = None, tx_n_well: int | None = None, + tx_leading_zeroes: bool = False, df: pd.DataFrame = None, id_column: str | None = None, ): @@ -368,6 +372,8 @@ def _map_tx_dict_to_df_id_col( The dictionary of treatments. tx_n_well : int or None, optional The number of wells in the plate. + tx_leading_zeroes : bool, optional + Whether to use leading zeroes in the plate map. Default is False. df : pd.DataFrame The DataFrame to map treatments to. id_column : str or None, optional @@ -380,7 +386,7 @@ def _map_tx_dict_to_df_id_col( """ if isinstance(tx_n_well, int): - plate = PlateMapper(tx_n_well) + plate = PlateMapper(tx_n_well, leading_zeroes=tx_leading_zeroes) plate.assign_treatments(tx) tx_map = plate.plate_map.set_index('well_id').to_dict(orient='index') else: