// // enrichplot.svl Binary QSAR analysis // // 03-apr-2008 (kt) bug fixed (when two DBVs) // 07-aug-2002 (jg) GUI and interactive graph zooming // 03-may-2002 (jg) created // // COPYRIGHT (C) 2001 RYOKA SYSTEMS INC. ALL RIGHTS RESERVED. // // PERMISSION TO USE, COPY, MODIFY AND DISTRIBUTE THIS SOFTWARE IS HEREBY // GRANTED PROVIDED THAT: (1) UNMODIFIED OR FUNCTIONALLY EQUIVALENT CODE // DERIVED FROM THIS SOFTWARE MUST CONTAIN THIS NOTICE; (2) ALL CODE DERIVED // FROM THIS SOFTWARE MUST ACKNOWLEDGE THE AUTHOR(S) AND INSTITUTION(S); (3) // THE NAMES OF THE AUTHOR(S) AND INSTITUTION(S) NOT BE USED IN ADVERTISING // OR PUBLICITY PERTAINING TO THE DISTRIBUTION OF THE SOFTWARE WITHOUT // SPECIFIC, WRITTEN PRIOR PERMISSION; (4) ALL CODE DERIVED FROM THIS SOFTWARE // BE EXECUTED WITH THE MOLECULAR OPERATING ENVIRONMENT (MOE) LICENSED FROM // RYOKA SYSTEMS INC. // // RYOKA SYSTEMS INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS // SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, // AND IN NO EVENT SHALL RYOKA SYSTEMS INC. BE LIABLE FOR ANY // SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER // RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF // CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #set title 'QuaSAR-Binary Analysis' #set class 'QuaSAR' #set version 'RSI 2002.08.07' #set main 'EnrichPlot' function QuaSAR_Descriptor_List; const panel= [ title: 'Binary QSAR Analysis', name: 'wname', text: ['OK', 'Cancel'], onTrigger: ['return', 'exit'], Hbox:[ Text: [ name: 'MDB', title: 'mdb file name:', extendH: 1, len:36, onTrigger: 'return'], Button : [text: 'Browse', name: 'fileselect', onTrigger: 'return'] ], Separator:[], Hbox:[ Option: [name: 'exp', title: 'Exp. : ', text:''], Text: [ name: 'T', title: ' Threashold :', len:6, type:'real'], bubbleHelp:tok_cat ['Higher than this value means active\n' 'in the training set.'] ], Option: [name: 'pred', title: 'Predicted : ', text:''], Option: [name: 'xpred', title: 'Cross validated : ', text:''] ]; local function _plot[mdb,X,Dexp,Drand,Dpred,Dxpred] static plot_attr1; plot_attr1 = []; plot_attr1.seriesMarker = rep ['dot',4]; plot_attr1.seriesColor = ['green','white','red','blue']; plot_attr1.showLegend = 1; plot_attr1.XAxisTitle = '# of molecules'; plot_attr1.YAxisTitle = '% of Active molecule'; plot_attr1.plotType = 'scatter'; plot_attr1.plotTitle = token swrite[ftail mdb]; static plot_attr2; plot_attr2 = []; plot_attr2.seriesMarker = ['dot','dot']; plot_attr2.seriesColor = ['white','red']; plot_attr2.XAxisTitle = '# of molecules'; plot_attr2.YAxisTitle = 'Enrichment (%)'; plot_attr2.plotType = 'scatter'; local X1L,X1H,Y1L,Y1H,X2L,X2H,Y2L,Y2H; X1L = minE X; X2L = X1L; X1H = maxE X; X2H = X1H; Y1L =0 ; Y2L = 0; Y1H = 100; Y2H = (maxE app maxE [Dpred/Drand]) * 100; if Dxpred === [] then local wkey = WindowCreate [ title: tok_cat['Binary QSAR model analysis for ',mdb], name: 'shell', windowName: 'Plot', text: ['Attributes(% Active)...','Attributes(Enrichment)...', 'Close'], onTrigger: ['return','return','exit'], Plot: [ name: 'plot1', resizeV: 1, resizeH: 1, extendH:1,extendV:1, onTrigger: 'return', background: 'black', foreground: 'white', Group: plot_attr1, showLegend:1, seriesTitle:['Exp','Pred','Rand'], series:[[X,Dexp],[X,Dpred],[X,Drand]], XAxisRange:[X1L,X1H],YAxisRange:[Y1L,Y1H] ], Plot: [ name: 'plot2', resizeV: 1, resizeH: 1, extendH:1,extendV:1, onTrigger: 'return', background: 'black', foreground: 'white', Group: plot_attr2, seriesTitle:['Pred','Xpred'], showLegend:1, series:[[X,Dpred/Drand*100]], XAxisRange:[X2L,X2H],YAxisRange:[Y2L,Y2H] ] ]; else wkey = WindowCreate [ title: tok_cat['Binary QSAR model analysis for ',mdb], name: 'shell', windowName: 'Plot', text: ['Attributes(% Active)...','Attributes(Enrichment)...', 'Close'], onTrigger: ['return','return','exit'], Plot: [ name: 'plot1', resizeV: 1, resizeH: 1, extendH:1,extendV:1, onTrigger: 'return', background: 'black', foreground: 'white', Group: plot_attr1, showLegend:1, seriesTitle:['Exp','Pred','Xpred','Rand'], series:[[X,Dexp],[X,Dpred],[X,Dxpred],[X,Drand]], XAxisRange:[X1L,X1H],YAxisRange:[Y1L,Y1H] ], Plot: [ name: 'plot2', resizeV: 1, resizeH: 1, extendH:1,extendV:1, onTrigger: 'return', background: 'black', foreground: 'white', Group: plot_attr2, seriesTitle:['Pred','Xpred'], showLegend:1, series:[[X,Dpred/Drand*100],[X,Dxpred/Drand*100]], XAxisRange:[X2L,X2H],YAxisRange:[Y2L,Y2H] ] ]; endif WindowShow wkey; loop local [values, trigger] = WindowWait wkey; local XL,YH,XH,YL,f; if trigger === 'shell' then if values.shell === 'Attributes(% Active)...' then if second task_fork[master:'parent'] === 'child' then PlotAttributesPrompt [ wkey, // window key 'plot1' // plot widget ]; exit[]; endif elseif values.shell === 'Attributes(Enrichment)...' then if second task_fork[master:'parent'] === 'child' then PlotAttributesPrompt [ wkey, // window key 'plot2' // plot widget ]; exit[]; endif endif endif if trigger === 'plot1' then [XL,YH,XH,YL] = values.plot1; if XL === XH and YL === YH then WindowSetAttr [wkey,[ plot1:[XAxisRange:[X1L,X1H],YAxisRange:[Y1L,Y1H]], plot2:[XAxisRange:[X2L,X2H],YAxisRange:[Y2L,Y2H]] ]]; else WindowSetAttr [wkey,[ plot1:[XAxisRange:[XL,XH],YAxisRange:[YL,YH]], plot2:[XAxisRange:[XL,XH],YAxisRange:[Y2L,Y2H]] ]]; endif else [XL,YH,XH,YL] = values.plot2; if XL === XH and YL === YH then WindowSetAttr [wkey,[ plot1:[XAxisRange:[X1L,X1H],YAxisRange:[Y1L,Y1H]], plot2:[XAxisRange:[X2L,X2H],YAxisRange:[Y2L,Y2H]] ]]; else WindowSetAttr [wkey,[ plot1:[XAxisRange:[XL,XH],YAxisRange:[Y1L,Y1H]], plot2:[XAxisRange:[XL,XH],YAxisRange:[YL,YH]] ]]; endif endif endloop endfunction local function Enrichment [mdb,expData,T,predData,xpredData] if xpredData === 'None' then local data = apt db_ReadColumn [mdb,[expData,predData]]; else data = apt db_ReadColumn [mdb,[expData,predData,xpredData]]; endif [expData,predData,xpredData] = data; if length expData > 50000 then local Bsize = 100; elseif length expData > 5000 then Bsize = 10; else Bsize = 1; endif local Rexp = rank expData; local Rpred = rank predData; expData = expData > T; local N = length expData; local Bin = floor (N/Bsize); predData = reverse perm [expData,Rpred]; if not (xpredData === []) then local Rxpred = rank xpredData; xpredData = reverse perm [expData,Rxpred]; endif expData = reverse perm [expData,Rexp]; local Nactive = iadd expData; local i,Dexp,Dpred,Dxpred,Drand,X; for i = 1,Bin loop Dpred(i) = iadd (keep [predData, Bsize * i])/Nactive; if not (xpredData === []) then Dxpred(i) = iadd (keep [xpredData, Bsize * i])/Nactive; endif Dexp(i) = iadd (keep [expData, Bsize * i])/Nactive; Drand(i) = (Bsize * i)/N; endloop X = Bsize * (igen Bin); Dpred = Dpred * 100; Dexp = Dexp * 100; Drand = Drand * 100; Dxpred = Dxpred * 100; _plot [mdb,X,Dexp,Drand,Dpred,Dxpred]; endfunction function EnrichPlot [] local wkey = WindowCreate panel; WindowShow wkey; local dbkey =dbv_ViewKeys []; if length dbkey <> 1 then WindowSetAttr [wkey,[exp:[text:'None'],pred:[text:'None'], xpred:[text:'None']]]; else WindowSetData [wkey,[MDB: db_Filename dbkey]]; local plotfields = first db_Fields dbkey|add ([second db_Fields dbkey] == ['int','float','double']); plotfields = plotfields | not add ([plotfields] == first QuaSAR_Descriptor_List []); WindowSetAttr [wkey,[exp:[text:plotfields], pred:[text:plotfields], xpred:[text:cat ['None',plotfields]]] ]; WindowSetData [wkey,[exp:'Activity',pred:'$PRED',xpred:'$XPRED']]; endif WindowSetData [wkey,[T:0]]; loop local [val,trigger] = WindowWait wkey; if trigger === 'fileselect' then val.MDB = db_Filename dbv_Open[]; WindowSetData [wkey, [MDB:val.MDB]]; plotfields = first db_Fields val.MDB |add ([second db_Fields val.MDB] == ['int','float','double']); plotfields = plotfields | not add ([plotfields] == first QuaSAR_Descriptor_List []); WindowSetAttr [wkey,[exp:[text:plotfields], pred:[text:plotfields], xpred:[text:cat ['None',plotfields]]] ]; WindowSetData [wkey,[exp:'Activity',pred:'$PRED',xpred:'$XPRED']]; elseif trigger === 'wname' then if second task_fork[master:'parent'] === 'child' then Enrichment [val.MDB,val.exp,val.T,val.pred,val.xpred]; exit[]; endif endif endloop endfunction