def detectCycles(HostTree, ParasiteTree, reconciliation): """This function takes as input the cycle checking graph, reconGraph. It returns a new version of reconGraph, newReconGraph, from which the transfer events responsible for the cycles have been removed. It also returns a list, guiltyTransferList, of the guilty transfers.""" hostTree = ReconciliationGraph.treeFormat(HostTree) parasiteTree = ReconciliationGraph.treeFormat(ParasiteTree) guiltyTransferList = [] markingDict = {} reconGraph, transferList = buildReconciliation(HostTree, ParasiteTree, reconciliation) Hroot = ReconciliationGraph.findRoot(HostTree) markingDict[Hroot] = ["check"] cycleNode = recurseChildren(reconGraph, markingDict, Hroot, parasiteTree) markingDict = {} newReconGraph, guiltyTransfer, transferList = deleteTransfer(reconGraph, transferList, cycleNode) if guiltyTransfer != []: guiltyTransferList.append(guiltyTransfer) while cycleNode != None: markingDict = {Hroot: ["check"]} cycleNode = recurseChildren(newReconGraph, markingDict, Hroot, parasiteTree) if cycleNode == None: for node in newReconGraph: if not checked(markingDict, node): check(markingDict, node) cycleNode = recurseChildren(newReconGraph, markingDict, node, parasiteTree) newReconGraph, guiltyTransfer, transferList = deleteTransfer(newReconGraph, transferList, cycleNode) if guiltyTransfer != []: guiltyTransferList.append(guiltyTransfer) return newReconGraph, guiltyTransferList, newReconGraph
def detectCycles(HostTree, ParasiteTree, reconciliation): """This function takes as input the cycle checking graph, reconGraph. It returns a new version of reconGraph, newReconGraph, from which the transfer events responsible for the cycles have been removed. It also returns a list, guiltyTransferList, of the guilty transfers.""" hostTree = ReconciliationGraph.treeFormat(HostTree) parasiteTree = ReconciliationGraph.treeFormat(ParasiteTree) guiltyTransferList = [] markingDict = {} reconGraph, transferList = buildReconciliation(HostTree, ParasiteTree, \ reconciliation) Hroot = ReconciliationGraph.findRoot(HostTree) markingDict[Hroot] = ['check'] cycleNode = recurseChildren(reconGraph, markingDict, Hroot, parasiteTree) markingDict = {} newReconGraph, guiltyTransfer, transferList = deleteTransfer(reconGraph, \ transferList, cycleNode) if guiltyTransfer != []: guiltyTransferList.append(guiltyTransfer) while cycleNode != None: markingDict = {Hroot: ['check']} cycleNode = recurseChildren(newReconGraph, markingDict, Hroot, parasiteTree) if cycleNode == None: for node in newReconGraph: if not checked(markingDict, node): check(markingDict, node) cycleNode = recurseChildren(newReconGraph, markingDict, node, parasiteTree) newReconGraph, guiltyTransfer, transferList = deleteTransfer(\ newReconGraph, transferList, cycleNode) if guiltyTransfer != []: guiltyTransferList.append(guiltyTransfer) return newReconGraph, guiltyTransferList, newReconGraph
def Reconcile(argList): """Takes command-line arguments of a .newick file, duplication, transfer, and loss costs, the type of scoring desired and possible switch and loss ranges. Creates Files for the host, parasite, and reconciliations""" fileName = argList[1] #.newick file D = float(argList[2]) # Duplication cost T = float(argList[3]) # Transfer cost L = float(argList[4]) # Loss cost freqType = argList[5] # Frequency type # Optional inputs if freqType == xscape switchLo = float(argList[6]) # Switch lower boundary switchHi = float(argList[7]) # Switch upper boundary lossLo = float(argList[8]) # Loss lower boundary lossHi = float(argList[9]) # Loss upper boundary host, paras, phi = newickFormatReader.getInput(fileName) hostRoot = ReconciliationGraph.findRoot(host) hostv = ReconciliationGraph.treeFormat(host) Order = orderGraph.date(hostv) # Default scoring function (if freqtype== Frequency scoring) DTLReconGraph, numRecon = DP.DP(host, paras, phi, D, T, L) #uses xScape scoring function if freqType == "xscape": DTLReconGraph = calcCostscapeScore.newScoreWrapper(fileName, switchLo, \ switchHi, lossLo, lossHi, D, T, L) #uses Unit scoring function elif freqType == "unit": DTLReconGraph = unitScoreDTL(host, paras, phi, D, T, L) DTLGraph = copy.deepcopy(DTLReconGraph) scoresList, rec = Greedy.Greedy(DTLGraph, paras) for n in range(len(rec)): graph = ReconciliationGraph.buildReconstruction(host, paras, rec[n]) currentOrder = orderGraph.date(graph) if currentOrder == "timeTravel": rec[n], currentOrder = detectCycles.detectCyclesWrapper( host, paras, rec[n]) currentOrder = orderGraph.date(currentOrder) hostOrder = hOrder(hostv, currentOrder) hostBranchs = branch(hostv, hostOrder) if n == 0: newickToVis.convert(fileName, hostBranchs, n, 1) else: newickToVis.convert(fileName, hostBranchs, n, 0) # filename[:-7] is the file name minus the .newick ReconConversion.convert(rec[n], DTLGraph, paras, fileName[:-7], n)
def Reconcile(argList): """Takes command-line arguments of a .newick file, duplication, transfer, and loss costs, the type of scoring desired and possible switch and loss ranges. Creates Files for the host, parasite, and reconciliations""" fileName = argList[1] #.newick file D = float(argList[2]) # Duplication cost T = float(argList[3]) # Transfer cost L = float(argList[4]) # Loss cost freqType = argList[5] # Frequency type # Optional inputs if freqType == xscape switchLo = float(argList[6]) # Switch lower boundary switchHi = float(argList[7]) # Switch upper boundary lossLo = float(argList[8]) # Loss lower boundary lossHi = float(argList[9]) # Loss upper boundary host, paras, phi = newickFormatReader.getInput(fileName) hostRoot = ReconciliationGraph.findRoot(host) hostv = ReconciliationGraph.treeFormat(host) Order = orderGraph.date(hostv) # Default scoring function (if freqtype== Frequency scoring) DTLReconGraph, numRecon = DP.DP(host, paras, phi, D, T, L) #uses xScape scoring function if freqType == "xscape": DTLReconGraph = calcCostscapeScore.newScoreWrapper(fileName, switchLo, \ switchHi, lossLo, lossHi, D, T, L) #uses Unit scoring function elif freqType == "unit": DTLReconGraph = unitScoreDTL(host, paras, phi, D, T, L) DTLGraph = copy.deepcopy(DTLReconGraph) scoresList, rec = Greedy.Greedy(DTLGraph, paras) for n in range(len(rec)): graph = ReconciliationGraph.buildReconstruction(host, paras, rec[n]) currentOrder = orderGraph.date(graph) if currentOrder == "timeTravel": rec[n], currentOrder = detectCycles.detectCyclesWrapper(host, paras, rec[n]) currentOrder = orderGraph.date(currentOrder) hostOrder = hOrder(hostv,currentOrder) hostBranchs = branch(hostv,hostOrder) if n == 0: newickToVis.convert(fileName,hostBranchs, n, 1) else: newickToVis.convert(fileName,hostBranchs, n, 0) # filename[:-7] is the file name minus the .newick ReconConversion.convert(rec[n], DTLGraph, paras, fileName[:-7], n)
def Reconcile(argList): """Takes command-line arguments of a .newick file, duplication, transfer, and loss costs, the type of scoring desired and possible switch and loss ranges. Creates Files for the host, parasite, and reconciliations""" fileName = argList[1] # .newick file D = float(argList[2]) # Duplication cost T = float(argList[3]) # Transfer cost L = float(argList[4]) # Loss cost freqType = argList[5] # Frequency type # Optional inputs if freqType == xscape switchLo = float(argList[6]) # Switch lower boundary switchHi = float(argList[7]) # Switch upper boundary lossLo = float(argList[8]) # Loss lower boundary lossHi = float(argList[9]) # Loss upper boundary try: host, paras, phi = newickFormatReader(fileName) hostRoot = ReconciliationGraph.findRoot(host) # Default scoring function (if freqtype== Frequency scoring) DTLReconGraph, numRecon, cost = DP.DP(host, paras, phi, D, T, L) # uses xScape scoring function # if freqType == "xscape": # DTLReconGraph = calcCostscapeScore.newScoreWrapper(fileName, switchLo, \ # switchHi, lossLo, lossHi, D, T, L) # uses Unit scoring function if freqType == "unit": DTLReconGraph = unitScoreDTL(host, paras, phi, D, T, L) DTLGraph = copy.deepcopy(DTLReconGraph) scoresList, recs = Greedy.Greedy(DTLGraph, paras) infeasible_recs = [] for rec in recs: if orderGraph.date(ReconciliationGraph.buildReconciliation(host, paras, rec)) == False: infeasible_recs.append(rec) except CheetaError: raise except: raise CheetaError(CheetaErrorEnum.Alg), None, sys.exc_info()[2] return infeasible_recs, recs, cost
def convert(fileName, HostOrder, n, writeParasite): """takes name of original .newick file and the dictionary of host tree branch lengths and creates files for the host + parasite trees. Parasite tree can be ommited if desired""" f = open(fileName, 'r') contents = f.read() host, paras, phi = newickFormatReader.getInput(fileName) hostRoot = ReconciliationGraph.findRoot(host) f.close() H, P, phi = contents.split(";") P = P.strip() H = H.strip() H = H + ';' host = treelib1.parse_newick(H, HostOrder) for key in HostOrder: H = H.replace(str(key), str(key) + ':' + str(HostOrder[key])) print "thing" f = open(fileName[:-7] + str(n) + ".stree", 'w') treelib1.write_newick(host, f, root_data=True) f.close() if writeParasite: f = open(fileName[:-7] + '.tree', 'w') f.write(P + ";") f.close()
def Reconcile(argList): """Takes command-line arguments of a .newick file, duplication, transfer, and loss costs, the type of scoring desired and possible switch and loss ranges. Creates Files for the host, parasite, and reconciliations""" fileName = argList[1] #.newick file D = float(argList[2]) # Duplication cost T = float(argList[3]) # Transfer cost L = float(argList[4]) # Loss cost freqType = argList[5] # Frequency type # Optional inputs if freqType == xscape switchLo = float(argList[6]) # Switch lower boundary switchHi = float(argList[7]) # Switch upper boundary lossLo = float(argList[8]) # Loss lower boundary lossHi = float(argList[9]) # Loss upper boundary host, paras, phi = newickFormatReader.getInput(fileName) hostRoot = ReconciliationGraph.findRoot(host) # Default scoring function (if freqtype== Frequency scoring) DTLReconGraph, numRecon = DP.DP(host, paras, phi, D, T, L) #uses xScape scoring function # if freqType == "xscape": # DTLReconGraph = calcCostscapeScore.newScoreWrapper(fileName, switchLo, \ # switchHi, lossLo, lossHi, D, T, L) #uses Unit scoring function if freqType == "unit": DTLReconGraph = unitScoreDTL(host, paras, phi, D, T, L) DTLGraph = copy.deepcopy(DTLReconGraph) scoresList, recs = Greedy.Greedy(DTLGraph, paras) infeasible_recs = [] for rec in recs: if orderGraph.date(ReconciliationGraph.buildReconciliation(host, paras, rec)) == False: infeasible_recs.append(rec) return infeasible_recs, recs
def convert(fileName, HostOrder, n, writeParasite): """takes name of original .newick file and the dictionary of host tree branch lengths and creates files for the host + parasite trees. Parasite tree can be ommited if desired""" f = open(fileName, "r") contents = f.read() host, paras, phi = newickFormatReader.getInput(fileName) hostRoot = ReconciliationGraph.findRoot(host) f.close() H, P, phi = contents.split(";") P = P.strip() H = H.strip() H = H + ";" host = treelib1.parse_newick(H, HostOrder) for key in HostOrder: H = H.replace(str(key), str(key) + ":" + str(HostOrder[key])) print "thing" f = open(fileName[:-7] + str(n) + ".stree", "w") treelib1.write_newick(host, f, root_data=True) f.close() if writeParasite: f = open(fileName[:-7] + ".tree", "w") f.write(P + ";") f.close()