Ejemplo n.º 1
0
    def test_plot_model_3(self):
        global ym
        global em
        global synthesis_p

        #Modify the plot settings accordingly
        plot_index = {
            1: ['p', synthesis_p],
        }
        titles = {
            1: {
                'p': 'Model 1 Protein',
                synthesis_p: 'Rate of Protein Synthesis'
            },
        }
        labels = {1: {1: 'Scenario 1', 2: 'Scenario 2'}}

        figs = [plt.figure()]
        AX_ = [figs[0].add_subplot(1, 2, i + 1) for i in range(2)]
        AX = {1: {'p': AX_[0], synthesis_p: AX_[1]}}

        figs, AX = sim.plot_model(plot_index,
                                  ym,
                                  e=em,
                                  titles=titles,
                                  labels=labels,
                                  figs=figs,
                                  AX=AX)

        assert len(figs) == 1
Ejemplo n.º 2
0
    def test_plot_model_1(self):
        global ym

        plot_index = {
            1: ['m', 'p'],
        }
        titles = {
            1: {
                'm': 'Model 1 mRNA',
                'p': 'Model 1 Protein'
            },
        }
        labels = {1: {1: 'Scenario 1', 2: 'Scenario 2'}}

        figs, AX = sim.plot_model(plot_index, ym, titles=titles, labels=labels)

        assert len(figs)
Ejemplo n.º 3
0
    def test_plot_model_2(self):
        global ym
        global em
        global synthesis_p

        #Modify the plot settings accordingly
        plot_index = {
            1: ['p', synthesis_p],
        }
        titles = {
            1: {
                'p': 'Model 1 Protein',
                synthesis_p: 'Rate of Protein Synthesis'
            },
        }
        labels = {1: {1: 'Scenario 1', 2: 'Scenario 2'}}

        figs, AX = sim.plot_model(plot_index,
                                  ym,
                                  e=em,
                                  titles=titles,
                                  labels=labels)

        assert len(figs)
    #Integrate the models numerically
    ym, em = sim.integrate_models(models, params)

    #Define plot settings
    plot_index = {
        1: ['Pep3'],
    }
    titles = {
        1: {
            'Pep3': 'Model 1 Protein'
        },
    }
    labels = {1: {1: 'Input=00', 2: 'Input=01', 3: 'Input=10', 4: 'Input=11'}}

    figs, AX = sim.plot_model(plot_index, ym, titles=titles, labels=labels)

    #Export simulation results
    prefix = ''

    #A new folder will be created inside the output_folder using this directory.
    directory = output_folder / 'simulation_results'

    sim.export_simulation_results(ym, em, prefix=prefix, directory=directory)
    '''Run curvefitting and model selection using the same configuration file.
    The steps are as follows:
        1. prepare configuration .ini file (aside from core model information)
            - guess, priors, parameter_bounds, fixed_parameters,
        2. get_sampler_args
        3. update sampler_args with information from experimental data file
        4. run curve fitting algorithm
    print('\nparams:\n', params)

    models[1]['int_args']['modify_params'] = modify_params
    print('\nUpdated params:\n', params)

    #Integrate the models numerically
    ym, em = sim.integrate_models(models, params)
    print('\nym:\n', ym[1][1][0].info())

    #Define plot settings
    plot_index = {
        1: ['N', 's0', 'r', 'a'],
    }
    titles = {
        1: {
            'N': 'N - Cell Number',
            's0': 's0 - Extracellular nutrient',
            'r': 'r - Ribosome',
            'a': 'a - Energy'
        },
    }

    #Only plot the last 600 mins ignoring the first 1e5 mins of steady-state run
    #which is required to form the initial conditions for this resource model
    ymedit = ym.copy()
    ymedit[1][1][0] = ym[1][1][0].iloc[1000001:]  #state dataframe
    ymedit[1][0] = ym[1][0][-60000:-1]  #Time array
    print('\nymedit:\n', ymedit[1][1][0].info())

    figs, AX = sim.plot_model(plot_index, ymedit, titles=titles)
    #Modify the plot settings accordingly
    plot_index = {
        1: ['p', synthesis_p],
    }
    titles = {
        1: {
            'p': 'Model 1 Protein',
            synthesis_p: 'Rate of Protein Synthesis'
        },
    }
    labels = {1: {1: 'Ind 0', 2: 'Ind 0.01', 3: 'Ind 0.05', 4: 'Ind 0.15'}}

    figs, AX = sim.plot_model(plot_index,
                              ym,
                              e=em,
                              titles=titles,
                              labels=labels)
    '''
    Supposed we have two segments to the experiment and that the inducer is removed in the second half.
    '''

    def change_inducer_by_scenario_and_segment(init_values, params, model_num,
                                               scenario_num, segment):
        '''
        Modifies the the current array of params based on model_num, scenario, segment and init_values.
        For safety, do not modify in place.
        '''
        inducer_conc = {1: 0, 2: 0.03, 3: 0.05, 4: 0.15}

        new_params = params.copy()
 ##Plot Settings
 '''
 The following arguments follow a similar format to models where the first key corresponds to the model being integrated.
 The definition of the values indexed by those keys are as follows:
 plot_index : A list of state variables to plot as well as extra functions for plotting.
 titles     : A list of title names corresponding the states in plot_index. This argument is optional.
 labels     : A dict of scenario: name pairs that will be used in the legend. This argument is optional.                            
 '''
 plot_index  = {1: ['m', 'p'],
                }
 titles      = {1: {'m': 'Model 1 mRNA', 'p': 'Model 1 Protein'},
                }
 labels      = {1: {1: 'Scenario 1', 2: 'Scenario 2'}
                }
 
 figs, AX = sim.plot_model(plot_index, ym, titles=titles, labels=labels)
 
 #Plotting extra variables
 '''
 Sometimes, we might want to examine quantities that are not time series of the state variables.
 In this case, we can come up with our own functions to evaluate extra variables.
 This extra function takes of the form of func(y, t, params).
 The arrays in ym and their corresponding rows in params are fed into this function.
 The return values are:
     1. The y axis values
     2. The x axis values
     3. The marker used for plotting (Refer to matplotlib)
 '''
 
 @jit(nopython=True)
 def synthesis_p(y, t, params):