--[[
Structure Finder by Crashguard303
Lua V2 version.
Searchs for chunks in a puzzle, cohesive segment sections with homogeneous secondary structure.
Checks for loop, helix and sheet sections, stores information in a user-defined table and prints them out.
For examples, see end of script.
]]--
function CreateSSsectionTables(SearchSS)
-- searchs for chunks with secondary structure which is set by variable SearchSS
-- creates two tables:
-- SegIndexATable, where start of the chunk by segment index is given
-- SegIndexBTable, where end of the chunk by segment index is given
-- For example, if you want to find all helix chunks, call this function by:
-- SegIndexATable, SegIndexBTable=CreateSSsectionTables("E")
-- SegIndexATable[1] will return start (first) segment index of 1st helix chunk
-- SegIndexBTable[1] will return end (last) segment index of 1st helix chunk
-- SegIndexATable[2] will return start (first) segment index of 2nd helix chunk
-- SegIndexBTable[2] will return end (last) segment index of 2nd helix chunk
-- and so on
local SegIndexATable = {} -- initialize chunk start segment index table
local SegIndexBTable = {} -- initialize chunk end segment index table
local k
for k=1,structure.GetCount() do -- by variable k, cycle through all puzzle segments -- Maybe you want to exchange structure.GetCount() by tot
if structure.GetSecondaryStructure(k)==SearchSS then -- if segment with index k has the same ss than we are looking for by variable SearchSS
if #SegIndexBTable>0 and SegIndexBTable[#SegIndexBTable]==(k-1) then
-- 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)
SegIndexBTable[#SegIndexBTable]=k
-- apply end segment information to current segment index
else -- if we don't have a list entry OR found segment index is not adjacent to last one
SegIndexATable[#SegIndexBTable+1]=k -- create new list entry with start
SegIndexBTable[#SegIndexBTable+1]=k -- and end segment index
-- which are equal at the beginning, as it can be a separate 1-segment-chunk with searched ss
-- we will adapt this if we find more segments with the searched ss
end -- if #SegIndexATable>0
end -- if structure.GetSecondaryStructure(k)
end -- k
return SegIndexATable,SegIndexBTable -- return both tables to be usable outside the function
end -- function CreateSSsectionTables
function GetAllChunkSections()
-- feeds segment chunk start and end tables
local SegIndexATable = {} -- initialize chunk start segment index table for ss letters
local SegIndexBTable = {} -- initialize chunk end segment index table for ss letters
local l
for l=1,#ss_letterIndex do -- by variable l, cycle through all ss letters by index
local SearchSS=ss_letterIndex[l] -- set variable SearchSS to what is in table ss_letterIndex variable l
SegIndexATable[SearchSS] = {} -- initialize chunk start segment index table with letter SearchSS for index values
SegIndexBTable[SearchSS] = {} -- initialize chunk end segment index table with letter SearchSS for index values
SegIndexATable[SearchSS], SegIndexBTable[SearchSS]=CreateSSsectionTables(SearchSS)
-- by variable SearchSS, for each secondary structrure feed chunk start and end tables with information
end -- l
return SegIndexATable,SegIndexBTable -- return both tables to be usable outside the function
end -- function GetAllChunkSections
function ShowAllChunkSections(SegIndexATable,SegIndexBTable)
-- shows what is stored in chunk tables
local l
for l=1,#ss_letterIndex do -- by variable l, cycle through all ss letters by index
local SearchSS=ss_letterIndex[l] -- set variable SearchSS to what is in table ss_letterIndex variable l
print()
local OS="Sections with secondary structure: "..ss_lettername[SearchSS].." ("..SearchSS..")" -- show ss name and letter
print(OS)
local k
for k=1,#SegIndexBTable[SearchSS] do
-- by variable k, cycle through first to last index of table (# gives last index with data)
--(we can use #SegIndexATable as well as #SegIndexBTable, as they have the same amount of entries)
local OS=k..".: "..SegIndexATable[SearchSS][k]..":"..SegIndexBTable[SearchSS][k]
-- show chunk number first (start) and last (end) segment which has the searched ss
print(OS)
end -- k
end -- l
end -- function ShowAllChunkSections
-- SCRIPT MAIN PART STARTS HERE !!! --
ss_letterIndex={"L";"H";"E"}
-- intitialize table containing all ss letters which should be checked, stored and printed (global)
-- you can change order here or let some out, however
ss_lettername={}
-- initialize table containing ss names which can by fetched by their letters, so the script can tell you what a ss letter does mean
ss_lettername["L"]="loop"
ss_lettername["H"]="helix"
ss_lettername["E"]="sheet"
StartTable,EndTable=GetAllChunkSections() -- fill user tables StartTable and EndTable with chunk information
ShowAllChunkSections(StartTable,EndTable) -- use these tables to display information
--[[
Examples, if you executed StartTable,EndTable=GetAllChunkSections() :
in StartTable["L"][1] returns start (first) segment index of 1st loop chunk
in EndTable["L"][1] returns end (last) segment index of 1st loop chunk
in StartTable["H"][2] returns start (first) segment index of 2nd helix chunk
in EndTable["H"][2] returns end (last) segment index of 2nd helix chunk
in StartTable["E"][3] returns start (first) segment index of 3rd sheet chunk
in EndTable["E"][3] returns end (last) segment index of 3rd sheet chunk
remember that you will get nil if there are no chunks with this secondary structure or not that many as your selected index
to check, how many and what chuks are thre, use:
#StartTable["L"] or #EndTable["L"] return number of loop chunks
#StartTable["H"] or #EndTable["H"] return number of helix chunks
#StartTable["E"] or #EndTable["E"] return number of sheet chunks
]]--