def plotCost(number_points=0): rand_samples = [] for model_index in range(num_models_regions): region = model_regions[model_index] if number_points: samples = region.points[np.random.choice( region.points.shape[0], number_points, replace=False), :] else: samples = region.points rand_samples.append(samples) all_costs = [] _, axes = plt.subplots(1, 3) for box_plot in range(num_models_fitness): ax = axes.flat[box_plot] #plt.subplot(1,3,box_plot+1) ax.set_title(str(box_plot + 1) + '-bit model') ax.set_xlabel('region id') if box_plot == 0: ax.set_ylabel('cost') model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[box_plot]) model_evals = [] for model_index in range(num_models_regions): evals = [] for sample in rand_samples[model_index]: evals.append(-model.eval(sample)[0]) model_evals.append(evals) #plt.boxplot(model_evals) ax.violinplot(model_evals) ax.boxplot(model_evals) ax.set_xticks([1, 2, 3]) all_costs.append(model_evals) #dump data to file f = open(os.path.join(base_path_robustness, "cost_distrib.p"), "wb") pickle.dump(all_costs, f) f.close() plt.savefig(os.path.join(base_path_robustness, 'cost_distrib.pdf'), bbox_inches='tight') plt.show()
def calculateVolumes(model_indexes=None): if model_indexes == None: model_indexes = range(num_models_regions) elif type(model_indexes) == int: model_indexes = [model_indexes] for model_index in model_indexes: model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[model_index], avg_dev=30) print(model.threshold) solver = Solver(model) _, vol_desc = solver.getViableVolume([model_regions[model_index]]) model_str = '0' + str(model_index + 1) + '_' f = open( os.path.join(base_path_robustness, model_str + "viable_volume.txt"), "w") f.write(vol_desc) f.close()
def calculateVolumesRepeats(model_indexes=None, repeats=10): if model_indexes == None: model_indexes = range(num_models_regions) elif type(model_indexes) == int: model_indexes = [model_indexes] df = pd.DataFrame(columns=["Model id", "Volume", "Total", "Ratio"]) for model_index in model_indexes: model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[model_index], avg_dev=30) print(model.threshold) solver = Solver(model) for _ in range(repeats): (volume, total, ratio), _ = solver.getViableVolume([model_regions[model_index]]) df = df.append( { "Model id": model_index + 1, "Volume": volume, "Total": total, "Ratio": ratio }, ignore_index=True) df.to_csv(os.path.join(base_path_robustness, 'volumes.csv'), index=False)
def getCosts(number_points=0, file_name=""): rand_samples = [] for model_index in range(num_models_regions): region = model_regions[model_index] if number_points: samples = region.points[np.random.choice( region.points.shape[0], number_points, replace=False), :] else: samples = region.points rand_samples.append(samples) df = pd.DataFrame(columns=['Model id', 'Region id', 'cost']) for model_id in range(num_models_fitness): model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[model_id]) for region_id in range(num_models_regions): for sample in rand_samples[region_id]: cost = -model.eval(sample)[0] df = df.append( { 'Model id': model_id + 1, 'Region id': region_id + 1, 'cost': cost }, ignore_index=True) if file_name: df.to_csv(file_name, index=False) return df
} } #model_mode = one_bit_processor_ext #model_mode = two_bit_processor_ext #model_mode = three_bit_processor_ext model_mode = four_bit_processor_ext folder_name = "results_opt" if model_mode == one_bit_processor_ext: file_name = "01_bioproc" elif model_mode == two_bit_processor_ext: file_name = "02_bioproc" elif model_mode == three_bit_processor_ext: file_name = "03_bioproc" else: file_name = "04_bioproc" filename = os.path.join(".", folder_name, file_name) print(filename) model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=model_mode, parameter_values=param_values, avg_dev=30) sol = solver.Solver(model) sol.run(filename, maxDepth=1) #do not cluster
def plotStochasticSimulations(from_file=True, number_points=3, plotFlipflops=False, pickle_dump=False): sns.set_style("white") #flatui = ['#f7f7f7','#d9d9d9','#bdbdbd','#969696','#737373','#525252','#252525'] #flatui = ['#bdbdbd','#969696','#737373','#525252','#252525','#000000'] flatui = ['#d9d9d9', '#bdbdbd', '#969696', '#737373', '#525252', '#252525'] #sns.palplot(sns.color_palette(flatui)) sns.set_palette(flatui) print("Plotting stochastic simulations") fig, axs = plt.subplots(3, number_points, sharey='row') for model_index in range(3): print(model_index) region = model_regions[model_index] model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[model_index], plot_fitness=False, plot_devs=False) samples = [] if not from_file: samples = region.points[np.random.choice( region.points.shape[0], number_points, replace=False), :] else: for i in range(number_points): samples.append( pickle.load( open( "selected_points\\model" + str(model_index + 1) + "sample" + str(i + 1) + ".p", "rb"))) sample_num = 0 for sample in samples: print(sample) T, Y = model.simulateStochastic(sample) Y_ode = model.simulate(sample) colors = plt.rcParams["axes.prop_cycle"]() #get color iterator for i in range(model_index + 1): if plotFlipflops: c = next(colors)["color"] axs[model_index, sample_num].plot(T, Y[:, i * 4 + 2], label='q' + str(i + 1), color=c, alpha=0.7) axs[model_index, sample_num].plot(model.ts, Y_ode[:, i * 4 + 2], color=c, linestyle="--") #axs[model_index, sample_num].get_xaxis().set_visible(False) for i in range(2 * (model_index + 1)): c = next(colors)["color"] axs[model_index, sample_num].plot(T, Y[:, -(2 * (model_index + 1) - i)], label="i" + str(i + 1), color=c, alpha=0.7) axs[model_index, sample_num].plot(model.ts, Y_ode[:, -(2 * (model_index + 1) - i)], color=c, linestyle="--") if not from_file: pickle.dump( sample, open( "selected_points\\test_model" + str(model_index + 1) + "sample" + str(sample_num + 1) + ".p", "wb+")) sample_num += 1 for i in range(len(samples)): axs[2, i].set(xlabel='Time [h]') for i in range(3): axs[i, 0].set(ylabel='Concentration [nM]') #plt.legend(loc="upper left") #plt.legend() plt.legend(ncol=10, loc='upper center', bbox_to_anchor=(0.5, 0.95), bbox_transform=plt.gcf().transFigure) plt.gcf().set_size_inches(15, 12) plt.savefig(os.path.join(base_path_robustness, 'ssa.pdf'), bbox_inches='tight') if pickle_dump: pickle.dump(fig, open("selected_points\\plot_SSA.pickle", "wb")) plt.show()
# models = [ one_bit_processor_ext, two_bit_processor_ext, three_bit_processor_ext, four_bit_processor_ext ] #folders = [os.path.join(base_path, "one_bit_model"), os.path.join(base_path, "two_bit_model"), os.path.join(base_path, "three_bit_model")] model_regions = [] for model_index in range(num_models_regions): #folder = folders[model_index] model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=models[model_index]) solver = Solver(model) model_str = '0' + str(model_index + 1) + '_' region_files = [] for base_path_opt in base_paths_opt: if ga_solutions: region_files.append( os.path.join(base_path_opt, model_str + "bioprocViableSet_IterGA.p")) if local_solutions: for i in range(10): region_files.append(
"Kd": { "min": 0.01, "max": 250 }, "protease_concentration": { "min": 10, "max": 1000 } } #flip flop with instructions external clock filename = os.path.join(".", "bioproc", "three_bit_model_new_new", "bioproc") print(filename) model = BioProc(np.array([ "protein_production", "protein_production", "protein_production", "protein_production", "protein_degradation", "protein_degradation", "Kd", "hill", "protein_production", "protein_degradation", "Kd", "hill" ]), model_mode=three_bit_processor_ext, parameter_values=param_values, avg_dev=30) solver = Solver(model) solver.run(filename, maxDepth=1) #do not cluster """ model modes: - one_bit_processor_ext - two_bit_processor_ext - three_bit_processor_ext """