-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevdistance.lua
More file actions
50 lines (44 loc) · 1.31 KB
/
Copy pathlevdistance.lua
File metadata and controls
50 lines (44 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
bk = require('bk-tree')
torch = require('torch')
xlua = require('xlua')
bio = require('bio')
moses = require('moses')
local cmd = torch.CmdLine()
cmd:option('-f', 'lev.csv', 'input file')
cmd:option('-d', 'compared-all', 'temporary output directory for data processing')
local opt = cmd:parse(arg or {})
dstr = bio.csv({file = "./".. opt.d .."/structures.csv"})
dstart = bio.csv({file = "./".. opt.d .."/start.csv"})
dend = bio.csv({file = "./".. opt.d .."/end.csv"})
table.remove(dstr)
table.remove(dstart)
table.remove(dend)
dstr = bio.flatten(dstr)
dstart = bio.flatten(dstart)
dend = bio.flatten(dend)
duni = moses.unique(dstr)
du = bio.select(duni, 1, #duni)
dr = bio.select(dstr, 1, #dstr)
ds = bio.select(dstart, 1, #dstart)
de = bio.select(dend, 1, #dend)
print("Making Levenshtein distance matrix")
tm = torch.Tensor(tonumber(#dr), tonumber(#du)):zero()
for k, v in ipairs(du) do
xlua.progress(k, #du)
for q, z in ipairs(dr) do
tm[{q, k}] = bk.levenshtein_dist(v, z)
end
end
t = {}
for i = 1, tm:size()[1] do
for j = 1, tm:size()[2] do
if j == tm:size()[2] then
t[(#t+1)] = tm[{i,j}] .. "\n"
else
t[(#t+1)] = tm[{i,j}] .. ","
end
end
end
file = assert(io.open("/files/projects/RNAgrep/v1.0/src/".. opt.d .."/" .. opt.f, "w"))
file:write(table.concat(t, ""))
file:close()