File: dat2cpp.py

package info (click to toggle)
seqan2 2.4.0%2Bdfsg-16
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 224,180 kB
  • sloc: cpp: 256,886; ansic: 91,672; python: 8,330; sh: 995; xml: 570; makefile: 252; awk: 51; javascript: 21
file content (47 lines) | stat: -rwxr-xr-x 1,345 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
"""Convert RazerS gapped params .dat file to C++ fragment."""

USAGE = 'dat2cpp.py INPUT.dat'

__author__ = 'Manuel Holtgrewe <manuel.holtgrewe@fu-berlin.de>'

import os.path
import re
import sys

def parseFile(f, n, d):
    res = []
    header = f.readline()
    ws = f.readline()
    assert not ws.strip()
    for line in f:
        errors, shape, t, loss_rate, pot_mat = tuple([x.strip() for x in line.split()])
        errors = int(errors)
        t = int(t)
        loss_rate = float(loss_rate)
        pot_mat = int(pot_mat)
        res.append(tuple([n, '\'%s\'' % d, errors, '"' + shape + '"', t, loss_rate, pot_mat]))
    return res

def main():
    # Check arguments.
    if len(sys.argv) == 1:
        print(USAGE, file=sys.stderr)
        return 1
    # Process each file.
    records = []
    paths = sys.argv[1:]
    for path in paths:
        fname = os.path.basename(path)
        t = re.match('results_N([0-9]+)_([LH])', fname).groups()
        n = int(t[0])
        d = t[1]
        with open(fname, 'rb') as f:
            records += parseFile(f, n, d)
    print('/* Gapped params.  Generated by dat2cpp.py. */\n')
    for r in sorted(records):
        print('{ %s },' % ', '.join(map(str, r)))
    print('{ 0, \'\\0\', 0, 0, 0, 0, 0 } /* terminator */')

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