// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // ! This script is provided "as is" by Applied Maths. ! // ! You are free to use and modify this script for your own needs. ! // ! Redistribution or reproduction of the script is prohibited. ! // ! DISCLAIMER: ! // ! Improper use of scripts may corrupt your database. ! // ! Running this script is entirely at your own responsibility. ! // ! Applied Maths accepts no lialibility for any consequences ! // ! resulting from its use. ! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //$MENU window=comparison;popup=File;insertafter=Export similarity matrix...;name=Export Dendrogram (Newick) string fieldlist,fieldsel,filename,key,st; integer i,j,ok,nodecount,idx,parentID,finished,complete; DIALOG dlg; BRANCH root,nde,parentnde,nodelist[]; string nodename[],nodestring[]; integer nodeparent[]; float nodesimil[]; float simil; FILE fp; if not(CmpIsPresent) then CmpAttach; if not(CmpIsPresent) then { message("ERROR: no comparison present!"); stop; } if CluGetCurrent="" then { message("ERROR: there is no dendrogram displayed"); stop; } fieldlist="Key"; for i=1 to dbgetfieldcount do fieldlist=fieldlist+" "+DbGetFieldName(i); fieldsel=fieldlist;fieldsel=splitstring(fieldsel," "); DlgAddText(dlg,"Select the field to export",15,15,150,15); DlgAddList(dlg,fieldlist,fieldsel,15,40,150,150,"LIST"); if not(DlgShow(dlg,"Export dendrogram '"+CluGetCurrent+"' as text",280,250)) then stop; filename="*.txt"; if not(FilePromptName("Enter export file",filename,0)) then stop; if substring(filename,length(filename)-3,9999)<>".txt" then filename=filename+".txt"; setbusy("Exporting..."); CluGetRoot(CluGetCurrent,root); ok=CluEnumStart(root,nde); nodecount=0; while ok do { idx=CluGetEntryNr(nde); CluGetInfo(nde,simil,0.1,0,0,0); parentID=0; if CluGetParent(nde,parentnde) then { i=nodecount; while i>0 do { if CluIsEqual(parentnde,nodelist[i]) then { parentID=i; i=-1; } i=i-1; } } st=""; if idx>0 then { key=CmpGetEntryKey(idx);st=key; if fieldsel<>"Key" then st=DbGetField(key,fieldsel); } replace(st," ","_"); nodecount=nodecount+1;CluGetCommon(nde,nde,nodelist[nodecount]); nodename[nodecount]=st; nodesimil[nodecount]=simil; if st<>"" then nodestring[nodecount]=st+":"+str(simil-nodesimil[parentID],0,5); nodeparent[nodecount]=parentID; ok=CluEnumNext(nde); } finished=0; while not(finished) do { finished=1; for i=1 to nodecount do if nodestring[i]="" then { finished=0; st="";complete=1; for j=1 to nodecount do if nodeparent[j]=i then { if nodestring[j]<>"" then { if st<>"" then st=st+","; st=st+nodestring[j]; } else complete=0; } if complete then { st="("+st+"):"; parentID=nodeparent[i]; if parentID>0 then st=st+str(nodesimil[i]-nodesimil[parentID],0,5); else st=st+"0.00000"; nodestring[i]=st; } } } st=nodestring[1]+";"; if not(fileopenwrite(fp,filename)) then { message("Unable to save file"); stop; } filewrite(fp,st); filewriteline(fp); fileclose(fp); setbusy(""); execute("notepad.exe "+filename);