From 6894c76aaf66604508de408744b8b13fd13da54c Mon Sep 17 00:00:00 2001
From: DIANE <abderrahim.diane@cefe.cnrs.fr>
Date: Mon, 15 Apr 2024 11:49:00 +0200
Subject: [PATCH] score plot(group samples based on metadata or on clustering
 results

---
 pages/1-samples_selection.py | 39 +++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/pages/1-samples_selection.py b/pages/1-samples_selection.py
index 121d467..314bf96 100644
--- a/pages/1-samples_selection.py
+++ b/pages/1-samples_selection.py
@@ -121,26 +121,41 @@ if not t.empty:
     with scores:
         st.write('Scores plot')
         # scores plot with clustering
-        if list(labels):
+        if list(labels) and meta_data.empty:
             fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = labels)
-        else:
+
         # scores plot with metadata
-            if not meta_data.empty: 
-                filter = meta_data.columns[1:]
-                col = st.selectbox('filter', options= filter)
-                if col == 0:
-                    fig = px.scatter_3d(t, 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])) )
+        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)
+            else:
+                fig = px.scatter_3d(t, 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:
+            if clus_method in cluster_methods[1:]:
+                filter = ['None', clus_method]
+                filter.extend(meta_data.columns[1:])
+            else: 
+                filter = meta_data.columns[1:].insert(0,'None')
+
+            col = st.selectbox('Group by:', options= filter)
+            if col == "None":
+                fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3) 
+            elif col == clus_method:
+                fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3, color = labels)
             else:
-        # scores plot with neither metadata nor clustering
-                fig = px.scatter_3d(t, x=axis1, y=axis2, z = axis3)        
+                fig = px.scatter_3d(t, 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.update_traces(marker=dict(size=4))
         st.plotly_chart(fig)
 
 
 
-
 if not spectra.empty:
     if dim_red_method == dim_red_methods[1]:
         with loadings:
-- 
GitLab