Advertisement
Crashguard303

CG303 Section Tables V1.00

Jun 4th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. function CreateSSsectionTables(SearchSS)
  2. -- searchs for chunks in a puzzle.
  3. -- chunks are cohesive sections which have the same secondary structure which is set by variable SearchSS
  4. -- creates two tables:
  5.  -- SegIndexStartTable, where start of the chunk by segment index is given
  6.  -- SegIndexEndTable, where end of the chunk by segment index is given
  7.  
  8.  -- For example, if you want to find all helix chunks, call this function by:
  9.  -- SegIndexStartTable, SegIndexEndTable=CreateSSsectionTables("E")
  10.  -- SegIndexStartTable[1] will return start (first) segment index of 1st helix chunk
  11.  -- SegIndexEndTable[1] will return end (last) segment index of 1st helix chunk
  12.  -- SegIndexStartTable[2] will return start (first) segment index of 2nd helix chunk
  13.  -- SegIndexEndTable[2] will return end (last) segment index of 2ns helix chunk
  14.  -- and so on
  15.  
  16.  local SegIndexStartTable = {} -- initialize chunk start segment index table
  17.  local SegIndexEndTable = {} -- initialize chunk end segment index table
  18.  
  19.  local k
  20.  for k=1,structure.GetCount() do -- by variable k, cycle through all puzzle segments -- Maybe you want to exchange structure.GetCount() by tot
  21.   if structure.GetSecondaryStructure(k)==SearchSS then -- if segment with index k has the same ss than we are looking for by variable SearchSS
  22.    if #SegIndexEndTable>0 and SegIndexEndTable[#SegIndexEndTable]==(k-1) then
  23.    -- 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)
  24.      SegIndexEndTable[#SegIndexEndTable]=k
  25.      -- apply end segment information to current segment index
  26.     else -- if we don't have a list entry OR found segment index is not adjacent to last one
  27.      SegIndexStartTable[#SegIndexEndTable+1]=k -- create new list entry with start
  28.      SegIndexEndTable[#SegIndexEndTable+1]=k -- and end segment index
  29.      -- which are equal at the beginning, as it can be a separate 1-segment-chunk with searched ss
  30.      -- we will adapt this if we find more segments with the searched ss
  31.    end -- if #SegIndexStartTable>0
  32.   end -- if structure.GetSecondaryStructure(k)
  33.  end -- k
  34.  
  35.  return SegIndexStartTable,SegIndexEndTable -- return both tables to be usable outside the function
  36. end -- function
  37.  
  38. NumATable = {} -- table containing chunk start segment indices
  39. NumBTable = {} -- table containing chunk end segment indices
  40. SearchSS="H" -- This variable is just to show text, you could use the expression directly
  41.  
  42. NumATable, NumBTable=CreateSSsectionTables(SearchSS) -- feed chunk start and end tables with information, searching for secondary structures given in SearchSS
  43.  
  44. local OS="Chunks containing secondary structure: "..SearchSS -- show which ss we wanted to be searched
  45. print(OS)
  46.  
  47. local k
  48. for k=1,#NumBTable do
  49.  -- by variable k, cycle through first to last index of table (# gives last index with data)
  50.  --(we can use #NumATable as well as #NumBTable, as they have the same amount of entries)
  51.  local OS="Chunk "..k..": "..NumATable[k]..":"..NumBTable[k]
  52.  -- show chunk number (which could be selected via input dialog box later), first (start) and last (end) segment which has the searched ss
  53.  print(OS)
  54. end -- k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement