+ fix
authorfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Fri, 25 Jan 2008 17:09:36 +0000 (17:09 +0000)
committerfabio <fabio@e1793c9e-67f9-0310-80fc-b846ff1f7b36>
Fri, 25 Jan 2008 17:09:36 +0000 (17:09 +0000)
git-svn-id: http://svn.tuebingen.mpg.de/ag-raetsch/projects/QPalma@7587 e1793c9e-67f9-0310-80fc-b846ff1f7b36

scripts/qpalma.py

index 9392639..e32f8aa 100644 (file)
@@ -24,10 +24,7 @@ from numpy.matlib import mat,zeros,ones,inf
 from numpy.linalg import norm
 
 import QPalmaDP
-
 import qpalma
-import qpalma.Configuration
-
 from qpalma.SIQP_CPX import SIQPSolver
 from qpalma.DataProc import *
 from qpalma.generateEvaluationData import *
@@ -42,6 +39,8 @@ from qpalma.Plif import Plf
 
 from qpalma.tools.splicesites import getDonAccScores
 
+from qpalma.Configuration import *
+
 class para:
    pass
 
@@ -62,12 +61,12 @@ class QPalma:
       #self.ARGS.train_with_splicesitescoreinformation = False
 
       # Load the whole dataset 
-      if Configuration.mode == 'normal':
+      if Conf.mode == 'normal':
          #Sequences, Acceptors, Donors, Exons, Ests, Noises = paths_load_data_pickle('training',self.genome_info,self.ARGS)
          Sequences, Acceptors, Donors, Exons, Ests, Qualities = loadArtificialData(1000)
          self.use_quality_scores = False
 
-      elif Configuration.mode == 'using_quality_scores':
+      elif Conf.mode == 'using_quality_scores':
 
          filename = 'real_dset_%s'% 'recent'
          if True:# not os.path.exists(filename):
@@ -107,15 +106,15 @@ class QPalma:
       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)
-      print 'Number of features: %d\n'% Configuration.numFeatures
+      print 'Number of features: %d\n'% Conf.numFeatures
 
    def plog(self,string):
       self.logfh.write(string)
       self.logfh.flush()
 
    def train(self):
-      beg = Configuration.training_begin
-      end = Configuration.training_end
+      beg = Conf.training_begin
+      end = Conf.training_end
 
       Sequences   = self.Sequences[beg:end]
       Exons       = self.Exons[beg:end]
@@ -124,13 +123,13 @@ class QPalma:
       Acceptors   = self.Acceptors[beg:end]
       Donors      = self.Donors[beg:end]
 
-      iteration_steps         = Configuration.iter_steps ; #upper bound on iteration steps
-      remove_duplicate_scores = Configuration.remove_duplicate_scores 
-      print_matrix            = Configuration.print_matrix 
-      anzpath                 = Configuration.anzpath 
+      iteration_steps         = Conf.iter_steps ; #upper bound on iteration steps
+      remove_duplicate_scores = Conf.remove_duplicate_scores 
+      print_matrix            = Conf.print_matrix 
+      anzpath                 = Conf.anzpath 
 
       # Initialize parameter vector  / param = numpy.matlib.rand(126,1)
-      param = Configuration.fixedParam 
+      param = Conf.fixedParam 
 
       # Set the parameters such as limits penalties for the Plifs
       [h,d,a,mmatrix,qualityPlifs] = set_param_palma(param,self.ARGS.train_with_intronlengthinformation)
@@ -144,9 +143,9 @@ class QPalma:
       #         Donors[i] = 1
 
       # Initialize solver 
-      if Configuration.USE_OPT:
+      if Conf.USE_OPT:
          self.plog('Initializing problem...\n')
-         solver = SIQPSolver(Configuration.numFeatures,self.numExamples,Configuration.C,self.logfh)
+         solver = SIQPSolver(Conf.numFeatures,self.numExamples,Conf.C,self.logfh)
 
       # stores the number of alignments done for each example (best path, second-best path etc.)
       num_path = [anzpath]*self.numExamples
