Skip to content

Commit

Permalink
Clarify comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-l-kong committed Jan 22, 2022
1 parent f2902b6 commit b4c0319
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ark/phenotyping/som_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ def test_apply_cell_meta_cluster_remapping():
os.path.join(temp_dir, 'sample_cell_som_cluster_chan_avgs.csv'), index=False
)

# since the equivalent weighted channel table for meta clusters will be overwritten
# since the equivalent average weighted channel table for meta clusters will be overwritten
# just make it a blank slate
pd.DataFrame().to_csv(
os.path.join(temp_dir, 'sample_cell_meta_cluster_chan_avgs.csv'), index=False
Expand Down
14 changes: 7 additions & 7 deletions ark/utils/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def plot_pixel_cell_cluster_overlay(img_xr, fovs, cluster_id_to_name_path, metac
# verify cluster_id_to_name_path exists
if not os.path.exists(cluster_id_to_name_path):
raise FileNotFoundError(
'Cluster to name mapping %s does not exist' % cluster_id_to_name_path
'Metacluster id to renamed metacluster mapping %s does not exist' %
cluster_id_to_name_path
)

# read the cluster to name mapping
Expand All @@ -127,11 +128,11 @@ def plot_pixel_cell_cluster_overlay(img_xr, fovs, cluster_id_to_name_path, metac

# assert the metacluster index in colors matches with the ids in metacluster_id_to_name
verify_same_elements(
colors_metacluster_index=list(metacluster_colors.keys()),
metacluster_ids=metacluster_id_to_name['metacluster'].values
metacluster_colors_ids=list(metacluster_colors.keys()),
metacluster_mapping_ids=metacluster_id_to_name['metacluster'].values
)

# sort the colors Series so we can assign it directly to metacluster_id_to_name
# use metacluster_colors to add the colors to metacluster_id_to_name
metacluster_id_to_name['color'] = metacluster_id_to_name['metacluster'].map(
metacluster_colors
)
Expand All @@ -154,7 +155,7 @@ def plot_pixel_cell_cluster_overlay(img_xr, fovs, cluster_id_to_name_path, metac
unique_clusters = np.sort(np.unique(fov_img))

# assign any metacluster id not in metacluster_id_to_name to 0 (not including 0 itself)
# done as a precaution
# done as a precaution, should not usually happen
acceptable_cluster_ids = [0] + list(unique_clusters)
fov_img[~np.isin(fov_img, acceptable_cluster_ids)] = 0

Expand All @@ -172,8 +173,7 @@ def plot_pixel_cell_cluster_overlay(img_xr, fovs, cluster_id_to_name_path, metac
origin='upper'
)

# define the colorbar
# TODO: make customizable?
# define the colorbar with annotations
cax = fig.add_axes([0.9, 0.1, 0.01, 0.8])
cbar = plt.colorbar(
overlay,
Expand Down
4 changes: 3 additions & 1 deletion ark/utils/plot_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_plot_pixel_cell_cluster_overlay():
)

with tempfile.TemporaryDirectory() as td:
# define the path to the cluster map
mapping_path = os.path.join(td, 'sample_mapping_path.csv')

# invalid columns provided in mapping
Expand All @@ -75,7 +76,8 @@ def test_plot_pixel_cell_cluster_overlay():
df = df.rename({'bad_cluster_col': 'cluster'}, axis=1)
df.to_csv(mapping_path, index=False)

# invalid mapping provided
# invalid sample_mapping dict provided, metaclusters do not match
# those found in mapping_path
bad_sample_mapping = {i + 2: (0.0, 0.0, 0.0) for i in np.arange(5)}

with pytest.raises(ValueError):
Expand Down

0 comments on commit b4c0319

Please sign in to comment.