+ added feature calculation for the labels
[qpalma.git] / python / computeSpliceAlignWithQuality.py
index f53098a..d69b2eb 100644 (file)
@@ -1,9 +1,10 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-from numpy.matlib import zeros
+from numpy.matlib import mat,zeros,ones,inf
 import pdb
-from Plif import *
+from Plif import Plf,base_coord,linspace
+import Configuration
 
 def  computeSpliceAlignWithQuality(dna, exons, quality):
    """
@@ -61,9 +62,13 @@ def  computeSpliceAlignWithQuality(dna, exons, quality):
    # counts the occurences of a,c,g,t,n in this order
    numChar = [0]*sizeMatchmatrix
 
-   trueQualityPlifs =  [Plf()] * 24
+   # counts the occurrnces of a,c,g,t,n with their quality scores
+   trueQualityPlifs =  [Plf(Configuration.numQualSuppPoints)] * Configuration.numQualPlifs
+   for currentPlif in trueQualityPlifs:
+      currentPlif.limits = mat(linspace(0,40,10)).reshape(10,1)
+      currentPlif.penalties = zeros((10,1))
 
-   for elem in est:
+   for pos, elem in enumerate(est):
       if elem == 'a':
          numChar[0] += 1
       if elem == 'c':
@@ -75,6 +80,20 @@ def  computeSpliceAlignWithQuality(dna, exons, quality):
       if elem == 'n':
          numChar[4] += 1
 
+      currentPlif = trueQualityPlifs[base_coord(elem,elem)]
+      currentQualityScore = quality[pos]
+
+      if currentQualityScore < currentPlif.limits[0]:
+            currentPlif.penalties[0] += 1
+
+      elif currentQualityScore >= currentPlif.limits[-1]:
+            currentPlif.penalties[-1] += 1
+
+      else:
+         for idx in range(1,currentPlif.len):
+            if currentPlif.limits[idx-1] <= currentQualityScore < currentPlif.limits[idx]:
+               currentPlif.penalties[idx] += 1
+
    totalNumChar = 0
    for idx in range(sizeMatchmatrix):
       totalNumChar += numChar[idx]