+ parser works now with mmap and sscanf
[qpalma.git] / python / set_param_palma.py
index 39eb949..25746ce 100644 (file)
@@ -3,37 +3,63 @@
 
 import math
 import numpy.matlib
+import QPalmaDP
+import pdb
 
 def linspace(a,b,n):
    intervalLength = b-a
-   stepSize = intervalLength / n
+   stepSize = 1.0*intervalLength / (n-1)
    
    interval = [0]*n
-   for i in range(n):
-      interval[i] = a+i*stepSize
+   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
-   intervalSize = b-a
+   begin = 10.0**a
+   end = 10.0**b
+   intervalSize = 1.0*(b-a)/(n-1)
+   interval[0] = begin
+   interval[-1] = end
 
-   interval[n-1] = b
-
-   for i in range(n-2,0,-1):
-      interval[i] = interval[i+1] / math.e
+   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
-   len = 0
-   limits = []
-   penalties = []
-   transform = ''
-   name = ''
-   max_len = 0
-   min_len = 0
+
+   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.len = len(self.limits)
+   
+      ps.limits = QPalmaDP.createDoubleArrayFromList(self.limits)
+      ps.penalties = QPalmaDP.createDoubleArrayFromList(self.penalties)
+
+      ps.max_len = self.max_len
+      ps.min_len = self.min_len
+      ps.transform = 0
+      ps.name = self.name
+
+      return ps
+
 
 def set_params_pa():
    h = plf()
@@ -81,7 +107,6 @@ def set_param_palma(param, train_with_intronlengthinformation,\
       min_svm_score=-5
       max_svm_score=5
 
-   
    h = Plf()
    d = Plf()
    a = Plf()
@@ -90,7 +115,7 @@ def set_param_palma(param, train_with_intronlengthinformation,\
    # 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:30].flatten().tolist()[0]
    #h.transform = '+1' 
    h.transform = '' 
    h.name      = 'h' 
@@ -105,7 +130,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[30:60].flatten().tolist()[0]
    #d.transform = '+1' 
    d.transform = '' 
    d.name      = 'd' 
@@ -120,7 +145,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[60:90].flatten().tolist()[0]
    #a.transform = '+1' 
    a.transform = '' 
    a.name      = 'a' 
@@ -138,3 +163,12 @@ def set_param_palma(param, train_with_intronlengthinformation,\
    mmatrix.reshape(6,6) 
 
    return h,d,a,mmatrix
+
+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)