File: mat2cpp.py

package info (click to toggle)
seqan 1.4.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 34,156 kB
  • ctags: 30,130
  • sloc: cpp: 226,267; python: 7,737; xml: 189; sh: 153; awk: 129; makefile: 48
file content (41 lines) | stat: -rwxr-xr-x 1,003 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python2.5
"""Simple converter for matrix files to C++ fragments.

A matrix file is read from stdin and appropriate C++ code for
score_matrix_data.h is written to stdout.
"""

import sys


# String for one level of indentation.n
INDENT = "    ";
# Start level of indentation.
INDENT_LEVEL = 2;


def main():
  comments = []
  data_lines = []
  first_data = True
  for line in sys.stdin:
    if line[0] == '#':
      comments.append('// ' + line[1:].strip())
      continue
    if first_data:
      first_data = False
      continue
    data = line.strip().split()[1:]
    formatted_data = ['%3d' % int(d) for d in data]
    data_lines.append(INDENT + ', '.join(formatted_data) + ',')
    

  print '\n'.join([INDENT_LEVEL * INDENT + l for l in comments])
  print INDENT_LEVEL * INDENT + 'static int const _data[TAB_SIZE] = {'
  print '\n'.join([INDENT_LEVEL * INDENT + l for l in data_lines])
  print INDENT_LEVEL * INDENT + '};'
  return 0


if __name__ == '__main__':
  sys.exit(main())