+ changed interface for decoded plif features -> directly access double array
[qpalma.git] / python / set_param_palma.py
index 761d7ff..694eb2e 100644 (file)
@@ -5,59 +5,8 @@ import math
 import numpy.matlib
 import QPalmaDP
 import pdb
-
-def linspace(a,b,n):
-   intervalLength = b-a
-   stepSize = 1.0*intervalLength / (n-1)
-   
-   interval = [0]*n
-   interval[0] = a
-   interval[-1] = b
-   for i in range(1,n-1):
-      interval[i] = a+(i*stepSize)
-
-   return interval
-
-def logspace(a,b,n):
-   interval = [0]*n
-   begin = 10.0**a
-   end = 10.0**b
-   intervalSize = 1.0*(b-a)/(n-1)
-   interval[0] = begin
-   interval[-1] = end
-
-   for i in range(1,n-1):
-      interval[i] = 10**(a+i*intervalSize)
-
-   return interval
-
-def log10(x):
-   return math.log(x)/math.log(10)
-
-class Plf: #means piecewise linear function
-
-   def __init_(self):
-      self.len = 0
-      self.limits = []
-      self.penalties = []
-      self.transform = ''
-      self.name = ''
-      self.max_len = 0
-      self.min_len = 0
-
-   def convert2SWIG(self):
-      ps = QPalmaDP.penalty_struct()
-   
-      ps.limits = QPalmaDP.createDoubleArrayFromList(self.limits)
-      ps.penalties = QPalmaDP.createDoubleArrayFromList([elem[0] for elem in self.penalties.tolist()])
-
-      ps.max_len = self.max_len
-      ps.min_len = self.min_len
-      ps.transform = 0
-      ps.name = self.name
-
-      return ps
-
+import Configuration
+from Plif import *
 
 def set_params_pa():
    h = plf()
@@ -108,12 +57,20 @@ def set_param_palma(param, train_with_intronlengthinformation,\
    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[0:30] 
+   h.penalties = param[0:lengthSP].flatten().tolist()[0]
    #h.transform = '+1' 
    h.transform = '' 
    h.name      = 'h' 
@@ -128,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[30:60]
+   d.penalties = param[lengthSP:lengthSP+donSP].flatten().tolist()[0]
    #d.transform = '+1' 
    d.transform = '' 
    d.name      = 'd' 
@@ -143,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[60:90]
+   a.penalties = param[lengthSP+donSP:lengthSP+donSP+accSP].flatten().tolist()[0]
    #a.transform = '+1' 
    a.transform = '' 
    a.name      = 'a' 
@@ -153,20 +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_intron_len=20
-   #max_intron_len=1000
-   #print logspace(math.log(min_intron_len,10),math.log(max_intron_len,10),30) 
-
    min_svm_score=-5
    max_svm_score=5
    print linspace(min_svm_score,max_svm_score,30)