Skip to content

Commit

Permalink
Merge pull request #139 from TimMonko/plate-map-leading0s
Browse files Browse the repository at this point in the history
add leading zeroes to measure_props
  • Loading branch information
TimMonko authored Dec 23, 2024
2 parents e1aa01b + 68b2ad3 commit 767893d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/napari_ndev/_tests/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/napari_ndev/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
):
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 767893d

Please sign in to comment.