Exemple #1
0
 def sparseAlignSimple(self, stateMachine, points, size):
     p = points["points"][:]
     gp = points["gapPoints"][:]
     blp = points["blGaps"][:]
     trp = points["trGaps"][:]
     
     print "points ", p
     print "gapPoints ", gp
     print "blPoints ", blp
     print "trPoints ", trp
     
     pPA = {}
     for i in p:
         pPA[i] = Maths.NEG_INFINITY
     
     def makeMatrix(values):
         matrix = [ [False]*size for i in xrange(0, size) ]
         for i in values:
             matrix[i[0]][i[1]] = True
         return matrix
     fMatrix = [ [ [Maths.NEG_INFINITY]*stateMachine.stateNo() for j in xrange(0, size) ] for i in xrange(0, size) ]
     bMatrix = [ [ [Maths.NEG_INFINITY]*stateMachine.stateNo() for j in xrange(0, size) ] for i in xrange(0, size) ]
 
     def fn3(i):
         if i == MATCH:
             return 0
         return Maths.NEG_INFINITY
     startStates = [ fn3(i) for i in stateMachine.getStateTypes() ]
 
 
     fMatrix[0][0] = startStates[:]  #[0]*stateMachine.stateNo()
     bMatrix[size-1][size-1] = startStates[:]#[0]*stateMachine.stateNo()
     
     #fMatrix[0][0] = [0]*stateMachine.stateNo()
     #bMatrix[size-1][size-1] = [0]*stateMachine.stateNo()
 
     def bTransition(s, sI, s2, sI2, i, j, t, de, *args):
         s2[i] = Maths.logAdd(s2[i], s[j] + t + de)
 
     print "doing backwards "
 
     fn = stateMachine.getFns(bTransition)
     computeMatrixR(bMatrix, makeMatrix(gp),
                    makeMatrix(p),
                    makeMatrix(blp),
                    makeMatrix(trp),
                    fn[(MATCH, GAP)],
                    fn[(GAP, GAP)],
                    fn[(GAP, MATCH)],
                    fn[(MATCH, MATCH)])
     stateNo = stateMachine.stateNo()
     total = SparseAlign.logSum([ bMatrix[0][0][i] + startStates[i] for i in range(0, stateNo)]) 
     #total = bMatrix[0][0][0]#SparseAlign.logSum(bMatrix[0][0])
     stateNo = stateMachine.stateNo()
     
     print "doing forwards "
     
     def fTransition(s, sI, s2, sI2, i, j, t, de, x2, y2, x1, y1):
         l = s[i] + t + de
         s2[j] = Maths.logAdd(s2[j], l)
         l += bMatrix[x1][y1][j] - total
         #print x1, x2, "boo"
         if x2 >= x1:
             raise IndexError()
         for k in xrange(0, x1-x2):
             pPA[(x1-k, y1-k)] = Maths.logAdd(pPA[(x1-k, y1-k)], l)
     fn = stateMachine.getFns(fTransition)
     
     def fTransition2(s, sI, s2, sI2, i, j, t, de, x2, y2, x1, y1):
         l = s[i] + t + de
         s2[j] = Maths.logAdd(s2[j], l)
     fn2 = stateMachine.getFns(fTransition2)
     
     print "gp", gp
     
     computeMatrix(fMatrix, makeMatrix(gp),
                   makeMatrix(p),
                   makeMatrix(blp),
                   makeMatrix(trp),
                   fn2[(MATCH, GAP)],
                   fn2[(GAP, GAP)],
                   fn[(GAP, MATCH)],
                   fn[(MATCH, MATCH)])
     print "fmatrix ", fMatrix
     
     print "bmatrix ", bMatrix
     
     print fMatrix[0][0], "cro", SparseAlign.logSum(bMatrix[0][0])
     return (SparseAlign.logSum([ fMatrix[size-1][size-1][i] + startStates[i] for i in range(0, stateNo)]), 
             SparseAlign.logSum([ bMatrix[0][0][i] + startStates[i] for i in range(0, stateNo)]) , pPA)