+ extended test cases
[qpalma.git] / tools / spliceScoreConverter.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import array
5 import os.path
6 import sys
7
8 mes = 'Usage: python spliceScoreConverter.py infile outfile'
9
10 def convert2binary(in_fn,out_fn):
11 """
12 """
13
14 # count number of lines
15 file_content = open(in_fn).read()
16 size = len([e for e in file_content if e == '\n'])
17
18 positions = array.array('I',[0]*size)
19 scores = array.array('f',[0.0]*size)
20
21 for idx,line in enumerate(open(in_fn)):
22 line.strip()
23 pos,score = line.split(' ')
24 pos = int(pos)
25 score = float(score)
26
27 positions[idx] = pos
28 scores[idx] = score
29
30 positions.tofile(open('%s.pos'%out_fn,'wb'))
31 scores.tofile(open('%s.Conf'%out_fn,'wb'))
32
33
34 if __name__ == '__main__':
35 if len(sys.argv)-1 != 2:
36 print mes
37
38 filename = sys.argv[1]
39 assert os.path.exists(filename), mes
40
41 out_filename = sys.argv[2]
42
43 convert2binary(filename,out_filename)