+ changed design
authorfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Thu, 6 Dec 2007 12:03:46 +0000 (12:03 +0000)
committerfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Thu, 6 Dec 2007 12:03:46 +0000 (12:03 +0000)
+ fixed variable names
+ introduced more auxiliary functions

git-svn-id: http://svn.tuebingen.mpg.de/ag-raetsch/projects/QPalma@6934 e1793c9e-67f9-0310-80fc-b846ff1f7b36

python/.qpalma.py.swp
python/qpalma.log
python/qpalma.py

index 7d97710..d0afb30 100644 (file)
Binary files a/python/.qpalma.py.swp and b/python/.qpalma.py.swp differ
index 0bf5031..725f6dc 100644 (file)
@@ -1,4 +1,4 @@
 genome_info.basedir is /fml/ag-raetsch/share/projects/palma/elegans_uncut/
+Initializing problem...
 Number of training examples: 4604
-Starting training...Initializing problem...
-Starting training...
+Starting training...Starting training...
index 3277d43..d0af41a 100644 (file)
 import sys
 import subprocess
 import scipy.io
-from paths_load_data import *
 import pdb
+
 from numpy.matlib import mat,zeros,ones,inf
-from set_param_palma import *
-from computeSpliceAlign import *
 
-from computeSpliceWeights import *
 import QPalmaDP
+
 from SIQP_CPX import SIQPSolver
 
+from paths_load_data import *
+from computeSpliceWeights import *
+from set_param_palma import *
+from computeSpliceAlign import *
 from penalty_lookup_new import *
 from compute_donacc import *
-
 from TrainingParam import Param
 
 """
 A training method for the QPalma project
-
-Overall procedure:
-   1. Load the data -> via paths_load_data
-   2. Create a QP using SIQP (paths_create_qp)
-   3. Set initial params using set_param_palma -> palma_utils
-   4. computeSpliceAlign
-   5. compute_SpliceAlignLocal
-   6. computeSpliceWeights
-   7. myalign_local
-
 """
 
