+ added export_param function to export parameters to "palma definition files" (param...
[qpalma.git] / python / 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_len_limits=%s\n'%(plif.name,str(plif.limits)))
12 fid.write('%s_len_penalties=%s\n'%(plif.name,str(plif.penalties)))
13 fid.write('%s_len_bins=%d\n'%(plif.name,len(plif.limits)))
14
15 if plif.name == 'intron':
16 fid.write('%s_len_min=%d\n'%(plif.name,plif.min_len))
17 fid.write('%s_len_max=%d\n'%(plif.name,plif.max_len))
18 fid.write('%s_len_transform=%s\n'%(plif.name,plif.transform))
19
20 def export_param(filename,h,d,a,mmatrix):
21
22 # Exports a bz2 file with the trained PALMA. Assumes splice sites and intron length used.
23 h.name = 'intron'
24 d.name = 'donor'
25 a.name = 'acceptor'
26
27 fid = bz2.BZ2File(filename+'.bz2','w')
28
29 fid.write('%palma definition file version: 1.0\n\n')
30 fid.write('%penalties\n');
31
32 writeStruct(fid, h);
33 writeStruct(fid, a);
34 writeStruct(fid, d);
35
36 # substitution matrix
37 mmatrix = mmatrix.reshape(6,6)
38 fid.write('substitution_matrix=[')
39 for row in range(6):
40 if row == 5:
41 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]))
42 else:
43 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]))
44
45 fid.close()