+ parameter transfer to python layer works
[qpalma.git] / python / qpalma.py
index d615b6a..47f0dd0 100644 (file)
@@ -86,25 +86,7 @@ class QPalma:
       gen_file= '%s/genome.config' % self.ARGS.basedir
 
       ginfo_filename = 'genome_info.pickle'
-
-      if not os.path.exists(ginfo_filename):
-         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')
-         self.genome_info = ginfo['genome_info']
-         cPickle.dump(self.genome_info,open(ginfo_filename,'w+'))
-
-      else:
-         self.genome_info = cPickle.load(open(ginfo_filename))
+      self.genome_info = fetch_genome_info(ginfo_filename)
 
       self.plog('genome_info.basedir is %s\n'%self.genome_info.basedir)
 
@@ -308,6 +290,8 @@ class QPalma:
 
             print "Fetched results from c-code"
 
+            #print '%d %d %d' % (dna_len*num_path[exampleIdx],est_len*num_path[exampleIdx],mm_len*num_path[exampleIdx])
+
             newSpliceAlign = zeros((num_path[exampleIdx]*dna_len,1))
             newEstAlign = zeros((est_len*num_path[exampleIdx],1))
             newWeightMatch = zeros((num_path[exampleIdx]*mm_len,1))
@@ -334,7 +318,7 @@ class QPalma:
 
             print 'newQualityPlifs'
             for i in range(num_path[exampleIdx]*24):
-               newQualityPlifs[i+1] = c_qualityPlifs[i]
+               newQualityPlifs[i] = QPalmaDP.penaltyArray_getitem(c_qualityPlifs, i)
 
             print "Calling destructors"
 
@@ -364,8 +348,14 @@ class QPalma:
 
                weightDon, weightAcc, weightIntron = computeSpliceWeights(d, a, h, newSpliceAlign[pathNr,:].flatten().tolist()[0], don_supp, acc_supp)
 
-               #
-               qualityWeights = computeSpliceQualityWeights()
+               testPlif = newQualityPlifs[24*pathNr]
+               print "testPlif.penalties"
+               print type(testPlif)
+               for tidx in range(testPlif.len):
+                  #elem = testPlif.penalties[tidx]
+                  elem = QPalmaDP.doubleFArray_getitem(testPlif.penalties, tidx)
+                  print '%f ' % elem, 
+               print
 
                # sum up positionwise loss between alignments
                for alignPosIdx in range(len(newSpliceAlign[pathNr,:])):
@@ -447,6 +437,26 @@ class QPalma:
       self.logfh.close()
       print 'Training completed'
 
+def fetch_genome_info(ginfo_filename):
+   if not os.path.exists(ginfo_filename):
+      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')
+      cPickle.dump(self.genome_info,open(ginfo_filename,'w+'))
+      return ginfo['genome_info']
+
+   else:
+      return cPickle.load(open(ginfo_filename))
+
 if __name__ == '__main__':
    qpalma = QPalma()
    qpalma.run()