Пример #1
0
def inclusion_plots_suite(data=None, out_dir=EXPERIMENT_OUT_DIR):
    n_snapshots = 5
    tagged_molecules = [('inclusion_body', ), (
        'front',
        'aggregate',
    ), (
        'back',
        'aggregate',
    )]

    # multigen plot
    plot_settings = {}
    plot_agents_multigen(data, plot_settings, out_dir)

    # extract data for snapshots
    bounds = LATTICE_CONFIG['multibody']['bounds']
    agents, fields = format_snapshot_data(data)

    # snapshots plot
    plot_snapshots(bounds=bounds,
                   agents=agents,
                   fields=fields,
                   n_snapshots=n_snapshots,
                   out_dir=out_dir,
                   filename='inclusion_snapshots')

    # tags plot
    plot_tags(
        data=data,
        bounds=bounds,
        tagged_molecules=tagged_molecules,
        n_snapshots=n_snapshots,
        convert_to_concs=False,
        out_dir=out_dir,
    )
def plot_fields(data, config, out_dir='out', filename='fields'):
    fields = {time: time_data['fields'] for time, time_data in data.items()}
    snapshots_data = {
        'fields': fields,
        'config': config}
    plot_config = {
        'out_dir': out_dir,
        'filename': filename}
    plot_snapshots(snapshots_data, plot_config)
def main():
    out_dir = os.path.join(COMPOSITE_OUT_DIR, NAME)
    os.makedirs(out_dir, exist_ok=True)
    parser = argparse.ArgumentParser(description='lattice composite')
    parser.add_argument('-exchange',
                        '-e',
                        action='store_true',
                        default=False,
                        help='simulate agents with exchange')
    args = parser.parse_args()

    bounds = [25, 25]

    if args.exchange:
        # GrowDivide agents with Exchange
        data = test_lattice(exchange=True,
                            n_agents=3,
                            total_time=4000,
                            bounds=bounds)
    else:
        # GrowDivide agents
        n_bins = [20, 20]
        initial_field = np.zeros((n_bins[0], n_bins[1]))
        initial_field[:, -1] = 100
        data = test_lattice(n_agents=3,
                            total_time=4000,
                            bounds=bounds,
                            n_bins=n_bins,
                            initial_field=initial_field)

    # format the data for plot_snapshots
    agents, fields = format_snapshot_data(data)
    initial_ids = list(data[0]['agents'].keys())
    agent_ids = get_agent_ids(agents)

    # make colors based on initial agents
    agent_colors = {}
    hues = [n / 360 for n in [120, 270, 300, 240, 360, 30, 60]]
    for idx, initial_id in enumerate(initial_ids):
        hue = hues[idx]
        color = [hue] + DEFAULT_SV
        for agent_id in agent_ids:
            if agent_id.startswith(initial_id, 0, len(initial_id)):
                agent_colors[agent_id] = color

    plot_snapshots(
        bounds,
        agents=agents,
        fields=fields,
        n_snapshots=4,
        agent_colors=agent_colors,
        out_dir=out_dir,
        filename=f"lattice_snapshots{'_exchange' if args.exchange else ''}")
def run_mother_machine(time=10, out_dir='out'):
    config = get_mother_machine_config()

    # configure the experiment
    agent_ids = config.get('agent_ids', ['0'])

    # get the environment composite
    environment = Lattice(config.get('environment', {}))
    composite = environment.generate({})

    # add the agents
    growth_division = GrowDivide(config.get('growth_division', {}))
    for agent_id in agent_ids:
        agent = growth_division.generate({'agent_id': agent_id})
        composite.merge(composite=agent, path=('agents', agent_id))

    experiment = Engine(
        **{
            'processes': composite['processes'],
            'topology': composite['topology'],
            'initial_state': config.get('initial_state', {}),
            'progress_bar': True,
        })

    # simulate
    settings = {'total_time': time, 'return_raw_data': True}
    data = simulate_experiment(experiment, settings)

    # agents plot
    plot_settings = {'agents_key': 'agents'}
    plot_agents_multigen(data, plot_settings, out_dir)

    # snapshot plot
    agents, fields = format_snapshot_data(data)
    bounds = config['environment']['multibody']['bounds']
    plot_snapshots(bounds,
                   agents=agents,
                   fields=fields,
                   n_snapshots=4,
                   out_dir=out_dir,
                   filename=f"mother_machine")

    # make snapshot video
    make_video(
        data,
        bounds,
        plot_type='fields',
        step=100,
        out_dir=out_dir,
        filename=f"mother_machine",
    )
