+ parser works now with mmap and sscanf
[qpalma.git] / python / set_param_palma.py
index 1402e0d..25746ce 100644 (file)
@@ -8,26 +8,32 @@ 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
 
    def __init_(self):
@@ -41,9 +47,11 @@ class Plf: #means piecewise linear function
 
    def convert2SWIG(self):
       ps = QPalmaDP.penalty_struct()
+
+      ps.len = len(self.limits)
    
       ps.limits = QPalmaDP.createDoubleArrayFromList(self.limits)
-      ps.penalties = QPalmaDP.createDoubleArrayFromList([elem[0] for elem in self.penalties.tolist()])
+      ps.penalties = QPalmaDP.createDoubleArrayFromList(self.penalties)
 
       ps.max_len = self.max_len
       ps.min_len = self.min_len
@@ -99,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()
@@ -108,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' 
@@ -123,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' 
@@ -138,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' 
@@ -156,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)