@@ -158,15 +157,15 @@ class QPalma:
       #############################################################################################
       self.plog('Starting training...\n')
 
-      donSP       = Configuration.numDonSuppPoints
-      accSP       = Configuration.numAccSuppPoints
-      lengthSP    = Configuration.numLengthSuppPoints
-      mmatrixSP   = Configuration.sizeMatchmatrix[0]\
-      *Configuration.sizeMatchmatrix[1]
-      numq        = Configuration.numQualSuppPoints
-      totalQualSP = Configuration.totalQualSuppPoints
+      donSP       = Conf.numDonSuppPoints
+      accSP       = Conf.numAccSuppPoints
+      lengthSP    = Conf.numLengthSuppPoints
+      mmatrixSP   = Conf.sizeMatchmatrix[0]\
+      *Conf.sizeMatchmatrix[1]
+      numq        = Conf.numQualSuppPoints
+      totalQualSP = Conf.totalQualSuppPoints
 
-      currentPhi = zeros((Configuration.numFeatures,1))
+      currentPhi = zeros((Conf.numFeatures,1))
       totalQualityPenalties = zeros((totalQualSP,1))
 
       iteration_nr = 0
@@ -183,10 +182,10 @@ class QPalma:
             dna = Sequences[exampleIdx] 
             est = Ests[exampleIdx] 
 
-            if Configuration.mode == 'normal':
+            if Conf.mode == 'normal':
                quality = [40]*len(est)
 
-            if Configuration.mode == 'using_quality_scores':
+            if Conf.mode == 'using_quality_scores':
                quality = Qualities[exampleIdx]
 
             exons = Exons[exampleIdx] 
@@ -208,7 +207,7 @@ class QPalma:
             currentPhi[donSP+accSP+lengthSP:donSP+accSP+lengthSP+mmatrixSP]   = mmatrix[:]
 
             #pdb.set_trace()
-            if Configuration.mode == 'using_quality_scores':
+            if Conf.mode == 'using_quality_scores':
                totalQualityPenalties = param[-totalQualSP:]
                currentPhi[donSP+accSP+lengthSP+mmatrixSP:]                    = totalQualityPenalties[:]
 
@@ -218,7 +217,7 @@ class QPalma:
             # The allWeights vector is supposed to store the weight parameter
             # of the true alignment as well as the weight parameters of the
             # num_path[exampleIdx] other alignments
-            allWeights = zeros((Configuration.numFeatures,num_path[exampleIdx]+1))
+            allWeights = zeros((Conf.numFeatures,num_path[exampleIdx]+1))
             allWeights[:,0] = trueWeight[:,0]
 
             AlignmentScores = [0.0]*(num_path[exampleIdx]+1)
@@ -250,7 +249,7 @@ class QPalma:
             chastity = QPalmaDP.createDoubleArrayFromList([.0]*est_len)
 
             matchmatrix = QPalmaDP.createDoubleArrayFromList(mmatrix.flatten().tolist()[0])
-            mm_len = Configuration.sizeMatchmatrix[0]*Configuration.sizeMatchmatrix[1]
+            mm_len = Conf.sizeMatchmatrix[0]*Conf.sizeMatchmatrix[1]
 
             d_len = len(donor)
             donor = QPalmaDP.createDoubleArrayFromList(donor)
@@ -258,7 +257,7 @@ class QPalma:
             acceptor = QPalmaDP.createDoubleArrayFromList(acceptor)
 
             # Create the alignment object representing the interface to the C/C++ code.
-            currentAlignment = QPalmaDP.Alignment(Configuration.numQualPlifs,Configuration.numQualSuppPoints, self.use_quality_scores)
+            currentAlignment = QPalmaDP.Alignment(Conf.numQualPlifs,Conf.numQualSuppPoints, self.use_quality_scores)
 
             c_qualityPlifs = QPalmaDP.createPenaltyArrayFromList([elem.convert2SWIG() for elem in qualityPlifs])
             #print 'Calling myalign...'
