Icon representing a recipe

Recipe: Bad Mutation Checker

created by brow42

Profile


Name
Bad Mutation Checker
ID
40456
Shared with
Public
Parent
None
Children
None
Created on
April 09, 2012 at 08:55 AM UTC
Updated on
April 09, 2012 at 08:55 AM UTC
Description

Lists what's mutable and what's locked, then tells you if any locked segments have been mutated (for select puzzles) (run this after your mutation script) Needs DEVPREV

Best for


Code


--[[ * Bad Mutation Checker 1.0 Apr. 8 2012 * This script lists all the locked and mutable segments in range notation * If the puzzle starting sequence is stored, it will compare looking for mutated locked segments. * Also checks for selectable locked segments * Add sequences as new design puzzles are added and need to be checked. --]] do_mutate_all = false -- True Set this to test the puzzle...otherwise False test the current structure (from a recipe) initialsegs = {} -- saved structurs for puzzles -- 537 CO2 and You Too! initialsegs[992272] = 'kwahrvmatehiprlvmqairavlldlpamitggelvvrtlikagvehlfglhgihidtifqacldhdvpiidtrheaaaghaaeglgvalvtagggftnavtpiavlfltgsgalrddetntlqagidqvamaaahrvmatehiprlvmqairaalpvlldlpwdilmnqidedsviiptnavtpianawldrtapitkpvivlgsepvfadyeglgglvqnlysfakadaaplvlmlgarfglntghgsgqliphsaqviqvdpdacelgrlqgikvtdlaqeryasiaaksssehalhpfhasqvtvvadggltylwlsevmgflchgylnsmgvgfgtalgtilvtgdgsvgysigeiviimnnqswgwtlhfqqlavgpnrvtgtrlengsinvavaldpippeeliligmdp' -- 529 CO2 And You! initialsegs[992128] = 'kwahrvmatehiprlvmqairavlldlpgmitggelvsrtlikagvehlfglhgrhideifqsalkhnvpiidtrheaaaghaaeglgvalvtagggftnavtpiavlfltgsgallnddtnsdqagidqvamaaahrvmatehiprlvmqairaalpvlldlpwyvlmnkvdedsviiptnavtpianawldrtapitkpvivlgsepvfadyeglgglvqnlysfakadaaplvlmlgarfgrhtgggdgrliphsaqviqvdpdacelgrlqgikvtdlaqeryasiaaksssehalhpfhasqvtvvadggrtykwlsevmgflchgylnsmgvgfgtalgtilvtgdgsvgysigeiviimnnnswgeatwfqilqkgpnfvygtrdengsinvavasgpippqeliengytp' -- 504 Flu Design Puzzle 4: Unfrozen! initialsegs[991577] = 'statlclghhavpngtlvktitddqievtnatelvqssstgkicntcisecitpngsipndkpfqnvnkitygacpkyvkqntlklatgmrnvpgwegmidgwygfrhqnsegtgqaadlkstqaaidqingklnrviektnekidlwsynaellvalenqhtidltdsemnklfektrrqlrenaeemgngcfkiyhkcdnaciesirngtydhdvyrdealnnrfqkfsekiakdyaksfkr' -- structure.IsLocked = function() return false end -- for main client, just to get the structure and puzzle id if structure.IsLocked == nil then print('This must be run on dev client!') return end print(puzzle.GetName(),os.date()) N = structure.GetCount() while structure.GetSecondaryStructure(N) == 'M' and N > 0 do N = N - 1 end function RangeString(first,last) if first == last then return string.format('%d',first) end return string.format('(%d - %d)', first, last) end -- Turn consecutive segments into range notations function Compress(func,val) local count = 0 local result = {} for i = 1,N do if func(i) == val then count = count + 1 else if count > 0 then result[#result+1] = RangeString(i-count,i-1) end count = 0 end end if count > 0 then result[#result+1] = RangeString(N+1-count,N) end return result end -- Print segments print('Locked:',table.concat(Compress(structure.IsLocked,true),', ')) print('Not Locked:',table.concat(Compress(structure.IsLocked,false),', ')) print('Mutable:',table.concat(Compress(structure.IsMutable,true),', ')) print('Not Mutable:',table.concat(Compress(structure.IsMutable,false),', ')) print('Mutable But Locked:',table.concat(Compress(function(i) return structure.IsMutable(i) and structure.IsLocked(i) end,true),', ')) print('Mutable and Not Locked:',table.concat(Compress(function(i) return structure.IsMutable(i) and not structure.IsLocked(i) end,true),', ')) selection.SelectAll() print('Selected and Locked:',table.concat(Compress(function(i) return selection.IsSelected(i) and structure.IsLocked(i) end,true),', ')) -- Print primary sequence for adding to script tmp = {} for i = 1,N do tmp[i] = structure.GetAminoAcid(i) end print('Primary Structure:',table.concat(tmp)) ref = initialsegs[puzzle.GetPuzzleID()] -- saved for this puzzle if ref == nil then print('No saved sequence for this puzzle (add it). #', puzzle.GetPuzzleID()) return end if N ~= #ref then print('This script is confused by insert/delete, just check mutations') return end -- tries to change everything to alanine or glycine function MutateAll() print('Mutating everything') local a for i = 1,N do a = structure.GetAminoAcid(i) structure.SetAminoAcid(i, a=='g' and 'a' or 'g') end end if do_mutate_all then MutateAll() -- Run this if you want to test the puzzle and not another script end -- Look for the bad mutations bad_muts = {} for i = 1,N do if structure.GetAminoAcid(i) ~= ref:sub(i,i) and structure.IsLocked(i) then bad_muts[#bad_muts+1] = i end end if #bad_muts == 0 then print('No bad mutations found') else print('Found bad mutations:',table.concat(bad_muts,', ')) end

Comments