+ added small parts to docu
[qpalma.git] / tools / plot_param.py
1
2 """A tool to visualise the parameter vector of QPalma"""
3
4 import pylab
5 import cPickle
6 import numpy
7 import sys
8
9 import qpalma
10 from qpalma.set_param_palma import set_param_palma
11 import qpalma.Configuration as Configuration
12
13 # remember to check for consistency with Configuration.py
14
15 # some variables for testing
16 #filename = 'param_1.pickle'
17 #train_with_intronlengthinformation = 1
18
19
20
21 def plot_param(filename,train_with_intronlengthinformation=1):
22 """Load filename, and plot 3 figures:
23 - match matrix
24 - acceptor and donor scores
25 - intron length scores
26 """
27 assert(Configuration.mode == 'using_quality_scores')
28 param = cPickle.load(open(filename))
29 [h,d,a,mmatrix,qualityPlifs] =\
30 set_param_palma(param,train_with_intronlengthinformation,None)
31
32 # construct the substitution matrix using the last value of qualityPlif
33 substmat = numpy.matlib.zeros((1,(Configuration.estPlifs+1)*Configuration.dnaPlifs))
34 substmat[0,:Configuration.sizeMatchmatrix[0]] = mmatrix.T
35
36 for sidx,plif in enumerate(qualityPlifs):
37 substmat[0,sidx+Configuration.sizeMatchmatrix[0]] = plif.penalties[-1]
38
39 substmat = numpy.reshape(substmat,(Configuration.estPlifs+1,Configuration.dnaPlifs))
40
41 # set up default parameters
42 pylab.rcParams.update({'xtick.labelsize' : 20,
43 'ytick.labelsize' : 20,
44 'legend.fontsize' : 20,
45 })
46
47 # plot the substitution matrix
48 fig1=pylab.imshow(substmat,cmap=pylab.cm.summer,interpolation='nearest')
49 pylab.colorbar()
50 fig1.axes.xaxis.set_ticks_position('top')
51 fig1.axes.xaxis.set_label_position('top')
52 pylab.xticks( numpy.arange(0.5,6,1), ('-', 'A', 'C', 'G', 'T', 'N') )
53 pylab.yticks( numpy.arange(5.5,0,-1), ('-', 'A', 'C', 'G', 'T', 'N') )
54 pylab.xlabel('DNA',fontsize=20)
55 pylab.ylabel('EST',fontsize=20)
56
57 pylab.savefig('matrix.eps')
58 pylab.clf()
59
60 # plot donor and acceptor transformations
61 pylab.figure()
62 pylab.plot(a.limits,a.penalties,'bd-',label='Acceptor',hold=True)
63 pylab.plot(d.limits,d.penalties,'ro--',label='Donor')
64 pylab.xlabel('SVM output',fontsize=20)
65 pylab.ylabel('transition score',fontsize=20)
66 pylab.legend()
67
68 pylab.savefig('donacc.eps')
69 pylab.clf()
70
71 # plot intron length transformations
72 pylab.figure()
73 pylab.plot(h.limits,h.penalties,'k+-')
74 pylab.xlabel('intron length',fontsize=20)
75 pylab.ylabel('transition score',fontsize=20)
76
77 pylab.savefig('intron_len.eps')
78 pylab.clf()
79
80 # plot quality score transformations
81 pylab.figure()
82 for pos,plif in enumerate(qualityPlifs):
83 if pos in [1,8,15,22,7,13,19]:
84 #if pos in [3,9,21]:
85 pylab.plot(plif.limits,plif.penalties,'b^-',hold=True)
86
87 #pylab.plot(plif.limits,plif.penalties,'b^-',hold=True)
88 pylab.xlabel('quality value',fontsize=20)
89 pylab.ylabel('transition score',fontsize=20)
90
91 pylab.savefig('quality.eps')
92 pylab.clf()
93
94 #pylab.show()
95
96
97 if __name__ == '__main__':
98 twil = 1
99 if len(sys.argv) < 2:
100 print 'usage: python plot_param.py paramfile.pickle [train_with_intronlengthinformation]'
101 exit()
102 elif len(sys.argv) == 3:
103 twil = sys.argv[2]
104 filename = sys.argv[1]
105
106 plot_param(filename,twil)
107 try:
108 dummy = input('Hit enter when finished.')
109 except:
110 exit()
111
112