SHARE
TWEET

CG303 Structure Sections V3.00

Crashguard303 Jun 4th, 2012 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. Structure Finder by Crashguard303
  3. Lua V2 version.
  4. Searchs for chunks in a puzzle, cohesive segment sections with homogeneous secondary structure.
  5. Checks for loop, helix and sheet sections, stores information in a user-defined table and prints them out.
  6.  
  7. For examples, see end of script.
  8. ]]--
  9.  
  10. function CreateSSsectionTables(SearchSS)
  11. -- searchs for chunks with secondary structure which is set by variable SearchSS
  12. -- creates two tables:
  13.  -- SegIndexATable, where start of the chunk by segment index is given
  14.  -- SegIndexBTable, where end of the chunk by segment index is given
  15.  
  16.  -- For example, if you want to find all helix chunks, call this function by:
  17.  -- SegIndexATable, SegIndexBTable=CreateSSsectionTables("E")
  18.  -- SegIndexATable[1] will return start (first) segment index of 1st helix chunk
  19.  -- SegIndexBTable[1] will return end (last) segment index of 1st helix chunk
  20.  -- SegIndexATable[2] will return start (first) segment index of 2nd helix chunk
  21.  -- SegIndexBTable[2] will return end (last) segment index of 2nd helix chunk
  22.  -- and so on
  23.  
  24.  local SegIndexATable = {} -- initialize chunk start segment index table
  25.  local SegIndexBTable = {} -- initialize chunk end segment index table
  26.  
  27.  local k
  28.  for k=1,structure.GetCount() do -- by variable k, cycle through all puzzle segments -- Maybe you want to exchange structure.GetCount() by tot
  29.   if structure.GetSecondaryStructure(k)==SearchSS then -- if segment with index k has the same ss than we are looking for by variable SearchSS
  30.    if #SegIndexBTable>0 and SegIndexBTable[#SegIndexBTable]==(k-1) then
  31.    -- if we already have a list entry and the last entry of end segment index is just one index before (so, current found segment is directly after last found segment)
  32.      SegIndexBTable[#SegIndexBTable]=k
  33.      -- apply end segment information to current segment index
  34.     else -- if we don't have a list entry OR found segment index is not adjacent to last one
  35.      SegIndexATable[#SegIndexBTable+1]=k -- create new list entry with start
  36.      SegIndexBTable[#SegIndexBTable+1]=k -- and end segment index
  37.      -- which are equal at the beginning, as it can be a separate 1-segment-chunk with searched ss
  38.      -- we will adapt this if we find more segments with the searched ss
  39.    end -- if #SegIndexATable>0
  40.   end -- if structure.GetSecondaryStructure(k)
  41.  end -- k
  42.  
  43.  return SegIndexATable,SegIndexBTable -- return both tables to be usable outside the function
  44. end -- function CreateSSsectionTables
  45.  
  46. function GetAllChunkSections()
  47.  -- feeds segment chunk start and end tables
  48.  local SegIndexATable = {} -- initialize chunk start segment index table for ss letters
  49.  local SegIndexBTable = {} -- initialize chunk end segment index table for ss letters
  50.  
  51.  local l
  52.  for l=1,#ss_letterIndex do  -- by variable l, cycle through all ss letters by index
  53.   local SearchSS=ss_letterIndex[l] -- set variable SearchSS to what is in table ss_letterIndex variable l
  54.   SegIndexATable[SearchSS] = {} -- initialize chunk start segment index table with letter SearchSS for index values
  55.   SegIndexBTable[SearchSS] = {} -- initialize chunk end segment index table with letter SearchSS for index values
  56.   SegIndexATable[SearchSS], SegIndexBTable[SearchSS]=CreateSSsectionTables(SearchSS)
  57.   -- by variable SearchSS, for each secondary structrure feed chunk start and end tables with information
  58.  end -- l
  59.  
  60.  return SegIndexATable,SegIndexBTable -- return both tables to be usable outside the function
  61. end -- function GetAllChunkSections
  62.  
  63. function ShowAllChunkSections(SegIndexATable,SegIndexBTable)
  64.  -- shows what is stored in chunk tables
  65.  local l
  66.  for l=1,#ss_letterIndex do  -- by variable l, cycle through all ss letters by index
  67.   local SearchSS=ss_letterIndex[l] -- set variable SearchSS to what is in table ss_letterIndex variable l
  68.  
  69.   print()
  70.   local OS="Sections with secondary structure: "..ss_lettername[SearchSS].." ("..SearchSS..")" -- show ss name and letter
  71.   print(OS)
  72.  
  73.   local k
  74.   for k=1,#SegIndexBTable[SearchSS] do
  75.    -- by variable k, cycle through first to last index of table (# gives last index with data)
  76.    --(we can use #SegIndexATable as well as #SegIndexBTable, as they have the same amount of entries)
  77.    local OS=k..".: "..SegIndexATable[SearchSS][k]..":"..SegIndexBTable[SearchSS][k]
  78.    -- show chunk number first (start) and last (end) segment which has the searched ss
  79.    print(OS)
  80.   end -- k
  81.  end -- l
  82. end -- function ShowAllChunkSections
  83.  
  84.  
  85. -- SCRIPT MAIN PART STARTS HERE !!! --
  86.  
  87. ss_letterIndex={"L";"H";"E"}
  88. -- intitialize table containing all ss letters which should be checked, stored and printed (global)
  89. -- you can change order here or let some out, however
  90.  
  91. ss_lettername={}
  92. -- initialize table containing ss names which can by fetched by their letters, so the script can tell you what a ss letter does mean
  93. ss_lettername["L"]="loop"
  94. ss_lettername["H"]="helix"
  95. ss_lettername["E"]="sheet"
  96.  
  97. StartTable,EndTable=GetAllChunkSections() -- fill user tables StartTable and EndTable with chunk information
  98.  
  99. ShowAllChunkSections(StartTable,EndTable) -- use these tables to display information
  100.  
  101.  
  102. --[[
  103. Examples, if you executed StartTable,EndTable=GetAllChunkSections() :
  104.  
  105. in StartTable["L"][1] returns start (first) segment index of 1st loop chunk
  106. in EndTable["L"][1] returns end (last) segment index of 1st loop chunk
  107.  
  108. in StartTable["H"][2] returns start (first) segment index of 2nd helix chunk
  109. in EndTable["H"][2] returns end (last) segment index of 2nd helix chunk
  110.  
  111. in StartTable["E"][3] returns start (first) segment index of 3rd sheet chunk
  112. in EndTable["E"][3] returns end (last) segment index of 3rd sheet chunk
  113.  
  114. remember that you will get nil if there are no chunks with this secondary structure or not that many as your selected index
  115. to check, how many and what chuks are thre, use:
  116.  
  117. #StartTable["L"] or #EndTable["L"] return number of loop chunks
  118. #StartTable["H"] or #EndTable["H"] return number of helix chunks
  119. #StartTable["E"] or #EndTable["E"] return number of sheet chunks
  120. ]]--
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top