//************************************************************* // Sample script provided "as is" by Applied Maths. // You are free to use and modify this script for your // own purposes. // Please notice that improper use of script commands may // corrupt your database. Running this script is entirely at // your own responsibility. Applied Maths accepts no // liability for any damage that results from using // this script. //************************************************************* // needs: comparison containing 2 different fingerprints for which dendrograms are calculated // step 1: select branch in one of the dendrograms // step 2: run script // step 3: best matching branch is selected //$MENU window=comparison;popup=clustering;insertafter=set minimum ;name=Find best approximating branch BRANCH root,bra,bra2,nodes[]; string expername1,expername2,st,experlist,st_penab,st_penba,st2,keystring,copykeystring,pen; float simil,signif,penab,penba,match,bestmatch; integer ok,nodecount,i,j,entrycount,idx,subcount,nodekeep,contains,help; TABLE tb; DIALOG dlg; INDEX idxpresent,idxcompare; if not(CmpIsPresent) then CmpAttach; if not(CmpIsPresent) then { message("No comparison is currently open"); stop; } expername1=CluGetCurrent; if (expername1="") then { message("Please select a branch in a clustering"); stop; } ok=CluGetRoot(expername1,root); if not(ok) then { message("There is no clustering present"); stop; } // Select experiment to look for comparable dendrogram for i=1 to DbGetExperCount do experlist=experlist+DbGetExperName(i)+" "; expername2=experlist;expername2=splitstring(expername2," "); DlgAddText(dlg,"Selected branch in experiment "+expername1,15,15,200,40); DlgAddText(dlg,"Select the experiment where a best approximating branch has to be found:",15,60,250,40); DlgAddList(dlg,experlist,expername2,15,115,150,150,"LIST"); if not(DlgShow(dlg,"Find best matching branch",300,300)) then stop; DlgReset(dlg); st_penba=TempRecall(pen); st_penab=splitstring(st_penba," "); if length(st_penab)=0 then st_penab="100"; if length(st_penba)=0 then st_penba="100"; DlgAddText(dlg,"Set penalty for entry present in branch in "+expername1+ " and not in branch in "+expername2+" (in %):",15,15,200,60); DlgAddEdit(dlg,st_penab,220,20,50,20); DlgAddText(dlg,"Set penalty for entry present in branch in "+expername2+ " and not in branch in "+expername1+" (in %:)",15,80,200,60); DlgAddEdit(dlg,st_penba,220,85,50,20); if not(DlgShow(dlg,"Set penalties",300,250)) then stop; penab=val(st_penab)/100; penba=val(st_penba)/100; Tempstore(pen,st_penab+" "+st_penba); // look for entries in parent dendrogram CluGetCursor(expername1,bra); ok=CluEnumStart(bra,bra2); entrycount=0; IdxReset(idxpresent); keystring=""; while ok do { if CluGetEntryNr(bra2)>0 then { entrycount=entrycount+1; st = CmpGetEntryKey(CluGetEntryNr(bra2)); IdxSet(idxpresent,st,entrycount); keystring=keystring+st+" "; } ok=CluEnumNext(bra2); } ok=CluSetCurrent(expername2); if not(ok) then { message("There is no clustering for this experiment"); stop; } st = ""; CluGetRoot(expername2,root); CluEnumStart(root,bra); ok=1;nodecount=0; while ok do { nodecount=nodecount+1; CluEnumStart(bra,nodes[nodecount]); CluGetInfo(bra,simil,signif,0,0,0); st=st+str(simil,0,1)+" "; ok=CluEnumNext(bra); } bestmatch=-10000; for i=1 to nodecount do { match = 0; IdxReset(idxcompare); idx=0; CluGetInfo(nodes[i],simil,signif,subcount,0,0); if subcount-entrycount < 0 then match=match-(subcount-entrycount)*penab; CluEnumstart(nodes[i],bra); ok=1; while ok do { if CluGetEntryNr(bra)>0 then { st=CmpGetEntryKey(CluGetEntryNr(bra)); idx = idx+1; IdxSet(idxcompare,st,idx); st2 = str(IdxGet(idxpresent,st),0,0); if IdxGet(idxpresent,st) > 0 then match = match+1; else match = match-penba; } ok=CluEnumNext(bra); } copykeystring=keystring; for j=1 to entrycount do { st = splitstring(copykeystring," "); help=IdxGet(idxcompare,st); if help=0 then match=match-penab; } if match>bestmatch then { bestmatch = match; contains = subcount; nodekeep = i; } if match=bestmatch and subcount < contains then { bestmatch = match; contains = subcount; nodekeep = i; } } CluSetCursor(nodes[nodekeep]);