def costOfResFunction(sequence, mRate, size, maxResSwitchNumb, n): days = len(sequence) k = 1 resistances = main.expResAssign(size, n, 0, maxResSwitchNumb) popArr = main.calcPopDistribution(int(size), 1) mutationRatesUp, mutationRatesDown = main.detMutationRate(mRate, size) growthRate = main.costOfRes(.25, resistances) resultArr = odeint( main.calculateChange, popArr, np.arange(0, days, 1), (growthRate, mutationRatesUp, mutationRatesDown, k, resistances, main.periodicDrugDay(sequence, days), np.zeros(popArr.size))) return np.sum(resultArr)
def tumorSizeCalcExp(sequence, mRate, size, reachMaxRes): days = len(sequence) k = 1 growthRates = np.full(size, .5) resistances = main.expResAssign(size, 1.001, 0, reachMaxRes) popArr = main.calcPopDistribution(int(size), .01) mutationRatesUp, mutationRatesDown = main.detMutationRate(mRate, size) resultArr = odeint( main.calculateChange, popArr, np.arange(0, days, 1), (growthRates, mutationRatesUp, mutationRatesDown, k, resistances, main.periodicDrugDay(sequence, days), np.zeros(popArr.size))) return np.sum(resultArr)
def tumorSizeCalcLinear(sequence, mRate, size): days = len(sequence) k = 1 growthRates = np.full(size, .5) resistances = main.assignResistance(size, [0, 1]) popArr = main.calcPopDistribution(int(size), .01) mutationRatesUp, mutationRatesDown = main.detMutationRate( mRate, size, True, False) resultArr = odeint( main.calculateChange, popArr, np.arange(0, days, 1), (growthRates, mutationRatesUp, mutationRatesDown, k, resistances, main.periodicDrugDay(sequence, days), np.zeros(popArr.size))) return np.sum(resultArr[50, :])
def varyParametersSize(initialMutRate, endMutRate, maxSize, isDrug): xs = np.arange(initialMutRate, endMutRate + .01, .01) ys = np.arange(2, maxSize + 1, 1) results = np.zeros((len(ys), len(xs))) for x, mRate in enumerate(xs): for y, size in enumerate(ys): mutationRateUp, mutationRateDown = main.detMutationRate( mRate * size, size) growthRates = np.full(size, .5) resistanceVal = main.expResAssign(size, 1.15, 0, size - 1) #plotters.PlotHist(resistanceVal) #plt.xlabel("State"); plt.ylabel("Resistance Values"); plt.title("Resistance Histogram") #plt.show() eigVal = main.getEig(growthRates, resistanceVal, mutationRateUp, mutationRateDown, isDrug) results[y, x] = eigVal[1] return results, xs, ys
def varyExpMRate(initialMutRate, endMutRate, resistanceArr, n, size, growthRates, isDrug, isMin): step = .01 xs = np.arange(initialMutRate, endMutRate, step) ys = np.arange(resistanceArr[0], resistanceArr[1], 1) results = np.zeros((len(ys), len(xs))) for x, mRate in enumerate(xs): mutationRateUp, mutationRateDown = main.detMutationRate(mRate, size) for y, resVal in enumerate(ys): if isMin: resistances = main.expResAssign(size, n, resVal, size) else: resistances = main.expResAssign(size, n, 0, resVal) eigVal = main.getEig(growthRates, resistances, mutationRateUp, mutationRateDown, isDrug) results[y, x] = eigVal[1] return results, xs, ys
def varyParametersPop(initialMutRate, endMutRate, maxSize, k, drugWeeks, timesteps, initPopSize): xs = np.arange(initialMutRate, endMutRate, .01) ys = range(2, maxSize + 1) resultsArr = np.zeros((len(ys), len(xs))) for x, mRate in enumerate(xs): for y, size in enumerate(ys): mutationRateUp, mutationRateDown = main.detMutationRate( mRate * size, size) popArr = main.calcPopDistribution(size, initPopSize) resistances = main.assignResistance(size, [0, 1]) change = np.zeros(size) growthRates = np.full(size, 1) results = odeint(main.calculateChange, popArr, timesteps, (growthRates, mutationRateUp, mutationRateDown, k, resistances, drugWeeks, change)) resultsArr[y, x] = np.sum(results[:][-1]) return resultsArr, xs, ys
def objectiveFun(sequence): days = 10 size = 5 k = 1 mRate = .05 growthRates = np.full(size, .5) popArr = main.calcPopDistribution(size, .01) resistances = main.expResAssign(size, 2, 0, size - 1) mutationRatesUp, mutationRatesDown = main.detMutationRate( mRate, size, True, False) resultArr = odeint( main.calculateChange, popArr, np.arange(0, days, 1), (growthRates, mutationRatesUp, mutationRatesDown, k, resistances, main.periodicDrugDay(sequence, days), np.zeros(popArr.size))) weightAns = 0 for i in range(0, len(resistances)): for j in range(0, len(resultArr)): weightAns = weightAns + (resistances[i] * resultArr[j][i]) return weightAns
def varyParameters(initialMutRate, endMutRate, resistanceArr, size, growthRates, isDrug, isMin): step = .05 xs = np.arange(initialMutRate, endMutRate + step, step) ys = np.arange(resistanceArr[0], resistanceArr[1] + 1, 1) results = np.zeros((len(ys), len(xs))) for x, mRate in enumerate(xs): for y, resVal in enumerate(ys): mutationRateUp, mutationRateDown = main.detMutationRate( mRate, size) if isMin: resistances = main.resAssign(size, [0, 1], resVal, size - 1) else: resistances = main.resAssign(size, [0, 1], 0, resVal) print(resistances) eigVal = main.getEig(growthRates, resistances, mutationRateUp, mutationRateDown, isDrug) results[y, x] = eigVal[1] return results, xs, ys
def nextSimulation(initialPop, mRate, k, tolerance, size, days, sequence): popArr = main.calcPopDistribution(size, initialPop) resistanceArr = main.assignResistance(size, [0, 1]) growthRates = np.full(size, 1) mutationRatesUp, mutationRatesDown = main.detMutationRate(mRate, size) results = odeint( main.calculateChange, popArr, np.arange(0, 100, 1), (growthRates, mutationRatesUp, mutationRatesDown, k, resistanceArr, main.periodicDrugDay(sequence, days), np.zeros(size))) totalPops = np.sum(results, axis=0) sumPop = np.sum(totalPops) mean, standardDev = main.getMeanAndStandardDeviation(popArr) info.append([sumPop, mean, standardDev]) # For next iteration (essentially a recursion) tolerance = tolerance - 1 if tolerance > 0: nextSimulation(initialPop, mRate, k, tolerance, size + 1, days, sequence) return info