@@ -276,7 +275,7 @@ class QPalma:
             c_WeightMatch       = QPalmaDP.createIntArrayFromList([0]*(mm_len*num_path[exampleIdx]))
             c_DPScores   = QPalmaDP.createDoubleArrayFromList([.0]*num_path[exampleIdx])
 
-            c_qualityPlifsFeatures = QPalmaDP.createDoubleArrayFromList([.0]*(Configuration.totalQualSuppPoints*num_path[exampleIdx]))
+            c_qualityPlifsFeatures = QPalmaDP.createDoubleArrayFromList([.0]*(Conf.totalQualSuppPoints*num_path[exampleIdx]))
 
             currentAlignment.getAlignmentResults(c_SpliceAlign, c_EstAlign,\
             c_WeightMatch, c_DPScores, c_qualityPlifsFeatures)
@@ -287,7 +286,7 @@ class QPalma:
             newEstAlign    = zeros((est_len*num_path[exampleIdx],1))
             newWeightMatch = zeros((num_path[exampleIdx]*mm_len,1))
             newDPScores    = zeros((num_path[exampleIdx],1))
-            newQualityPlifsFeatures = zeros((Configuration.totalQualSuppPoints*num_path[exampleIdx],1))
+            newQualityPlifsFeatures = zeros((Conf.totalQualSuppPoints*num_path[exampleIdx],1))
 
             #print 'newSpliceAlign'
             for i in range(dna_len*num_path[exampleIdx]):
@@ -310,7 +309,7 @@ class QPalma:
 
 
             if self.use_quality_scores:
-               for i in range(Configuration.totalQualSuppPoints*num_path[exampleIdx]):
+               for i in range(Conf.totalQualSuppPoints*num_path[exampleIdx]):
                   newQualityPlifsFeatures[i] = c_qualityPlifsFeatures[i]
 
             #  equals palma up to here
@@ -342,9 +341,9 @@ class QPalma:
                h, newSpliceAlign[pathNr,:].flatten().tolist()[0], don_supp,\
                acc_supp)
 
-               decodedQualityFeatures = zeros((Configuration.totalQualSuppPoints,1))
-               for qidx in range(Configuration.totalQualSuppPoints):
-                  decodedQualityFeatures[qidx] = newQualityPlifsFeatures[(pathNr*Configuration.totalQualSuppPoints)+qidx]
+               decodedQualityFeatures = zeros((Conf.totalQualSuppPoints,1))
+               for qidx in range(Conf.totalQualSuppPoints):
+                  decodedQualityFeatures[qidx] = newQualityPlifsFeatures[(pathNr*Conf.totalQualSuppPoints)+qidx]
 
                #pdb.set_trace()
 
@@ -405,7 +404,7 @@ class QPalma:
                   differenceVector  = trueWeights - firstFalseWeights
                   #pdb.set_trace()
 
-                  if Configuration.USE_OPT:
+                  if Conf.USE_OPT:
                      const_added = solver.addConstraint(differenceVector, exampleIdx)
                      const_added_ctr += 1
                #
@@ -413,7 +412,7 @@ class QPalma:
                #
 
             # call solver every nth example //added constraint
-            if exampleIdx != 0 and exampleIdx % 100 == 0 and Configuration.USE_OPT:
+            if exampleIdx != 0 and exampleIdx % 100 == 0 and Conf.USE_OPT:
                objValue,w,self.slacks = solver.solve()
       
                print "objValue is %f" % objValue
@@ -454,8 +453,8 @@ class QPalma:
 
 
    def predict(self):
-      beg = Configuration.prediction_begin
-      end = Configuration.prediction_end
+      beg = Conf.prediction_begin
+      end = Conf.prediction_end
 
       Sequences   = self.Sequences[beg:end]
       Exons       = self.Exons[beg:end]
@@ -764,10 +763,9 @@ def evaluateExample(dna,est,exons,SpliceAlign,newEstAlign,spos):
       up_off   = int(math.fabs(e1_end - exons[0,1]))
       down_off = int(math.fabs(e2_begin - exons[1,0]))
 
-   #pdb.set_trace()
-
    return up_off,down_off
 
+
 if __name__ == '__main__':
 
    qpalma = QPalma()