Profile


Name
Meh Mutate
ID
104216
Shared with
Public
Parent
None
Children
None
Created on
December 15, 2020 at 22:27 PM UTC
Updated on
December 15, 2020 at 22:27 PM UTC
Description

Supposed to be a faster, smarter mutate tool. Ended up being really laggy. Use at your own risk. Maybe someone will get some value out of it. Based on Maaa and Mutate No Wiggle.

Best for


Code


-- Smart Mutate by joshmiller -- A faster, smarter mutate tool. Based on Maaa and Mutate No Wiggle. -- MAIN prompt = dialog.CreateDialog("Smart Mutate") prompt.Select = dialog.AddCheckbox("Use Selection", false) prompt.Orange = dialog.AddCheckbox("Orange Guard (No orange->blue)", true) prompt.Malek = dialog.AddCheckbox("MALEK only for helices", true) prompt.Sheets = dialog.AddCheckbox("YFWTVI only for sheets", true) prompt.Shake = dialog.AddCheckbox("Shake", true) prompt.Wiggle = dialog.AddCheckbox("Wiggle", true) prompt.NoCys = dialog.AddCheckbox("Exclude Cys", true) prompt.NoGly = dialog.AddCheckbox("Exclude Gly in Helix/Sheet", false) prompt.NoPro = dialog.AddCheckbox("Exclude Pro in Helix/Sheet", false) prompt.NoAla = dialog.AddCheckbox("Exclude Ala in Helix/Sheet", false) prompt.NoST = dialog.AddCheckbox("Exclude S/T in Helices", false) prompt.Iters = dialog.AddSlider("Iterations", 5, 1, 25, 0) prompt.Cancel = dialog.AddButton("Cancel", 0) prompt.Advanced = dialog.AddButton("Advanced", 1) prompt.OK = dialog.AddButton("OK", 2) advanced = dialog.CreateDialog("Smart Mutate - Advanced") advanced.Inst = dialog.AddLabel("Use duplicate letters to increase chance for including") advanced.IncludeAll = dialog.AddTextbox("Always Include", "") advanced.ExcludeAll = dialog.AddTextbox("Always Exclude", "") advanced.IncludeSheet = dialog.AddTextbox("Include in Sheets", "") advanced.ExcludeSheet = dialog.AddTextbox("Exclude in Sheets", "") advanced.IncludeHelix = dialog.AddTextbox("Include in Helices", "") advanced.ExcludeHelix = dialog.AddTextbox("Exclude in Helices", "") advanced.IncludeLoop = dialog.AddTextbox("Include in Loops", "") advanced.ExcludeLoop = dialog.AddTextbox("Exclude in Loops", "") advanced.Back = dialog.AddButton("Back", 1) selectedOranges = {} -- map res index to SS, either H E L selectedBlues = {} -- map res index to SS, either H E L helixAllowed = "arndceqghilkmfpstwyv" sheetAllowed = "arndceqghilkmfpstwyv" loopAllowed = "arndceqghilkmfpstwyv" helixAAs = "" sheetAAs = "" loopAAs = "" helixAAsOrange = "" sheetAAsOrange = "" loopAAsOrange = "" oranges = "acgilmfpwyv" individualBestAAs = {} individualBestScores = {} bestSeq = "" bestScore = -99999 function charInString(target, s) for c in string.gmatch(s, ".") do if target == c then return true end end return false end function doMain() useSelected = prompt.Select.value for i = 1, structure.GetCount() do if structure.IsMutable(i) and (not useSelected or selection.IsSelected(i)) then individualBestAAs[i] = structure.GetAminoAcid(i) individualBestScores[i] = current.GetSegmentEnergyScore(i) bestSeq = bestSeq .. individualBestAAs[i] if structure.IsHydrophobic(i) then selectedOranges[i] = structure.GetSecondaryStructure(i) else selectedBlues[i] = structure.GetSecondaryStructure(i) end end end helixAllowed = helixAllowed .. advanced.IncludeAll.value sheetAllowed = sheetAllowed .. advanced.IncludeAll.value loopAllowed = loopAllowed .. advanced.IncludeAll.value helixAllowed = helixAllowed .. advanced.IncludeHelix.value sheetAllowed = sheetAllowed .. advanced.IncludeSheet.value loopAllowed = loopAllowed .. advanced.IncludeLoop.value helixExclude = advanced.ExcludeHelix.value sheetExclude = advanced.ExcludeSheet.value loopExclude = advanced.ExcludeLoop.value if prompt.Malek.value then helixExclude = helixExclude .. "rndcqghifpstwyv" end if prompt.Sheets.value then sheetExclude = sheetExclude .. "arndceqghlkmps" end if prompt.NoCys.value then helixExclude = helixExclude .. "c" sheetExclude = sheetExclude .. "c" loopExclude = loopExclude .. "c" end if prompt.NoPro.value then helixExclude = helixExclude .. "p" sheetExclude = sheetExclude .. "p" end if prompt.NoGly.value then helixExclude = helixExclude .. "g" sheetExclude = sheetExclude .. "g" end if prompt.NoAla.value then helixExclude = helixExclude .. "a" sheetExclude = sheetExclude .. "a" end if prompt.NoST.value then helixExclude = helixExclude .. "st" end for c in string.gmatch(helixAllowed, ".") do if not charInString(c, helixExclude) then helixAAs = helixAAs .. c if charInString(c, oranges) then helixAAsOrange = helixAAsOrange .. c end end end for c in string.gmatch(sheetAllowed, ".") do if not charInString(c, sheetExclude) then sheetAAs = sheetAAs .. c if charInString(c, oranges) then sheetAAsOrange = sheetAAsOrange .. c end end end for c in string.gmatch(loopAllowed, ".") do if not charInString(c, loopExclude) then loopAAs = loopAAs .. c if charInString(c, oranges) then loopAAsOrange = loopAAsOrange .. c end end end print("Helix choices are " .. helixAAs) print("Sheet choices are " .. sheetAAs) print("Loop choices are " .. loopAAs) for ii = 1, prompt.Iters.value do oneIter() end -- try restoring each individual seg to their best scoring AA, note overall score for index,SS in pairs(selectedOranges) do structure.SetAminoAcid(index, individualBestAAs[index]) end for index,SS in pairs(selectedBlues) do structure.SetAminoAcid(index, individualBestAAs[index]) end structure.ShakeSidechainsAll(1) structure.WiggleAll(1) if current.GetScore() > bestScore then return end -- finally, restore to the best overall score, if it wasn't the individual sums pointer = 1 print("Best sequence was " .. bestSeq) for index,SS in pairs(selectedOranges) do structure.SetAminoAcid(index, string.sub(bestSeq, pointer, pointer)) pointer = pointer + 1 end for index,SS in pairs(selectedBlues) do structure.SetAminoAcid(index, string.sub(bestSeq, pointer, pointer)) pointer = pointer + 1 end end function oneIter() orangeGuard = prompt.Orange.value aaSeq = "" for index,SS in pairs(selectedOranges) do if "H" == SS then if orangeGuard then SelectableAAs = helixAAsOrange else SelectableAAs = helixAAs end elseif "E" == SS then if orangeGuard then SelectableAAs = sheetAAsOrange else SelectableAAs = sheetAAs end else if orangeGuard then SelectableAAs = loopAAsOrange else SelectableAAs = loopAAs end end AAindex = math.random(string.len(SelectableAAs)) newAA = string.sub(SelectableAAs, AAindex, AAindex) aaSeq = aaSeq .. newAA structure.SetAminoAcid(index, newAA) if current.GetSegmentEnergyScore(index) > individualBestScores[index] then individualBestAAs[index] = newAA individualBestScores[index] = current.GetSegmentEnergyScore(index) end end for index,SS in pairs(selectedBlues) do if "H" == SS then SelectableAAs = helixAAs elseif "E" == SS then SelectableAAs = sheetAAs else SelectableAAs = loopAAs end AAindex = math.random(string.len(SelectableAAs)) newAA = string.sub(SelectableAAs, AAindex, AAindex) aaSeq = aaSeq .. newAA structure.SetAminoAcid(index, newAA) end -- Shake and Wiggle if desired if prompt.Shake.value then if prompt.Select.value then structure.ShakeSidechainsSelected(1) else structure.ShakeSidechainsAll(1) end end if prompt.Wiggle.value then if prompt.Select.value then structure.WiggleSelected(1) else structure.WiggleAll(1) end end -- Save Scores for index,SS in pairs(selectedOranges) do if current.GetSegmentEnergyScore(index) > individualBestScores[index] then individualBestAAs[index] = newAA individualBestScores[index] = current.GetSegmentEnergyScore(index) end end for index,SS in pairs(selectedBlues) do if current.GetSegmentEnergyScore(index) > individualBestScores[index] then individualBestAAs[index] = newAA individualBestScores[index] = current.GetSegmentEnergyScore(index) end end if current.GetScore() > bestScore then bestSeq = aaSeq bestScore = current.GetScore() end end function ShowPrompt() local buttonClick = dialog.Show(prompt) if buttonClick == 1 then if dialog.Show(advanced) then ShowPrompt() end end if buttonClick == 2 then doMain() end end ShowPrompt()

Comments