//************************************************************* // 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. //************************************************************* // PERFORMS MLST-SEARCH // Maximum number of characters in set: 60 // Maximum number of identifiers per character: 20 //$MENU window=main;popup=edit;insertafter=Search entries...;name=MLST Search integer i,j,k,l,nbchar,nbent,yof,xof,xofe,xlen,ylen,match,good,countgood,value,present; integer maxchar,maxsearch,nsearch[],search,misma,nega,keep,rv; string expcl,experlist,expername,methodlist,method,report,charname,searchread[]; string searchdo[][],inpmisma,keepstring,selectstring,selcrit; DIALOG dlg; CHARSET cs; maxchar=60; maxsearch=20; // Get character experiment for which centrotype has to be calculated for i=1 to DbGetExperCount do { expcl=DbGetExperClass(i); if expcl="CHR" then { experlist=experlist+DbGetExperName(i)+" "; expername=experlist;expername=splitstring(expername," "); } } DlgAddText(dlg,"Select the character type experiment to use:",15,15,150,30); DlgAddList(dlg,experlist,expername,15,55,150,130,"LIST"); if not(DlgShow(dlg,"MLST search",300,230)) then stop; nbchar=ChrSetGetCount(expername); nbent = DbGetEntryCount; if nbchar>maxchar then { report = report+"Number of characters in experiment: "+str(nbchar,3,0)+"~n~n"; report=report+"Maximum number of characters is "+str(maxchar,0,0)+".~n"; DlgReset(dlg); DlgAddtext(dlg,report,20,20,200,60); if not(DlgShow(dlg,"MLST search: notification",400,200)) then stop; else stop; report=""; } // Get values from selected entries, store into array search=1; i=0; j=0; while search and i= 1 then { l = nsearch[i]; keepstring = keepstring+searchdo[i][l]; } keepstring=keepstring+" "; } // Get selection criteria DlgReset(dlg); DlgAddText(dlg,"Give seleciton criteria:",15,30,150,20); for i=1 to nbchar do { charname = ChrSetGetChar(expername,i)+":"; searchread[i]=""; xof = 15+floor((i-1)/20)*250; xofe = xof+55; yof = 30+(i-floor((i-1)/20)*20)*25; DlgAddtext(dlg,charname,xof,yof,50,15); DlgAddEdit(dlg,searchread[i],xofe,yof,120,15); } if floor(nbchar/20) = nbchar/20 then { xlen=floor(nbchar/20)*250+50;} else xlen=(1+floor(nbchar/20))*250+50; if xlen<500 then xlen=500; if floor(nbchar/20)>0 then ylen = 550; else ylen = nbchar*25+40; DlgAddCheck(dlg,"Negative search",nega,20,ylen+40,100,15); methodlist="Add to list Replace list Search in list"; method="Add to list"; DlgAddText(dlg,"Selection method:",20,ylen+90,90,15); DlgAddList(dlg,methodlist,method,120,ylen+90,130,60,"LIST"); DlgAddText(dlg,"Maximum number of mismatches:",20,ylen+150,160,15); inpmisma="0"; ylen=ylen+150; DlgAddEdit(dlg,inpmisma,190,ylen,30,20); DlgAddButton(dlg,"Paste from selected entries",10,xlen-200,ylen-140,150,30); DlgAddButton(dlg,"Paste from previous search",12,xlen-200,ylen-100,150,30); DlgAddButton(dlg,"Search",21,xlen-200,ylen-50,150,30); DlgAddButton(dlg,"Cancel",22,xlen-200,ylen-10,150,30); ylen=ylen+100; selectstring=TempRecall(selcrit); rv=DlgShow(dlg,"MLST search",xlen,ylen); while rv<20 do { if rv=10 then selectstring=keepstring; if rv=12 then selectstring=TempRecall(selcrit); for i=1 to nbchar do { charname = ChrSetGetChar(expername,i)+":"; xof = 15+floor((i-1)/20)*250; xofe = xof+55; yof = 30+(i-floor((i-1)/20)*20)*25; searchread[i]=splitstring(selectstring," "); } rv = DlgShow(dlg,"MLST search",xlen,ylen); } if rv=22 then stop; misma=val(inpmisma); DlgReset(dlg); // Copy selection criteria into array, prepare for search report=""; for i=1 to nbchar do { nsearch[i]=0; while length(searchread[i])>0 do { nsearch[i]=nsearch[i]+1; j = nsearch[i]; if nsearch[i]=maxsearch then { report=report+ChrSetGetChar(expername,i); report=report+": only 20 first values are used~n~n"; } if nsearch[i] < 20 then { if find(searchread[i],",",1)>0 then { searchdo[i][j] = splitstring(searchread[i],","); } else { searchdo[i][j]=searchread[i]; searchread[i]=""; } } } } if length(report)>0 then { DlgReset(dlg); ylen = nbchar*30; DlgAddText(dlg,report,20,20,300,ylen); ylen = nbchar*50; if not(DlgShow(dlg,"MLST search: report",400,ylen)) then stop; DlgReset(dlg); report=""; } // Copy selection criteria into string to keep for next search keepstring=""; for i=1 to nbchar do { for j=1 to nsearch[i]-1 do { keepstring = keepstring+searchdo[i][j]+","; } if nsearch[i] >= 1 then { l = nsearch[i]; keepstring = keepstring+searchdo[i][l]; } keepstring=keepstring+" "; } Tempstore(selcrit,keepstring); countgood=0; // Perform search for k=1 to nbent do { if k/20=floor(k/20) then setbusy("Scanning database - "+str(k,0,0)); if method="Replace list" then DbSetSel(DbGetEntryKey(k),0); if method="Add to list" and DbGetSel(DbGetEntryKey(k)) then keep=1; if (method<>"Search in list") or DbGetSel(DbGetEntryKey(k)) then { ChrLoad(cs,DbGetEntryKey(k),expername); good=0; match=0; for i=1 to nbchar do { if nsearch[i]=0 then match=match+1; else { for j=1 to nsearch[i] do { if ChrGetVal(cs,i) = val(searchdo[i][j]) then match=match+1; } } } if nbchar <= match+misma then good=1; if nega then good = not(good); if keep then good=1; DbSetSel(DbGetEntryKey(k),good); countgood=countgood+good; keep=0; } } setbusy(""); // Give report report=report+"Number of entries found:"+str(countgood,0,0)+"~n~n"; DlgReset(dlg); DlgAddText(dlg,report,20,20,200,60); if not(DlgShow(dlg,"MLST search: report",300,200)) then stop;