def parseMods(mods, alignerArgs, indices, skipped): mods.reverse() while mods: mod = mods.pop() if mod == '-' + indices[0]: alignerArgs.NEWICK_TREE_STRING = mods.pop() continue if mod == '-' + indices[1]: alignerArgs.SEQUENCE_FILES = parseVarArgs(mods) continue if mod == '-' + indices[2]: alignerArgs.OUTPUT_FILE = mods.pop() continue if mod == '-' + indices[3]: alignerArgs.OUTPUT_TREE_FILE = mods.pop() continue if mod == '-' + indices[4]: alignerArgs.OUTPUT_SCORE_FILE = mods.pop() continue if mod == '-' + indices[5]: A = float(mods.pop()) C = float(mods.pop()) G = float(mods.pop()) T = float(mods.pop()) alignerArgs.EXPECTED_CHARACTER_FREQUENCIES = normaliseWV([ A, C, G, T ]) continue if mod == '-' + indices[6]: alignerArgs.EMPIRICALLY_ESTIMATE_CHARACTER_FREQUENCIES = True continue if mod == '-' + alignerArgs.MAKE_FINAL_ALIGNMENT_INDICE: alignerArgs.MAKE_FINAL_ALIGNMENT = not alignerArgs.MAKE_FINAL_ALIGNMENT continue skipped.append(mod) return indices[7:]
def calculateTreeNodeCosts(binaryTree, alpha=1.5): def avg(binaryTree, i, j): if binaryTree.internal: return (i[binaryTree.left.traversalID.mid] - normaliseWV(j[binaryTree.left.traversalID.mid])[0]) + \ (i[binaryTree.right.traversalID.mid] - normaliseWV(j[binaryTree.right.traversalID.mid])[0]) return 0.0 def subMatrix(distance): i = 0.5 + 0.5*math.exp(-2.0*distance*alpha) return ( (i, 1.0 - i), (1.0 - i, i) ) binaryTreeNodes = [] getBinaryTreeNodes(binaryTree, binaryTreeNodes) subMatrices = [ subMatrix(i.distance) for i in binaryTreeNodes ] leaves = [ (1.0, 0.0) for i in xrange(0, binaryTree.traversalID.midEnd) ] j = felsensteins(binaryTree, subMatrices, (0.5, 0.5), leaves, 2) for i in j.keys(): j[i] = normaliseWV(j[i])[0] finalCosts = [ avg(i, j, felsensteins(i, subMatrices, (0.5, 0.5), leaves, 2)) for i in binaryTreeNodes ] return finalCosts
def calculateTreeNodeCosts(binaryTree, alpha=1.5): def avg(binaryTree, i, j): if binaryTree.internal: return (i[binaryTree.left.traversalID.mid] - normaliseWV(j[binaryTree.left.traversalID.mid])[0]) + \ (i[binaryTree.right.traversalID.mid] - normaliseWV(j[binaryTree.right.traversalID.mid])[0]) return 0.0 def subMatrix(distance): i = 0.5 + 0.5 * math.exp(-2.0 * distance * alpha) return ((i, 1.0 - i), (1.0 - i, i)) binaryTreeNodes = [] getBinaryTreeNodes(binaryTree, binaryTreeNodes) subMatrices = [subMatrix(i.distance) for i in binaryTreeNodes] leaves = [(1.0, 0.0) for i in xrange(0, binaryTree.traversalID.midEnd)] j = felsensteins(binaryTree, subMatrices, (0.5, 0.5), leaves, 2) for i in j.keys(): j[i] = normaliseWV(j[i])[0] finalCosts = [ avg(i, j, felsensteins(i, subMatrices, (0.5, 0.5), leaves, 2)) for i in binaryTreeNodes ] return finalCosts
def avg(binaryTree, i, j): if binaryTree.internal: return (i[binaryTree.left.traversalID.mid] - normaliseWV(j[binaryTree.left.traversalID.mid])[0]) + \ (i[binaryTree.right.traversalID.mid] - normaliseWV(j[binaryTree.right.traversalID.mid])[0]) return 0.0
def empiricallyEstimateNucleotideFrequencies(seqFiles): return normaliseWV(sumWVA([ calculateCharacterFrequencies(fastaRead(seqFile), dNAMap_IUPACToInt, 4) for seqFile in seqFiles ], 4))