def get_ec50(model: IfnModel, times: list or int, dose_species: str, response_species: str, custom_parameters={}, rflag=False): if type(times) == int or type(times) == float: dr_curve = [el[0] for el in model.doseresponse([times], response_species, dose_species, list(logspace(-3, 5)), parameters=custom_parameters, return_type='list')[response_species]] top, K = fit_MM(list(logspace(-3, 5)), dr_curve, [max(dr_curve), 1000]) if rflag: return top, K else: return K elif type(times) == list: dr_curve = model.doseresponse(times, response_species, dose_species, list(logspace(-3, 5)), parameters=custom_parameters, return_type='list')[response_species] top_list = [] K_list = [] for t in range(len(times)): tslice = [el[t] for el in dr_curve] top, K = fit_MM(list(logspace(-3, 5)), tslice, [max(tslice), 1000]) top_list.append(top) K_list.append(K) if rflag: return top_list, K_list else: return K_list else: raise TypeError("Could not identify type for variable times")
def chi2(model: IfnModel, new_parameters: dict, times: list): reset_dict = dict( zip(new_parameters, [model.parameters[key] for key in new_parameters.keys()])) dra1 = model.doseresponse(times, 'TotalpSTAT', 'Ia', list(logspace(-1, 5)), parameters={'Ib': 0}, return_type='list')['TotalpSTAT'] drb1 = model.doseresponse(times, 'TotalpSTAT', 'Ib', list(logspace(-2, 4)), parameters={'Ia': 0}, return_type='list')['TotalpSTAT'] model.set_parameters(new_parameters) dra2 = model.doseresponse(times, 'TotalpSTAT', 'Ia', list(logspace(-1, 5)), parameters={'Ib': 0}, return_type='list')['TotalpSTAT'] drb2 = model.doseresponse(times, 'TotalpSTAT', 'Ib', list(logspace(-2, 4)), parameters={'Ia': 0}, return_type='list')['TotalpSTAT'] model.set_parameters(reset_dict) alpha_norm = max(max([item for sublist in dra1 for item in sublist]), max([item for sublist in dra2 for item in sublist])) beta_norm = max(max([item for sublist in drb1 for item in sublist]), max([item for sublist in drb2 for item in sublist])) value = (np.sum(np.square(np.divide(np.subtract(dra1, dra2), alpha_norm))) + np.sum(np.square(np.divide(np.subtract(drb1, drb2), beta_norm)))) / times[-1] value = np.nan_to_num(value) return value
def likelihood(parameter_vector, sampled_parameter_names=param_names): # Make model from ifnclass.ifnmodel import IfnModel import numpy as np model = IfnModel(model_name) # Change model parameter values to current location in parameter space (values are in log10(value) format) param_dict = { pname: 10**pvalue for pname, pvalue in zip(sampled_parameter_names, parameter_vector) } model.set_parameters(param_dict) # Simulate experimentally measured values. total_simulation_data = model.doseresponse( times, response_species, dose_species, doses, parameters={n: 0 for n in IC_names if n != dose_species}, return_type='dataframe', dataframe_labels=dose_species, scale_factor=100.0 / model.parameters['EpoR_IC']) sim_data = np.array([[el[0] for el in dose] for dose in total_simulation_data.values ]).flatten() # Calculate log probability contribution from simulated experimental values. logp_ctotal = np.sum(like_ctot.logpdf(sim_data)) # If model simulation failed due to integrator errors, return a log probability of -inf. if np.isnan(logp_ctotal): logp_ctotal = -np.inf return logp_ctotal
'krecT_a': 0.001, 'krecT_b': 0.001, 'kpa_IntTa': 0.001, 'kpa_IntTb': 0.000005 }) scale_factor = 0.242052437849 scale_data = lambda q: (scale_factor * q[0], scale_factor * q[1]) times = [1, 5, 60] experimental_doses = [0.051, 0.51, 1.54, 5.13, 15.4, 51.3] simulation_doses = list(logspace(log10(0.01), log10(2000))) dradf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ia', simulation_doses, parameters={'Ib': 0}, return_type='dataframe', dataframe_labels='Alpha') drbdf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ib', simulation_doses, parameters={'Ia': 0}, return_type='dataframe', dataframe_labels='Beta') for i in range(len(times)): dradf.loc['Alpha'].iloc[:, i] = dradf.loc['Alpha'].iloc[:, i].apply( scale_data) drbdf.loc['Beta'].iloc[:,
'kd4': 1.0, 'kd3': 0.001, 'kint_a': 0.0014, 'krec_a1': 9e-03, 'krec_a2': 0.05 }) scale_factor = 0.036 scale_data = lambda q: (scale_factor * q[0], scale_factor * q[1]) dose_list = list(logspace(-2, 8, num=35)) times = [2.5, 5, 15, 20, 30, 60] dradf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ia', list(logspace(-1, 5)), parameters={'Ib': 0}, return_type='dataframe', dataframe_labels='Alpha') drbdf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ib', list(logspace(-2, 4)), parameters={'Ia': 0}, return_type='dataframe', dataframe_labels='Beta') for i in range(len(times)): dradf.loc['Alpha'].iloc[:, i] = dradf.loc['Alpha'].iloc[:, i].apply( scale_data) drbdf.loc['Beta'].iloc[:,
# --------------------------------- # Make theory dose response curves # --------------------------------- IC_names = ['Epo_IC', 'EMP1_IC', 'EMP33_IC'] # Make predictions response_species = 'T_Epo' dose_species = 'Epo_IC' times = [60.0] # min Epo_doses = Moraga_data.get_doses()['T_Epo'] # pM dr_Epo = IfnData( 'custom', df=model.doseresponse( times, response_species, dose_species, Epo_doses, parameters={n: 0 for n in IC_names if n != dose_species}, return_type='dataframe', dataframe_labels=dose_species, scale_factor=100.0 / model.parameters['EpoR_IC']), conditions={}) # ------------------------------- # Plot model dose response curves # ------------------------------- palette = sns.color_palette("muted") Epo_plot = DoseresponsePlot((1, 1)) # Add data Epo_plot.add_trajectory(Moraga_data, 60,
#print(scale_factor) #Mixed_Model = stepfit.model # ----------------------------- # End Stepwise Fit # ----------------------------- scale_factor = 0.2050499 scale_data = lambda q: (scale_factor * q[0], scale_factor * q[1]) # Make predictions dradf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ia', list( logspace( log10(alpha_doses_20190108[1]), log10(alpha_doses_20190108[-1]))), parameters={'Ib': 0}, return_type='dataframe', dataframe_labels='Alpha') drbdf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ib', list( logspace( log10(beta_doses_20190108[1]), log10(beta_doses_20190108[-1]))), parameters={'Ia': 0}, return_type='dataframe', dataframe_labels='Beta') for i in range(len(times)):
plt.title('Fraction pSTAT vs Cell Radius\n 20 pM IFN at 60 minutes') plt.show() # -------------------------------------------------------------- # Two dose response curves # Large cells are 20% of population # Small cells have 20% R1 and R2 but are 80% of the population # -------------------------------------------------------------- # Small cells radius = 1E-6 volPM = 2 * radius ** 2 + 4 * radius * 8E-6 volCP = 8E-6 * radius ** 2 small_cells_alpha = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ia', list(np.logspace(np.log10(doses_alpha[0]), np.log10(doses_alpha[-1]))), parameters={'Ib': 0, 'R1': 1200 * 0.20, 'R2': 4920 * 0.20}, return_type='dataframe', dataframe_labels='Alpha', scale_factor=scale_factor * 0.8) small_cells_beta = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ib', list(np.logspace(np.log10(doses_beta[0]), np.log10(doses_beta[-1]))), parameters={'Ia': 0, 'R1': 1200 * 0.20, 'R2': 4920 * 0.20}, return_type='dataframe', dataframe_labels='Beta', scale_factor=scale_factor * 0.8) small_cells_alpha_IFNdata = IfnData('custom', df=small_cells_alpha, conditions={'Alpha': {'Ib': 0}}) small_cells_beta_IFNdata = IfnData('custom', df=small_cells_beta, conditions={'Beta': {'Ia': 0}}) # Large (normal) cells radius = 30E-6
'R1': 9000.0, 'R2': 1511.1 } testModel = IfnModel('Mixed_IFN_ppCompatible') testModel.set_parameters(best_fit_params) # -------------------- # Perform simulations # -------------------- times = [2.5, 5.0, 10.0, 20.0, 30.0, 60.0] doses = [10, 100, 300, 1000, 3000, 10000, 100000] df = testModel.doseresponse(times, 'TotalpSTAT', 'Ia', doses, parameters={'Ib': 0}, scale_factor=4.1, return_type='dataframe', dataframe_labels='Alpha') print(df) DR_Simulation = IfnData('custom', df=df, conditions={'Alpha': {'Ib': 0}}) DR_Simulation.drop_sigmas() # ----------------------------------------------------------- # Load several sets of experimental data and align them # ----------------------------------------------------------- # These datasets are already prepared for use in /ifndatabase expdata_1 = IfnData("20190214_pSTAT1_IFN_Bcell") expdata_2 = IfnData("20190121_pSTAT1_IFN_Bcell") expdata_3 = IfnData("20190119_pSTAT1_IFN_Bcell")
'krec_a1': 0.01, 'krec_a2': 0.01, 'krec_b1': 0.005, 'krec_b2': 0.05}) scale_factor = 1.46182313424 # ------------------------------------------ # Make model predictions for mixtures of IFN # ------------------------------------------ times = newdata_4.get_times('Alpha') doses_alpha = newdata_4.get_doses('Alpha') doses_alpha = [0.0] + [round(el, 2) for el in list(np.logspace(np.log10(doses_alpha[0]), np.log10(doses_alpha[-1])))] doses_beta = newdata_4.get_doses('Beta') doses_beta = [0.0] + [round(el, 2) for el in list(np.logspace(np.log10(doses_beta[0]), np.log10(doses_beta[-1])))] model_scan = {} for d in doses_beta: dradf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ia', doses_alpha, parameters={'Ib': d*1E-12*6.022E23*1E-5}, return_type='dataframe', dataframe_labels='Alpha', scale_factor=scale_factor) model_scan.update({d: dradf}) # ------------------------------- # Plot Heatmaps # ------------------------------- fig, axes = plt.subplots(nrows=1, ncols=len(times)) for ax in axes: ax.set_xlabel(r'IFN$\alpha$ (pM)') ax.set_ylabel(r'IFN$\beta$ (pM)') fig.set_size_inches(8*6, 8) for t_idx, t in enumerate(times): axes[t_idx].set_title('{} min'.format(t)) response_data = [[]]*len(doses_beta) for d_idx, d in enumerate(doses_beta): row = [el[0] for el in model_scan[d].loc['Alpha'].iloc[:, t_idx].values]
ImmuneCell_Model = IfnModel('Immune_Cell_model') IFNg_doses = list(logspace(-1.5, 2, num=15)) times = [15, 30, 60] fig = DoseresponsePlot((2, 2)) fig.axes[0][0].set_title('pSTAT1') fig.axes[0][1].set_title('pSTAT3') print("Dose-response 1") IFNg_naive_res = ImmuneCell_Model.doseresponse(times, ['pSTAT1', 'pSTAT3'], 'IFN_gamma_IC', IFNg_doses, parameters={ 'IFNAR1_IC': 0, 'IFNAR2_IC': 0, 'IFN_alpha2_IC': 0, 'IFN_beta_IC': 0, 'SOCS2_IC': 0 }, return_type='dataframe', dataframe_labels='IFNgamma') naive_IFNg_pSTAT1_df = IfnData(name='custom', df=IFNg_naive_res.xs(['pSTAT1'])) naive_IFNg_pSTAT3_df = IfnData(name='custom', df=IFNg_naive_res.xs(['pSTAT3'])) print("Dose-response 2") IFNg_SOCS_res = ImmuneCell_Model.doseresponse(times, ['pSTAT1', 'pSTAT3'], 'IFN_gamma_IC', IFNg_doses, parameters={ 'IFNAR1_IC': 0, 'IFNAR2_IC': 0,
ImmuneCell_Model = IfnModel('Immune_Cell_model') # ------------------------------------------- # Get naive responses (i.e. one IFN at a time) # ------------------------------------------- IFNg_doses = list(logspace(-2, 2, num=30)) IFNa_doses = list(logspace(0, 4, num=30)) # (pM) IFNb_doses = list(logspace(-1, 3, num=30)) # (pM) times = [15, 30, 60] # IFN gamma IFNg_naive_res = ImmuneCell_Model.doseresponse(times, ['pSTAT1', 'pSTAT3'], 'IFN_gamma_IC', IFNg_doses, parameters={ 'IFNAR1_IC': 0, 'IFNAR2_IC': 0, 'IFN_alpha2_IC': 0, 'IFN_beta_IC': 0 }, return_type='dataframe', dataframe_labels='IFNgamma') naive_IFNg_pSTAT1_df = IfnData(name='custom', df=IFNg_naive_res.xs(['pSTAT1'])) naive_IFNg_pSTAT3_df = IfnData(name='custom', df=IFNg_naive_res.xs(['pSTAT3'])) naive_IFNgec50_pSTAT1 = naive_IFNg_pSTAT1_df.get_ec50s() naive_IFNgec50_pSTAT3 = naive_IFNg_pSTAT3_df.get_ec50s() naive_pSTAT1_response_at_IFNgec50 = { key: val / 2 for (key, val) in naive_IFNg_pSTAT1_df.get_max_responses()['IFNgamma'] } naive_pSTAT3_response_at_IFNgec50 = {
'kd3': 0.001, 'kint_a': 0.0014, 'krec_a1': 9e-03, 'krec_a2': 0.05 }) dose_list = list(logspace(-2, 8, num=35)) # --------------------------------------------------- # First make the figure where we increase K4 # --------------------------------------------------- dr_curve_a = [ el[0] for el in Mixed_Model.doseresponse([60], 'TotalpSTAT', 'Ia', dose_list, parameters={'Ib': 0}, return_type='list')['TotalpSTAT'] ] dr_curve_b = [ el[0] for el in Mixed_Model.doseresponse([60], 'TotalpSTAT', 'Ib', dose_list, parameters={'Ia': 0}, return_type='list')['TotalpSTAT'] ] # Now compute the 20* refractory response k4sf1 = 2 Mixed_Model.set_parameters({'kd4': 1.0 * k4sf1, 'k_d4': 0.06 * k4sf1})
class DualMixedPopulation: """ Documentation - A DualMixedPopulation instance contains two IfnModels which describe two subpopulations. Attributes ---------- name = name of model (for import) model_1 = IfnModel(name) model_2 = IfnModel(name) w1 = float in [0,1] reflecting fraction of total population described by model_1 w2 = float in [0,1] reflecting fraction of total population described by model_2 Methods ------- mixed_dose_response(): perform a dose response as per any IfnModel, but weighted by each subpopulation stepwise_fit(): perform a stepwise fit of the mixed population model to given data """ def __init__(self, name, pop1_weight, pop2_weight): self.name = name self.model_1 = IfnModel(name) self.model_2 = IfnModel(name) self.w1 = pop1_weight self.w2 = pop2_weight def set_parameters(self, param_dict): self.model_1.set_parameters(param_dict) self.model_2.set_parameters(param_dict) def reset_global_parameters(self): """ This method is not safe for maintaining detailed balance (ie. no D.B. check) :return: None """ self.model_1.reset_parameters() self.model_2.reset_parameters() def update_parameters(self, param_dict): """ This method will act like set_parameters for any parameters that do not end in '_1' or '_2'. Parameters with names ending in '_1' or '_2' will be updated only in Model 1 or Model 2 respectively. :param param_dict: dictionary of parameter names and the values to use :return: 0 """ shared_parameters = { key: value for key, value in param_dict.items() if key[-2] != '_' } model1_parameters = { key[:-2]: value for key, value in param_dict.items() if key[-2:] == '_1' } model2_parameters = { key[:-2]: value for key, value in param_dict.items() if key[-2:] == '_2' } self.model_1.set_parameters(shared_parameters) self.model_2.set_parameters(shared_parameters) self.model_1.set_parameters(model1_parameters) self.model_2.set_parameters(model2_parameters) return 0 def get_parameters(self): """ This method will retrieve all parameters from each of model_1 and model_2, and return a parameter dictionary of the form {pname: pvalue} where the pname will have '_1' if its value is unique to model_1 and '_2' if it is unique to model_2. :return: dict """ all_parameters = {} for key, value in self.model_1.parameters.items(): if self.model_1.parameters[key] != self.model_2.parameters[key]: all_parameters[key + '_1'] = self.model_1.parameters[key] all_parameters[key + '_2'] = self.model_2.parameters[key] else: all_parameters[key] = self.model_1.parameters[key] return all_parameters def mixed_dose_response(self, times, observable, dose_species, doses, parameters={}, sf=1, **kwargs): return_type = kwargs.get('return_type', 'DataFrame') if return_type not in ['DataFrame', 'IfnData']: raise TypeError('Invalid return type requested') response_1 = self.model_1.doseresponse( times, observable, dose_species, doses, parameters=parameters)[observable] response_2 = self.model_2.doseresponse( times, observable, dose_species, doses, parameters=parameters)[observable] weighted_sum_response = np.add(np.multiply(response_1, self.w1), np.multiply(response_2, self.w2)) if sf != 1: weighted_sum_response = [[el * sf for el in row] for row in weighted_sum_response] if dose_species == 'Ia': labelled_data = [[ 'Alpha', doses[row], *[(el, nan) for el in weighted_sum_response[row]] ] for row in range(0, len(weighted_sum_response))] elif dose_species == 'Ib': labelled_data = [[ 'Beta', doses[row], *[(el, nan) for el in weighted_sum_response[row]] ] for row in range(0, len(weighted_sum_response))] else: labelled_data = [[ 'Cytokine', doses[row], *[(el, nan) for el in weighted_sum_response[row]] ] for row in range(0, len(weighted_sum_response))] column_labels = ['Dose_Species', 'Dose (pM)' ] + [str(el) for el in times] drdf = pd.DataFrame.from_records(labelled_data, columns=column_labels) drdf.set_index(['Dose_Species', 'Dose (pM)'], inplace=True) if return_type == 'DataFrame': return drdf if return_type == 'IfnData': return IfnData(name='custom', df=drdf, conditions=parameters) def __score_mixed_models__(self, shared_parameters, mixed_parameters, data): # ------------------------------ # Initialize variables # ------------------------------ times = data.get_times(species='Alpha') alpha_doses = data.get_doses(species='Alpha') beta_doses = data.get_doses(species='Beta') model_1_old_parameters = self.model_1.parameters model_2_old_parameters = self.model_2.parameters # Set parameters for each population self.model_1.set_parameters(shared_parameters) self.model_1.set_parameters(mixed_parameters[0]) self.model_2.set_parameters(shared_parameters) self.model_1.set_parameters(mixed_parameters[1]) # ------------------------- # Make predictions # ------------------------- alpha_response = self.mixed_dose_response(times, 'TotalpSTAT', 'Ia', alpha_doses, parameters={'Ib': 0}) beta_response = self.mixed_dose_response(times, 'TotalpSTAT', 'Ib', beta_doses, parameters={'Ia': 0}) total_response = pd.concat([alpha_response, beta_response]) # ------------------------- # Score predictions vs data # ------------------------- def __score_target__(scf, data, sim): diff_table = np.zeros((len(data), len(data[0]))) for r in range(len(data)): for c in range(len(data[r])): if not np.isnan(data[r][c][1]): diff_table[r][c] = (sim[r][c][0] * scf - data[r][c][0]) / data[r][c][1] else: diff_table[r][c] = (sim[r][c][0] * scf - data[r][c][0]) return np.sum(np.square(diff_table)) opt = minimize(__score_target__, [0.1], args=(data.data_set.values, total_response.values)) sf = opt['x'][0] score = opt['fun'] self.model_1.set_parameters(model_1_old_parameters) self.model_2.set_parameters(model_2_old_parameters) return score, sf def stepwise_fit(self, data, parameters_to_test, ntest_per_param, mixed_p): number_of_parameters = len(parameters_to_test.keys()) final_fit = OrderedDict({}) # Local scope function def separate_parameters(p_to_test, mixed_p_list): shared_variables = {} mixed_variables = [{}, {}] for key, value in p_to_test.items(): if key[-3:] == '__1': if key[0:-3] in mixed_p_list: mixed_variables[0].update({key[0:-3]: value}) elif key[-3:] == '__2': if key[0:-3] in mixed_p_list: mixed_variables[1].update({key[0:-3]: value}) else: shared_variables.update({key: value}) return shared_variables, mixed_variables, # Fit each parameter, ordered from most important to least initial_score, _ = self.__score_mixed_models__({}, [{}, {}], data) for i in range(number_of_parameters): print("{}% of the way done".format(i * 100 / number_of_parameters)) reference_score = 0 best_scale_factor = 1 best_parameter = [] # Test all remaining parameters, using previously fit values for p, (min_test_val, max_test_val) in parameters_to_test.items(): residuals = [] scale_factor_list = [] # Try all test values for current parameter for j in np.linspace(min_test_val, max_test_val, ntest_per_param): test_parameters = { p: j, **final_fit } # Includes previously fit parameters base_parameters, subpopulation_parameters = separate_parameters( test_parameters, mixed_p) score, scale_factor = self.__score_mixed_models__( base_parameters, subpopulation_parameters, data) residuals.append(score) scale_factor_list.append(scale_factor) # Choose best value for current parameter best_parameter_value = np.linspace( min_test_val, max_test_val, ntest_per_param)[residuals.index(min(residuals))] # Decide if this is the best parameter so far in this round of 'i' loop if min(residuals) < reference_score or reference_score == 0: reference_score = min(residuals) best_scale_factor = scale_factor_list[residuals.index( min(residuals))] best_parameter = [p, best_parameter_value] # Record the next best parameter and remove it from parameters left to test final_fit.update({best_parameter[0]: best_parameter[1]}) final_scale_factor = best_scale_factor del parameters_to_test[best_parameter[0]] print("Score improved from {} to {} after {} iterations".format( initial_score, reference_score, number_of_parameters)) final_shared_parameters, final_mixed_parameters = separate_parameters( final_fit, mixed_p) return final_shared_parameters, final_mixed_parameters, final_scale_factor
'kd3': 6.52e-05, 'kint_a': 0.0015, 'kint_b': 0.002, 'krec_a1': 0.01, 'krec_a2': 0.01, 'krec_b1': 0.005, 'krec_b2': 0.05} scale_factor = 1.46182313424 Mixed_Model.set_parameters(default_parameters) Mixed_Model.default_parameters.update(default_parameters) # Produce plots times = [60] # No Negative Feedback Mixed_Model.set_parameters({'kSOCSon': 0, 'kIntBasal_r1': 0, 'kIntBasal_r2': 0, 'kint_a': 0, 'kint_b': 0}) dradf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ia', list(logspace(-2, 8)), parameters={'Ib': 0}, return_type='dataframe', dataframe_labels='Alpha', scale_factor=scale_factor) drbdf = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ib', list(logspace(-2, 8)), parameters={'Ia': 0}, return_type='dataframe', dataframe_labels='Beta', scale_factor=scale_factor) # Show internalization effects Mixed_Model.reset_parameters() Mixed_Model.set_parameters({'kSOCSon': 0}) dradf_int = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ia', list(logspace(-2, 8)), parameters={'Ib': 0}, return_type='dataframe', dataframe_labels='Alpha', scale_factor=scale_factor) drbdf_int = Mixed_Model.doseresponse(times, 'TotalpSTAT', 'Ib', list(logspace(-2, 8)), parameters={'Ia': 0}, return_type='dataframe', dataframe_labels='Beta', scale_factor=scale_factor)
# {'kSOCSon': (5e-8, 8e-7), # 'kint_a': (0.0001, 0.002), 'kint_b': (0.002, 0.0001), # 'krec_a1': (1e-03, 1e-02), 'krec_a2': (0.1, 0.01), # 'krec_b1': (0.005, 0.0005), 'krec_b2': (0.05, 0.005)}, n=6) #best_parameters, scale_factor = stepfit.fit() #print(best_parameters) #print(scale_factor) #Mixed_Model = stepfit.model # ------------------------------- # Make predictions # ------------------------------- dradf = Mixed_Model.doseresponse( times, 'TotalpSTAT', 'Ia', list(np.logspace(np.log10(doses_alpha[0]), np.log10(doses_alpha[-1]))), parameters={'Ib': 0}, return_type='dataframe', dataframe_labels='Alpha') drbdf = Mixed_Model.doseresponse( times, 'TotalpSTAT', 'Ib', list(np.logspace(np.log10(doses_beta[0]), np.log10(doses_beta[-1]))), parameters={'Ia': 0}, return_type='dataframe', dataframe_labels='Beta') for i in range(len(times)): dradf.loc['Alpha'].iloc[:, i] = dradf.loc['Alpha'].iloc[:, i].apply( scale_data) drbdf.loc['Beta'].iloc[:,
IFN_Model = IfnModel('Mixed_IFN_ppCompatible') IFN_Model.set_parameters(initial_parameters) IFN_Model.set_parameters({'R1': 12000.0, 'R2': 1511.1}) # --------------------------------- # Make theory dose response curves # --------------------------------- # Make predictions times = [2.5, 5.0, 7.5, 10.0, 20.0, 60.0] alpha_doses_20190108 = [0, 10, 100, 300, 1000, 3000, 10000, 100000] beta_doses_20190108 = [0, 0.2, 6, 20, 60, 200, 600, 2000] dradf = IFN_Model.doseresponse(times, 'TotalpSTAT', 'Ia', list(logspace(1, 5.2)), parameters={'Ib': 0}, scale_factor=scale_factor, return_type='dataframe', dataframe_labels='Alpha') drbdf = IFN_Model.doseresponse(times, 'TotalpSTAT', 'Ib', list(logspace(-1, 4)), parameters={'Ia': 0}, scale_factor=scale_factor, return_type='dataframe', dataframe_labels='Beta') dra60 = IfnData('custom', df=dradf, conditions={'Alpha': {'Ib': 0}}) drb60 = IfnData('custom', df=drbdf, conditions={'Beta': {'Ia': 0}})