@@ -11,6 +11,8 @@ import JSME from "../../../components/tools/toolViz/JSMEComp";
1111import Dropdown from "../../../components/tools/toolViz/DropDown" ;
1212import { Button , Group , Input , Select } from "@mantine/core" ;
1313import FoldMetricBarplot from "../../../components/tools/toolViz/BarChart" ;
14+ import DiscreteScatterplot from "../../../components/tools/toolViz/DiscreteScatterPlot" ;
15+ import { round } from "mathjs" ;
1416
1517export default function MLLayout ( { children } ) {
1618 const [ screenData , setScreenData ] = useState ( [ ] ) ;
@@ -22,7 +24,6 @@ export default function MLLayout({ children }) {
2224 const { rdkit } = useContext ( RDKitContext ) ;
2325 const { pyodide } = useContext ( PyodideContext ) ;
2426 const { setTarget, target } = useContext ( TargetContext ) ;
25-
2627 const pathname = usePathname ( ) ;
2728
2829 // -----------------------------
@@ -64,14 +65,16 @@ export default function MLLayout({ children }) {
6465
6566 pyodide . postMessage ( {
6667 id : "job-123" ,
67- opts : 0 ,
68+ opts : target . machine_learning_inference_type === "regression" ? 1 : 2 ,
6869 fp : [ mol_fp ] ,
6970 func : "ml-screen" ,
7071 } ) ;
7172
7273 pyodide . onmessage = ( event ) => {
7374 if ( event . data . success === "ok" ) {
7475 setOneOffSmilesResult ( event . data . results [ 0 ] ) ;
76+ console . log ( oneOffSMILESResult )
77+ console . log ( typeof ( oneOffSMILESResult ) )
7578 }
7679 } ;
7780 }
@@ -90,12 +93,12 @@ export default function MLLayout({ children }) {
9093 // Merge fold scatter data
9194 // -----------------------------
9295 const mergedData : { x : number ; y : number } [ ] = [ ] ;
93- const foldColorProperty : number [ ] = [ ] ;
96+ const foldColorProperty : string [ ] = [ ] ;
9497
9598 perFoldPreds . forEach ( ( fold , foldIndex ) => {
9699 fold . forEach ( ( point ) => {
97100 mergedData . push ( { x : point . x , y : point . y } ) ;
98- foldColorProperty . push ( foldIndex + 1 ) ;
101+ foldColorProperty . push ( `Fold ${ foldIndex + 1 } ` ) ;
99102 } ) ;
100103 } ) ;
101104
@@ -106,63 +109,100 @@ export default function MLLayout({ children }) {
106109 < div className = "tools-container" >
107110 < MLResultsContext . Provider value = { setScreenData } >
108111 { /* ---------------- Task Type Selector ---------------- */ }
109- < Select
110- label = "ML Task Type"
111- value = { target . machine_learning_inference_type || "regression" }
112- onChange = { ( v ) => setTarget ( { ...target , machine_learning_inference_type : v } ) }
113- data = { [
114- { value : "regression" , label : "Regression" } ,
115- { value : "classification" , label : "Classification" } ,
116- ] }
117- mb = "md"
118- />
119-
120- { /* ---------------- Children get taskType prop ---------------- */ }
121- { children }
122-
123- { /* ---------------- Single molecule prediction ---------------- */ }
112+ { /* Task Type Selector + Clear Button */ }
124113 < Group >
125- < h2 > Predict the activity of a single molecule</ h2 >
126-
127- < Input
128- ref = { inputRef }
129- style = { { width : "20%" } }
130- onChange = { ( e ) => setOneOffSmiles ( e . target . value ) }
131- placeholder = "Input your SMILES string"
114+ < h3 > ML Task Type</ h3 >
115+ < Select
116+ value = { target . machine_learning_inference_type }
117+ onChange = { ( v ) => setTarget ( { ...target , machine_learning_inference_type : v } ) }
118+ data = { [
119+ { value : "regression" , label : "Regression" } ,
120+ { value : "classification" , label : "Classification" } ,
121+ ] }
122+ style = { { flex : 1 } }
123+ disabled = { hasResults } // Still lock after results
132124 />
133125
134- < Dropdown buttonText = "Draw the molecule" >
135- < JSME
136- width = "300px"
137- height = "300px"
138- onChange = { ( smiles ) => setOneOffSmiles ( smiles ) }
139- />
140- </ Dropdown >
141-
142- < Button onClick = { oneOffPred } > Predict Activity</ Button >
143-
144- { oneOffSMILESResult !== undefined && (
145- < span >
146- Predicted { target . activity_columns [ 0 ] } : < b > { oneOffSMILESResult } </ b >
147- </ span >
126+ { hasResults && (
127+ < Button
128+ variant = "light"
129+ color = "gray"
130+ onClick = { ( ) => {
131+ setTarget ( {
132+ ...target ,
133+ machine_learning : [ ] ,
134+ machine_learning_inference_type : "regression" // Reset to allow re-selection
135+ } ) ;
136+ setOneOffSmilesResult ( undefined ) ;
137+ } }
138+ >
139+ Clear Results
140+ </ Button >
148141 ) }
149142 </ Group >
150143
144+
145+ { /* ---------------- Children get taskType prop ---------------- */ }
146+ { children }
147+
151148 { /* ---------------- Scatterplot or barplot ---------------- */ }
152149 { hasResults && (
153150 < >
154- { target . machine_learning_inference_type === "regression" ? (
155- < Scatterplot
156- data = { mergedData }
157- discreteColor = { true }
158- colorProperty = { foldColorProperty }
159- xAxisTitle = "Experimental Activity"
160- yAxisTitle = "Predicted Activity"
151+ { /* ---------------- Single molecule prediction ---------------- */ }
152+ < Group >
153+ < h2 > Predict the activity of a single molecule</ h2 >
154+
155+ < Input
156+ ref = { inputRef }
157+ style = { { width : "20%" } }
158+ onChange = { ( e ) => setOneOffSmiles ( e . target . value ) }
159+ placeholder = "Input your SMILES string"
161160 />
162- ) : (
163- < FoldMetricBarplot metricName = "R2" data = { metric2 } color = "#f59e0b" />
161+
162+ < Dropdown buttonText = "Draw the molecule" >
163+ < JSME
164+ width = "300px"
165+ height = "300px"
166+ onChange = { ( smiles ) => setOneOffSmiles ( smiles ) }
167+ />
168+ </ Dropdown >
169+
170+ < Button onClick = { oneOffPred } > Predict Activity</ Button >
171+
172+ { oneOffSMILESResult !== undefined && (
173+ < span >
174+ < b > { target . machine_learning_inference_type === "regression" && < >
175+ Predicted { target . activity_columns [ 0 ] } : { round ( oneOffSMILESResult , 2 ) }
176+ </ > }
177+ </ b >
178+ < b > { target . machine_learning_inference_type === "classification" &&
179+ < Group style = { { marginLeft : "10px" } } >
180+ < span > Active Probability: { oneOffSMILESResult [ 0 ] } </ span >
181+ < span > Inactive Probability: { oneOffSMILESResult [ 1 ] } </ span >
182+ </ Group >
183+ }
184+ </ b >
185+ </ span >
186+ ) }
187+ </ Group >
188+ { target . machine_learning_inference_type === "regression" && (
189+ < >
190+ < DiscreteScatterplot
191+ data = { mergedData }
192+ discreteColor = { true }
193+ colorLabels = { foldColorProperty }
194+ xAxisTitle = "Experimental Activity"
195+ yAxisTitle = "Predicted Activity"
196+ />
197+ < FoldMetricBarplot metricName = "Mean Absolute Error" data = { metric1 } color = "#3b82f6" />
198+ </ >
199+ ) }
200+ { target . machine_learning_inference_type === "classification" && (
201+ < Group align = "flex-start" >
202+ < FoldMetricBarplot metricName = "Accuracy" data = { metric1 } color = "#3b82f6" />
203+ < FoldMetricBarplot metricName = "ROC-AUC Score" data = { metric2 } color = "#f59e0b" />
204+ </ Group >
164205 ) }
165- < FoldMetricBarplot metricName = "Accuracy" data = { metric1 } color = "#3b82f6" />
166206 </ >
167207 ) }
168208 </ MLResultsContext . Provider >
0 commit comments