From 41be037372c04c8d20c5515141b176675f23ff7d Mon Sep 17 00:00:00 2001 From: DIANE <abderrahim.diane@cefe.cnrs.fr> Date: Mon, 15 Apr 2024 12:24:03 +0200 Subject: [PATCH] samples selection --- Class_Mod/UMAP_.py | 2 +- pages/1-samples_selection.py | 40 +++++++++++++++++------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Class_Mod/UMAP_.py b/Class_Mod/UMAP_.py index 21d2f82..90d0566 100644 --- a/Class_Mod/UMAP_.py +++ b/Class_Mod/UMAP_.py @@ -10,7 +10,7 @@ class Umap: self.model = UMAP(n_neighbors=20, n_components=4, min_dist=0.0,) # random_state=42,) self.model.fit(self.x) self.scores = self.model.transform(self.x) - self.scores = pd.DataFrame(self.scores, index = self.numerical_data.index) + self.scores = pd.DataFrame(self.scores) @property def scores_(self): diff --git a/pages/1-samples_selection.py b/pages/1-samples_selection.py index 314bf96..eb05693 100644 --- a/pages/1-samples_selection.py +++ b/pages/1-samples_selection.py @@ -101,17 +101,18 @@ if not spectra.empty: # clustering if not t.empty: + tcr = standardize(t) # Clustering - if clus_method == cluster_methods[1]: - ncluster = scores.number_input(min_value=2, max_value=30, value=3, label = 'Select the desired number of clusters') - cl_model = Sk_Kmeans(t, max_clusters = 30) - fig2 = px.scatter(cl_model.inertia_.T, y = 'inertia') - scores.plotly_chart(fig2) - data, labels = cl_model.fit_optimal(nclusters = ncluster) - - elif clus_method == cluster_methods[2]: - from hdbscan import HDBSCAN_function - labels, hdbscan_score = HDBSCAN_function(t, min_cluster_size=10) + if clus_method == cluster_methods[1]: + ncluster = scores.number_input(min_value=2, max_value=30, value=3, label = 'Select the desired number of clusters') + cl_model = Sk_Kmeans(tcr, max_clusters = 30) + fig2 = px.scatter(cl_model.inertia_.T, y = 'inertia') + scores.plotly_chart(fig2) + data, labels = cl_model.fit_optimal(nclusters = ncluster) + + elif clus_method == cluster_methods[2]: + from hdbscan import HDBSCAN_function + labels, hdbscan_score = HDBSCAN_function(tcr, min_cluster_size=10) ##### Plots @@ -122,16 +123,16 @@ if not t.empty: st.write('Scores plot') # scores plot with clustering if list(labels) and meta_data.empty: - fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = labels) + fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = labels) # scores plot with metadata elif len(list(labels)) == 0 and not meta_data.empty: filter = meta_data.columns[1:] col = st.selectbox('Group by:', options= filter) if col == 0: - fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3) + fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3) else: - fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col])) ) + fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col])) ) # color with scores and metadata elif len(list(labels)) > 0 and not meta_data.empty: @@ -143,14 +144,14 @@ if not t.empty: col = st.selectbox('Group by:', options= filter) if col == "None": - fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3) + fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3) elif col == clus_method: - fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = labels) + fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = labels) else: - fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col]))) + fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3, color = list(map(str.lower,meta_data[col]))) else: - fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3) + fig = px.scatter_3d(tcr, x=axis1, y=axis2, z = axis3) fig.update_traces(marker=dict(size=4)) st.plotly_chart(fig) @@ -183,7 +184,4 @@ if not spectra.empty: hotelling = dr_model.hotelling_ fig = px.scatter(t, x=hotelling[ax2], y=residuals[ax2]).update_layout(xaxis_title="T²",yaxis_title="Residuals") - st.plotly_chart(fig) - - - + st.plotly_chart(fig) \ No newline at end of file -- GitLab