I'm unsure if you are willing to help out as this isn't related to addon authorship, but I do trust this community's expertise when it comes to Lua coding. I am attempting to trial a large database of samples we have and the only language I kind of know is Lua.
We have 50,000 samples on 521 96 well plates. 520 of these 96 well plates are full. They are set up in 12 column, 8 row format. The 521st plate has 10 columns and 8 rows. I need to randomly select 400 of these samples, format them like so (123:A:10) with leading 0's on the first number for excel formatting. Lastly (and the place I'm having difficulty with) is ensuring there are no duplicates. I could just run the code until I don't get duplicates, but I would prefer not to as I'd have to submit my code to the journal publishing the results.
Lua Code:
local plate, row, column, printout
local rntl = {} --row number to letter table
local dct = {} --duplicate check table
rntl[1] = 'A'
rntl[2] = 'B'
rntl[3] = 'C'
rntl[4] = 'D'
rntl[5] = 'E'
rntl[6] = 'F'
rntl[7] = 'G'
rntl[8] = 'H'
local samplechoice = function(plate, column, row, rntl, dct, i)
plate = math.random(1,521) --50,000 samples divided on 520, 96 well plates, with 1 plate only having 80 samples
if plate == 521 then --Check to see if randomly got the one plate with only 80 samples
column = math.random(1,10)
else
column = math.random(1,12)
end
if plate < 10 then --Format to add double 0's for excel sorting purposes
plate = '00'..plate
elseif plate < 100 then --Format to add single 0's for excel sorting purposes
plate = '0'..plate
end
row = math.random(1,8)
dct[i] = plate..':'..rntl[row]..':'..column --format eg. 234:D:8
end
for i = 1,400 do
samplechoice(plate, column, row, rntl, dct, i)
for j = 1, i-1 do --Second for loop that starts with dct[1] and goes until just before the current iteration checking for string matches
if dct[i] == dct[j] then --if it finds a string match, it needs to reiterate until it doesnt
samplechoice(plate, column, row, rntl, dct, i)
end
end
print(dct[i])
end
If this is deemed inappropriate for this forum, I understand.
I think my issue lies with my function definition and call.