+ changed interface for decoded plif features -> directly access double array
[qpalma.git] / python / set_param_palma.py
index 39eb949..694eb2e 100644 (file)
@@ -3,37 +3,10 @@
 
 import math
 import numpy.matlib
-
-def linspace(a,b,n):
-   intervalLength = b-a
-   stepSize = intervalLength / n
-   
-   interval = [0]*n
-   for i in range(n):
-      interval[i] = a+i*stepSize
-
-   return interval
-
-  
-def logspace(a,b,n):
-   interval = [0]*n
-   intervalSize = b-a
-
-   interval[n-1] = b
-
-   for i in range(n-2,0,-1):
-      interval[i] = interval[i+1] / math.e
-
-   return interval
-
-class Plf: #means piecewise linear function
-   len = 0
-   limits = []
-   penalties = []
-   transform = ''
-   name = ''
-   max_len = 0
-   min_len = 0
+import QPalmaDP
+import pdb
+import Configuration
+from Plif import *
 
 def set_params_pa():
    h = plf()
@@ -81,16 +54,23 @@ def set_param_palma(param, train_with_intronlengthinformation,\
       min_svm_score=-5
       max_svm_score=5
 
-   
    h = Plf()
    d = Plf()
    a = Plf()
+   qualityPlifs = [None]*Configuration.numQualPlifs
+
+   donSP       = Configuration.numDonSuppPoints
+   accSP       = Configuration.numAccSuppPoints
+   lengthSP    = Configuration.numLengthSuppPoints
+   mmatrixSP   = Configuration.sizeMatchmatrix[0]\
+   *Configuration.sizeMatchmatrix[1]
+   totalQualSP = Configuration.totalQualSuppPoints
 
    ####################
    # Gapfunktion
    ####################
    h.limits    = logspace(math.log(min_intron_len,10),math.log(max_intron_len,10),30) 
-   h.penalties = param[1:30] 
+   h.penalties = param[0:lengthSP].flatten().tolist()[0]
    #h.transform = '+1' 
    h.transform = '' 
    h.name      = 'h' 
@@ -105,7 +85,7 @@ def set_param_palma(param, train_with_intronlengthinformation,\
    # Donorfunktion
    ####################
    d.limits    = linspace(min_svm_score,max_svm_score,30) 
-   d.penalties = param[31:60]
+   d.penalties = param[lengthSP:lengthSP+donSP].flatten().tolist()[0]
    #d.transform = '+1' 
    d.transform = '' 
    d.name      = 'd' 
@@ -120,7 +100,7 @@ def set_param_palma(param, train_with_intronlengthinformation,\
    # Acceptorfunktion
    ####################
    a.limits    = linspace(min_svm_score,max_svm_score,30) 
-   a.penalties = param[61:90]
+   a.penalties = param[lengthSP+donSP:lengthSP+donSP+accSP].flatten().tolist()[0]
    #a.transform = '+1' 
    a.transform = '' 
    a.name      = 'a' 
@@ -130,11 +110,31 @@ def set_param_palma(param, train_with_intronlengthinformation,\
    a.use_svm   = 0 
    a.next_id   = 0 
 
-
    ####################
    # Matchmatrix
    ####################
-   mmatrix = numpy.matlib.mat(param[90:126])
+   mmatrix = numpy.matlib.mat(param[lengthSP+donSP+accSP:lengthSP+donSP+accSP+mmatrixSP])
    mmatrix.reshape(6,6) 
 
-   return h,d,a,mmatrix
+   ####################
+   # Quality Plifs
+   ####################
+   for idx in range(Configuration.numQualPlifs):
+      currentPlif = Plf()
+      currentPlif.limits    = linspace(Configuration.min_qual,Configuration.max_qual,Configuration.numQualSuppPoints) 
+      begin                 = lengthSP+donSP+accSP+mmatrixSP+(idx*Configuration.numQualSuppPoints)
+      end                   = lengthSP+donSP+accSP+mmatrixSP+((idx+1)*Configuration.numQualSuppPoints)
+      print begin,end
+      currentPlif.penalties = param[begin:end].flatten().tolist()[0]
+      currentPlif.transform = '' 
+      currentPlif.name      = 'q' 
+      currentPlif.max_len   = Configuration.max_qual 
+      currentPlif.min_len   = Configuration.min_qual
+      qualityPlifs[idx] = currentPlif
+
+   return h,d,a,mmatrix,qualityPlifs
+
+if __name__ == '__main__':
+   min_svm_score=-5
+   max_svm_score=5
+   print linspace(min_svm_score,max_svm_score,30)