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 make_snapshot_function(data, bounds, agent_colors=None, **kwargs): agent_colors = agent_colors or {} multibody_agents, multibody_fields = format_snapshot_data(data) # make the snapshot plot function time_vec = list(multibody_agents.keys()) # get fields and agent colors multibody_field_range = get_field_range(multibody_fields, time_vec) multibody_agent_colors = get_agent_colors(multibody_agents) multibody_agent_colors.update(agent_colors) def plot_single_snapshot(t_index): time_indices = np.array([t_index]) snapshot_time = [time_vec[t_index]] fig = make_snapshots_figure(time_indices=time_indices, snapshot_times=snapshot_time, agents=multibody_agents, agent_colors=multibody_agent_colors, fields=multibody_fields, field_range=multibody_field_range, n_snapshots=1, bounds=bounds, default_font_size=12, plot_width=PLOT_WIDTH, scale_bar_length=0, **kwargs) return fig return plot_single_snapshot, time_vec
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 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", )
def make_tags_function(data, bounds, agent_colors=None, tagged_molecules=None, tag_colors=None, convert_to_concs=False, **kwargs): agent_colors = agent_colors or {} tag_colors = tag_colors or {} multibody_agents, multibody_fields = format_snapshot_data(data) # make the snapshot plot function time_vec = list(multibody_agents.keys()) time_indices = np.array(range(0, len(time_vec))) # get agent colors, and ranges tag_ranges, tag_colors = get_tag_ranges(agents=multibody_agents, tagged_molecules=tagged_molecules, time_indices=time_indices, convert_to_concs=convert_to_concs, tag_colors=tag_colors) # make the function for a single snapshot def plot_single_tags(t_index): time_index = np.array([t_index]) snapshot_time = [time_vec[t_index]] fig = make_tags_figure(time_indices=time_index, snapshot_times=snapshot_time, agents=multibody_agents, agent_colors=agent_colors, tagged_molecules=tagged_molecules, convert_to_concs=convert_to_concs, tag_ranges=tag_ranges, tag_colors=tag_colors, n_snapshots=1, bounds=bounds, default_font_size=12, plot_width=PLOT_WIDTH, scale_bar_length=0, **kwargs) return fig return plot_single_tags, time_vec
def main(): parser = argparse.ArgumentParser(description='access data from db') parser.add_argument('experiment_id', type=str, default=False) parser.add_argument('--multigen', '-1', action='store_true', default=False) parser.add_argument('--fields', '-2', action='store_true', default=False) parser.add_argument('--tags', '-3', action='store_true', default=False) parser.add_argument('--single_tags', '-4', action='store_true', default=False) parser.add_argument('--all', '-a', action='store_true', default=False) args = parser.parse_args() experiment_id = args.experiment_id # make a directory for the figures out_dir = f'out/analyze/{experiment_id}' if not os.path.exists(out_dir): os.makedirs(out_dir) # retrieve the data output, bounds = access(experiment_id) del output[0.0] for t in list(output.keys()): if t > 43200: # cutoff at 12 hours del output[t] agents, fields = format_snapshot_data(output) # run the plot functions if args.multigen or args.all: agent_colors = get_agent_colors(agents) plot_phylogeny_fig(output, bounds, agent_colors, out_dir) plot_multigen_fig(output, agent_colors, out_dir) if args.fields or args.all: plot_fields_fig(output, bounds, out_dir) if args.tags or args.all: plot_tags_fig(output, bounds, out_dir) if args.single_tags or args.all: plot_single_tags(agents, bounds, out_dir)
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