Profile
- Name
- Note 10 random V1.0
- ID
- 44042
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- August 27, 2012 at 20:21 PM UTC
- Updated on
- August 27, 2012 at 20:21 PM UTC
- Description
places a brief Note onto segs chosen randomly (10 segs by default)
Best for
Code
-- Note 10 random V1.0
--
-- places a brief Note onto segs chosen randomly (10 segs by default)
--
-- by gramps (John McLeod)
-- V1.0 -- August 27, 2012
--
progname = "Note 10 random V1.0"
--
function NoteSpecified(turkey_count_arg, use_luckrank, use_score,
use_segno, use_AA) -- Notes the specified segs
local hit_count = 0
local begin_no = 0
local end_no = 0
local the_note = ""
-- apply the random seed
-- we'll apply a random "score" below and sort on this
-- Timo van der Laan provided workaround code in feedback
seed = (os.time() * 5779) % 10000
math.randomseed(seed)
print('seed =', seed)
-- This should work but is broken
-- refer feedback 992549
-- seed = recipe.GetRandomSeed()
-- print('seed=, seed)
-- math.randomseed(seed)
-- sort code adapted from Mutate Tweak Worst v0.1 BETA - Brow 42
targets = {}
for i = 1,structure.GetCount() do
if structure.GetSecondaryStructure(i) ~= 'M' then
targets[#targets+1] = {i, math.random()} -- random "score"
end
end
function SortFunc(a,b) -- pairs are sorted ascending by random "score"
return a[2] < b[2]
end
table.sort(targets,SortFunc)
print('Sorted',#targets,'segments.')
begin_no=1
if tonumber(turkey_count_arg) < #targets then
end_no = tonumber(turkey_count_arg)
else
end_no = #targets
end
for i = begin_no, end_no do
hit_count = hit_count + 1
the_note=""
if use_luckrank then
the_note = the_note .. " " .. i
end
if use_score then
the_note = the_note .. " " .. string.format("%3.1f",
current.GetSegmentEnergyScore(targets[i][1]))
end
if use_segno then
the_note = the_note .. " " .. targets[i][1]
end
if use_AA then
the_note = the_note .. " " .. string.upper(structure.GetAminoAcid(targets[i][1]))
end
structure.SetNote(targets[i][1], the_note)
print(the_note)
end
print("segments Noted:", hit_count)
end -- function NoteSpecified
--
-- MAIN stuff
--
print(progname,"started")
--
local ask = dialog.CreateDialog("Note 10 random")
ask.Instructions = dialog.AddLabel("random segs will be Noted: 10 by default")
ask.OK = dialog.AddButton("OK", 1)
ask.Cancel = dialog.AddButton("Cancel", 0)
ask.TurkeyCount = dialog.AddTextbox("Number to list", "10")
ask.LuckRank = dialog.AddCheckbox("Note the Luck Rank", true)
ask.Score = dialog.AddCheckbox("Note the score", false)
ask.SegNo = dialog.AddCheckbox("Note the seg num", false)
ask.AA = dialog.AddCheckbox("Note the AA code", false)
if (dialog.Show(ask) > 0) then
if nil ~= tonumber(ask.TurkeyCount.value) then
NoteSpecified(ask.TurkeyCount.value, ask.LuckRank.value,
ask.Score.value, ask.SegNo.value, ask.AA.value)
else
print("invalid worst count")
end
else
print("user canceled operation")
end
--
print(progname,"ended")
--
-- end Note 10 random V1.0