napari-clusters-plotter icon indicating copy to clipboard operation
napari-clusters-plotter copied to clipboard

Enhancement: Selected point in layer could be an interactive cluster in "Clustering" options

Open ClementCaporal opened this issue 10 months ago • 3 comments

Motivation

Using the plugin I can find objects from the PlotterWidget to the layer using the MANUAL_CLUSTER_ID. I would like to also find objects from the layer.selected_data to the PlotterWidget.

For example what are the features of the left part of the annotations.

If this is in the scope of this plugin, I can try to make a PR.

Workaround

If this is out of scope of this plugin, one can use this code to reproduce the described behaviour using point_layer

import napari
import numpy as np
import pandas as pd

viewer = napari.Viewer()

n_points = 200
points = np.random.rand(n_points, 2) * 100

features = pd.DataFrame({
    'feature1': np.linspace(0, 1, n_points),
    'feature2': np.random.rand(n_points),
    'SELECTED_CLUSTER': 0,
})

point_layer = viewer.add_points(points, features=features)

def on_selection_change(selected):
    point_layer.features['SELECTED_CLUSTER'] = 0
    point_layer.features.loc[selected, 'SELECTED_CLUSTER'] = 1

point_layer.selected_data.events.items_changed.connect(on_selection_change)

from napari_clusters_plotter import PlotterWidget

pw = PlotterWidget(viewer)
pw.plot_x_axis.setCurrentIndex(0)
pw.plot_y_axis.setCurrentIndex(1)
pw.plot_cluster_id.setCurrentIndex(1)
viewer.window.add_dock_widget(pw)


point_layer.selected_data = np.arange(40)


pw.run(point_layer.features, "feature1", "feature2", "SELECTED_CLUSTER")

Image

ClementCaporal avatar Jan 26 '25 20:01 ClementCaporal

Hi @ClementCaporal ,

That's a cool idea that would give the clusters plotter a sort of bi-directionality which could be very helpful. Similar to #104, I would put this feature into 0.9.0 where it should be easier to implement, anyway.

Your code snippet should already be half the work :)

jo-mueller avatar Jan 28 '25 12:01 jo-mueller

Cool! Thank you very much. Tell me if you think I can participate!

ClementCaporal avatar Jan 28 '25 13:01 ClementCaporal

I'd say PRs are always welcome :)

jo-mueller avatar Jan 29 '25 11:01 jo-mueller