Icon representing a recipe

Recipe: ListStructDiffs2

created by jeff101

Profile


Name
ListStructDiffs2
ID
100728
Shared with
Public
Parent
None
Children
None
Created on
February 25, 2015 at 04:03 AM UTC
Updated on
February 25, 2015 at 04:03 AM UTC
Description

*2b.txt 553pm 2/24/15 code

Best for


Code


-- ListStructDiffs1 originally made 12/3/14 by jeff101 -- ListStructDiffs2 originally made 2/24/15 by jeff101 -- -- 2/24/15 adapted from ListStructDiffs1c.txt 607pm 12/3/14 version -- to handle puzzles with Exploration Multipliers equal to nil -- -- last updated 553pm 2/24/15 -- goal is to list information about 1 or more structures -- and to list the differences between certain pairs of them -- how to get filter scores? function Main() local subscores,f1,f2,ci,nn,n,ask,dialog_show_ask,res,ires,qflag,isok,gotone,outstr local codename='ListStructDiffs2' local tmp_slot_str=99 -- quickslot for temporarily saving current structure local cmp_slot_str=13 -- quickslots storing structures to compare with current structure local ignore_ss=true local getexpmul=false -- try to read the Exploration Multiplier local tmp_slot,cmp_slots,cmp_slot local tmp_str,cmp_str ci=behavior.GetClashImportance() print('Running '..codename..' on') print('puzzle '..puzzle.GetName()..' with ID '..puzzle.GetPuzzleID()) print('and clashing importance = '..ci..' at '..os.date()..'.') print(' ') subscores=puzzle.GetPuzzleSubscoreNames() print('The subscores available for each segment are:') for nn=1,#subscores do print(' '..subscores[nn]) end -- for nn print('Subscores that equal 0 are not listed below.') print(' ') qflag=0 while qflag==0 do ask = dialog.CreateDialog(codename) ask.Label1a = dialog.AddLabel('tmp_slot=where current structure gets stored. ') ask.Label1b = dialog.AddLabel('tmp_slot=1-100 for a quick slot, rb for RecentBest.') ask.tmp_slot_str = dialog.AddTextbox("tmp_slot: ",tmp_slot_str) ask.Label2a = dialog.AddLabel('cmp_slots=structures to compare with current one. ') ask.Label2b = dialog.AddLabel('cmp_slots=1-100 for quick slots, rb for RecentBest,') ask.Label2c = dialog.AddLabel(' cb for CreditBest, vb for VeryBest. ') ask.cmp_slot_str = dialog.AddTextbox("cmp_slots: ",cmp_slot_str) ask.ignore_ss = dialog.AddCheckbox("Ignore secondary structure differences.",ignore_ss) ask.getexpmul = dialog.AddCheckbox("Get Exploration Multiplier",getexpmul) ask.OK = dialog.AddButton("OK", 1) ask.Cancel = dialog.AddButton("Cancel", 0) dialog_show_ask = dialog.Show(ask) ignore_ss=ask.ignore_ss.value getexpmul=ask.getexpmul.value if dialog_show_ask == 0 then qflag=1 else -- dialog_show_ask must be 1 print('Getting tmp_slot from \''..ask.tmp_slot_str.value..'\':') gotone=0 for res in string.gmatch(ask.tmp_slot_str.value,'[^br%d]*([r%d][b%d]*)') do -- just want the first value for res that has res=1-100 or rb if gotone==0 then if is_int(res) then print('res=\''..res..'\' is an integer.') ires=res+0 res=ires else print('res=\''..res..'\' is not an integer.') ires=0 end if res=='rb' then isok=1 elseif ires>=1 and ires<=100 then isok=1 else print(' ERROR: want tmp_slot to be rb or 1-100, not '..res..'.') isok=0 end -- if res if isok==1 then print(' Got tmp_slot='..res..'.') tmp_slot=res gotone=1 end -- if isok end -- if gotone end -- for res print(' ') if gotone==1 then qflag=1 nn=0 cmp_slots={} outstr='' print('Getting cmp_slots from \''..ask.cmp_slot_str.value..'\':') for res in string.gmatch(ask.cmp_slot_str.value,'[^bcrv%d]*([crv%d][b%d]*)') do -- in cmp_slots want every res in ask.cmp_slot_str.value that has -- res=1-100,rb,cb,vb and differs from tmp_slot if is_int(res) then print('res=\''..res..'\' is an integer.') ires=res+0 res=ires else print('res=\''..res..'\' is not an integer.') ires=0 end if res==tmp_slot then print(' ERROR: cmp_slots should not include tmp_slot='..tmp_slot..'.') isok=0 elseif res=='cb' or res=='rb' or res=='vb' then isok=1 elseif ires>=1 and ires<=100 then isok=1 else print(' ERROR: cmp_slots should include cb, rb, vb, or 1-100, not '..res..'.') isok=0 end -- if res for n=1,nn do if isok==1 and res==cmp_slots[n] then print(' ERROR: cmp_slots should not include '..res..' more than once.') isok=0 end -- if isok end -- for n if isok==1 then nn=nn+1 cmp_slots[nn]=res print(' Got cmp_slots['..nn..']='..res..'.') outstr=outstr..res..' ' end -- if isok==1 end -- for res if nn>0 then print(string.format(' Got cmp_slots[%d-%d] = %sabove.',1,nn,outstr)) else print(' Got no elements for cmp_slots above.') end -- if nn print(' ') end -- if gotone==1 end -- if dialog_show_ask end -- while qflag==0 if dialog_show_ask==1 then if ignore_ss then print('Will ignore differences in secondary structures.') else print('Will skip comparison if secondary structures differ.') end -- if ignore_ss if getexpmul then print('Will find differences in the Exploration Multiplier.') else print('Will ignore differences in the Exploration Multiplier.') end print(' ') if #cmp_slots>0 then if tmp_slot=='rb' then tmp_str='RecentBest' recentbest.Save() -- save present structure to RecentBest else tmp_str='Slot '..tmp_slot save.Quicksave(tmp_slot+0) -- save present structure to quicksave slot tmp_slot end -- if tmp_slot print('Saving current structure to '..tmp_str..'.') end -- if #cmp_slots print('===========================================================================================================') f1=ReadPrintStruct(subscores,'Current',getexpmul) print('===========================================================================================================') if #cmp_slots>0 then for n=1,#cmp_slots do cmp_slot=cmp_slots[n] if cmp_slot=='cb' then cmp_str='CreditBest' creditbest.Restore() -- load CreditBest elseif cmp_slot=='rb' then cmp_str='RecentBest' recentbest.Restore() -- load RecentBest elseif cmp_slot=='vb' then cmp_str='VeryBest' absolutebest.Restore() -- load VeryBest else cmp_str='Slot '..cmp_slot save.Quickload(cmp_slot+0) -- load from quicksave slot cmp_slot end -- if cmp_slot f2=ReadPrintStruct(subscores,cmp_str,getexpmul) print('===========================================================================================================') ListDiffs(f1,f2,subscores,ignore_ss) print('===========================================================================================================') end -- for n print('Reloading current structure from '..tmp_str..'.') if tmp_slot=='rb' then recentbest.Restore() -- reload from RecentBest else save.Quickload(tmp_slot+0) -- reload from quicksave slot tmp_slot end -- if tmp_slot end -- if #cmp_slots end -- if dialog_show_ask == 1 print(' ') print('All done at '..os.date()..'.') end -- Main() function ReadPrintStruct(subscores,nam,getexpmul) local fn,n,nn,ss,aa,note,pflag fn={} fn.nam=nam fn.rtot=structure.GetCount() fn.nbands=band.GetCount() -- next lines failed on puzzle 1052 2/24/15 -- if current.GetExplorationMultiplier()~=nil then -- if current.GetExplorationMultiplier()~=0 then if getexpmul then fn.expmul=current.GetExplorationMultiplier() else fn.expmul=nil end fn.score1=current.GetScore() fn.sss='' fn.aas='' fn.num1s='' fn.num10s='' fn.num100s='' fn.ss={} fn.aa={} fn.note={} fn.segscore1={} fn.subscore={} fn.score2=0 -- total of fn.segscore1 for all segments fn.segscore2={} -- total of fn.subscore for all subscores fn.score3=0 -- total of fn.subscore for all segments & subscores -- same as total of fn.segscore2 for all segments fn.subscoretot={} -- total of fn.subscore for all segments for nn=1,#subscores do fn.subscoretot[nn]=0 end -- for nn for n=1,fn.rtot do fn.ss[n]=structure.GetSecondaryStructure(n) fn.aa[n]=structure.GetAminoAcid(n) fn.note[n]=structure.GetNote(n) fn.segscore1[n]=current.GetSegmentEnergyScore(n) fn.segscore2[n]=0 fn.score2=fn.score2+fn.segscore1[n] fn.subscore[n]={} for nn=1,#subscores do fn.subscore[n][nn]=current.GetSegmentEnergySubscore(n,subscores[nn]) fn.subscoretot[nn]=fn.subscoretot[nn]+fn.subscore[n][nn] fn.segscore2[n]=fn.segscore2[n]+fn.subscore[n][nn] end -- for nn fn.score3=fn.score3+fn.segscore2[n] fn.sss=fn.sss..fn.ss[n] fn.aas=fn.aas..fn.aa[n] num100s=math.floor(n/100) num10s=math.floor((n-100*num100s)/10) num1s=n-100*num100s-10*num10s fn.num1s=fn.num1s..num1s fn.num10s=fn.num10s..num10s fn.num100s=fn.num100s..num100s if num1s==0 and n<fn.rtot then fn.sss=fn.sss..'|' fn.aas=fn.aas..'|' fn.num1s=fn.num1s..'|' fn.num10s=fn.num10s..'|' fn.num100s=fn.num100s..'|' end -- if num1s end -- for n print(fn.nam..' structure has '..fn.rtot..' amino acids and '..fn.nbands..' bands:') print(' ') print(fn.num100s..'\n'..fn.num10s..'\n'..fn.num1s..'\n'..fn.aas..'\n'..fn.sss) print(' ') pflag=0 for n=1,fn.rtot do if fn.note[n]~='' then print('Note '..n..': '..fn.note[n]) pflag=1 end end -- for n if pflag==1 then print(' ') end if fn.expmul~=nil then print('Exploration multiplier = '..fn.expmul..'.') end print('Total score 1,2 = '..fn.score1..', '..fn.score2..' (differ by '..(fn.score1-fn.score2)..').') print('Total score 1,3 = '..fn.score1..', '..fn.score3..' (differ by '..(fn.score1-fn.score3)..').') print('Total score 2,3 = '..fn.score2..', '..fn.score3..' (differ by '..(fn.score2-fn.score3)..').') for nn=1,#subscores do if fn.subscoretot[nn]~=0 then print('Total for '..subscores[nn]..' = '..fn.subscoretot[nn]..'.') end end -- for nn print(' ') for n=1,fn.rtot do print('Segment '..fn.aa[n]..n..' has ss '..fn.ss[n]..' and the subscores below:') for nn=1,#subscores do if fn.subscore[n][nn]~=0 then print(' '..subscores[nn]..' = '..fn.subscore[n][nn]..'.') end end -- for nn print('Segment '..fn.aa[n]..n..' has score '..fn.segscore1[n]..' = '..fn.segscore2[n]..' (differ by '..(fn.segscore1[n]-fn.segscore2[n])..').') if n<fn.rtot then print(' ') end -- if n end -- for n return fn end -- ReadPrintStruct() function ListDiffs(f1,f2,subscores,ignore_ss) local n,nn,tmp print('Comparing '..f1.nam..' and '..f2.nam..' Structures:') if f1.rtot~=f2.rtot then print('They have '..f1.rtot..' vs '..f2.rtot..' amino acids:') print(' ') print(f1.num100s..'\n'..f1.num10s..'\n'..f1.num1s..'\n'..f1.aas..'\n'..f1.sss) print(' ') print(f2.num100s..'\n'..f2.num10s..'\n'..f2.num1s..'\n'..f2.aas..'\n'..f2.sss) elseif f1.aas~=f2.aas then print('They have different sequences:') print(' ') print(f1.num100s..'\n'..f1.num10s..'\n'..f1.num1s..'\n'..f1.aas..'\n'..f2.aas) elseif not (ignore_ss or f1.sss==f2.sss) then print('They have different secondary structures:') print(' ') print(f1.num100s..'\n'..f1.num10s..'\n'..f1.num1s..'\n'..f1.aas..'\n'..f1.sss..'\n'..f2.sss) else if f1.sss==f2.sss then print('Both have identical secondary structures:') print(' ') print(f1.num100s..'\n'..f1.num10s..'\n'..f1.num1s..'\n'..f1.aas..'\n'..f1.sss) else print('They have different secondary structures:') print(' ') print(f1.num100s..'\n'..f1.num10s..'\n'..f1.num1s..'\n'..f1.aas..'\n'..f1.sss..'\n'..f2.sss) if ignore_ss then print(' ') print('Ignoring differences in secondary structures.') end -- if ignore_ss end -- if f1.sss print(' ') if f1.expmul~=nil and f2.expmul~=nil then print('Exploration multiplier differs by '..f1.expmul..' - '..f2.expmul..' = '..(f1.expmul-f2.expmul)..'.') end print('Total score 1 differs by '..f1.score1..' - '..f2.score1..' = '..(f1.score1-f2.score1)..'.') print('Total score 2 differs by '..f1.score2..' - '..f2.score2..' = '..(f1.score2-f2.score2)..'.') print('Total score 3 differs by '..f1.score3..' - '..f2.score3..' = '..(f1.score3-f2.score3)..'.') for nn=1,#subscores do tmp=f1.subscoretot[nn]-f2.subscoretot[nn] if tmp~=0 then print('Total for '..subscores[nn]..' differs by '..f1.subscoretot[nn]..' - '..f2.subscoretot[nn]..' = '..tmp..'.') end end -- for nn print(' ') for n=1,f1.rtot do print('Segment '..f1.aa[n]..n..' has ss '..f1.ss[n]..','..f2.ss[n]..' and the subscore differences below:') for nn=1,#subscores do tmp=f1.subscore[n][nn]-f2.subscore[n][nn] if tmp~=0 then print(' '..subscores[nn]..' = '..f1.subscore[n][nn]..' - '..f2.subscore[n][nn]..' = '..tmp..'.') end end -- for nn tmp=f1.segscore1[n]-f2.segscore1[n] if tmp~=0 then print('Segment '..f1.aa[n]..n..' has score 1 = '..f1.segscore1[n]..', '..f2.segscore1[n]..' (differ by '..tmp..').') end -- if tmp tmp=f1.segscore2[n]-f2.segscore2[n] if tmp~=0 then print('Segment '..f1.aa[n]..n..' has score 2 = '..f1.segscore2[n]..', '..f2.segscore2[n]..' (differ by '..tmp..').') end -- if tmp if n<f1.rtot then print(' ') end -- if n end -- for n end -- if f1.rtot end -- ListDiffs() function is_int(res) local val,tmp tmp=string.gsub(res,'[%d]+','1') -- print('res=\''..res..'\' gives tmp=\''..tmp..'\'') if tmp=='1' then val=true else val=false end return val end -- is_int() Main()

Comments


jeff101 Lv 1

ListStructDiffs2 compares the current structure with one or more of the following structures:

Quicksave Slots 1-100
RecentBest
CreditBest
VeryBest

It lists each structure's scores and subscores
as well as the differences between these and the current structure's.

It copies the current structure temporarily to tmp_slot,
which can be rb for RecentBest or 1-100 for Quicksave Slots 1-100.
At the end, it copies the current structure back from tmp_slot.

ListStructDiffs2 is very similar to its parent,
ListStructDiffs1 (http://fold.it/portal/recipe/100351),
but ListStructDiffs2 makes using the Exploration Multiplier optional.