Beispiel #1
0
def plot_death_freeze_state_test():
    out_dir = os.path.join(PROCESS_OUT_DIR, 'death_freeze_state')
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    timeseries = test_death_freeze_state(asserts=False)
    plot_settings = {}
    plot_simulation_output(timeseries, plot_settings, out_dir)
Beispiel #2
0
def run_master(out_dir):
    timeseries = test_master()
    volume_ts = timeseries['global']['volume']
    print('growth: {}'.format(volume_ts[-1] / volume_ts[0]))
    expression_plot_settings = {
        'name': 'gene_expression',
        'ports': {
            'transcripts': 'transcripts',
            'molecules': 'metabolites',
            'proteins': 'proteins'
        }
    }
    plot_gene_expression_output(timeseries, expression_plot_settings, out_dir)

    plot_settings = {
        'max_rows':
        20,
        'remove_zeros':
        True,
        'skip_ports': [
            'prior_state', 'null', 'flux_bounds', 'chromosome', 'reactions',
            'exchange'
        ]
    }
    plot_simulation_output(timeseries, plot_settings, out_dir)
Beispiel #3
0
def main():
    out_dir = os.path.join(TEST_OUT_DIR, NAME)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    timeseries = run_injector()
    plot_settings = {}
    plot_simulation_output(timeseries, plot_settings, out_dir)
    save_timeseries(timeseries, out_dir)
