Icon representing a recipe

Recipe: FreezeSelectSome0

created by jeff101

Profile


Name
FreezeSelectSome0
ID
101715
Shared with
Public
Parent
None
Children
Created on
December 29, 2015 at 03:37 AM UTC
Updated on
December 29, 2015 at 03:37 AM UTC
Description

FreezeSelectSome0d.txt 12/28/15 858pm code

Best for


Code


-- global variables -- don't let any depend on functions defined below recipename='FreezeSelectSome0' tot=structure.GetCount() -- # of AA's in protein -- FreezeSelectSome0 begun 103pm 12/23/15 -- last updated 12/28/15 858pm function Main() local bandsi,bandsf,username,scorei,scoref local snum,smin,smax,fflag,dobb,dosc,sflag local srng,sdir,todo,ask,runit bandsi=band.GetCount() -- # of user-supplied bands scorei=current.GetScore() -- initial score username=user.GetPlayerName() print(recipename..' begins at '..os.date()..' on puzzle ID '..puzzle.GetPuzzleID()) print(' with name '..puzzle.GetName()..',') print(' score '..trunc3(scorei)..', '..tot..' residues, and '..bandsi..' bands.') print(' ') makereport() -- default values smin=1 smax=tot sdir=1 fflag=0 dobb=false dosc=false sflag=0 runit=1 repeat -- start main loop -- read inputs ask=dialog.CreateDialog(recipename) ask.Label1=dialog.AddLabel(' \nsmin & smax: process segments from smin to smax\n ') ask.smin=dialog.AddSlider("smin: ",smin,1,tot,0) ask.smax=dialog.AddSlider("smax: ",smax,1,tot,0) ask.Label2=dialog.AddLabel(' \nfflag: -1=unfreeze them, 0=let them be, 1=freeze them\n ') ask.fflag=dialog.AddSlider("fflag: ",fflag,-1,1,0) ask.dobb=dialog.AddCheckbox("Freeze/Unfreeze their backbones",dobb) ask.dosc=dialog.AddCheckbox("Freeze/Unfreeze their sidechains",dosc) ask.Label4=dialog.AddLabel(' \nsflag: -1=deselect them, 0=let them be, 1=select them\n ') ask.sflag=dialog.AddSlider("sflag: ",sflag,-1,1,0) ask.run = dialog.AddButton("Do Above", 1) ask.quit = dialog.AddButton("Quit Now", 0) runit = dialog.Show(ask) if runit==1 then -- do most of main loop smin=ask.smin.value+0 smax=ask.smax.value+0 fflag=ask.fflag.value+0 dobb=ask.dobb.value dosc=ask.dosc.value sflag=ask.sflag.value+0 sdir=1 -- should increment snum from lo # to hi # if sdir==sdir then if smin>smax then sdir= -1 -- should increment snum in reverse (from hi # to lo #) end -- if smin else -- want smin<=smax so sdir=1 can always hold if smin>smax then res=smin smin=smax smax=res end -- if smin end -- if sdir if fflag==0 then dobb=false dosc=false end -- if fflag if not (dobb or dosc) then fflag=0 end -- if not -- print the inputs print('Got the following inputs by '..os.date()..':') print(' smin='..smin..' smax='..smax..' sdir='..sdir) print(' fflag='..fflag..' dobb='..tostring(dobb)..' dosc='..tostring(dosc)) print(' sflag='..sflag..'.') -- execute the commands if sflag==0 and (fflag==0 or not (dobb or dosc)) then print('Making no changes.\n ') else srng=(smin..' to '..smax..'.') if sflag==1 then -- means to select print('Selecting '..srng) if sflag~=sflag then selection.SelectRange(smin,smax) -- acted oddly < 12/28/15 else for snum=smin,smax,sdir do -- never letting sdir= -1 acted oddly < 12/28/15 selection.Select(snum) end -- for snum end -- if sflag elseif sflag== -1 then -- means to deselect print('Deselecting '..srng) for snum=smin,smax,sdir do selection.Deselect(snum) end -- for snum end -- if sflag if dobb or dosc then if dobb and dosc then todo='both backbone and sidechains' elseif dobb then todo='backbone but not sidechains' elseif dosc then todo='sidechains but not backbone' else todo='neither backbone nor sidechains' end -- if dobb todo=(todo..' for '..srng) if fflag==1 then -- means to freeze print('Freezing '..todo) for snum=smin,smax,sdir do freeze.Freeze(snum,dobb,dosc) end -- for snum elseif fflag== -1 then -- means to unfreeze print('Unfreezing '..todo) for snum=smin,smax,sdir do freeze.Unfreeze(snum,dobb,dosc) end -- for snum end -- if fflag end -- if dobb or dosc print(' ') makereport() end -- if sflag end -- if runit, end of most of main loop until runit==0 -- repeat, end of main loop bandsf=band.GetCount() -- final # of bands scoref=current.GetScore() print('Ending with '..bandsf..' bands and score '..trunc3(scoref)..' at '..os.date()..'.') end -- Main() function makereport() local snum,res,bbf,scf local j100s,j10s,j1s,aa,ss local Cs,Gs,Ps,Hs,Es,Ls local sel,des,frbbsc,frbb,frsc,frnone local jnk,totsel,totfbs,totfb,totfs local totsel1,totfbb,totfsc -- prep output j100s={} j10s={} j1s={} aa={} ss={} Cs={} Gs={} Ps={} Hs={} Es={} Ls={} sel={} des={} frbb={} frsc={} frbbsc={} frnone={} for snum=1,tot do res=snum j100s[snum]=trunc0(res/100) res=res-100*j100s[snum] j10s[snum]=trunc0(res/10) res=res-10*j10s[snum] j1s[snum]=res aa[snum]=structure.GetAminoAcid(snum) ss[snum]=structure.GetSecondaryStructure(snum) Cs[snum]=0 Gs[snum]=0 Ps[snum]=0 Hs[snum]=0 Es[snum]=0 Ls[snum]=0 if aa[snum]=='c' then Cs[snum]=1 elseif aa[snum]=='g' then Gs[snum]=1 elseif aa[snum]=='p' then Ps[snum]=1 end -- if aa if ss[snum]=='H' then Hs[snum]=1 elseif ss[snum]=='E' then Es[snum]=1 elseif ss[snum]=='L' then Ls[snum]=1 end -- if ss res=selection.IsSelected(snum) -- 12/23/15 seems gives one output if res then sel[snum]=1 des[snum]=0 else sel[snum]=0 des[snum]=1 end -- if res bbf,scf=freeze.IsFrozen(snum) -- 12/26/15 seems gives two outputs frnone[snum]=0 frbb[snum]=0 frsc[snum]=0 frbbsc[snum]=0 if bbf and scf then frbbsc[snum]=1 elseif bbf then frbb[snum]=1 elseif scf then frsc[snum]=1 else frnone[snum]=1 end -- if bbf end -- for snum -- output results totsel1=selection.GetCount() totfbb,totfsc=freeze.GetCount() jnk=outlist(' ',j100s,1) jnk=outlist(' ',j10s,1) jnk=outlist(' ',j1s,1) jnk=outlist(' aa=',aa,1) jnk=outlist(' ss=',ss,1) totsel=outlist('sel=',sel,1) jnk=outlist('des=',des,1) if totsel1~=totsel then print(' total sel above ('..totsel..') differs from selection.GetCount() ('..totsel1..').') end -- if totsel1 totfbs=outlist('fbs=',frbbsc,1) totfb=outlist('fb-=',frbb,1) totfs=outlist('f-s=',frsc,1) jnk=outlist('f--=',frnone,1) if totfbb~=totfbs+totfb then print(' total bb above ('..totfbs+totfb..') differs from freeze.GetCount() ('..totfbb..').') end -- if totfbb if totfsc~=totfbs+totfs then print(' total sc above ('..totfbs+totfs..') differs from freeze.GetCount() ('..totfsc..').') end -- if totfsc print(' ') jnk=outlist('cys=',Cs,2) jnk=outlist('gly=',Gs,2) jnk=outlist('pro=',Ps,2) jnk=outlist(' Hs=',Hs,2) jnk=outlist(' Es=',Es,2) jnk=outlist(' Ls=',Ls,2) totsel=outlist('sel=',sel,2) jnk=outlist('des=',des,2) if totsel1~=totsel then print(' total sel above ('..totsel..') differs from selection.GetCount() ('..totsel1..').') end -- if totsel1 totfbs=outlist('fbs=',frbbsc,2) totfb=outlist('fb-=',frbb,2) totfs=outlist('f-s=',frsc,2) jnk=outlist('f--=',frnone,2) if totfbb~=totfbs+totfb then print(' total bb above ('..totfbs+totfb..') differs from freeze.GetCount() ('..totfbb..').') end -- if totfbb if totfsc~=totfbs+totfs then print(' total sc above ('..totfbs+totfs..') differs from freeze.GetCount() ('..totfsc..').') end -- if totfsc print(' ') end -- makereport() -- way 1 lists vals as a 0 or 1 for each amino acid -- way 2 lists vals as groups of 1's (like 1-20 45-78 99 102-105) -- and lists the total # of 1's in vals function outlist(stri,vals,way) local stro='' local snum local numgot=0 if way==1 then for snum=1,tot do stro=(stro..vals[snum]) if vals[snum]==1 then numgot=numgot+1 end -- if vals if snum<tot then if snum==10*trunc0(snum/10) then stro=(stro..'|') -- puts '|' after every 10 chars -- but not after the final character end -- if snum end -- if snum end -- for snum stro=(stri..stro) else -- way==2 for snum=1,tot do if vals[snum]==1 then numgot=numgot+1 if snum==1 then stro=(stro..snum) elseif vals[snum-1]==0 then if numgot>1 then stro=(stro..' '..snum) else -- numgot<=1 stro=(stro..snum) end -- if numgot elseif snum==tot then stro=(stro..'-'..snum) elseif vals[snum+1]==0 then stro=(stro..'-'..snum) end -- if snum end -- if vals end -- for snum if numgot==0 then stro='none' elseif numgot==tot then stro='all' end -- if numgot stro=string.format('%s%3d=%s',stri,numgot,stro) end -- if way print(stro) return numgot end -- outlist() -- below rounds down to 3 decimal places function trunc3(numi) local numo=trunc0(numi*1000)/1000 return numo end -- trunc3() -- below rounds val down to nearest integer function trunc0(val) return math.floor(val) end -- trunc0() Main()

Comments


jeff101 Lv 1

FreezeSelectSome0 uses a menu with sliders and checkboxes to let you interactively pick ranges of segments to select, deselect, freeze, or unfreeze. For freezing and unfreezing, you can also choose backbones, sidechains, both, or neither.

As this recipe runs, it makes charts listing amino acids, secondary structure, and which segments are selected, deselected, frozen, or unfrozen. It even tells which segments have both backbones and sidechains frozen (fbs), which have frozen backbones but not sidechains (fb-), which have frozen sidechains but not backbones (f-s), and which have neither backbones nor sidechains frozen (f–). Many of these charts use 0's to indicate no or false, and 1's to indicate yes or true.

This recipe also lists which segments are cysteine (cys), glycine (gly), or proline (pro).

jeff101 Lv 1

This recipe makes selection/deselection easier in the Original Interface and freezing/unfreezing easier in the Selection Interface.

Initial tests show that this recipe works better in the Original than in the Selection Interface. In the Selection Interface, this recipe doesn't always select/deselect residues as desired. If you can find ways to improve this recipe's behavior in the Selection Interface, please let me know.

Thanks!

Bruno Kestemont Lv 1

It's m particularity useful for selection in Original Interface (I don't know other ways to select segments in the Original Interface)