Пример #5
0
def plot_fields_snapshots(output,
                          bounds=None,
                          include_fields=None,
                          n_snapshots=4,
                          colorbar_decimals=4,
                          scale_bar_length=5,
                          phylogeny_colors=False,
                          out_dir=None,
                          filename=None,
                          **kwargs):

    agents, fields = format_snapshot_data(output)

    fig1 = plot_snapshots(bounds=bounds,
                          agents=agents,
                          fields=fields,
                          phylogeny_names=phylogeny_colors,
                          n_snapshots=n_snapshots,
                          scale_bar_length=scale_bar_length,
                          colorbar_decimals=colorbar_decimals,
                          include_fields=include_fields,
                          out_dir=out_dir,
                          filename=filename,
                          **kwargs)

    return fig1
def run_growth_division(
        out_dir='out',
        animate=True,
):
    n_agents = 2
    agent_ids = [
        str(agent_id)
        for agent_id in range(n_agents)]

    # configure the multibody process
    bounds = DEFAULT_BOUNDS
    multibody_config = {
        'animate': animate,
        # 'jitter_force': 1e0,
        'bounds': bounds}
    body_config = {
        'bounds': bounds,
        'agent_ids': agent_ids}
    multibody_config.update(agent_body_config(body_config))

    # experiment settings
    experiment_settings = {
        'progress_bar': False,
        'display_info': False}

    # run the test
    gd_data = test_growth_division(
        config=multibody_config,
        growth_rate=0.05,
        growth_rate_noise=0.001,
        division_volume=volume_from_length(4, 1),
        total_time=100,
        experiment_settings=experiment_settings)

    agents, fields = format_snapshot_data(gd_data)
    return plot_snapshots(
        bounds, agents=agents, fields=fields, out_dir=out_dir)
def main():
    total_time = 7000
    bounds = [15, 15]
    data = run_sim(
        total_time=total_time,
        bounds=bounds,
    )

    out_dir = 'out/stochastic_expression'
    os.makedirs(out_dir, exist_ok=True)

    # format the data for plot_snapshots
    agents, fields = format_snapshot_data(data)

    # save snapshots figure
    plot_snapshots(
        bounds,
        agents=agents,
        fields=fields,
        n_snapshots=4,
        out_dir=out_dir,
        filename='snapshots'
    )

    # tags plot
    n_snapshots = 5
    time_vec = list(agents.keys())
    time_indices = np.round(np.linspace(0, len(time_vec) - 1, n_snapshots)).astype(int)
    snapshot_times = [time_vec[i] for i in time_indices]
    tagged_molecules = [
        ('RNA', 'C'),
        ('Protein', 'X'),
    ]
    make_tags_figure(
        agents=agents,
        bounds=bounds,
        n_snapshots=n_snapshots,
        time_indices=time_indices,
        snapshot_times=snapshot_times,
        convert_to_concs=False,
        tagged_molecules=tagged_molecules,
        out_dir=out_dir,
        filename='tags'
    )

    # make snapshot video
    tagged_molecules = [
        ('RNA', 'C'),  # use RNA_counts?
        ('Protein', 'X'),
    ]
    make_video(
        data,
        bounds,
        plot_type='tags',
        step=100,  # render every nth snapshot
        tagged_molecules=tagged_molecules,
        out_dir=out_dir,
        filename=f'snapshots_video',
    )

    div_number = 0
    for t in data.keys():
        if len(data[t]['agents'].keys()) > div_number:
            print(f"time {t}: agent_ids {list(data[t]['agents'].keys())}")
            div_number += 1