def main():
    out_dir = os.path.join(PROCESS_OUT_DIR, AntibioticTransport.name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
    timeseries = run_antibiotic_transport()
    plot_settings = {}
    plot_simulation_output(timeseries, plot_settings, out_dir)
    save_timeseries(timeseries, out_dir)
Beispiel #5
0
def test_expression_chemotaxis(n_flagella=5, total_time=10, out_dir='out'):

    environment_port = 'external'
    ligand_id = 'MeAsp'
    initial_conc = 0

    # configure timeline
    exponential_random_config = {
        'ligand': ligand_id,
        'environment_port': environment_port,
        'time': total_time,
        'timestep': 1,
        'initial_conc': initial_conc,
        'base': 1 + 4e-4,
        'speed': 14
    }

    # make the compartment
    config = {
        'external_path': (environment_port, ),
        'ligand_id': ligand_id,
        'initial_ligand': initial_conc,
        'n_flagella': n_flagella
    }
    compartment = ChemotaxisExpressionFlagella(config)

    # run experiment
    initial_state = get_flagella_initial_state({'molecules': 'internal'})
    experiment_settings = {
        'initial_state': initial_state,
        'timeline': {
            'timeline':
            get_exponential_random_timeline(exponential_random_config),
            'ports': {
                'external': ('boundary', 'external')
            }
        },
    }
    timeseries = simulate_compartment_in_experiment(compartment,
                                                    experiment_settings)

    # plot settings for the simulations
    plot_settings = {
        'max_rows': 30,
        'remove_zeros': True,
        'skip_ports': ['chromosome', 'ribosomes']
    }
    plot_simulation_output(timeseries, plot_settings, out_dir)

    # gene expression plot
    plot_config = {
        'ports': {
            'transcripts': 'transcripts',
            'proteins': 'proteins',
            'molecules': 'internal'
        }
    }
    plot_gene_expression_output(timeseries, plot_config, out_dir)
Beispiel #6
0
def run_flagella_compartment(
        compartment,
        initial_state=None,
        out_dir='out'):

    # get flagella data
    flagella_data = FlagellaChromosome()

    # run simulation
    settings = {
        # a cell cycle of 2520 sec is expected to express 8 flagella.
        # 2 flagella expected in approximately 630 seconds.
        'total_time': 2520,
        'emit_step': COMPARTMENT_TIMESTEP,
        'verbose': True,
        'initial_state': initial_state}
    timeseries = simulate_compartment_in_experiment(compartment, settings)

    # save reference timeseries
    save_timeseries(timeseries, out_dir)

    plot_config = {
        'name': 'flagella_expression',
        'ports': {
            'transcripts': 'transcripts',
            'proteins': 'proteins',
            'molecules': 'molecules'}}

    plot_gene_expression_output(
        timeseries,
        plot_config,
        out_dir)

    # just-in-time figure
    plot_config2 = plot_config.copy()
    plot_config2.update({
        'name': 'flagella',
        'plot_ports': {
            'transcripts': list(flagella_data.chromosome_config['genes'].keys()),
            'proteins': flagella_data.complexation_monomer_ids + flagella_data.complexation_complex_ids,
            'molecules': list(nucleotides.values()) + list(amino_acids.values())}})

    plot_timeseries_heatmaps(
        timeseries,
        plot_config2,
        out_dir)

    # make a basic sim output
    plot_settings = {
        'max_rows': 30,
        'remove_zeros': True,
        'skip_ports': ['chromosome', 'ribosomes']}
    plot_simulation_output(
        timeseries,
        plot_settings,
        out_dir)
def plot_timeseries(timeseries, out_dir):
    # plot settings for the simulations
    plot_settings = {
        'max_rows': 30,
        'remove_zeros': True,
        'skip_ports': ['chromosome', 'ribosomes']
    }
    plot_simulation_output(
        timeseries,
        plot_settings,
        out_dir)
def main():
    out_dir = os.path.join(COMPARTMENT_OUT_DIR, Antibiotics.name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    plot_settings = {
        'max_rows': 25,
    }

    timeseries = run_antibiotics_composite()
    plot_simulation_output(timeseries, plot_settings, out_dir)
    save_timeseries(timeseries, out_dir)
Beispiel #9
0
def run_template_process(out_dir='out'):
    # initialize the process by passing initial_parameters
    initial_parameters = {}
    template_process = Template(initial_parameters)

    # run the simulation
    sim_settings = {'total_time': 10}
    output = simulate_process_in_experiment(template_process, sim_settings)

    # plot the simulation output
    plot_settings = {}
    plot_simulation_output(output, plot_settings, out_dir)
Beispiel #10
0
def run_gene_expression(total_time=10, out_dir='out'):
    timeseries = test_gene_expression(total_time)
    plot_settings = {
        'name': 'gene_expression',
        'ports': {
            'transcripts': 'transcripts',
            'molecules': 'molecules',
            'proteins': 'proteins'}}
    plot_gene_expression_output(timeseries, plot_settings, out_dir)

    sim_plot_settings = {'max_rows': 25}
    plot_simulation_output(timeseries, sim_plot_settings, out_dir)
Beispiel #11
0
def test_variable_chemotaxis(n_flagella=5, total_time=10, out_dir='out'):

    environment_port = 'external'
    ligand_id = 'MeAsp'
    initial_conc = 0

    # configure timeline
    exponential_random_config = {
        'ligand': ligand_id,
        'environment_port': environment_port,
        'time': total_time,
        'timestep': 1,
        'initial_conc': initial_conc,
        'base': 1 + 4e-4,
        'speed': 14
    }

    # make the compartment
    config = {
        'external_path': (environment_port, ),
        'ligand_id': ligand_id,
        'initial_ligand': initial_conc,
        'n_flagella': n_flagella
    }
    compartment = ChemotaxisVariableFlagella(config)

    # run experiment
    experiment_settings = {
        'timeline': {
            'timeline':
            get_exponential_random_timeline(exponential_random_config),
            'ports': {
                'external': ('boundary', 'external')
            }
        },
    }
    timeseries = simulate_compartment_in_experiment(compartment,
                                                    experiment_settings)

    # plot settings for the simulations
    plot_settings = {
        'max_rows': 20,
        'remove_zeros': True,
    }
    plot_simulation_output(timeseries, plot_settings, out_dir)
def run_chemotaxis_master(out_dir):
    total_time = 10

    # make the compartment
    compartment = ChemotaxisMaster({})

    # save the topology network
    settings = {'show_ports': True}
    plot_compartment_topology(compartment, settings, out_dir)

    # run an experinet
    settings = {'timestep': 1, 'total_time': total_time}
    timeseries = simulate_compartment_in_experiment(compartment, settings)

    volume_ts = timeseries['boundary']['volume']
    print('growth: {}'.format(volume_ts[-1] / volume_ts[0]))

    # plots
    # simulation output
    plot_settings = {
        'max_rows': 40,
        'remove_zeros': True,
        'skip_ports': ['reactions', 'prior_state', 'null']
    }
    plot_simulation_output(timeseries, plot_settings, out_dir)

    # gene expression plot
    gene_exp_plot_config = {
        'name': 'flagella_expression',
        'ports': {
            'transcripts': 'transcripts',
            'proteins': 'proteins',
            'molecules': 'internal'
        }
    }
    plot_gene_expression_output(timeseries, gene_exp_plot_config, out_dir)
def analyze_transport_metabolism(timeseries, config={}, out_dir='out'):
    environment_volume = config.get('environment_volume', 1e-14)

    # calculate growth
    volume_ts = timeseries['boundary']['volume']
    print('growth: {}'.format(volume_ts[-1] / volume_ts[1]))

    # simulation plot
    plot_settings = {
        'max_rows': 30,
        'remove_flat': True,
        'remove_zeros': True,
        'skip_ports': ['null', 'reactions'],
    }
    plot_simulation_output(timeseries, plot_settings, out_dir)

    # diauxic plot
    settings = {
        'internal_path': ('cytoplasm', ),
        'external_path': ('boundary', 'external'),
        'global_path': ('boundary', ),
        'environment_volume': environment_volume,  # L
    }
    plot_diauxic_shift(timeseries, settings, out_dir)
    return simulate_process_in_experiment(expression, settings)


if __name__ == '__main__':
    out_dir = os.path.join(PROCESS_OUT_DIR, NAME)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    parser = argparse.ArgumentParser(description='ODE expression')
    parser.add_argument('--lacY', '-l', action='store_true', default=False)
    parser.add_argument('--flagella', '-f', action='store_true', default=False)
    args = parser.parse_args()

    if args.flagella:
        timeline = [(2520, {})]
        timeseries = test_expression(get_flagella_expression(), timeline)
        plot_simulation_output(timeseries, {}, out_dir, 'flagella_expression')
    else:
        total_time = 5000
        shift_time1 = int(total_time / 5)
        shift_time2 = int(3 * total_time / 5)
        timeline = [(0, {
            ('external', 'glc__D_e'): 10
        }), (shift_time1, {
            ('external', 'glc__D_e'): 0
        }), (shift_time2, {
            ('external', 'glc__D_e'): 10
        }), (total_time, {})]
        timeseries = test_expression(get_lacy_config(), timeline)
        plot_simulation_output(timeseries, {}, out_dir, 'lacY_expression')
Beispiel #15
0
                point_0 = (middle[0] + delta[0] / 2, middle[1] + delta[1] / 2)
                point_1 = ((middle[0] - delta[0] / 2),
                           (middle[1] - delta[1] / 2))
                x_0 = point_0[0] * bin_size_x
                y_0 = point_0[1] * bin_size_y
                x_1 = point_1[0] * bin_size_x
                y_1 = point_1[1] * bin_size_y

                plt.plot([x_0, x_1], [y_0, y_1], linewidth=5, color='r')

    fig_path = os.path.join(out_dir, filename)
    plt.subplots_adjust(wspace=0.7, hspace=0.1)
    plt.savefig(fig_path, bbox_inches='tight')
    plt.close(fig)


if __name__ == '__main__':
    out_dir = os.path.join(PROCESS_OUT_DIR, NAME)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    # 2-site network
    config = get_two_compartment_config()
    timeseries = test_diffusion_network(config, 20)
    plot_simulation_output(timeseries, {}, out_dir, '2_sites')

    # grid network
    config = get_grid_config()
    timeseries = test_diffusion_network(config, 30)
    plot_diffusion_field_output(timeseries, config, out_dir, 'grid')
Beispiel #16
0
        return {'internal': internal_update}


# test functions
def get_toy_expression_config():
    toy_expression_rates = {
        'protein1': 1e-2,
        'protein2': 1e-1,
        'protein3': 1e0
    }

    return {'expression_rates': toy_expression_rates}


def test_expression(end_time=10):
    expression_config = get_toy_expression_config()
    # load process
    expression = MinimalExpression(expression_config)
    settings = {'total_time': end_time}
    return simulate_process_in_experiment(expression, settings)


if __name__ == '__main__':
    out_dir = os.path.join(PROCESS_OUT_DIR, NAME)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    timeseries = test_expression(1000)
    plot_simulation_output(timeseries, {}, out_dir)
Beispiel #17
0
    rna_degradation = RnaDegradation(TOY_CONFIG)

    # initial state
    proteins = {protein: 10 for protein in rna_degradation.protein_order}
    molecules = {molecule: 10 for molecule in rna_degradation.molecule_order}
    transcripts = {
        transcript: 10
        for transcript in rna_degradation.transcript_order
    }

    settings = {
        'total_time': end_time,
        'initial_state': {
            'molecules': molecules,
            'proteins': proteins,
            'transcripts': transcripts
        }
    }

    return simulate_process(rna_degradation, settings)


if __name__ == '__main__':
    out_dir = os.path.join(PROCESS_OUT_DIR, NAME)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    plot_settings = {}
    timeseries = test_rna_degradation(100)
    plot_simulation_output(timeseries, plot_settings, out_dir)
        'external_path': environment_port
    }
    compartment = ChemotaxisMinimal(get_chemotaxis_config(config))

    # run experiment
    experiment_settings = {
        'timeline': {
            'timeline':
            get_exponential_random_timeline(exponential_random_config),
            'ports': {
                'external': ('boundary', 'external')
            }
        },
        'timestep': 0.01,
        'total_time': 100
    }
    timeseries = simulate_compartment_in_experiment(compartment,
                                                    experiment_settings)

    # plot settings for the simulations
    plot_settings = {
        'max_rows': 20,
        'remove_zeros': True,
        'overlay': {
            'reactions': 'flux'
        },
        'skip_ports': ['prior_state', 'null', 'global']
    }
    plot_simulation_output(timeseries, plot_settings, out_dir,
                           'exponential_timeline')
        save_timeseries(timeseries, out_dir)
        volume_ts = timeseries['global']['volume']
        mass_ts = timeseries['global']['mass']
        print('volume growth: {}'.format(volume_ts[-1] / volume_ts[0]))
        print('mass growth: {}'.format(mass_ts[-1] / mass_ts[0]))

        # plot settings
        plot_settings = {
            'max_rows': 30,
            'remove_zeros': True,
            'skip_ports': ['exchange', 'reactions']
        }

        # make plots from simulation output
        plot_simulation_output(timeseries, plot_settings, out_dir,
                               'BiGG_simulation')
        plot_exchanges(timeseries, sim_settings, out_dir)

        # # make plot of energy reactions
        # stoichiometry = metabolism.fba.stoichiometry
        # energy_carriers = [get_synonym(mol_id) for mol_id in BiGG_energy_carriers]
        # energy_reactions = get_reactions(stoichiometry, energy_carriers)
        # energy_plot_settings = {'reactions': energy_reactions}
        # energy_synthesis_plot(timeseries, energy_plot_settings, out_dir)

        # make a gephi network
        run_sim_save_network(get_iAF1260b_config(), out_dir)

    else:
        timeseries = test_toy_metabolism()
        plot_settings = {}
Beispiel #20
0
def simulate_txp_mtb_ge(config={}, out_dir='out'):

    end_time = 2520  # 2520 sec (42 min) is the expected doubling time in minimal media
    environment_volume = 1e-14
    timeline = [
        (0, {
            ('external', 'glc__D_e'): 3.0,
            ('external', 'lcts_e'): 3.0,
        }),
        # (500, {
        #     ('external', 'glc__D_e'): 0.0,
        #     ('external', 'lcts_e'): 3.0,
        # }),
        (end_time, {})
    ]

    sim_settings = {
        'environment': {
            'volume': environment_volume * units.L,
            'ports': {
                'external': ('boundary', 'external'),
                'exchange': ('boundary', 'exchange'),
            }
        },
        'timeline': {
            'timeline': timeline,
            'ports': {
                'external': ('boundary', 'external')
            }
        }
    }

    # run simulation
    compartment = TransportMetabolism({})
    timeseries = simulate_compartment_in_experiment(compartment, sim_settings)

    # calculate growth
    volume_ts = timeseries['boundary']['volume']
    try:
        print('growth: {}'.format(volume_ts[-1] / volume_ts[0]))
    except:
        print('no volume!')

    ## plot
    # diauxic plot
    settings = {
        'internal_path': ('cytoplasm', ),
        'external_path': ('boundary', 'external'),
        'global_path': ('boundary', ),
        'exchange_path': ('boundary', 'exchange'),
        'environment_volume': 1e-13,  # L
        # 'timeline': timeline
    }
    plot_diauxic_shift(timeseries, settings, out_dir)

    # simulation plot
    plot_settings = {
        'max_rows': 30,
        'remove_zeros': True,
        'skip_ports': ['null', 'reactions'],
    }
    plot_simulation_output(timeseries, plot_settings, out_dir)
                    '_emit': True,
                }
            },
            'global': {},
        }

    def derivers(self):
        return {
            'my_deriver': {
                'deriver': 'mass_deriver',
                'port_mapping': {
                    'global': 'global',
                },
                'config': {},
            },
        }


if __name__ == '__main__':
    parameters = {
        'k_cat': 1.5,
    }
    my_process = GlucosePhosphorylation(parameters)

    settings = {
        'total_time': 10,
        'timestep': 0.1,
    }
    timeseries = simulate_process(my_process, settings)
    plot_simulation_output(timeseries, {}, './')