~ubuntu-branches/ubuntu/quantal/genometools/quantal-backports

« back to all changes in this revision

Viewing changes to testdata/gtscripts/scorematrix2c.lua

  • Committer: Package Import Robot
  • Author(s): Sascha Steinbiss
  • Date: 2012-07-09 14:10:23 UTC
  • Revision ID: package-import@ubuntu.com-20120709141023-juuu4spm6chqsf9o
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--[[
 
2
  Copyright (c) 2007-2009 Gordon Gremme <gremme@zbh.uni-hamburg.de>
 
3
  Copyright (c) 2007-2008 Center for Bioinformatics, University of Hamburg
 
4
 
 
5
  Permission to use, copy, modify, and distribute this software for any
 
6
  purpose with or without fee is hereby granted, provided that the above
 
7
  copyright notice and this permission notice appear in all copies.
 
8
 
 
9
  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
10
  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
11
  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 
12
  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
13
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
14
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 
15
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
16
]]
 
17
 
 
18
-- testing the Lua bindings for the ScoreMatrix class
 
19
 
 
20
function usage()
 
21
  io.stderr:write(string.format("Usage: %s score_matrix_file\n", arg[0]))
 
22
  io.stderr:write("Parse protein score_matrix_file and show it as C program.\n")
 
23
  os.exit(1)
 
24
end
 
25
 
 
26
if #arg == 1 then
 
27
  score_matrix_file = arg[1]
 
28
else
 
29
  usage()
 
30
end
 
31
 
 
32
protein_alpha = gt.alphabet_new_protein()
 
33
score_matrix = gt.score_matrix_new_read_protein(score_matrix_file)
 
34
assert(protein_alpha:size() == score_matrix:get_dimension())
 
35
 
 
36
print("#include <limits.h>\n")
 
37
print("int main(int argc, char *argv[])")
 
38
print("{")
 
39
print("  int score_matrix[CHAR_MAX][CHAR_MAX] = {{0}};")
 
40
for idx1 = 0, score_matrix:get_dimension()-1 do
 
41
  for idx2 = 0, score_matrix:get_dimension()-1 do
 
42
    print(string.format("  score_matrix['%s']['%s'] = %d;",
 
43
          protein_alpha:decode(idx1), protein_alpha:decode(idx2),
 
44
          score_matrix:get_score(idx1, idx2)))
 
45
  end
 
46
end
 
47
print("  return 0;")
 
48
print("}")