+ added export_param function to export parameters to "palma definition files" (param...
[qpalma.git] / python / qpalma.py
index 33ac32d..977d340 100644 (file)
@@ -26,6 +26,7 @@ from computeSpliceAlign import *
 from penalty_lookup_new import *
 from compute_donacc import *
 from TrainingParam import Param
+from export_param import *
 
 import Configuration
 
@@ -81,15 +82,15 @@ class QPalma:
 
       #Sequences, Acceptors, Donors, Exons, Ests, QualityScores = paths_load_data('training',self.genome_info,self.ARGS)
 
+
       # number of training instances
       N = len(Sequences) 
       self.numExamples = N
       assert N == len(Acceptors) and N == len(Acceptors) and N == len(Exons)\
       and N == len(Ests), 'The Seq,Accept,Donor,.. arrays are of different lengths'
-
       self.plog('Number of training examples: %d\n'% N)
 
-      iteration_steps = 200 ; #upper bound on iteration steps
+      iteration_steps = 10 ; #upper bound on iteration steps
 
       remove_duplicate_scores = False
       print_matrix = False
@@ -102,6 +103,7 @@ class QPalma:
       # Set the parameters such as limits penalties for the Plifs
       [h,d,a,mmatrix] = set_param_palma(param,self.ARGS.train_with_intronlengthinformation)
 
+
       # delete splicesite-score-information
       if not self.ARGS.train_with_splicesitescoreinformation:
          for i in range(len(Acceptors)):
@@ -129,7 +131,8 @@ class QPalma:
       iteration_nr = 1
 
       while True:
-         print 'Iteration step: %d'% iteration_nr
+         if iteration_nr == iteration_steps:
+            break
 
          for exampleIdx in range(self.numExamples):
             if exampleIdx% 1000 == 0:
@@ -197,39 +200,37 @@ class QPalma:
             qualityMat = QPalmaDP.createDoubleArrayFromList(qualityMatrix)
             currentAlignment.setQualityMatrix(qualityMat,self.numQualSuppPoints)
 
-            print 'PYTHON: Calling myalign...'
+            #print 'PYTHON: Calling myalign...'
             # calculates SpliceAlign, EstAlign, weightMatch, Gesamtscores, dnaest
             currentAlignment.myalign( num_path[exampleIdx], dna, dna_len,\
             est, est_len, ps, matchmatrix, mm_len, donor, d_len,\
             acceptor, a_len, remove_duplicate_scores, print_matrix)
-            print 'PYTHON: After myalign call...'
+            #print 'PYTHON: After myalign call...'
 
             newSpliceAlign       = QPalmaDP.createIntArrayFromList([0]*(dna_len*num_path[exampleIdx]))
             newEstAlign          = QPalmaDP.createIntArrayFromList([0]*(est_len*num_path[exampleIdx]))
             newWeightMatch       = QPalmaDP.createIntArrayFromList([0]*(mm_len*num_path[exampleIdx]))
             newAlignmentScores   = QPalmaDP.createDoubleArrayFromList([.0]*num_path[exampleIdx])
 
-            pdb.set_trace()
-
             currentAlignment.getAlignmentResults(newSpliceAlign, newEstAlign, newWeightMatch, newAlignmentScores)
 
             spliceAlign = zeros((num_path[exampleIdx]*dna_len,1))
             weightMatch = zeros((num_path[exampleIdx]*mm_len,1))
 
-            print 'spliceAlign'
-            for i in range(dna_len*num_path[exampleIdx]):
-               spliceAlign[i] = newSpliceAlign[i]
-               print '%f' % (spliceAlign[i])
+            #print 'spliceAlign'
+            #for i in range(dna_len*num_path[exampleIdx]):
+            #   spliceAlign[i] = newSpliceAlign[i]
+            #   print '%f' % (spliceAlign[i])
 
-            print 'weightMatch'
-            for i in range(mm_len*num_path[exampleIdx]):
-               weightMatch[i] = newWeightMatch[i]
-               print '%f' % (weightMatch[i])
+            #print 'weightMatch'
+            #for i in range(mm_len*num_path[exampleIdx]):
+            #   weightMatch[i] = newWeightMatch[i]
+            #   print '%f' % (weightMatch[i])
 
             for i in range(num_path[exampleIdx]):
                AlignmentScores[i+1] = newAlignmentScores[i]
 
-            print AlignmentScores
+            #print AlignmentScores
                
             spliceAlign = spliceAlign.reshape(num_path[exampleIdx],dna_len)
             weightMatch = weightMatch.reshape(num_path[exampleIdx],mm_len)
@@ -305,12 +306,18 @@ class QPalma:
                      for elem in self.slacks:
                         sum_xis +=  elem
 
-            if exampleIdx==0:
+                  for i in range(len(param)):
+                     param[i] = w[i]
+
+                  [h,d,a,mmatrix] = set_param_palma(param,self.ARGS.train_with_intronlengthinformation)
+                  
+
+            if exampleIdx==10:
                break
 
          iteration_nr += 1
-         break
 
+      export_param('test_params',h,d,a,mmatrix)
       self.logfh.close()
       print 'Training completed'