def to_english(self): cond = _assemble_agent_str(self.condition_entity).agent_str target = _assemble_agent_str(self.target_entity).agent_str if self.direction == 'up': dir_verb = 'increases' else: dir_verb = 'decreases' return f'{cond} {dir_verb} {target}.'
def to_english(self): source_str = _assemble_agent_str(self.source) target_str = _assemble_agent_str(self.target) sb = SentenceBuilder() if self.relation == 'is_ref': rel_str = ' is a refinement of ' elif self.relation == 'has_ref': rel_str = ' has a refinement ' sb.append_as_sentence([source_str, rel_str, target_str]) sb.make_sentence() return sb.sentence
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 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]) + 0.25 * 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 + 0.05 * max_val_lim < max_val_lim: plt.text(10, thresh + 0.05 * max_val_lim, 'High', fontsize=10) plt.text(10, thresh - 0.05 * max_val_lim, 'Low') for tspan, yobs in results: plt.plot(tspan, yobs[obs_name]) plt.ylim(-5, max_val_lim) plt.xlim(-100, 10100) plt.xlabel('Time (s)') plt.ylabel('Amount (molecules)') agent_str = english_assembler._assemble_agent_str(agent).agent_str plt.title('Simulation results for %s' % agent_str) fig_path = get_img_path(obs_name + '.png') plt.savefig(fig_path) return fig_path
def test_agent_mod3(): mc = ModCondition('phosphorylation', 'tyrosine', '1111') a = Agent('EGFR', mods=mc) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'EGFR phosphorylated on Y1111' assert _substring_by_coords(ag.agent_str, ag.coords) == '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_mods_pos_only(): mc1 = ModCondition('phosphorylation', None, '1111') a = Agent('EGFR', mods=[mc1]) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'EGFR phosphorylated on amino acid 1111' assert _substring_by_coords(ag.agent_str, ag.coords) == 'EGFR'
def test_agent_not_bound(): bc = BoundCondition(Agent('EGF'), False) a = Agent('EGFR', bound_conditions=[bc]) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'EGFR not bound to EGF' assert _substring_by_coords(ag.agent_str, ag.coords) == '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_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 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) fig_path = get_img_path(obs_name + '.png') plt.savefig(fig_path) return fig_path
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 pybel_edge_to_english(pybel_edge): source_str = _assemble_agent_str(pybel_edge.source) target_str = _assemble_agent_str(pybel_edge.target) sb = SentenceBuilder() if pybel_edge.relation == 'partOf': if pybel_edge.reverse: rel_str = ' has a component ' else: rel_str = ' is a part of ' elif pybel_edge.relation == 'hasVariant': if pybel_edge.reverse: rel_str = ' is a variant of ' else: rel_str = ' has a variant ' sb.append_as_sentence([source_str, rel_str, target_str]) sb.make_sentence() return sb.sentence
def test_agent_bound_mixed(): bc = BoundCondition(Agent('EGF'), True) bc2 = BoundCondition(Agent('EGFR'), False) a = Agent('EGFR', bound_conditions=[bc, bc2]) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'EGFR bound to EGF and not bound to EGFR' assert _substring_by_coords(ag.agent_str, ag.coords) == 'EGFR'
def test_agent_mods3(): mc1 = ModCondition('phosphorylation', 'tyrosine', '1111') mc2 = ModCondition('phosphorylation') a = Agent('EGFR', mods=[mc1, mc2]) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'EGFR phosphorylated on Y1111 and an unknown residue' assert ag.agent_str[ag.coords[0]:ag.coords[1]] == 'EGFR'
def test_agent_mut_plus(): a = Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')], location='nucleus') ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'BRAF-V600E in the nucleus' assert _substring_by_coords(ag.agent_str, ag.coords) == 'BRAF'
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 test_agent_mods(): mc1 = ModCondition('phosphorylation', 'tyrosine', '1111') mc2 = ModCondition('phosphorylation', 'tyrosine', '1234') a = Agent('EGFR', mods=[mc1, mc2]) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'EGFR phosphorylated on Y1111 and Y1234' assert _substring_by_coords(ag.agent_str, ag.coords) == 'EGFR'
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]) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'EGFR bound to EGF, EGFR, and GRB2' assert _substring_by_coords(ag.agent_str, ag.coords) == 'EGFR'
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).agent_str plt.title('Simulation results for %s' % agent_str) plt.legend() fig_path = get_img_path(obs_name + '.png') plt.savefig(fig_path) return fig_path
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() fig_path = get_img_path(obs_name + '.png') plt.savefig(fig_path) return fig_path
def to_english(self): agent = _assemble_agent_str(self.entity).agent_str if self.entity_role == 'subject': verb = statement_base_verb(self.stmt_type.lower()) verb = verb[0].lower() + verb[1:] sentence = f'What does {agent} {verb}?' elif self.entity_role == 'object': verb = statement_present_verb(self.stmt_type.lower()) verb = verb[0].lower() + verb[1:] sentence = f'What {verb} {agent}?' sentence = sentence[0].upper() + sentence[1:] if self.terminal_ns: sentence += f' ({", ".join(self.terminal_ns).upper()})' return sentence
def to_english(self): agent = _assemble_agent_str(self.entity).agent_str agent = agent[0].upper() + agent[1:] if self.pattern_type == 'always_value': pattern = 'always' elif self.pattern_type == 'eventual_value': pattern = 'eventually' elif self.pattern_type == 'sometime_value': pattern = 'sometimes' elif self.pattern_type == 'no_change': pattern = 'not changing' else: pattern = self.pattern_type if self.quant_value: return f'{agent} is {pattern} {self.quant_value}.' return f'{agent} is {pattern}.'
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'
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_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_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_basic(): s = ea._assemble_agent_str(Agent('EGFR')) print(s) assert (s == 'EGFR')
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_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_mut(): a = Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')]) print(ea._assemble_agent_str(a)) assert ea._assemble_agent_str(a) == 'BRAF-V600E'
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_mut(): a = Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')]) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'BRAF-V600E' assert _substring_by_coords(ag.agent_str, ag.coords) == 'BRAF'
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_basic(): s = ea._assemble_agent_str(Agent('EGFR')) print(s) assert (s == '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_basic(): ag = ea._assemble_agent_str(Agent('EGFR')) assert isinstance(ag, ea.AgentWithCoordinates) print(ag.agent_str) assert ag.agent_str == 'EGFR' assert _substring_by_coords(ag.agent_str, ag.coords) == '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_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_mods_pos_only(): mc1 = ModCondition('phosphorylation', None, '1111') a = Agent('EGFR', mods=[mc1]) s = ea._assemble_agent_str(a) print(s) assert (s == 'EGFR phosphorylated on amino acid 1111')
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)) ag = ea._assemble_agent_str(a) print(ag.agent_str) assert ag.agent_str == 'active BRAF' assert _substring_by_coords(ag.agent_str, ag.coords) == 'BRAF'
def test_agent_mod(): mc = ModCondition('phosphorylation') a = Agent('EGFR', mods=mc) s = ea._assemble_agent_str(a) print(s) assert (s == 'phosphorylated EGFR')