+ renamed main dir in order to create python module hierarchy
[qpalma.git] / qpalma / export_param.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 ###########################################################
5 #
6 ###########################################################
7
8 import bz2
9
10 def writeStruct(fid,plif):
11 fid.write('%s_limits=%s\n'%(plif.name,str(plif.limits)))
12 fid.write('%s_penalties=%s\n'%(plif.name,str(plif.penalties)))
13 fid.write('%s_bins=%d\n'%(plif.name,len(plif.limits)))
14
15 if plif.name == 'intron':
16 fid.write('%s_len_limits=%s\n'%(plif.name,str(plif.limits)))
17 fid.write('%s_len_penalties=%s\n'%(plif.name,str(plif.penalties)))
18 fid.write('%s_len_bins=%d\n'%(plif.name,len(plif.limits)))
19 fid.write('%s_len_min=%d\n'%(plif.name,plif.min_len))
20 fid.write('%s_len_max=%d\n'%(plif.name,plif.max_len))
21 fid.write('%s_len_transform=%s\n'%(plif.name,plif.transform))
22
23 def export_param(filename,h,d,a,mmatrix,qualityPlifs):
24
25 # Exports a bz2 file with the trained PALMA. Assumes splice sites and intron length used.
26 h.name = 'intron'
27 d.name = 'donor'
28 a.name = 'acceptor'
29
30 fid = bz2.BZ2File(filename+'.bz2','w')
31
32 fid.write('%palma definition file version: 1.0\n\n')
33 fid.write('%penalties\n');
34
35 writeStruct(fid, h);
36 writeStruct(fid, a);
37 writeStruct(fid, d);
38
39 # substitution matrix
40 mmatrix = mmatrix.reshape(6,6)
41 fid.write('substitution_matrix=[')
42 for row in range(6):
43 if row == 5:
44 fid.write('%f, %f, %f, %f, %f, %f]\n'%(mmatrix[row,0],mmatrix[row,1],mmatrix[row,2],mmatrix[row,3],mmatrix[row,4],mmatrix[row,5]))
45 else:
46 fid.write('%f, %f, %f, %f, %f, %f;\n'%(mmatrix[row,0],mmatrix[row,1],mmatrix[row,2],mmatrix[row,3],mmatrix[row,4],mmatrix[row,5]))
47
48
49 for elem in qualityPlifs:
50 writeStruct(fid, elem);
51
52 fid.close()