Learn Scripting!

Started by themarquis

Crashguard303 Lv 1

It's some time ago, when I programmed a sorting alogrithm only for a one-dimensional array, but for two, it's similar.

To get the 5 worst scores, at first you have to check ALL scores.
You have to create two 1-dimensional arrays which store ALL segment-numbers and scores.

For example, if the puzzle is 200 sgements, and we want to check the chlashing score per segment.
The array is index[1to200], score[1to200]

so, index[1]=1 and score[1]=get_segment_score_part("clashing",1),
index[2]=2 and score[2]=get_segment_score_part("clashing",2)

until index[200]=200 and score[200]=get_segment_score_part("clashing",200)

Then you have to run a loop from 200 to 2 backwards (let's call it k)

and IN this loop another loop, (let's call it l, running from k-1 to 1 backwards)

You have to check if score[l]>score[k]

IF so, swap score[k] with score[l] and index[k] with index[l]

QBASIC had a SWAP-function, we do this by:
temp=score[k] score[k]=score[l] score[l]=temp
temp=index[k] index[k]=index[l] index[l]=temp

to pull all worst scores AND their index-number upwards within the list.

This will give you a list with indexnumber and score, starting with index[1] and score[1] is worst and index[1] and score[1] is best.

So, fetching index[1to5] and score[1to5] will give you the 5 segment-numbers with the 5 worst scores.

I can write the algorithm this this week, but today I'm to exhausted from work, sorry :(

Btw I: To make a Best list, you ONLY have to change the condition 'score[l]>score[k]' to score[l]<score[k]!!!

Btw II: Where are the functions in the wiki gone?

regards,
Alex

Crashguard303 Lv 1

…couldn't edit my text.

"This will give you a list with indexnumber and score, starting with index[1] and score[1] is worst and index[1] and score[1] is best."

has to be:

This will give you a list with indexnumber and score, starting with index[1] and score[1] is worst and index[200] and score[200] is best.

Maybe, there is a way to make the alogithm run shorter, if you only want to have 5 values.

I'll think about it.

Crashguard303 Lv 1

Okay, I thought about it.

The shorter version needs a flag-array, where we mark the segments we have already found!

Again, index values between 1 and 200

dimensions:
flag[1 to 200], index[1to5], score[1to5]

Process k from 1 to 5 (position of new list)
set score[k]=10000 (a very high value)
Process l from 1 to 200 (check all segments)
Check if score[k]>get_segment_score_part("clashing",l) and flag[l]~=1 (index has not to be used already?)
If yes, score[k]=get_segment_score_part("clashing",l) and index[k]=l (take actual values)
end
set flag[index[k]] to 1 (mark the found index, so it is not used anymore)
end

themarquis Lv 1

there are a lot of different sorting algorithms out there. I don't think it matters which one we use. What you describe sounds great. I was thinking of something similar to your flag aray, but instead we just remove an element from the unsorted array and insert into sorted array or something like that.

Re: tables and arrays in lua,

Lua is a bit strange, because tables and arrays are the same thing. They are both objects where one set of values is associated with another set of values (of any type). So we can initialize a table:

days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
nums = {1, 2, 4, 5, 7}

These are technically tables, but they work just like arrays. days[1] is Sunday, nums[3] is 4, and so on (note that indexes start at 1).

But we can also make tables where the indices are other kinds of values. So:

opnames = {["+"] = "add", ["-"] = "sub",
           ["*"] = "mul", ["/"] = "div"}

or
days = {["M"] = "Monday", ["T"] = "Tuesday" … }

and so on. Any value of any type can be associated with any other value of any type. We can even put functions in tables, which is very interesting!

I think they can be used like records or complex data types. Like this:

segment = {["index"] = 1, ["score"] = 12, ["aa"] = "GLY"}

There are some interesting possibilities….

Crashguard303 Lv 1

Sounds nice!

And we don't need to give the dimensions in the beginning, we just can start with filling them?

Normally, some programs want to know the dimensions before, so they can reserve memory at first, and only then you can use it.

themarquis Lv 1

No – Lua automaically manages the size of tables/arrays. I really like the way tables work in Lua – so simple and powerful.

themarquis Lv 1

yes! a table can expand and contract as needed and it's easy to add or change items.

unfortunately, there is a library of table functions with things like add, remove, iterate functions, etc. that we can't use (grr!).

I put up a couple of functions on our "library" page. they may or may not be that useful but they involve forming tables of data pulled from the protein. A person can just call the function and then they have all the data at their disposal.

I'm working on a generalized version of this (may replace one of the ones I have up) that works like this:

function getProteinTable()
pTable = {}

curSeg = 1

while curSeg <= get_segment_count() do
    pTable[curSeg] = {}      -- table of tables!
        pTable[curSeg]["struct"] = get_ss(curSeg)
    pTable[curSeg]["amino"] = get_aa(curSeg)
    ... many other things like subscores 
    curSeg = curSeg + 1
end end

I want to set it up to pull out every bit of information we can get about segments, for example, all the segment score parts. The user can call the function once and it populates pTable for them. Ptable is a table of tables (one separate table for each segment in protein). They can grab things out of the pTable whenever desired with an easy method: for example, pTable[5]["amino"] will return the amino acid at segment 5. we can also make a simple print function to iterate thru ptable and print in a formatted manner. we can also have simple search and sort functions.

Maybe this is how we can tackle that issue of "worst score" sorting. We can use genralized methods instead of building a special worst score function. The user just calls the function to make the ptable and then can call something like pTableSort(backbone) (or somethng similar). pTableSort iterates thru ptable looking at backbone subscores, sorts them from worst to best (or best to worst?) and populates new table and returns that. New table has all the same info as the original ptable, just sorted based on backbone score (or whatever). Then the user can do whatever they want with the sorted table or part of it, like feed it into another function.

On a similar note of table functions, it would be cool (and simple) to alter some elements of the command set so that they take tables. For example, replace_ss(). We can make our own function pt_replace_ss() (pt for ptable) that takes a ptable of whatever size. The code would be simple, something like this:

pt_replace_ss(ptable)
for i = 1, # ptable
replace_ss(ptable[i])
end
end

We can make select and band commands do this, too (and probably others). Then a user can say make the ptable, sort for five worst scoring segments (the sort function returns a table), then send the new table to overloaded select, then run some algorithm like wiggle shake band rebuild whatever – the result is you can do whatever you want but all of it targets the worst scoring segments in the protein and leaves best scoring segs alone.

heather-1 Lv 1

This all looks easy enough. I guess I am late in looking into this. I once opened cookbook to see what it was and kept right on using regular folding methods. Have now tried a couple of scripts!!

I have several problems: (1) My receipe menu won't add any functions beyond the first one I put in and
sometimes not even that. Thus I can't construct an experimental recipe.
What do I do to fix that? re-download fold.it? or something else?

                        (2) I have now written a couple of scripts-before I run these is there someone
                            who would look them over before I crash my computer?  Where would I send 
                            it?  [Like sometimes one uses 'end' sometimes not.  [I am not an 
                            experienced programer, but have dibbeled and dabbeled in the past].