def plot_results(self, results, agent, obs_name, thresh=50): plt.figure() plt.ion() max_val_lim = max(max(numpy.max(results[0][1][obs_name]), 101.0), thresh) max_time = max([result[0][-1] for result in results]) lr = matplotlib.patches.Rectangle((0, 0), max_time, thresh, color='red', alpha=0.1) hr = matplotlib.patches.Rectangle((0, thresh), max_time, max_val_lim - thresh, color='green', alpha=0.1) ax = plt.gca() ax.add_patch(lr) ax.add_patch(hr) if thresh + 5 < max_val_lim: plt.text(10, thresh + 5, 'High', fontsize=10) plt.text(10, thresh - 5, 'Low') for tspan, yobs in results: plt.plot(tspan, yobs[obs_name]) plt.ylim(-1, max_val_lim) plt.xlim(-100, 10100) plt.xlabel('Time (s)') plt.ylabel('Amount (molecules)') agent_str = english_assembler._assemble_agent_str(agent) plt.title('Simulation results for %s' % agent_str) dir_path = os.path.dirname(os.path.realpath(__file__)) fig_path = os.path.join(dir_path, '%s.png' % obs_name) plt.savefig(fig_path) return fig_path
def test_agent_bound_mixed(): bc = BoundCondition(Agent('EGF'), True) bc2 = BoundCondition(Agent('EGFR'), False) a = Agent('EGFR', bound_conditions=[bc, bc2]) s = ea._assemble_agent_str(a) print(s) assert (s == 'EGFR bound to EGF and not bound to EGFR')
def test_agent_mods3(): mc1 = ModCondition('phosphorylation', 'tyrosine', '1111') mc2 = ModCondition('phosphorylation') a = Agent('EGFR', mods=[mc1, mc2]) s = ea._assemble_agent_str(a) print(s) assert (s == 'EGFR phosphorylated on Y1111 and an unknown residue')
def test_agent_bound_three(): bc = BoundCondition(Agent('EGF'), True) bc2 = BoundCondition(Agent('EGFR'), True) bc3 = BoundCondition(Agent('GRB2'), True) a = Agent('EGFR', bound_conditions=[bc, bc2, bc3]) s = ea._assemble_agent_str(a) print(s) assert (s == 'EGFR bound to EGF, EGFR and GRB2')
def plot_compare_conditions(self, ts, results, agent, obs_name): plt.figure() plt.ion() plt.plot(ts, results[0][:len(ts)], label='Without condition') plt.plot(ts, results[-1][:len(ts)], label='With condition') plt.xlabel('Time (s)') plt.ylabel('Amount (molecules)') agent_str = english_assembler._assemble_agent_str(agent) plt.title('Simulation results for %s' % agent_str) plt.legend() dir_path = os.path.dirname(os.path.realpath(__file__)) fig_path = os.path.join(dir_path, '%s.png' % obs_name) plt.savefig(fig_path) return fig_path
def test_agent_mod3(): mc = ModCondition('phosphorylation', 'tyrosine', '1111') a = Agent('EGFR', mods=mc) s = ea._assemble_agent_str(a) print(s) assert (s == 'EGFR phosphorylated on Y1111')
def test_agent_loc(): a = Agent('BRAF', location='cytoplasm') print(ea._assemble_agent_str(a)) assert (ea._assemble_agent_str(a) == 'BRAF in the cytoplasm')
def test_agent_mod(): mc = ModCondition('phosphorylation') a = Agent('EGFR', mods=mc) s = ea._assemble_agent_str(a) print(s) assert (s == 'phosphorylated EGFR')
def test_agent_activity(): a = Agent('BRAF', activity=ActivityCondition('activity', True)) print(ea._assemble_agent_str(a)) assert (ea._assemble_agent_str(a) == 'active BRAF')
def test_agent_mut_plus(): a = Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')], location='nucleus') print(ea._assemble_agent_str(a)) assert (ea._assemble_agent_str(a) == 'BRAF-V600E in the nucleus')
def test_agent_not_bound(): bc = BoundCondition(Agent('EGF'), False) a = Agent('EGFR', bound_conditions=[bc]) s = ea._assemble_agent_str(a) print(s) assert (s == 'EGFR not bound to EGF')
def test_agent_basic(): s = ea._assemble_agent_str(Agent('EGFR')) print(s) assert (s == 'EGFR')
def test_agent_loc(): a = Agent('BRAF', location='cytoplasm') print(ea._assemble_agent_str(a)) assert(ea._assemble_agent_str(a) == 'BRAF in the cytoplasm')
def test_agent_mut(): a = Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')]) print(ea._assemble_agent_str(a)) assert (ea._assemble_agent_str(a) == 'BRAF-V600E')