70 lines
1.4 KiB
Lua
70 lines
1.4 KiB
Lua
|
function comparison_matrix(seq)
|
||
|
matrix = {}
|
||
|
for i=1,#seq do
|
||
|
matrix[i] = {}
|
||
|
for j=1,#seq do
|
||
|
if seq[i] == seq[j] then
|
||
|
matrix[i][j] = 1
|
||
|
else
|
||
|
matrix[i][j] = 0
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
return matrix
|
||
|
end
|
||
|
|
||
|
function split_char(seq)
|
||
|
t = {}
|
||
|
seq:gsub(".",function(c) table.insert(t,c) end)
|
||
|
return t
|
||
|
end
|
||
|
|
||
|
function repr_matrix(matrix)
|
||
|
repr = ""
|
||
|
for i=1,#matrix do
|
||
|
for j=1,#matrix do
|
||
|
repr = repr .. matrix[i][j] .. " "
|
||
|
end
|
||
|
repr = repr .. "\n"
|
||
|
end
|
||
|
return repr
|
||
|
end
|
||
|
function comparison_matrix_tabular(matrix, seq1, seq2)
|
||
|
seq2 = seq2 or seq1
|
||
|
n=#seq1
|
||
|
m=#seq2
|
||
|
repr = [[\begin{tabular}{]] .. string.rep("c", n+1) .. "} \n"
|
||
|
repr = repr .. " "
|
||
|
for i=1,n do
|
||
|
repr = repr .. "& " .. seq1[i] .. " "
|
||
|
end
|
||
|
repr = repr .. "\\\\ \n "
|
||
|
for j=1,m do
|
||
|
repr = repr .. seq2[j] .. " "
|
||
|
for i=1,n do
|
||
|
repr = repr .. "& " .. matrix[i][j] .. " "
|
||
|
end
|
||
|
repr = repr .. " \\\\ \n "
|
||
|
end
|
||
|
repr = repr .. [[\end{tabular}]]
|
||
|
return repr
|
||
|
end
|
||
|
|
||
|
function main()
|
||
|
seq = split_char("ACGUUACGUUGUU")
|
||
|
|
||
|
matrix = comparison_matrix(seq)
|
||
|
|
||
|
print(comparison_matrix_tabular(matrix, seq))
|
||
|
end
|
||
|
|
||
|
function repr_comparison_matrix(seq)
|
||
|
seq = split_char(seq)
|
||
|
matrix = comparison_matrix(seq)
|
||
|
return comparison_matrix_tabular(matrix, seq)
|
||
|
end
|
||
|
|
||
|
main()
|
||
|
|
||
|
return { comparison_matrix=comparison_matrix, comparison_matrix_tabular, repr_comparison_matrix=repr_comparison_matrix }
|