Example #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)
Example #3
0
def buildReconciliation(HostTree, ParasiteTree, reconciliation):
    """Takes as input a host tree, a parasite tree, and a reconciliation, and
    returns a graph where the keys are host or parasite nodes, and the values
    are a list of the children of a particular node. The graph represents
    temporal relationships between events. The function also returns a list
    transferList containing all the transfers in the reconciliation in the
    form """

    # create a dictionary with a list of parents of each host and parasite node
    parents = createParentsDict(HostTree, ParasiteTree)
    H = treeFormat(HostTree)
    P = treeFormat(ParasiteTree)
    cycleCheckingGraph = H
    cycleCheckingGraph.update(P)
    transferList = []
    for key in reconciliation:
        # deal with transfer case:
        if reconciliation[key][0] == 'T':
            # add the children of the parasite node to the list of children
            # of the host node in cycleCheckingGraph
            cycleCheckingGraph[key[0]] = P[key[0]] + \
                                         [reconciliation[key][1][1], reconciliation[key][2][1]]
            # find the parents of the take-off and landing host nodes
            parent1 = parents[reconciliation[key][1][1]]
            parent2 = parents[reconciliation[key][2][1]]
            # add the parasite node as a child of parent1 and parent2
            cycleCheckingGraph[parent1] = cycleCheckingGraph[parent1] + \
                                          [key[0]]
            cycleCheckingGraph[parent2] = cycleCheckingGraph[parent2] + \
                                          [key[0]]
            transferEdge1 = reconciliation[key][1][1]
            transferEdge2 = reconciliation[key][2][1]
            transferList.append([key[0], parent1, transferEdge1, parent2, \
                                 transferEdge2])

        # deal with speciation case:
        elif reconciliation[key][0] == 'S':
            parent = parents[key[0]]
            if parent != 'Top':
                cycleCheckingGraph[parent] = cycleCheckingGraph[parent] + \
                                             [key[1]]
            cycleCheckingGraph[key[1]] = cycleCheckingGraph[key[1]] + \
                                         cycleCheckingGraph[key[0]]

        # deal with duplication case:
        elif reconciliation[key][0] == 'D':
            parent = parents[key[1]]
            if parent != 'Top':
                cycleCheckingGraph[parent] = cycleCheckingGraph[parent] + \
                                             [key[0]]
            cycleCheckingGraph[key[0]] = cycleCheckingGraph[key[0]] + [key[1]]

        # deal with contemporary case:
        elif reconciliation[key][0] == 'C':
            cycleCheckingGraph[key[1]] = [None]
            cycleCheckingGraph[key[0]] = [None]

    for key in cycleCheckingGraph:
        cycleCheckingGraph[key] = list(set(cycleCheckingGraph[key]))

    return cycleCheckingGraph, transferList