-def plog(fh,string):
-   fh.write(string)
-
-def run():
-   ARGS = Param()
-
-   logfh = open('qpalma.log','w+')
-
-   gen_file= '%s/genome.config' % ARGS.basedir
-
-   cmd = ['']*4
-   cmd[0] = 'addpath /fml/ag-raetsch/home/fabio/svn/tools/utils'
-   cmd[1] = 'addpath /fml/ag-raetsch/home/fabio/svn/tools/genomes'
-   cmd[2] = 'genome_info = init_genome(\'%s\')' % gen_file
-   cmd[3] = 'save genome_info.mat genome_info'  
-   full_cmd = "matlab -nojvm -nodisplay -r \"%s; %s; %s; %s; exit\"" % (cmd[0],cmd[1],cmd[2],cmd[3])
-
-   obj = subprocess.Popen(full_cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
-   out,err = obj.communicate()
-   assert err == '', 'An error occured!\n%s'%err
-
-   ginfo = scipy.io.loadmat('genome_info.mat')
-   genome_info = ginfo['genome_info']
-
-   plog(logfh,'genome_info.basedir is %s\n'%genome_info.basedir)
-
-   Sequences, Acceptors, Donors, Exons, Ests, Noises = paths_load_data('training',genome_info,ARGS)
-
-   # number of training instances
-   N = len(Sequences) 
-   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'
-
-   plog(logfh,'Number of training examples: %d\n'% N)
-
-   random_N = 100 ; # number of constraints to generate per iteration
-   iteration_steps = 200 ; #upper bound on iteration steps
-
-   remove_duplicate_scores = 0
-   anzpath = 2
-   print_matrix = 0
-
-   # param = numpy.matlib.rand(126,1)
-   param = numpy.matlib.mat([[ 0.62870709], [ 0.7012026 ], [ 0.60236784],
-    [ 0.51316259], [ 0.20220814], [ 0.70324863], [ 0.37218684], [ 0.82178927],
-    [ 0.60394866], [ 0.70371272], [ 0.07548074], [ 0.63412803], [ 0.97442266],
-    [ 0.13216791], [ 0.71041168], [ 0.2093887 ], [ 0.35227344], [ 0.3405142 ],
-    [ 0.69677236], [ 0.41673747], [ 0.564245  ], [ 0.37613432], [ 0.88805642],
-    [ 0.88691608], [ 0.69476752], [ 0.81659504], [ 0.17801859], [ 0.71048235],
-    [ 0.08188783], [ 0.54884803], [ 0.84039558], [ 0.6982093 ], [ 0.41686176],
-    [ 0.38568873], [ 0.29401347], [ 0.12704074], [ 0.30640858], [ 0.89578031],
-    [ 0.84621571], [ 0.11783439], [ 0.0944695 ], [ 0.34081575], [ 0.44157643],
-    [ 0.77847185], [ 0.04283567], [ 0.45107823], [ 0.89789891], [ 0.41045519],
-    [ 0.49073531], [ 0.29727627], [ 0.94711483], [ 0.24898204], [ 0.26181212],
-    [ 0.71760957], [ 0.60326883], [ 0.80887576], [ 0.09448718], [ 0.88064525],
-    [ 0.84317654], [ 0.48893703], [ 0.24847021], [ 0.84203596], [ 0.34104156],
-    [ 0.75604701], [ 0.91703057], [ 0.69325475], [ 0.61276969], [ 0.16335226],
-    [ 0.4684374 ], [ 0.16553371], [ 0.79594434], [ 0.6440283 ], [ 0.80922237],
-    [ 0.5349296 ], [ 0.31924316], [ 0.10960695], [ 0.40151062], [ 0.50473641],
-    [ 0.14812671], [ 0.73523169], [ 0.35141625], [ 0.80364238], [ 0.02128181],
-    [ 0.0061226 ], [ 0.34541924], [ 0.07694485], [ 0.05551339], [ 0.23087636],
-    [ 0.87016395], [ 0.31682377], [ 0.27375113], [ 0.72226332], [ 0.62914149],
-    [ 0.59236012], [ 0.2070238 ], [ 0.52390942], [ 0.11894098], [ 0.55725917],
-    [ 0.72706009], [ 0.087196  ], [ 0.04745082], [ 0.95636492], [ 0.31524576],
-    [ 0.79685218], [ 0.80386771], [ 0.70942604], [ 0.82869417], [ 0.26906569],
-    [ 0.51848039], [ 0.64169354], [ 0.07114973], [ 0.39249454], [ 0.07002803],
-    [ 0.94667567], [ 0.02252752], [ 0.01039039], [ 0.5721312 ], [ 0.06065969],
-    [ 0.69422476], [ 0.4310939 ], [ 0.03069099], [ 0.35969779], [ 0.18047331],
-    [ 0.4177651 ], [ 0.01360547], [ 0.29069319]])
-
-   [h,d,a,mmatrix] = set_param_palma(param,ARGS.train_with_intronlengthinformation)
-
-   # checked values till this position
-
-   # delete splicesite-score-information
-   if not ARGS.train_with_splicesitescoreinformation:
-      for i in range(len(Acceptors)):
-         if Acceptors[i] > -20:
-            Acceptors[i] = 1
-         if Donors[i] >-20:
-            Donors[i] = 1
-
-   #############################################################################################
-   # Training
-   #############################################################################################
-   plog(logfh,'Starting training...')
-
-   numExamples = N
-   C=1.0
-
-   numDonSuppPoints     = 30
-   numAccSuppPoints     = 30
-   numLengthSuppPoints  = 30 
-   sizeMMatrix          = 36
-   numQualSuppPoints    = 16*0
-
-   numFeatures = numDonSuppPoints + numAccSuppPoints + + numLengthSuppPoints\
-               + sizeMMatrix + numQualSuppPoints
-
-   qualityMatrix = zeros((numQualSuppPoints,1))
-   
-   plog(logfh,'Initializing problem...\n')
-
-   #problem = SIQPSolver(numFeatures,numExamples,C,logfile)
-   num_path = anzpath*ones((1,N)) ; # nr of alignments done (best path, second-best path etc.)
-   gap = zeros((1,N))
-
-   plog(logfh,'Starting training...\n')
-
-   iteration_nr = 1
-
-   while True:
-      print 'Iteration step: %d'% iteration_nr
-
-      for exampleId in range(numExamples):
-         if exampleId % 1000 == 0:
-            print 'Current example nr %d' % exampleId
-
-         dna = Sequences[exampleId] 
-         est = Ests[exampleId] 
-
-         exons = Exons[exampleId] 
-         # NoiseMatrix = Noises[exampleId] 
-         don_supp = Donors[exampleId] 
-         acc_supp = Acceptors[exampleId] 
 
-         # Berechne die Parameter des wirklichen Alignments (but with untrained d,a,h ...)    
-         trueSpliceAlign, trueWeightMatch = computeSpliceAlign(dna, exons)
-         
-         pdb.set_trace()
-
-         # Calculate
-         trueWeightDon, trueWeightAcc, trueWeightIntron = computeSpliceWeights(d, a, h, trueSpliceAlign, don_supp, acc_supp)
 
-         # Reshape currentW param 
-         currentW = zeros((numFeatures,1))
-      
-         currentW[0:numDonSuppPoints,0] = trueWeightDon[:,0]
-         currentW[numDonSuppPoints:numDonSuppPoints+numAccSuppPoints,0] = trueWeightAcc[:,0]
-         currentW[numDonSuppPoints+numAccSuppPoints:numDonSuppPoints+numAccSuppPoints+numLengthSuppPoints,0] = trueWeightIntron[:,0]
-         currentW[numDonSuppPoints+numAccSuppPoints+numLengthSuppPoints:numDonSuppPoints+numAccSuppPoints+numLengthSuppPoints+sizeMMatrix,0] = trueWeightMatch[:,0]
-         currentW[numDonSuppPoints+numAccSuppPoints+numLengthSuppPoints+sizeMMatrix:numDonSuppPoints+numAccSuppPoints+numLengthSuppPoints+sizeMMatrix+numQualSuppPoints,0] = qualityMatrix[:,0]
+class QPalma:
+   
+   def __init__(self):
+      self.ARGS = Param()
 
-         currentPhi = zeros((numFeatures,1))
-         currentPhi[0:30]     = mat(d.penalties[:]).reshape(30,1)
-         currentPhi[30:60]    = mat(a.penalties[:]).reshape(30,1)
-         currentPhi[60:90]    = mat(h.penalties[:]).reshape(30,1)
-         currentPhi[90:126]   = mmatrix[:]
-         currentPhi[126:]   = qualityMatrix[:]
+      self.logfh = open('qpalma.log','w+')
 
-         # Calculate w'phi(x,y) the total score of the alignment
-         alignmentScore = currentW.T * currentPhi
+      gen_file= '%s/genome.config' % self.ARGS.basedir
 
-         ################## Calculate wrong alignment(s) ######################
+      cmd = ['']*4
+      cmd[0] = 'addpath /fml/ag-raetsch/home/fabio/svn/tools/utils'
+      cmd[1] = 'addpath /fml/ag-raetsch/home/fabio/svn/tools/genomes'
+      cmd[2] = 'genome_info = init_genome(\'%s\')' % gen_file
+      cmd[3] = 'save genome_info.mat genome_info'  
+      full_cmd = "matlab -nojvm -nodisplay -r \"%s; %s; %s; %s; exit\"" % (cmd[0],cmd[1],cmd[2],cmd[3])
 
-         # Compute donor, acceptor with penalty_lookup_new
-         # returns two double lists
-         donor, acceptor = compute_donacc(don_supp, acc_supp, d, a)
+      obj = subprocess.Popen(full_cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
+      out,err = obj.communicate()
+      assert err == '', 'An error occured!\n%s'%err
 
-         #myalign wants the acceptor site on the g of the ag
-         acceptor = acceptor[1:]
-         acceptor.append(-inf)
+      ginfo = scipy.io.loadmat('genome_info.mat')
+      self.genome_info = ginfo['genome_info']
 
-         ####################### checked above values ##########################################
-         nr_paths = 2
+      self.plog('genome_info.basedir is %s\n'%self.genome_info.basedir)
 
-         dna = str(dna)
-         est = str(est)
-         dna_len = len(dna)
-         est_len = len(est)
+      self.C=1.0
 
-         ps = h.convert2SWIG()
+      self.numDonSuppPoints     = 30
+      self.numAccSuppPoints     = 30
+      self.numLengthSuppPoints  = 30 
+      self.sizeMMatrix          = 36
+      self.numQualSuppPoints    = 16*0
 
-         matchmatrix = QPalmaDP.createDoubleArrayFromList(mmatrix.flatten().tolist()[0])
-         mm_len = 36
+      self.numFeatures = self.numDonSuppPoints + self.numAccSuppPoints + self.numLengthSuppPoints\
+                  + self.sizeMMatrix + self.numQualSuppPoints
 
-         d_len = len(donor)
-         donor = QPalmaDP.createDoubleArrayFromList(donor)
-         a_len = len(acceptor)
-         acceptor = QPalmaDP.createDoubleArrayFromList(acceptor)
+      self.plog('Initializing problem...\n')
 
-         remove_duplicate_scores = False
-         print_matrix = False
 
-         currentAlignment = QPalmaDP.Alignment()
-         qualityMat = QPalmaDP.createDoubleArrayFromList(qualityMatrix)
-         currentAlignment.setQualityMatrix(qualityMat,numQualSuppPoints)
+   def createParameterVector(self, trueWeightDon, trueWeightAcc, trueWeightIntron, trueWeightMatch, qualityMatrix):
+      currentW = zeros((self.numFeatures,1))
 
-         print 'PYTHON: Calling myalign...'
-         # returns [SpliceAlign, EstAlign, weightMatch, Gesamtscores, dnaest]
-         currentAlignment.myalign( nr_paths, dna, dna_len,\
-         est, est_len, ps, matchmatrix, mm_len, donor, d_len,\
-         acceptor, a_len, remove_duplicate_scores, print_matrix)
+      donS = self.numDonSuppPoints
+      accS = self.numAccSuppPoints
+      lenS = self.numLengthSuppPoints
+      matS = self.sizeMMatrix
+      qualS = self.numQualSuppPoints
 
-         #newSpliceAlign       = QPalmaDP.createIntArrayFromList([0]*(dna_len*nr_paths))
-         #newEstAlign          = QPalmaDP.createIntArrayFromList([0]*(est_len*nr_paths))
-         #newWeightMatch       = QPalmaDP.createIntArrayFromList([0]*(mm_len*nr_paths))
-         #newAlignmentScores   = QPalmaDP.createDoubleArrayFromList([.0]*nr_paths)
+      currentW[0:donS,0] = trueWeightDon[:,0]
+      currentW[donS:donS+accS,0] = trueWeightAcc[:,0]
+      currentW[donS+accS:donS+accS+lenS,0] = trueWeightIntron[:,0]
+      currentW[donS+accS+lenS:donS+accS+lenS+matS,0] = trueWeightMatch[:,0]
+      currentW[donS+accS+lenS+matS:donS+accS+lenS+matS+qualS,0] = qualityMatrix[:,0]
 
-         #currentAlignment.getAlignmentResults(newSpliceAlign, newEstAlign, newWeightMatch, newAlignmentScores)
+      return currentW
 
-         #print newSpliceAlign
 
-         print 'after myalign call...'
+   def plog(self,string):
+      self.logfh.write(string)
 
-         if exampleId == 2:
-            break
+      
+   def run(self):
+      Sequences, Acceptors, Donors, Exons, Ests, Noises = 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)
+
+      random_N = 100 ; # number of constraints to generate per iteration
+      iteration_steps = 200 ; #upper bound on iteration steps
+
+      remove_duplicate_scores = 0
+      anzpath = 2
+      print_matrix = 0
+
+      # param = numpy.matlib.rand(126,1)
+      param = numpy.matlib.mat([[ 0.62870709], [ 0.7012026 ], [ 0.60236784],
+       [ 0.51316259], [ 0.20220814], [ 0.70324863], [ 0.37218684], [ 0.82178927],
+       [ 0.60394866], [ 0.70371272], [ 0.07548074], [ 0.63412803], [ 0.97442266],
+       [ 0.13216791], [ 0.71041168], [ 0.2093887 ], [ 0.35227344], [ 0.3405142 ],
+       [ 0.69677236], [ 0.41673747], [ 0.564245  ], [ 0.37613432], [ 0.88805642],
+       [ 0.88691608], [ 0.69476752], [ 0.81659504], [ 0.17801859], [ 0.71048235],
+       [ 0.08188783], [ 0.54884803], [ 0.84039558], [ 0.6982093 ], [ 0.41686176],
+       [ 0.38568873], [ 0.29401347], [ 0.12704074], [ 0.30640858], [ 0.89578031],
+       [ 0.84621571], [ 0.11783439], [ 0.0944695 ], [ 0.34081575], [ 0.44157643],
+       [ 0.77847185], [ 0.04283567], [ 0.45107823], [ 0.89789891], [ 0.41045519],
+       [ 0.49073531], [ 0.29727627], [ 0.94711483], [ 0.24898204], [ 0.26181212],
+       [ 0.71760957], [ 0.60326883], [ 0.80887576], [ 0.09448718], [ 0.88064525],
+       [ 0.84317654], [ 0.48893703], [ 0.24847021], [ 0.84203596], [ 0.34104156],
+       [ 0.75604701], [ 0.91703057], [ 0.69325475], [ 0.61276969], [ 0.16335226],
+       [ 0.4684374 ], [ 0.16553371], [ 0.79594434], [ 0.6440283 ], [ 0.80922237],
+       [ 0.5349296 ], [ 0.31924316], [ 0.10960695], [ 0.40151062], [ 0.50473641],
+       [ 0.14812671], [ 0.73523169], [ 0.35141625], [ 0.80364238], [ 0.02128181],
+       [ 0.0061226 ], [ 0.34541924], [ 0.07694485], [ 0.05551339], [ 0.23087636],
+       [ 0.87016395], [ 0.31682377], [ 0.27375113], [ 0.72226332], [ 0.62914149],
+       [ 0.59236012], [ 0.2070238 ], [ 0.52390942], [ 0.11894098], [ 0.55725917],
+       [ 0.72706009], [ 0.087196  ], [ 0.04745082], [ 0.95636492], [ 0.31524576],
+       [ 0.79685218], [ 0.80386771], [ 0.70942604], [ 0.82869417], [ 0.26906569],
+       [ 0.51848039], [ 0.64169354], [ 0.07114973], [ 0.39249454], [ 0.07002803],
+       [ 0.94667567], [ 0.02252752], [ 0.01039039], [ 0.5721312 ], [ 0.06065969],
+       [ 0.69422476], [ 0.4310939 ], [ 0.03069099], [ 0.35969779], [ 0.18047331],
+       [ 0.4177651 ], [ 0.01360547], [ 0.29069319]])
+
+      [h,d,a,mmatrix] = set_param_palma(param,self.ARGS.train_with_intronlengthinformation)
+
+      # checked values till this position
+
+      # delete splicesite-score-information
+      if not self.ARGS.train_with_splicesitescoreinformation:
+         for i in range(len(Acceptors)):
+            if Acceptors[i] > -20:
+               Acceptors[i] = 1
+            if Donors[i] >-20:
+               Donors[i] = 1
+
+      #problem = SIQPSolver(numFeatures,numExamples,C,logfile)
+      # stores the number of alignments done for each example (best path, second-best path etc.)
+      num_path = [anzpath]*N 
+      # stores the gap for each example
+      gap      = [0.0]*N
+
+      qualityMatrix = zeros((self.numQualSuppPoints,1))
+      #############################################################################################
+      # Training
+      #############################################################################################
+      self.plog('Starting training...')
+
+
+      self.plog('Starting training...\n')
+
+      iteration_nr = 1
+
+      while True:
+         print 'Iteration step: %d'% iteration_nr
+
+         for exampleIdx in range(self.numExamples):
+            if exampleIdx% 1000 == 0:
+               print 'Current example nr %d' % exampleIdx
+
+            dna = Sequences[exampleIdx] 
+            est = Ests[exampleIdx] 
+
+            exons = Exons[exampleIdx] 
+            # NoiseMatrix = Noises[exampleIdx] 
+            don_supp = Donors[exampleIdx] 
+            acc_supp = Acceptors[exampleIdx] 
+
+            # Berechne die Parameter des wirklichen Alignments (but with untrained d,a,h ...)    
+            trueSpliceAlign, trueWeightMatch = computeSpliceAlign(dna, exons)
+            
+            # Calculate the weights
+            trueWeightDon, trueWeightAcc, trueWeightIntron = computeSpliceWeights(d, a, h, trueSpliceAlign, don_supp, acc_supp)
+
+            # Reshape currentW param 
+            currentW = self.createParameterVector(trueWeightDon, trueWeightAcc, trueWeightIntron, trueWeightMatch, qualityMatrix)
+
+            #currentPhi = createFeatureVector()
+
+            currentPhi = zeros((self.numFeatures,1))
+            currentPhi[0:30]     = mat(d.penalties[:]).reshape(30,1)
+            currentPhi[30:60]    = mat(a.penalties[:]).reshape(30,1)
+            currentPhi[60:90]    = mat(h.penalties[:]).reshape(30,1)
+            currentPhi[90:126]   = mmatrix[:]
+            currentPhi[126:]   = qualityMatrix[:]
+
+            # Calculate w'phi(x,y) the total score of the alignment
+            alignmentScore = currentW.T * currentPhi
+
+            ################## Calculate wrong alignment(s) ######################
+
+            # Compute donor, acceptor with penalty_lookup_new
+            # returns two double lists
+            donor, acceptor = compute_donacc(don_supp, acc_supp, d, a)
+
+            #myalign wants the acceptor site on the g of the ag
+            acceptor = acceptor[1:]
+            acceptor.append(-inf)
+
+            ####################### checked above values ##########################################
+            dna = str(dna)
+            est = str(est)
+            dna_len = len(dna)
+            est_len = len(est)
+
+            ps = h.convert2SWIG()
+
+            matchmatrix = QPalmaDP.createDoubleArrayFromList(mmatrix.flatten().tolist()[0])
+            mm_len = 36
+
+            d_len = len(donor)
+            donor = QPalmaDP.createDoubleArrayFromList(donor)
+            a_len = len(acceptor)
+            acceptor = QPalmaDP.createDoubleArrayFromList(acceptor)
+
+            remove_duplicate_scores = False
+            print_matrix = False
+
+            currentAlignment = QPalmaDP.Alignment()
+            qualityMat = QPalmaDP.createDoubleArrayFromList(qualityMatrix)
+            currentAlignment.setQualityMatrix(qualityMat,self.numQualSuppPoints)
+
+            print 'PYTHON: Calling myalign...'
+            # returns [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 '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])
 
-      iteration_nr += 1
-      break
+            currentAlignment.getAlignmentResults(newSpliceAlign, newEstAlign, newWeightMatch, newAlignmentScores)
+
+            #Berechne Gewichte der durch Alignment berechneten Pfade
+            true_map = zeros((1,1+num_path[exampleIdx]))
+            true_map[0] = 1
+            path_loss = [0]*num_path[exampleIdx]
 
-   logfh.close()
+            # for pathNr in range(num_path(exampleIdx)):
+            #    #dna_numbers = dnaest{1,pathNr}
+            #    #est_numbers = dnaest{2,pathNr}
+            #   
+            #    weightDon, weightAcc, weightIntron = compute_SpliceWeights(d, a, h, SpliceAlign[pathNr,:], don_supp, acc_supp)
 
-   """
-      const_added = solver.addConstraint(deltas, loss, pos, marginRescaling)
-      
-      objValue,w,self.slacks = solver.solve()
+            #    # sum up positionwise loss between alignments
+            #    for alignPosIdx in range(len(SpliceAlign[pathNr,:])):
+            #       if SpliceAlign[pathNr,alignPosIdx] != true_spliceAlign[alignPosIdx]:
+            #          path_loss[pathNr] += 1
+
+            #    # Gewichte in restliche Zeilen der Matrix speichern
+            #    Weights[pathNr+1,:] = [weightIntron, weightDon, weightAcc, weightMatch(pathNr,:)]
+
+            #    AlignmentScores(pathNr+1) = Weights(pathNr+1,:) * [h.penalties ; d.penalties ; a.penalties ; mmatrix(:)]
+
+            #    # Check wether scalar product + loss equals viterbi score
+            #    assert(abs(Gesamtscores(pathNr) - AlignmentScores(pathNr+1)) < 1e-6)
+
+            #    if norm(Weights(1,:)-Weights(pathNr+1,:))<1e-5,
+            #      true_map(pathNr+1)=1
+            #     
+            #    # the true label sequence should not have a larger score than the
+            #    # maximal one WHYYYYY?
+            #    if AlignmentScores(1) >= max(AlignmentScores(2:end))+1e-6,
+            #       AlignmentScores
+            #       warning('true score > max score\n') ;
+            #       keyboard
+            #    end ;
+
+            #    # %%set_param_palma should have done this right
+            #    for z = 1:num_path[exampleIdx]
+            #       assert(abs(Weights(z,:) * param(1:126) -AlignmentScores(z)) <= 1e-6)
+            #    end
+
+            #    if all(true_map==1)
+            #       num_path[exampleIdx]=num_path[exampleIdx]+1 ; %next iteration step: one alignment more
+            #    end ;
+
+            #    # Choose true and first false alignment for extending A
+            #    Weights = Weights([1 min(find(true_map==0))], :) ; 
+
+            #    # if there is a false alignment
+            #    if size(Weights,1)>1 & sum((Weights(1,:)-Weights(2,:)).*param)+xis[exampleIdx]<1+column_eps,
+            #       e=zeros(1,N) ; 
+            #       e[exampleIdx] = 1 ;
+            #       A=[A; Weights(2,:)-Weights(1,:) zeros(1,126) -e] ;
+            #       b=[b; -1] ;
+            #       gap[exampleIdx] = 1-sum((Weights(1,:)-Weights(2,:)).*param)-xis[exampleIdx] ;
+            #    else
+            #       gap[exampleIdx] = 0 ;
+            #    end ;
+
+            if exampleIdx== 10:
+               break
+
+         iteration_nr += 1
+         break
+
+      self.logfh.close()
+
+      """
+         const_added = solver.addConstraint(deltas, loss, pos, marginRescaling)
+         
+         objValue,w,self.slacks = solver.solve()
 
-      sum_xis = 0
-      for elem in self.slacks:
-         sum_xis +=  elem
-     
-   """
-   print 'Training completed'
+         sum_xis = 0
+         for elem in self.slacks:
+            sum_xis +=  elem
+        
+      """
+      print 'Training completed'
 
 if __name__ == '__main__':
-   run()
+   qpalma = QPalma()
+   qpalma.run()