Skip to content

Commit

Permalink
Add overlay visualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-l-kong committed Jul 22, 2021
1 parent dd23ddd commit d6fe88a
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 49 deletions.
41 changes: 15 additions & 26 deletions ark/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,44 +78,33 @@ def generate_cell_cluster_mask(fovs, base_dir, seg_dir, cell_consensus_name,
if not os.path.exists(seg_dir):
raise FileNotFoundError("seg_dir %s does not exist")

if not os.path.exists(os.path.join(base_dir, pixel_consensus_dir)):
if not os.path.exists(os.path.join(base_dir, cell_consensus_name)):
raise FileNotFoundError(
"consensus_dir %s does not exist in base_dir %s" % (pixel_consensus_dir, base_dir)
"consensus_dir %s does not exist in base_dir %s" % (cell_consensus_name, base_dir)
)

# load the consensus data in
cell_consensus_data = feather.read_dataframe(os.path.join(base_dir, cell_consensus_name))

# define the files for whole cell and nuclear
whole_cell_files = [fov + '_feature_0.tif' for fov in fovs]
nuclear_files = [fov + '_feature_1.tif' for fov in fovs]
# nuclear_files = [fov + '_feature_1.tif' for fov in fovs]

# load the segmentation labels in
current_labels_cell = load_utils.load_imgs_from_dir(data_dir=seg_dir,
files=whole_cell_files,
xr_dim_name='compartments',
xr_channel_names=['whole_cell'],
trim_suffix='_feature_0',
force_ints=True)

current_labels_nuc = load_utils.load_imgs_from_dir(data_dir=seg_dir,
files=nuclear_files,
xr_dim_name='compartments',
xr_channel_names=['nuclear'],
trim_suffix='_feature_1',
force_ints=True)

current_labels = xr.DataArray(np.concatenate((current_labels_cell.values,
current_labels_nuc.values),
axis=-1),
coords=[current_labels_cell.fovs,
current_labels_cell.rows,
current_labels_cell.cols,
['whole_cell', 'nuclear']],
dims=current_labels_cell.dims)
label_maps = load_utils.load_imgs_from_dir(data_dir=seg_dir,
files=whole_cell_files,
xr_dim_name='compartments',
xr_channel_names=['whole_cell'],
trim_suffix='_feature_0',
force_ints=True)

# use label_cells_by_cluster to create cell masks
return label_cells_by_cluster(fovs, cell_consensus_data, label_maps, cluster_column=cluster_col)
img_data = label_cells_by_cluster(
fovs, cell_consensus_data, label_maps, fov_col='fov',
cell_label_column='segmentation_label', cluster_column=cluster_col
)

return img_data


def generate_pixel_cluster_mask(fovs, base_dir, seg_dir, pixel_consensus_dir,
Expand Down
8 changes: 8 additions & 0 deletions ark/utils/data_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,11 @@ def test_label_cells_by_cluster():
# all pixels in fov2 should remain non-zero
labeled_img = res_xr[res_xr['fovs'] == fovs[2]].values.squeeze()
assert np.all(labeled_img[idx] > 0)


def test_generate_cell_cluster_mask():
pass


def test_generate_pixel_cluster_mask():
pass
150 changes: 127 additions & 23 deletions templates/example_pixel_cell_clustering.ipynb

Large diffs are not rendered by default.

0 comments on commit d6fe88a

Please sign in to comment.