+ added two scripts for the psl2gff step
[qpalma.git] / tools / plot_param.py
index 4091033..6a43fd5 100644 (file)
@@ -6,8 +6,9 @@ import cPickle
 import numpy
 import sys
 
-from set_param_palma import set_param_palma
-import Configuration
+import qpalma
+from qpalma.set_param_palma import set_param_palma
+import qpalma.Configuration as Configuration
 
 # remember to check for consistency with Configuration.py
 
@@ -23,30 +24,74 @@ def plot_param(filename,train_with_intronlengthinformation=1):
        - acceptor and donor scores
        - intron length scores
     """
+    assert(Configuration.mode == 'using_quality_scores')
     param = cPickle.load(open(filename))
-    [h,d,a,mmatrix,qualityPlifs] = set_param_palma(param,train_with_intronlengthinformation)
-    pylab.imshow(numpy.reshape(mmatrix,Configuration.sizeMatchmatrix),\
-                 cmap=pylab.cm.summer,interpolation='nearest')
+    [h,d,a,mmatrix,qualityPlifs] =\
+    set_param_palma(param,train_with_intronlengthinformation,None)
 
+    # construct the substitution matrix using the last value of qualityPlif
+    substmat = numpy.matlib.zeros((1,(Configuration.estPlifs+1)*Configuration.dnaPlifs))
+    substmat[0,:Configuration.sizeMatchmatrix[0]] = mmatrix.T
+    
+    for sidx,plif in enumerate(qualityPlifs):
+        substmat[0,sidx+Configuration.sizeMatchmatrix[0]] = plif.penalties[-1]
+
+    substmat = numpy.reshape(substmat,(Configuration.estPlifs+1,Configuration.dnaPlifs))
+
+    # set up default parameters
+    pylab.rcParams.update({'xtick.labelsize' : 20,
+                           'ytick.labelsize' : 20,
+                           'legend.fontsize' : 20,
+                           })
+
+    # plot the substitution matrix
+    fig1=pylab.imshow(substmat,cmap=pylab.cm.summer,interpolation='nearest')
+    pylab.colorbar()
+    fig1.axes.xaxis.set_ticks_position('top')
+    fig1.axes.xaxis.set_label_position('top')
+    pylab.xticks( numpy.arange(0.5,6,1), ('-', 'A', 'C', 'G', 'T', 'N') )
+    pylab.yticks( numpy.arange(5.5,0,-1), ('-', 'A', 'C', 'G', 'T', 'N') )
+    pylab.xlabel('DNA',fontsize=20)
+    pylab.ylabel('EST',fontsize=20)
+
+    pylab.savefig('matrix.eps')
+    pylab.clf()
+    
+    # plot donor and acceptor transformations
     pylab.figure()
     pylab.plot(a.limits,a.penalties,'bd-',label='Acceptor',hold=True)
     pylab.plot(d.limits,d.penalties,'ro--',label='Donor')
-    pylab.xlabel('SVM output')
-    pylab.ylabel('transition score')
+    pylab.xlabel('SVM output',fontsize=20)
+    pylab.ylabel('transition score',fontsize=20)
     pylab.legend()
 
+    pylab.savefig('donacc.eps')
+    pylab.clf()
+
+    # plot intron length transformations
     pylab.figure()
     pylab.plot(h.limits,h.penalties,'k+-')
-    pylab.xlabel('intron length')
-    pylab.ylabel('transition score')
+    pylab.xlabel('intron length',fontsize=20)
+    pylab.ylabel('transition score',fontsize=20)
 
+    pylab.savefig('intron_len.eps')
+    pylab.clf()
+
+    # plot quality score transformations
     pylab.figure()
-    for plif in qualityPlifs:
-        pylab.plot(plif.limits,plif.penalties,'b^-',hold=True)
-    pylab.xlabel('quality value')
-    pylab.ylabel('transition score')
+    for pos,plif in enumerate(qualityPlifs):
+      if pos in [1,8,15,22,7,13,19]:
+      #if pos in [3,9,21]:
+         pylab.plot(plif.limits,plif.penalties,'b^-',hold=True)
+
+      #pylab.plot(plif.limits,plif.penalties,'b^-',hold=True)
+    pylab.xlabel('quality value',fontsize=20)
+    pylab.ylabel('transition score',fontsize=20)
+
+    pylab.savefig('quality.eps')
+    pylab.clf()
 
-    pylab.show()
+    #pylab.show()
     
 
 if __name__ == '__main__':