Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CreateSSsectionTables(SearchSS)
- -- searchs for chunks in a puzzle.
- -- chunks are cohesive sections which have the same secondary structure which is set by variable SearchSS
- -- creates two tables:
- -- SegIndexStartTable, where start of the chunk by segment index is given
- -- SegIndexEndTable, where end of the chunk by segment index is given
- -- For example, if you want to find all helix chunks, call this function by:
- -- SegIndexStartTable, SegIndexEndTable=CreateSSsectionTables("E")
- -- SegIndexStartTable[1] will return start (first) segment index of 1st helix chunk
- -- SegIndexEndTable[1] will return end (last) segment index of 1st helix chunk
- -- SegIndexStartTable[2] will return start (first) segment index of 2nd helix chunk
- -- SegIndexEndTable[2] will return end (last) segment index of 2ns helix chunk
- -- and so on
- local SegIndexStartTable = {} -- initialize chunk start segment index table
- local SegIndexEndTable = {} -- 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 #SegIndexEndTable>0 and SegIndexEndTable[#SegIndexEndTable]==(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)
- SegIndexEndTable[#SegIndexEndTable]=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
- SegIndexStartTable[#SegIndexEndTable+1]=k -- create new list entry with start
- SegIndexEndTable[#SegIndexEndTable+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 #SegIndexStartTable>0
- end -- if structure.GetSecondaryStructure(k)
- end -- k
- return SegIndexStartTable,SegIndexEndTable -- return both tables to be usable outside the function
- end -- function
- NumATable = {} -- table containing chunk start segment indices
- NumBTable = {} -- table containing chunk end segment indices
- SearchSS="H" -- This variable is just to show text, you could use the expression directly
- NumATable, NumBTable=CreateSSsectionTables(SearchSS) -- feed chunk start and end tables with information, searching for secondary structures given in SearchSS
- local OS="Chunks containing secondary structure: "..SearchSS -- show which ss we wanted to be searched
- print(OS)
- local k
- for k=1,#NumBTable do
- -- by variable k, cycle through first to last index of table (# gives last index with data)
- --(we can use #NumATable as well as #NumBTable, as they have the same amount of entries)
- local OS="Chunk "..k..": "..NumATable[k]..":"..NumBTable[k]
- -- show chunk number (which could be selected via input dialog box later), first (start) and last (end) segment which has the searched ss
- print(OS)
- end -- k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement