Пример #1
0
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 = cycleCheckingGraph.findRoot(host)
    hostv = cycleCheckingGraph.treeFormat(host)
    Order = orderGraph.date(hostv)
    # Default scoring function (if freqtype== Frequency scoring)
    DTLReconGraph, numRecon = DP.DP(host, paras, phi, D, T, L)
    print DTLReconGraph, numRecon
    #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 = cycleCheckingGraph.buildReconciliation(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], DTLReconGraph, 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 = cycleCheckingGraph.findRoot(host)
    hostv = cycleCheckingGraph.treeFormat(host)
    Order = orderGraph.date(hostv)
    # Default scoring function (if freqtype== Frequency scoring)
    DTLReconGraph, numRecon = DP.DP(host, paras, phi, D, T, L)
    print DTLReconGraph, numRecon
    #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 = cycleCheckingGraph.buildReconciliation(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], DTLReconGraph, paras, fileName[:-7], n)
Пример #3
0
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 = cycleCheckingGraph.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]))
    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()
Пример #4
0
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 = cycleCheckingGraph.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]))
    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()
Пример #5
0
def detectCycles(HostTree, ParasiteTree, reconciliation):
    """This function takes as input the cycle checking graph,
    cycleCheckingGraph. It returns a new version of cycleCheckingGraph,
    newCycleCheckingGraph, from which the transfer events responsible for the
    cycles have been removed. It also returns a list, guiltyTransferList, of
    the guilty transfers."""

    guiltyTransferList = []
    markingDict = {}
    cycleCheckingGraph, transferList = buildReconciliation(HostTree,
                                                           ParasiteTree, reconciliation)
    Hroot = findRoot(HostTree)
    markingDict[Hroot] = ['check']
    cycleEdge = recurseChildren(cycleCheckingGraph, markingDict, Hroot)
    newCycleCheckingGraph, guiltyTransfer, transferList = deleteTransfer(
            cycleCheckingGraph, markingDict, transferList, cycleEdge)
    if guiltyTransfer:
        guiltyTransferList.append(guiltyTransfer)
    while cycleEdge is not None:
        markingDict = {}
        cycleEdge = recurseChildren(newCycleCheckingGraph,
                                    {Hroot: ['check']}, Hroot)
        if cycleEdge is None:
            for node in newCycleCheckingGraph:
                if not checked(markingDict, node):
                    check(markingDict, node)
                    cycleEdge = recurseChildren(newCycleCheckingGraph,
                                                markingDict, node)
                    if cycleEdge is not None:
                        break
        newCycleCheckingGraph, guiltyTransfer, transferList = deleteTransfer(
                newCycleCheckingGraph, markingDict, transferList, cycleEdge)
        if guiltyTransfer:
            guiltyTransferList.append(guiltyTransfer)

    return newCycleCheckingGraph, guiltyTransferList