Skip to content

Commit

Permalink
Document figure generation functions with figure numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
U8NWXD committed Apr 17, 2021
1 parent 0c7897b commit 3aeac7a
Showing 1 changed file with 118 additions and 74 deletions.
192 changes: 118 additions & 74 deletions src/make_figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,74 @@ def get_experiment_ids(
return id_obj


def make_snapshots_figure(
data: RawData,
environment_config: EnvironmentConfig,
name: str,
fields: Sequence[str],
agent_fill_color: Optional[str] = None,
agent_alpha: float = 1,
num_snapshots: int = NUM_SNAPSHOTS,
snapshot_times: Optional[Tuple[float, ...]] = None,
xlim: Tuple[float, float] = (10, 40),
ylim: Tuple[float, float] = (10, 40)
) -> dict:
'''Make a figure of snapshots.
Args:
data: The experiment data.
environment_config: Environment parameters.
name: Name of the output file (excluding file extension).
fields: List of the names of fields to include.
agent_fill_color: Fill color for agents.
agent_alpha: Transparency for agents.
num_snapshots: Number of snapshots.
snapshot_times: Times to take snapshots at. If
None, they are evenly spaced.
xlim: Limits of x-axis.
ylim: Limits of y-axis.
Returns:
Statistics.
'''
snapshots_data = Analyzer.format_data_for_snapshots(
data, environment_config)
if not fields:
data = RawData({
key: val
for key, val in data.items() if key != 'fields'
})
plot_config = {
'out_dir': FIG_OUT_DIR,
'filename': '{}.{}'.format(name, FILE_EXTENSION),
'include_fields': fields,
'field_label_size': 54,
'default_font_size': 54,
'agent_fill_color': agent_fill_color,
'dead_color': (0, 0, 0.79), # gray in HSV
'agent_alpha': agent_alpha,
'n_snapshots': num_snapshots,
'snapshot_times': snapshot_times,
'scale_bar_length': 10,
'scale_bar_color': 'white' if fields else 'black',
'xlim': xlim,
'ylim': ylim,
'min_color': '#FFFFFF',
'max_color': '#000000',
'grid_color': 'white' if fields else '',
}
stats = plot_snapshots(snapshots_data, plot_config)
return stats


def make_expression_heterogeneity_fig(
replicates_data: Iterable[DataTuple],
_: SearchData,
) -> dict:
'''Figure shows heterogeneous expression within wcEcoli agents.'''
'''Figure shows heterogeneous expression within wcEcoli agents.
Create Figure 3F.
'''
for i, (data, enviro_config) in enumerate(replicates_data):
tags_data = Analyzer.format_data_for_tags(data, enviro_config)
tagged_molecules = list(TAG_PATH_NAME_MAP.keys())
Expand Down Expand Up @@ -295,7 +358,10 @@ def make_expression_distributions_fig(
replicates_raw_data: Iterable[DataTuple],
_search_data: SearchData
) -> dict:
'''Figure shows the distributions of expression values.'''
'''Figure shows the distributions of expression values.
Create Figure 3G.
'''
replicates_data = []
colors = ('#333333', '#777777', '#BBBBBB')
for i, (raw_data, _) in enumerate(replicates_raw_data):
Expand Down Expand Up @@ -330,71 +396,14 @@ def make_expression_distributions_fig(
return stats


def make_snapshots_figure(
data: RawData,
environment_config: EnvironmentConfig,
name: str,
fields: Sequence[str],
agent_fill_color: Optional[str] = None,
agent_alpha: float = 1,
num_snapshots: int = NUM_SNAPSHOTS,
snapshot_times: Optional[Tuple[float, ...]] = None,
xlim: Tuple[float, float] = (10, 40),
ylim: Tuple[float, float] = (10, 40)
) -> dict:
'''Make a figure of snapshots.
Args:
data: The experiment data.
environment_config: Environment parameters.
name: Name of the output file (excluding file extension).
fields: List of the names of fields to include.
agent_fill_color: Fill color for agents.
agent_alpha: Transparency for agents.
num_snapshots: Number of snapshots.
snapshot_times: Times to take snapshots at. If
None, they are evenly spaced.
xlim: Limits of x-axis.
ylim: Limits of y-axis.
Returns:
Statistics.
'''
snapshots_data = Analyzer.format_data_for_snapshots(
data, environment_config)
if not fields:
data = RawData({
key: val
for key, val in data.items() if key != 'fields'
})
plot_config = {
'out_dir': FIG_OUT_DIR,
'filename': '{}.{}'.format(name, FILE_EXTENSION),
'include_fields': fields,
'field_label_size': 54,
'default_font_size': 54,
'agent_fill_color': agent_fill_color,
'dead_color': (0, 0, 0.79), # gray in HSV
'agent_alpha': agent_alpha,
'n_snapshots': num_snapshots,
'snapshot_times': snapshot_times,
'scale_bar_length': 10,
'scale_bar_color': 'white' if fields else 'black',
'xlim': xlim,
'ylim': ylim,
'min_color': '#FFFFFF',
'max_color': '#000000',
'grid_color': 'white' if fields else '',
}
stats = plot_snapshots(snapshots_data, plot_config)
return stats


def make_growth_fig(
raw_data: Dict[str, DataTuple],
_: SearchData,
) -> dict:
'''Make plot of colony mass of basal and anaerobic colonies.'''
'''Make plot of colony mass of basal and anaerobic colonies.
Create Figure 3E.
'''
data_dict = {
'basal': [data for data, _ in raw_data['basal']],
'anaerobic': [data for data, _ in raw_data['anaerobic']],
Expand All @@ -410,7 +419,10 @@ def make_threshold_scan_fig(
data_and_configs: Dict[str, DataTuple],
_: SearchData,
) -> dict:
'''Plot colony mass curves with various antibiotic thresholds.'''
'''Plot colony mass curves with various antibiotic thresholds.
Create Figure 5A.
'''
data_dict = dict({
threshold: list(
data for data, enviro_config in threshold_ids
Expand Down Expand Up @@ -438,7 +450,10 @@ def make_expression_survival_fig(
data_and_config: DataTuple,
search_data: SearchData,
) -> dict:
'''Make expression-survival figures.'''
'''Make expression-survival figures.
Create Figures 5G, 5H, and 5I.
'''
data, _ = data_and_config
fig = plot_expression_survival(
data, PUMP_PATH, BETA_LACTAMASE_PATH,
Expand Down Expand Up @@ -520,7 +535,10 @@ def make_expression_survival_dotplots(
data_and_config: DataTuple,
_search_data: SearchData,
) -> dict:
'''Make dotplots of protein concentrations colored by survival.'''
'''Make dotplots of protein concentrations colored by survival.
Create Figures 5E and 5F.
'''
data, _ = data_and_config
stats = {}
fig, stats['AcrAB-TolC'] = plot_expression_survival_dotplot(
Expand Down Expand Up @@ -549,7 +567,10 @@ def make_survival_centrality_fig(
data_and_config: DataTuple,
_search_data: SearchData,
) -> dict:
'''Plot box plot figure of agent distances from center.'''
'''Plot box plot figure of agent distances from center.
Create Figure 5C.
'''
data, _ = data_and_config
fig, stats = get_survival_against_centrality_plot(data)
fig.savefig(os.path.join(
Expand All @@ -563,7 +584,10 @@ def make_environment_section(
data_and_configs: Sequence[DataTuple],
_search_data: SearchData,
) -> dict:
'''Plot field concentrations in cross-section of final enviro.'''
'''Plot field concentrations in cross-section of final enviro.
Create Figure 3B.
'''
t_final = max(data_and_configs[0][0].keys())
fields_ts: List[Dict[float, Dict[str, SerializedField]]] = []
section_times = [
Expand All @@ -590,7 +614,10 @@ def make_growth_basal_fig(
replicates_data: Iterable[DataTuple],
_: SearchData,
) -> dict:
'''Create snapshots figure of colony on basal media.'''
'''Create snapshots figure of colony on basal media.
Create Figure 3C.
'''
stats = {}
for i, (data, enviro_config) in enumerate(replicates_data):
stats[i] = make_snapshots_figure(
Expand All @@ -602,7 +629,10 @@ def make_growth_anaerobic_fig(
replicates_data: Iterable[DataTuple],
_: SearchData,
) -> dict:
'''Create snapshots figure of colony on anaerobic media.'''
'''Create snapshots figure of colony on anaerobic media.
Create Figure 3D.
'''
stats = {}
for i, (data, enviro_config) in enumerate(replicates_data):
stats[i] = make_snapshots_figure(
Expand All @@ -614,7 +644,10 @@ def make_phylogeny_plot(
data_and_config: DataTuple,
_search_data: SearchData,
) -> dict:
'''Plot phylogenetic tree.'''
'''Plot phylogenetic tree.
Create Figure 5D.
'''
data, _ = data_and_config
tree, df = plot_phylogeny(data, os.path.join(
FIG_OUT_DIR, 'phylogeny.{}').format(FILE_EXTENSION),
Expand All @@ -634,7 +667,10 @@ def make_enviro_heterogeneity_fig(
replicates_data: Iterable[DataTuple],
_: SearchData,
) -> dict:
'''Plot snapshots of colony consuming glucose.'''
'''Plot snapshots of colony consuming glucose.
Create Figure 5A.
'''
stats = {}
for i, (data, enviro_config) in enumerate(replicates_data):
stats[i] = make_snapshots_figure(
Expand All @@ -648,7 +684,10 @@ def make_death_snapshots(
data_and_config: DataTuple,
_: SearchData,
) -> dict:
'''Plot colony exposed to antibiotics with death coloration.'''
'''Plot colony exposed to antibiotics with death coloration.
Create Figure 5B.
'''
data, config = data_and_config
return make_snapshots_figure(
data, config, 'death_snapshots', [],
Expand All @@ -662,7 +701,12 @@ def make_death_snapshots_antibiotic(
data_and_config: DataTuple,
_: SearchData,
) -> dict:
'''Plot colony consuming (or not) antibiotics.'''
'''Plot colony consuming (or not) antibiotics.
Create Figure X1. This figure is not used in the paper, but its
statistics are used to find the change in nitrocefin concentration
over time.
'''
data, config = data_and_config
return make_snapshots_figure(
data, config, 'death_snapshots_antibiotic',
Expand Down

0 comments on commit 3aeac7a

Please sign in to comment.