Ejemplo n.º 1
0
def fit_single_mother_and_bud(model,
                              mothercells_data,
                              daughtercells_data,
                              time_data,
                              cell_id,
                              parameters_to_fit, 
                              additional_concentrations={},
                              max_time=400,
                              params_ini={},
                              tolerance_factor=1):
  data = get_data_dict_for_cell(mothercells_data, daughtercells_data, time_data, cell_id)
  data_trunc = model_data.truncate_data(data)
  data_trunc['time'] = data_trunc['time'] + abs(min(data_trunc['time']))
  data_trunc = model_data.limit_time_in_data(data_trunc, max_time=max_time)
  additional_model_parameters = get_additional_model_parameters(data_trunc)
  
  if params_ini=={}:
    params_ini = get_initial_parameter_guess(data_trunc)
    print(params_ini)
  
  fitted_parameters = fit_data.fit_model_to_data(model, 
                                                 data_trunc, 
                                                 parameters_to_fit,   
                                                 'cmaes', 
                                                 additional_model_parameters=additional_model_parameters,
                                                 additional_concentrations=additional_concentrations,
                                                 params_ini=params_ini,
                                                 tolerance_factor=tolerance_factor)
  msd = fit_data.compute_objective_function(fitted_parameters, 
                                            model, 
                                            parameters_to_fit, 
                                            data_trunc, 
                                            additional_model_parameters, 
                                            additional_concentrations)
  return fitted_parameters, msd
Ejemplo n.º 2
0
def fit_model_to_all_cells(model, 
                           mothercells_data,
                           daughtercells_data,
                           time_data,
                           parameters_to_fit):
    fitting_results = []
    rows_and_cols = np.ceil(np.sqrt(len(mothercells_data)))
    for mother_pos in range(len(mothercells_data)):
        data = {'time': np.array(time_data), 'V_tot_fl': mothercells_data[mother_pos, :]}
        data = model_data.truncate_data(data)
        data['time'] = data['time'] + abs(min(data['time']))
        data = model_data.limit_time_in_data(data, max_time=300)
        additional_model_parameters = get_initial_volume_osmotic_from_data(model, data)
        fitted_parameters, opt_res = fit_model_to_data(model, 
                                              data, 
                                              parameters_to_fit, 
                                              'cmaes', 
                                              additional_model_parameters=additional_model_parameters)
        fitting_results.append(fitted_parameters)
        plt.subplot(rows_and_cols, rows_and_cols, mother_pos + 1)
        plot_fitting_result_and_data(model,
                                     fitted_parameters,
                                     data,
                                     parameters_to_fit,
                                     additional_model_parameters=additional_model_parameters,
                                     subplot=False,
                                     show=False)
    plt.show()
        
    return fitting_results
def fit_single_mother_and_bud(model,
                              mothercells_data,
                              daughtercells_data,
                              time_data,
                              cell_id,
                              parameters_to_fit,
                              additional_concentrations={},
                              additional_model_parameters={},
                              max_time=400,
                              params_ini={},
                              log=True,
                              bounds={},
                              tolfun=0.1,
                              sigma0_log_notlog=(1e-1, 4e-17)):
    additional_model_parameters = {}
    data = get_data_dict_for_cell(mothercells_data, daughtercells_data,
                                  time_data, cell_id)
    data_trunc = model_data.truncate_data(data)
    data_trunc['time'] = data_trunc['time'] + abs(min(data_trunc['time']))
    data_trunc = model_data.limit_time_in_data(data_trunc, max_time=max_time)
    #additional_model_parameters =  get_additional_model_parameters(data_trunc)
    para_ini_ids = ['budding_start', 'mother_r_os_0']
    params_ini = fit_data.get_initial_parameter_from_data(
        model, data_trunc, para_ini_ids)
    #bud_start_data = get_initial_bud_start_guess(data_trunc)

    bud_start_data = params_ini['budding_start']
    start_tolerance = 120 * 60

    bounds['budding_start'] = [
        bud_start_data - start_tolerance, bud_start_data + start_tolerance
    ]
    bounds['mother_r_os_0'] = [
        params_ini['mother_r_os_0'] - 0.3, params_ini['mother_r_os_0'] + 0.3
    ]
    #bounds['mother_phi']= [5.e-6, 5.e-1]
    #bounds['bud_phi']= [1.e-5, 5.e-1 ]
    #bounds['k_nutrient_']= [9.e-16, 9.e-17]
    #bounds['k_deg_0']= [1.e-15, 1.e-17]
    #bounds['mother_r_os'] = [0.1,2]

    fitted_parameters = fit_data.fit_model_to_data(
        model,
        data_trunc,
        parameters_to_fit,
        'cmaes',
        additional_model_parameters=additional_model_parameters,
        additional_concentrations=additional_concentrations,
        params_ini=params_ini,
        bounds=bounds,
        log=log,
        tolfun=tolfun,
        sigma0_log_notlog=sigma0_log_notlog)
    print(fitted_parameters)
    log = False
    msd = fit_data.compute_objective_function(fitted_parameters, model,
                                              parameters_to_fit, data_trunc,
                                              additional_model_parameters,
                                              additional_concentrations, log)
    return fitted_parameters, msd
