diff --git a/build/lib/fears/experiment.py b/build/lib/fears/experiment.py index 3fda143..a85d478 100644 --- a/build/lib/fears/experiment.py +++ b/build/lib/fears/experiment.py @@ -101,14 +101,6 @@ def __init__(self, else: self.experiment_type = experiment_type - # if experiment_type == 'dose-survival' and len(inoculants) > 1: - # raise Exception('The experiment type is set to dose-survival (default), but more than one inoculant is given.') - # elif experiment_type == 'inoculant-survival' and len(self.max_doses) > 1: - # # print('here') - # raise Exception('The experiment type is set to inoculant-survival, but more than one max dose is given.') - - # if experiment_type == 'inoculant-survival' and inoculants is None: - # raise Exception('The experiment type is set to inoculant-survival, but no inoculants are given.') self.ramp = ramp if self.experiment_type == 'ramp_up_down': self.p_landscape = Population(constant_pop = True, @@ -151,19 +143,6 @@ def __init__(self, self.set_ramp_ud(self.p_landscape) self.set_ramp_ud(self.p_seascape) - - # p_bottleneck = Population(max_dose = max_doses, - # n_sims = self.n_sims, - # curve_type = 'bottleneck' - # **self.population_options) - # self.populations.append(p_bottleneck) - - # p_no_bottleneck = Population(max_dose = max_doses, - # n_sims = self.n_sims, - # curve_type = 'constant' - # **self.population_options) - # self.populations.append(p_no_bottleneck) - if self.experiment_type == 'dose-survival': for curve_type in self.curve_types: for max_dose in self.max_doses: @@ -490,7 +469,7 @@ def run_experiment(self): save_folder = 'k_abs=' + str(p.k_abs) save_folder.replace('.',',') else: - save_folder = 'slope=' + str(p.slope) + save_folder = 'slope=' + str(p.k_abs) save_folder.replace('.',',') # self.save_counts(counts,n,save_folder) data_dict = {'counts':counts, @@ -498,15 +477,6 @@ def run_experiment(self): self.save_dict(data_dict,save_folder,num=n) if not self.debug: pickle.dump(self, open(self.experiment_info_path,"wb")) - # pickle.dump(self, open(self.experiment_info_path,"wb")) - - - # fig_savename = 'slope = ' + str(p.slope) - # self.figures = self.figures.append(fig) - # pbar.update() - # self.rate_survival_results.index = np.arange(len(self.rate_survival_results)) - - # pbar.close() # close progress bar # save counts as a csv in the given subfolder with the label 'num' def save_counts(self,counts,num,save_folder,prefix='sim_'): diff --git a/build/lib/fears/utils/pharm.py b/build/lib/fears/utils/pharm.py index 7fcab9e..9d97ec9 100644 --- a/build/lib/fears/utils/pharm.py +++ b/build/lib/fears/utils/pharm.py @@ -87,10 +87,18 @@ def gen_impulses(pop): # generate the drug dose regimen + if pop.dwell: + dwell_time = int(pop.dwell_time/pop.timestep_scale) + else: + dwell_time = 0 + if pop.regimen_length is None: regimen_length = pop.n_timestep else: - regimen_length = pop.regimen_length + regimen_length = pop.regimen_length + pop.dwell_time + + if regimen_length > pop.n_timestep: + regimen_length = pop.n_timestep while impulse_indx[i] < regimen_length*pop.timestep_scale-pop.dose_schedule: impulse_indx.append(pop.dose_schedule*(i+1)) @@ -108,7 +116,6 @@ def gen_impulses(pop): u[impulse_indx]=1 # list of impulses at the simulated drug dosage times if pop.dwell: - dwell_time = int(pop.dwell_time/pop.timestep_scale) u[0:dwell_time] = 0 return u diff --git a/build/lib/fears/utils/plotter.py b/build/lib/fears/utils/plotter.py index e87ff69..c9068a9 100644 --- a/build/lib/fears/utils/plotter.py +++ b/build/lib/fears/utils/plotter.py @@ -598,6 +598,7 @@ def plot_landscape(p,conc=10**0, plot_sub_network=False, sub_network=None, sub_network_color='white', + weight_list=None, **kwargs): """ Plots a graph representation of this landscape on the current matplotlib figure. @@ -872,7 +873,11 @@ def plot_landscape(p,conc=10**0, if trajectory_list is not None: - for trajectory in trajectory_list: + for i,trajectory in enumerate(trajectory_list): + + if weight_list is not None: + weight = weight_list[i] + arrowprops['lw'] = weight trajectory_pairs = [] @@ -918,7 +923,7 @@ def plot_landscape(p,conc=10**0, break # Draw trajectory arrows - + ax.annotate('', xy=end_pos, xytext=start_pos, arrowprops=arrowprops) @@ -1006,6 +1011,7 @@ def plot_kaplan_meier(pop, event_times, label=None, t_max=None, + t_vect = None, n_sims=None, ax=None, mode='resistant', @@ -1038,7 +1044,9 @@ def plot_kaplan_meier(pop, else: ylabel='% survival' - ax.plot(survival_curve,label=label,**kwargs) + if t_vect is None: + t_vect = np.arange(t_max) + ax.plot(t_vect,survival_curve,label=label,**kwargs) if errorband: # compute error bars @@ -1053,7 +1061,7 @@ def plot_kaplan_meier(pop, err[t] = 100*((p*q)/n)**0.5 # t = np.arange(t_max) - ax.fill_between(t,survival_curve-err,survival_curve+err,alpha=0.4) + ax.fill_between(t_vect,survival_curve-err,survival_curve+err,alpha=0.4) xticks = ax.get_xticks() xlabels = xticks diff --git a/fears/experiment.py b/fears/experiment.py index 3fda143..a85d478 100644 --- a/fears/experiment.py +++ b/fears/experiment.py @@ -101,14 +101,6 @@ def __init__(self, else: self.experiment_type = experiment_type - # if experiment_type == 'dose-survival' and len(inoculants) > 1: - # raise Exception('The experiment type is set to dose-survival (default), but more than one inoculant is given.') - # elif experiment_type == 'inoculant-survival' and len(self.max_doses) > 1: - # # print('here') - # raise Exception('The experiment type is set to inoculant-survival, but more than one max dose is given.') - - # if experiment_type == 'inoculant-survival' and inoculants is None: - # raise Exception('The experiment type is set to inoculant-survival, but no inoculants are given.') self.ramp = ramp if self.experiment_type == 'ramp_up_down': self.p_landscape = Population(constant_pop = True, @@ -151,19 +143,6 @@ def __init__(self, self.set_ramp_ud(self.p_landscape) self.set_ramp_ud(self.p_seascape) - - # p_bottleneck = Population(max_dose = max_doses, - # n_sims = self.n_sims, - # curve_type = 'bottleneck' - # **self.population_options) - # self.populations.append(p_bottleneck) - - # p_no_bottleneck = Population(max_dose = max_doses, - # n_sims = self.n_sims, - # curve_type = 'constant' - # **self.population_options) - # self.populations.append(p_no_bottleneck) - if self.experiment_type == 'dose-survival': for curve_type in self.curve_types: for max_dose in self.max_doses: @@ -490,7 +469,7 @@ def run_experiment(self): save_folder = 'k_abs=' + str(p.k_abs) save_folder.replace('.',',') else: - save_folder = 'slope=' + str(p.slope) + save_folder = 'slope=' + str(p.k_abs) save_folder.replace('.',',') # self.save_counts(counts,n,save_folder) data_dict = {'counts':counts, @@ -498,15 +477,6 @@ def run_experiment(self): self.save_dict(data_dict,save_folder,num=n) if not self.debug: pickle.dump(self, open(self.experiment_info_path,"wb")) - # pickle.dump(self, open(self.experiment_info_path,"wb")) - - - # fig_savename = 'slope = ' + str(p.slope) - # self.figures = self.figures.append(fig) - # pbar.update() - # self.rate_survival_results.index = np.arange(len(self.rate_survival_results)) - - # pbar.close() # close progress bar # save counts as a csv in the given subfolder with the label 'num' def save_counts(self,counts,num,save_folder,prefix='sim_'): diff --git a/fears/utils/pharm.py b/fears/utils/pharm.py index 7fcab9e..9d97ec9 100644 --- a/fears/utils/pharm.py +++ b/fears/utils/pharm.py @@ -87,10 +87,18 @@ def gen_impulses(pop): # generate the drug dose regimen + if pop.dwell: + dwell_time = int(pop.dwell_time/pop.timestep_scale) + else: + dwell_time = 0 + if pop.regimen_length is None: regimen_length = pop.n_timestep else: - regimen_length = pop.regimen_length + regimen_length = pop.regimen_length + pop.dwell_time + + if regimen_length > pop.n_timestep: + regimen_length = pop.n_timestep while impulse_indx[i] < regimen_length*pop.timestep_scale-pop.dose_schedule: impulse_indx.append(pop.dose_schedule*(i+1)) @@ -108,7 +116,6 @@ def gen_impulses(pop): u[impulse_indx]=1 # list of impulses at the simulated drug dosage times if pop.dwell: - dwell_time = int(pop.dwell_time/pop.timestep_scale) u[0:dwell_time] = 0 return u diff --git a/fears/utils/plotter.py b/fears/utils/plotter.py index e87ff69..c9068a9 100644 --- a/fears/utils/plotter.py +++ b/fears/utils/plotter.py @@ -598,6 +598,7 @@ def plot_landscape(p,conc=10**0, plot_sub_network=False, sub_network=None, sub_network_color='white', + weight_list=None, **kwargs): """ Plots a graph representation of this landscape on the current matplotlib figure. @@ -872,7 +873,11 @@ def plot_landscape(p,conc=10**0, if trajectory_list is not None: - for trajectory in trajectory_list: + for i,trajectory in enumerate(trajectory_list): + + if weight_list is not None: + weight = weight_list[i] + arrowprops['lw'] = weight trajectory_pairs = [] @@ -918,7 +923,7 @@ def plot_landscape(p,conc=10**0, break # Draw trajectory arrows - + ax.annotate('', xy=end_pos, xytext=start_pos, arrowprops=arrowprops) @@ -1006,6 +1011,7 @@ def plot_kaplan_meier(pop, event_times, label=None, t_max=None, + t_vect = None, n_sims=None, ax=None, mode='resistant', @@ -1038,7 +1044,9 @@ def plot_kaplan_meier(pop, else: ylabel='% survival' - ax.plot(survival_curve,label=label,**kwargs) + if t_vect is None: + t_vect = np.arange(t_max) + ax.plot(t_vect,survival_curve,label=label,**kwargs) if errorband: # compute error bars @@ -1053,7 +1061,7 @@ def plot_kaplan_meier(pop, err[t] = 100*((p*q)/n)**0.5 # t = np.arange(t_max) - ax.fill_between(t,survival_curve-err,survival_curve+err,alpha=0.4) + ax.fill_between(t_vect,survival_curve-err,survival_curve+err,alpha=0.4) xticks = ax.get_xticks() xlabels = xticks diff --git a/fears/utils/stats.py b/fears/utils/stats.py index 630ffe3..6e3b816 100644 --- a/fears/utils/stats.py +++ b/fears/utils/stats.py @@ -164,7 +164,7 @@ def get_entropy_timetrace(sim_num=0,condition_num=0,exp=None,exp_info_path=None) sim = exp + os.sep + sim data_dict = results_manager.get_data(sim) - data = data_dict['counts'] + data = data_dict['counts']/np.sum(data_dict['counts'],axis=1) return stats.entropy(data.T)