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