Profile


Name
ShowWorst
ID
48284
Shared with
Public
Parent
None
Children
None
Created on
February 19, 2014 at 20:35 PM UTC
Updated on
February 19, 2014 at 20:35 PM UTC
Description

See first comment

Best for


Code


components = { "Backbone" , "Clashing" , "Ideality" , "Bonding" , "Packing" , "Hiding" , "Sidechain" , "Disulfides" , "Reference" } use_components = {} scores = {} ids = {} residue = true show_best = false show_n = 5 -- Amino acids. single_letter_codes = { "g","a","v","l","i","m","f","w","p","s","t","c","y","n","q","d","e","k","r","h"} three_letter_codes = { "Gly","Ala","Val","Leu","Ile","Met","Phe","Trp","Pro","Ser","Thr","Cys","Tyr","Asn","Gln","Asp","Glu","Lys","Arg","His"} function get_aa3 ( i ) k = structure.GetAminoAcid ( i ) for j = 1, 20 do if ( k == single_letter_codes [ j ] ) then return three_letter_codes [ j ] end end return "Unk" end function r3 ( i ) -- printing convenience return i - i % 0.001 end function print_line ( id , v ) print ( get_aa3 ( id ) .. " " .. id .. " " .. r3 ( v ) ) end function print_dataset () print ( " " ) if ( show_best == false ) then for j = 1, math.min ( show_n , n_residues ) do print_line ( ids [ j ] , scores [ j ] ) end else for j = n_residues , math.max ( n_residues - show_n + 1 , 1 ) , -1 do print_line ( ids [ j ] , scores [ j ] ) end end print ( " " ) end function ShellSort () -- Adapted from Numerical Recipes in C inc = 1 repeat inc = inc * 3 + 1 until inc > n_residues repeat inc = inc / 3 inc = inc - inc % 1 for i = inc + 1 , n_residues do v = scores [ i ] w = ids [ i ] j = i flag = false while ( flag == false and scores [ j - inc ] > v ) do scores [ j ] = scores [ j - inc ] ids [ j ] = ids [ j - inc ] j = j - inc if ( j <= inc ) then flag = true end end scores [ j ] = v ids [ j ] = w end until inc <= 1 end function GetParameters () local dlog = dialog.CreateDialog ( "Show Worst" ) dlog.residue = dialog.AddCheckbox ( "Residue" , residue ) dlog.div_1 = dialog.AddLabel ( "__________________________" ) for i = 1 , #components do dlog [ "comp_" .. i ] = dialog.AddCheckbox ( components [ i ] , false ) end dlog.div_2 = dialog.AddLabel ( "__________________________" ) dlog.show_best = dialog.AddCheckbox ( "Show best" , show_best ) dlog.show_n = dialog.AddSlider ( "Show" , show_n , 2 , 20 , 0 ) dlog.ok = dialog.AddButton ( "OK" , 1 ) dlog.cancel = dialog.AddButton ( "Cancel" , 0 ) if ( dialog.Show ( dlog ) > 0 ) then residue = dlog. residue.value for i = 1 , #components do use_components [ i ] = dlog [ "comp_" .. i ].value end show_best = dlog.show_best.value show_n = dlog.show_n.value return true else return false end end function main () n_residues = structure.GetCount () if ( GetParameters () == false ) then return -- graceful exit end if ( residue == true ) then for j = 1 , n_residues do scores [ j ] = current.GetSegmentEnergyScore ( j ) ids [ j ] = j end ShellSort () if ( show_best == false ) then print ( "Worst residues" ) else print ( "Best residues" ) end print_dataset () end for i = 1 , #components do if ( use_components [ i ] == true ) then for j = 1 , n_residues do scores [ j ] = current.GetSegmentEnergySubscore ( j , components [ i ] ) ids [ j ] = j end ShellSort () if ( show_best == false ) then print ( "Worst " .. components [ i ] ) else print ( "Best " .. components [ i ] ) end print_dataset () end end end function cleanup () end main () --xpcall ( main , cleanup )

Comments


spvincent Lv 1

A utility script that prints out the worst (or best if that option is chosen) scoring amino acids; either by total score or component score. Not going to bother descring the dialog settings: they should be self-explanatory