Ejemplo n.º 4
0
def plot_fitting_for_all(model,
                         mothercells_data,
                         daughtercells_data,
                         time_data,
                         df_params,
                         additional_concentrations={},
                         max_time=400):
  assert len(df_params) == len(mothercells_data)
  df_params = df_params.copy()
  df_params = df_params.drop('MSD', axis=1)
  no_cols = 4
  no_rows = np.ceil(float(len(mothercells_data))/no_cols)
  fig = plt.figure(1, figsize=(10,12))
  ax = plt.subplot(no_rows, no_cols, 1)
  for cell_id in range(len(mothercells_data)):
    data = get_data_dict_for_cell(mothercells_data, daughtercells_data, time_data, cell_id)
    data_trunc = model_data.truncate_data(data)
    data_trunc['time'] = data_trunc['time'] + abs(min(data_trunc['time']))
    data_trunc = model_data.limit_time_in_data(data_trunc, max_time=max_time)
    additional_model_parameters = get_additional_model_parameters(data_trunc)
    print cell_id
    print additional_model_parameters
    print 
    fitted_parameters = df_params.iloc[cell_id]

    ax = plt.subplot(no_rows, no_cols, cell_id + 1, sharey=ax)
    fit_data.plot_fitting_result_and_data(model, 
                                          fitted_parameters, 
                                          data_trunc, 
                                          parameters_to_fit, 
                                          subplot=False, 
                                          additional_model_parameters=additional_model_parameters,
                                          additional_concentrations=additional_concentrations,
                                          legend=False)
    plt.ylabel('volume, fl')
    plt.xlabel('time, min')
    plt.title('Cell %s' %cell_id)
  plt.legend(bbox_to_anchor=(1.5, 1),
             loc=2, borderaxespad=0.,
             labels=['bud volume (fitted)',
             'bud volume ',
             'mother volume (fitted)',
             'mother volume '])

  plt.tight_layout()
Ejemplo n.º 5
0
def get_data_trunc(data,max_time):
    data_trunc = model_data.truncate_data(data)
    data_trunc['time'] = data_trunc['time'] + abs(min(data_trunc['time']))
    data_trunc = model_data.limit_time_in_data(data_trunc, max_time=max_time)
    return data_trunc
def plot_fitting_for_all(model,
                         mothercells_data,
                         daughtercells_data,
                         time_data,
                         df_params,
                         additional_concentrations={},
                         additional_model_parameters={},
                         max_time=400,
                         cols=4,
                         max_cell_ID=0):

    if max_cell_ID == 0:
        Cell_IDs = range(len(mothercells_data))
    else:
        Cell_IDs = range(max_cell_ID)

    assert len(df_params) == len(mothercells_data)
    df_params = df_params.copy()
    df_params.drop('MSD', inplace=True, axis=1)
    no_cols = cols
    no_rows = np.ceil(float(len(Cell_IDs)) / no_cols)
    fig = plt.figure(1, figsize=(8, 8))
    ax = plt.subplot(no_rows, no_cols, 1)

    for cell_id in Cell_IDs:
        data = get_data_dict_for_cell(mothercells_data, daughtercells_data,
                                      time_data, cell_id)
        data_trunc = model_data.truncate_data(data)
        data_trunc['time'] = data_trunc['time'] + abs(min(data_trunc['time']))
        data_trunc = model_data.limit_time_in_data(data_trunc,
                                                   max_time=max_time)
        #additional_model_parameters = get_additional_model_parameters(data_trunc)
        print cell_id
        #print additional_model_parameters
        fitted_parameters = df_params.iloc[cell_id]

        ax = plt.subplot(no_rows, no_cols, cell_id + 1, sharey=ax)

        try:
            fit_data.plot_fitting_result_and_data(
                model,
                fitted_parameters,
                data_trunc,
                parameters_to_fit,
                subplot=False,
                additional_model_parameters=additional_model_parameters,
                additional_concentrations=additional_concentrations,
                legend=False,
                observables=[])
        except:
            print('could not simulate for cell Nr. {0}'.format(cell_id))

        budstart = fitted_parameters['budding_start'] / 60
        nr_of_points = 10
        y = np.arange(0, 100, nr_of_points)
        x = [budstart] * nr_of_points
        plt.plot(x, y)

        plt.ylabel('volume, fl', fontsize='x-large')
        plt.xlabel('time, min', fontsize='x-large')
        plt.title('Cell %s' % cell_id)
    plt.legend(bbox_to_anchor=(1.5, 1),
               loc=2,
               borderaxespad=0.,
               labels=[
                   'bud volume (fitted)', 'bud volume ',
                   'mother volume (fitted)', 'mother volume '
               ])

    plt.tight_layout()