示例#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 randomReconWrapper(dirName, D, T, L, numSamples, typeGen):
    """Takes in a directory of newick files, dirName, duplication, loss and 
    transfer costs, the number of desired random reconciliations, and the type
    of generator (biased or uniform), and calls those random generators to
    build a file containing the number of temporal inconsistencies found in 
    those randomly generated reconciliations as well as other information 
    relating to the file"""
    totalTimeTravel = 0 # To record total number of time travels in directory
    outOf = 0 # To record total number of reconciliations made
    # loop through files in directory
    for fileName in os.listdir(dirName):
        if fileName.endswith('.newick'):
            f = open(fileName[:-7]+'.txt', 'w')
            f.write(typeGen+" random reconciliations"+"\n")
            hostTree, parasiteTree, phi = newickFormatReader.getInput\
                (dirName+"/"+fileName)
            # find size of parasite and host trees
            parasiteSize = len(parasiteTree)+1
            hostSize = len(hostTree)+1
            DTLReconGraph, numRecon = DP.DP(hostTree, parasiteTree, phi, D, T, L)
            rootList = rootGenerator(DTLReconGraph, parasiteTree)
            randomReconList = []
            for n in range(numSamples):
                timeTravelCount = 0
                startRoot = random.choice(rootList)
                if typeGen == "uniform":
                    currentRecon = uniformRecon(DTLReconGraph, [startRoot], {})
                else: 
                    normalizeDTL = normalizer(DTLReconGraph)
                    currentRecon = biasedRecon(normalizeDTL, [startRoot], {})
                for key in currentRecon.keys():
                    currentRecon[key] = currentRecon[key][:-1]
                randomReconList.append(currentRecon)
            # make sure there are no duplicate reconciliations
            uniqueReconList = []
            for recon in randomReconList:
                if not recon in uniqueReconList:
                    uniqueReconList.append(recon)
            outOf += len(uniqueReconList)
            for recon in uniqueReconList:
                graph = reconciliationGraph.buildReconstruction\
                    (hostTree, parasiteTree, recon)
                currentOrder = orderGraph.date(graph)
                numTrans = findTransfers(recon)
                if currentOrder == 'timeTravel':
                    f.write("Temporal Inconsistency, reconciliation has "+str(numTrans)+" transfers"+"\n")
                    timeTravelCount += 1
                    totalTimeTravel += 1
                else: 
                    f.write("No temporal inconsistencies, reconciliation has "+str(numTrans)+" transfers"+"\n")
            f.write(fileName+" contains "+str(timeTravelCount)+" temporal "+ \
                "inconsistencies out of "+ str(len(uniqueReconList))+ \
                " reconciliations."+"\n"+"Total number of reconciliations: "+\
                str(numRecon)+"\n"+"Host tree size: "+str(hostSize)+"\n"+\
                "Parasite tree size: "+str(parasiteSize)+ "\n")
            f.close()
    print "Total fraction of temporal inconsistencies in directory: ", \
            totalTimeTravel, '/', outOf
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
示例#5
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 = 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