Error in plot_utils.save_colored_masks
and plot.utils.plot_pixel_cell_cluster
#1117
Labels
bug
Something isn't working
Describe the bug
Both
plot_utils.save_colored_masks
andplot_utils.plot_pixel_cell_cluster
are not mapping the right color to the right cell population when the cluster IDs are not continuous. See the example below. Essentially, when there are breaks in the metacluster IDs (for example, numbers are skipped), the color mapping becomes incorrect.I think the reason for this is because the wrong column is being read in
MetaclusterColormap
. Due to some recent refactoring, we are now adding a "cluster_id" column tocell_meta_cluster_mapping.csv
(https://github.com/angelolab/ark-analysis/blob/main/src/ark/utils/data_utils.py#L444-L451), and these numbers are used to create the cell mask. However, the "cluster_id" column is being ignored in theMetaclusterColormap
functions (https://github.com/angelolab/ark-analysis/blob/main/src/ark/utils/plot_utils.py#L42), so the colors are being mapped to the wrong numbers.We are currently feeding in
raw_cmap
intoplot_utils.save_colored_masks
andplot_utils.plot_pixel_cell_cluster
. I think it would be safer to refactor that function and feedrenamed_cmap
into that function, sincerenamed_cmap
has the actual text labels for each cluster. I think that would be the best way to ensure the right colors are mapped to the right cells.Expected behavior
Generate accurate color overlays.
To Reproduce
Run the example dataset through notebook 3. Highlight all of metacluster 2 and click "new metacluster" to change metacluster 2 to metacluster 21. If you then look at the colored overlays, you'll see that cells that were previously in metacluster 2 are NOT properly assigned to metacluster 21 (as they should be). In the screenshot below, you can see that metacluster 2 no longer exists in the bottom (which is correct), but all cells that were previously metacluster 2 (light red in the top example) should now be green (color of metacluster 21 - it is correct in the legend), but they are not correctly colored (instead of green, they are a light teal color).
Original clustering:
![image](https://private-user-images.githubusercontent.com/11382352/308002396-0134bb0b-fce6-4af4-a946-b4cd5a0b2402.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5MDI1MDAsIm5iZiI6MTczOTkwMjIwMCwicGF0aCI6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RhODljNjdiMGNkMTU2MzNiNzEzMzJjOTBjYWMwN2RmNjQ1YTFiNTZlZDhiNjNjZTk2ZTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0._7-hdNYGJ9I7v_-kkTU3MSz-ZQHAhwc2P7cP9_7k3mA)
New clustering (the only change I made was change cluster 2 to cluster 21):
![image](https://private-user-images.githubusercontent.com/11382352/308002715-0fe9ce16-bb9d-4ad6-b354-05482d7fdf32.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5MDI1MDAsIm5iZiI6MTczOTkwMjIwMCwicGF0aCI6Ii8xMTM4MjM1Mi8zMDgwMDI3MTUtMGZlOWNlMTYtYmI5ZC00YWQ2LWIzNTQtMDU0ODJkN2ZkZjMyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE4VDE4MTAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEyZTlhNzg5NDhiMDk5ZWNhNGQwYzQ0YmJkYjc0YmI3MjUxZDJjMmNkMTY2ODc3YTM5ZDhiZmZmZDg0MTFhZTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.4WvcQdwarSkO5Y3UhPNomhdR2KUGdt6cZSKjbE89jJg)
![image](https://private-user-images.githubusercontent.com/11382352/308002600-a7253cfe-2f65-45da-8eea-6a7e5f9ada2d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5MDI1MDAsIm5iZiI6MTczOTkwMjIwMCwicGF0aCI6Ii8xMTM4MjM1Mi8zMDgwMDI2MDAtYTcyNTNjZmUtMmY2NS00NWRhLThlZWEtNmE3ZTVmOWFkYTJkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE4VDE4MTAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc5YWFmZjBmYWYzZjRiOGE4OWY4ZWRkYWM5ZTQ1NGI1OGY2MWI1MDE5ZjIxMWRkMDZmZDYyYjAyNWMwODEyZDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.d40V0awSxi4SNFAaTqvWTEcAgQujSu33omO0nGSvaII)
The text was updated successfully, but these errors were encountered: