Skip to content

Commit

Permalink
Ensure nuclear masks don't appear in cell table with updated ezSeg pi…
Browse files Browse the repository at this point in the history
…peline if nuclear_counts=False
  • Loading branch information
alex-l-kong committed Jan 18, 2024
1 parent f3391e5 commit b030d26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/ark/segmentation/marker_quantification.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,15 @@ def generate_cell_table(segmentation_dir, tiff_dir, img_sub_folder="TIFs",
whole_cell_file = fov_name + '_whole_cell.tiff'
nuclear_file = fov_name + '_nuclear.tiff'

# for each label given in the argument. read in that mask for the fov, and proceed with label and table appending
# for each label given in the argument, read in that mask for the fov, and proceed with
# label and table appending
mask_files = io_utils.list_files(segmentation_dir, substrs=fov_name)
mask_types = process_lists(fov_names=fovs, mask_names=mask_files)

# remove nuclear from mask_types if nuclear_counts False
if not nuclear_counts and "nuclear" in mask_types:
mask_types.remove("nuclear")

for mask_type in mask_types:
# load the segmentation labels in
fov_mask_name = fov_name + '_' + mask_type + ".tiff"
Expand Down
19 changes: 12 additions & 7 deletions tests/segmentation/marker_quantification_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,18 +735,20 @@ def test_generate_cell_table_tree_loading():
img_sub_folder=img_sub_folder, is_mibitiff=False, fovs=fovs_subset,
nuclear_counts=True)

assert norm_data_nuc.shape[0] == norm_data_fov_sub.shape[0]
# setting nuclear_counts True generates data for both whole_cell and nuclear
# so there should be double the number of rows
assert norm_data_nuc.shape[0] == norm_data_fov_sub.shape[0] * 2
assert norm_data_nuc.shape[1] == norm_data_fov_sub.shape[1] * 2
misc_utils.verify_in_list(
nuclear_col='nc_ratio',
nuc_cell_table_cols=norm_data_nuc.columns.values
)

assert arcsinh_data_nuc.shape[0] == arcsinh_data_fov_sub.shape[0]
assert arcsinh_data_nuc.shape[0] == arcsinh_data_fov_sub.shape[0] * 2
assert arcsinh_data_nuc.shape[1] == norm_data_fov_sub.shape[1] * 2
misc_utils.verify_in_list(
nuclear_col='nc_ratio',
nuc_cell_table_cols=norm_data_nuc.columns.values
nuc_cell_table_cols=arcsinh_data_nuc.columns.values
)


Expand Down Expand Up @@ -822,18 +824,20 @@ def test_generate_cell_table_mibitiff_loading():
img_sub_folder=tiff_dir, is_mibitiff=True, fovs=fovs_subset,
nuclear_counts=True)

assert norm_data_nuc.shape[0] == norm_data_fov_sub.shape[0]
# setting nuclear_counts True generates data for both whole_cell and nuclear
# so there should be double the number of rows
assert norm_data_nuc.shape[0] == norm_data_fov_sub.shape[0] * 2
assert norm_data_nuc.shape[1] == norm_data_fov_sub.shape[1] * 2
misc_utils.verify_in_list(
nuclear_col='nc_ratio',
nuc_cell_table_cols=norm_data_nuc.columns.values
)

assert arcsinh_data_nuc.shape[0] == arcsinh_data_fov_sub.shape[0]
assert arcsinh_data_nuc.shape[0] == arcsinh_data_fov_sub.shape[0] * 2
assert arcsinh_data_nuc.shape[1] == norm_data_fov_sub.shape[1] * 2
misc_utils.verify_in_list(
nuclear_col='nc_ratio',
nuc_cell_table_cols=norm_data_nuc.columns.values
nuc_cell_table_cols=arcsinh_data_nuc.columns.values
)


Expand Down Expand Up @@ -873,7 +877,8 @@ def test_generate_cell_table_extractions():

default_norm_data, _ = marker_quantification.generate_cell_table(
segmentation_dir=temp_dir, tiff_dir=tiff_dir,
img_sub_folder=img_sub_folder, is_mibitiff=False
img_sub_folder=img_sub_folder, is_mibitiff=False,
nuclear_counts=True
)

# verify total intensity extraction, same for whole_cell and nuclear mask types
Expand Down

0 comments on commit b030d26

Please sign in to comment.