Example #1
0
def checkMatrix(m, fV, AS=4, reversible=True):
    #print m
    for i in xrange(0, AS):
        j = sum(m[i])
        #print "AAAAA", j
        assert j <= 1.0001
        assert j >= 0.9999
        if reversible:
            for k in xrange(0, AS):
                #print "comp2", (fV[i] * m[i][k]), (fV[k] * m[k][i] )
                assert close(fV[i] * m[i][k], fV[k] * m[k][i], 0.00001)
    
    wV = fV
    wV2 = fV
    wV3 = transformByDistance(wV, m, AS)
    wV4 = transformByDistance(wV2, m, AS)
    i = sum(multiplyWV(wV2, wV3, AS))
    j = sum(multiplyWV(wV, wV4, AS))
    #print i, j
    assert close(i, j, 0.00001)
Example #2
0
def checkMatrix(m, fV, AS=4, reversible=True):
    #print m
    for i in xrange(0, AS):
        j = sum(m[i])
        #print "AAAAA", j
        assert j <= 1.0001
        assert j >= 0.9999
        if reversible:
            for k in xrange(0, AS):
                #print "comp2", (fV[i] * m[i][k]), (fV[k] * m[k][i] )
                assert close(fV[i] * m[i][k], fV[k] * m[k][i], 0.00001)

    wV = fV
    wV2 = fV
    wV3 = transformByDistance(wV, m, AS)
    wV4 = transformByDistance(wV2, m, AS)
    i = sum(multiplyWV(wV2, wV3, AS))
    j = sum(multiplyWV(wV, wV4, AS))
    #print i, j
    assert close(i, j, 0.00001)
Example #3
0
def subMatrix_HalpernBruno(d, freqColumn, subMatrix, AS=4):
    #return subMatrix_HKY(d, freqColumn[0], freqColumn[1], freqColumn[2], freqColumn[3], 2.0)
    #return subMatrix
    matrix = [ [ 0.0 ]*AS for i in xrange(0, AS) ]
    for i in xrange(0, AS):
        for j in xrange(0, AS):
            a = freqColumn[i] * subMatrix[i][j]
            b = freqColumn[j] * subMatrix[j][i]
            if not close(a, b, 0.0001):
                matrix[i][j] = subMatrix[i][j] * (math.log(b/a) / (1 - (a/b)))
            else:
                matrix[i][j] = subMatrix[i][j]
    #for i in xrange(0, AS):
    #    #print matrix[i][i], sum(matrix[i])
    #    matrix[i][i] -= sum(matrix[i]) - 1.0
    #    assert matrix[i][i] >= 0
    #checkMatrix(matrix, freqColumn)
    return matrix
Example #4
0
 def testRemodelTreeRemovingRoot(self):
     for test in range(0, self.testNo):
         binaryTree = getRandomTree()
         binaryTree_depthFirstNumbers(binaryTree)
         node = getRandomLeafNode(binaryTree)
         remodTree = remodelTreeRemovingRoot(binaryTree,
                                             node.traversalID.mid)
         print("test", test, printBinaryTree(binaryTree, True),
               printBinaryTree(node, True),
               printBinaryTree(remodTree, True))
         binaryTree_depthFirstNumbers(remodTree)
         distances = mapTraversalIDsBetweenTrees(binaryTree, remodTree)
         d = getDistancesBetweenLeaves(binaryTree)
         d2 = getDistancesBetweenLeaves(remodTree)
         print(d)
         print(d2)
         for key in d2:
             assert close(d2[key], d[key], 0.0001)
Example #5
0
def subMatrix_HalpernBruno(d, freqColumn, subMatrix, AS=4):
    #return subMatrix_HKY(d, freqColumn[0], freqColumn[1], freqColumn[2], freqColumn[3], 2.0)
    #return subMatrix
    matrix = [ [ 0.0 ]*AS for i in range(0, AS) ]
    for i in range(0, AS):
        for j in range(0, AS):
            a = freqColumn[i] * subMatrix[i][j]
            b = freqColumn[j] * subMatrix[j][i]
            if not close(a, b, 0.0001):
                matrix[i][j] = subMatrix[i][j] * (math.log(b/a) / (1 - (a/b)))
            else:
                matrix[i][j] = subMatrix[i][j]
    #for i in xrange(0, AS):
    #    #print matrix[i][i], sum(matrix[i])
    #    matrix[i][i] -= sum(matrix[i]) - 1.0
    #    assert matrix[i][i] >= 0
    #checkMatrix(matrix, freqColumn)
    return matrix