ceeaeec3072ae6a71d74a908a45abad2bacc294b
[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 if __name__ == '__main__':
34 if len(sys.argv)-1 != 2:
35 print mes
36
37 filename = sys.argv[1]
38 assert os.path.exists(filename), mes
39
40 out_filename = sys.argv[2]
41
42 convert2binary(filename,out_filename)