Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix color masking in Pixie #1127

Merged
merged 11 commits into from
Mar 21, 2024
Merged

Fix color masking in Pixie #1127

merged 11 commits into from
Mar 21, 2024

Conversation

camisowers
Copy link
Contributor

@camisowers camisowers commented Mar 19, 2024

If you haven't already, please read through our contributing guidelines before opening your PR

What is the purpose of this PR?

Closes #1117. Fixes colored masking for both pixel and cell clustering.

How did you implement your changes

The problem seemed to arise from non-sequential meta_cluster ids. If you change meta cluster 2 -> 21, then the IDs would be [1,3,4, ..., 21], which causes an issue when creating a colormap that expects only 20 clusters (and therefore values up to 20). However, upon further investigation, most of the cell cluster colors were being visualized incorrectly.

To ensure we are always matching the clusters correctly no matter the meta_cluster ID assignments, we

  1. Reassign regular (non-colored) mask values to be sequential ints and save it to the *_meta_cluster_mapping.csv for reference. Use sort_values(by=['cell_meta_cluster']) to ensure the cluster_id are generated by ascending meta cluster number every time for consistency.
    • The cell masks already did this, but it was not using the saved cluster_id values in *_meta_cluster_mapping.csv and was instead doing it's own (second) reassignment, which was why the mapping was wrong.
  2. When generating colored masks, simply go into the saved file so we can grab the cluster_id that corresponds to the meta_cluster number, and combine that with the raw_cmap (e.g. {meta_cluster: color}), so we can know for sure which mask integer ID connects to each color.

Old (no good) colored mask output:
image

New (correct) colored mask output:
Figure 3
Verified by me hand checking the label and the provided cell_meta_cluster_rename in the cell table for a bunch of random cells in the image. 😅

Remaining issues

  • Check pixel clustering mantis mapping file.

@camisowers camisowers added the bug Something isn't working label Mar 19, 2024
@camisowers camisowers self-assigned this Mar 19, 2024
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@camisowers camisowers requested a review from cliu72 March 19, 2024 18:55
Copy link
Contributor

@cliu72 cliu72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions!

src/ark/utils/plot_utils.py Outdated Show resolved Hide resolved
src/ark/utils/data_utils.py Show resolved Hide resolved
src/ark/utils/plot_utils.py Show resolved Hide resolved
src/ark/utils/plot_utils.py Outdated Show resolved Hide resolved
Copy link
Contributor

@cliu72 cliu72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Contributor

@alex-l-kong alex-l-kong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link
Contributor

@srivarra srivarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wild stuff!

@camisowers camisowers added this pull request to the merge queue Mar 21, 2024
Merged via the queue into main with commit 64a0445 Mar 21, 2024
18 checks passed
@camisowers camisowers deleted the fix_colored_masks branch March 21, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in plot_utils.save_colored_masks and plot.utils.plot_pixel_cell_cluster
4 participants