Skip to content

Commit

Permalink
linspace -> geomspace
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-krenz committed May 8, 2024
1 parent 525b5cd commit adb3341
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions core_algorithm/utils/response_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def get_table_values(table, col_name, input_cnt):

bar_values: dict[str:float] = {}

col_index = None
Expand All @@ -32,7 +31,6 @@ def get_table_values(table, col_name, input_cnt):


def plot_bars(filepath, plot_name, best_graph, table, units):

input_cnt = len(best_graph.inputs)
output_cnt = len(best_graph.outputs)

Expand All @@ -54,7 +52,7 @@ def plot_bars(filepath, plot_name, best_graph, table, units):
outputs_dict[k]['prev_node'] = best_graph.find_prev(outputs_dict[k]['node']).name

for k, o in outputs_dict.items():
if prev_node:=o['prev_node']:
if prev_node := o['prev_node']:
outputs_dict[k]['name'] = prev_node
outputs_dict[k]['scores_pre_HR'] = get_table_values(table, prev_node, input_cnt)
outputs_dict[k]['scores_post_HR'] = get_table_values(table, k, input_cnt)
Expand All @@ -64,8 +62,9 @@ def plot_bars(filepath, plot_name, best_graph, table, units):

# fig = plt.subplots()
px = 1 / plt.rcParams['figure.dpi']
plt.figure(figsize=(px*(640 + 180*input_cnt), px*(120 + output_cnt*(280 + 120*input_cnt))))
plt.subplots_adjust(top=0.8 + (0.03*output_cnt), hspace=0.5, wspace=0.5)
plt.figure(
figsize=(px * (640 + 180 * input_cnt), px * (120 + output_cnt * (280 + 120 * input_cnt))))
plt.subplots_adjust(top=0.8 + (0.03 * output_cnt), hspace=0.5, wspace=0.5)
if plot_name.endswith('.UCF'):
plot_name = plot_name[:-4]
plt.suptitle(f'{plot_name}: Response Plots', fontsize=15, y=.95, fontweight='bold')
Expand All @@ -80,38 +79,39 @@ def plot_bars(filepath, plot_name, best_graph, table, units):
for output, data in outputs_dict.items():

# Output Response Plots (all outputs)
ax1 = plt.subplot(output_cnt, 3, 3*i - 2)
ax1 = plt.subplot(output_cnt, 3, 3 * i - 2)
ax1.set_title(f'{data["name"]}', fontsize=12)
plt.bar(list(data['scores_pre_HR'].keys()), list(data['scores_pre_HR'].values()), color='gray')
plt.bar(list(data['scores_pre_HR'].keys()), list(data['scores_pre_HR'].values()),
color='gray')
plt.yscale('log')
plt.ylim(ax1.get_ylim()[0]*0.1, ax1.get_ylim()[1]*10)
plt.ylim(ax1.get_ylim()[0] * 0.1, ax1.get_ylim()[1] * 10)
plt.ylabel(f'Output ({units})', fontsize=12, fontweight='bold')

# Outputs with Hill Response functions (i.e. Communication Molecules) only...
if data['prev_node']:

# Hill Response Curve
curve = lambda ymax, ymin, kd, n, x : ymin + (ymax - ymin) / (1.0 + (kd / x)**n)
ax2 = plt.subplot(output_cnt, 3, 3*i - 1)
x = np.linspace(ax1.get_ylim()[0], ax1.get_ylim()[1], 1000)
curve = lambda ymax, ymin, kd, n, x: ymin + (ymax - ymin) / (1.0 + (kd / x) ** n)
ax2 = plt.subplot(output_cnt, 3, 3 * i - 1)
# for logspace, need ints corresponding to powers; geom uses real vals as endpoints
x = np.geomspace(ax1.get_ylim()[0] * 0.1, ax1.get_ylim()[1], 10000)
ax2.plot(x, curve(data['params']['ymax'], data['params']['ymin'], data['params']['kd'],
data['params']['n'], x))
ax2.set_title(f'{output} Hill', fontsize=12)
plt.yscale('log', )
plt.yscale('log')
plt.xscale('log')
if i == last:
plt.xlabel(f'Input ({units})', fontsize=12, fontweight='bold')

# Promoter Activity Bars
ax3 = plt.subplot(output_cnt, 3, 3*i)
ax3 = plt.subplot(output_cnt, 3, 3 * i)
ax3.sharey(ax2)
ax3.set_title(f'{output} Promoter', fontsize=12)
plt.bar(list(data['scores_post_HR'].keys()), list(data['scores_post_HR'].values()))
plt.yscale('log')

i += 1


# Suppress (useless) console output
matplotlib_logger = logging.getLogger("matplotlib")
matplotlib_logger.setLevel(logging.INFO)
Expand Down

0 comments on commit adb3341

Please sign in to comment.