Advertisement
Crashguard303

Section Tables All V 1.00

Jun 4th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 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. function ShowAllChunkSections()
  39.  local ss_letterIndex={"L";"H";"E"} -- intitialize table containing ss letters
  40.  local ss_lettername={} -- initialize table containing ss names which can fetched by their letters
  41.        ss_lettername["L"]="loop"
  42.        ss_lettername["H"]="helix"
  43.        ss_lettername["E"]="sheet"
  44.  
  45.  NumATable = {}
  46.  NumBTable = {}
  47.  
  48.  local l
  49.  for l=1,3 do  -- by variable l, cycle through all ss letters by index
  50.   local SearchSS=ss_letterIndex[l] -- set variable SearchSS to what is in table ss_letterIndex variable l
  51.   NumATable[SearchSS] = {} -- table containing chunk start segment indices
  52.   NumBTable[SearchSS] = {} -- table containing chunk end segment indices
  53.   NumATable[SearchSS], NumBTable[SearchSS]=CreateSSsectionTables(SearchSS)
  54.   -- feed chunk start and end tables with information, searching for secondary structures given in SearchSS
  55.  
  56.   local OS="Sections with secondary structure: "..ss_lettername[SearchSS].." ("..SearchSS..")" -- show which ss we want to be searched
  57.   print(OS)
  58.  
  59.   local k
  60.   for k=1,#NumBTable[SearchSS] do
  61.    -- by variable k, cycle through first to last index of table (# gives last index with data)
  62.    --(we can use #NumATable as well as #NumBTable, as they have the same amount of entries)
  63.    local OS=k..".: "..NumATable[SearchSS][k]..":"..NumBTable[SearchSS][k]
  64.    -- show chunk number (which could be selected via input dialog box later), first (start) and last (end) segment which has the searched ss
  65.    print(OS)
  66.   end -- k
  67.   print()
  68.  end -- l
  69. end -- function
  70.  
  71. ShowAllChunkSections()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement