def complex_assemble_one_step(stmt, model): pairs = itertools.combinations(stmt.members, 2) for pair in pairs: # Make a rule name nugget_name = '_'.join([get_agent_rule_str(m) for m in pair]) nugget_name += '_bind' action_name = nugget_name + '_act' kf_bind = 1e-6 nugget = Nugget(nugget_name, nugget_name, kf_bind) action_id = nugget.add_node(action_name) # Initialize dicts/lists for this nugget nugget.add_typing(action_id, 'bnd') for agent in pair: agent_id = nugget.add_agent(agent) agent_bs = get_binding_site_name(agent) agent_bs_id = nugget.add_node(agent_bs) nugget.add_edge(agent_bs_id, agent_id) nugget.add_edge(agent_bs_id, action_id) # Add to the Kami typing dict nugget.add_typing(agent_bs_id, 'locus') # Typing dicts linking the nugget to the Action Graph and to the # Kami graph typing_dict_ag = {'from': nugget_name, 'to': 'action_graph', 'mapping': {}, 'total': False, 'ignore_attrs': False} typing_dict_kami = {'from': nugget_name, 'to': 'kami', 'mapping': nugget.get_typing_dict(), 'total': True, 'ignore_attrs': True} # Add the graphs for this nugget to the graphs and typing lists model['typing'] += [typing_dict_ag, typing_dict_kami] model['graphs'].append(nugget.get_nugget_dict()) # In reverse reaction, assume that dissocition is unconditional nugget_name = '_'.join([get_agent_rule_str(m) for m in pair]) nugget_name += '_dissociate' action_name = nugget_name + '_act' kr_bind = 1e-1 nugget = Nugget(nugget_name, nugget_name, kr_bind) action_id = nugget.add_node(action_name) nugget.add_typing(action_id, 'brk') for agent in pair: agent_bs = get_binding_site_name(agent) agent_id = nugget.add_node(agent.name) agent_bs_id = nugget.add_node(agent_bs) nugget.add_edge(agent_bs_id, agent_id) nugget.add_edge(agent_bs_id, action_id) nugget.add_typing(agent_id, 'agent') nugget.add_typing(agent_bs_id, 'locus') # Typing dicts linking the nugget to the Action Graph and to the # Kami graph typing_dict_ag = {'from': nugget_name, 'to': 'action_graph', 'mapping': {}, 'total': False, 'ignore_attrs': False} typing_dict_kami = {'from': nugget_name, 'to': 'kami', 'mapping': nugget.get_typing_dict(), 'total': True, 'ignore_attrs': True} # Add the graphs for this nugget to the graphs and typing lists model['typing'] += [typing_dict_ag, typing_dict_kami] model['graphs'].append(nugget.get_nugget_dict())
def _mod_demod_assemble_one_step(stmt, model, is_mod): # Define some basic parameters for the modification mc = stmt._get_mod_condition() mod_condition_name = mc.mod_type mod_site = get_mod_site_name(mc) rule_enz_str = get_agent_rule_str(stmt.enz) rule_sub_str = get_agent_rule_str(stmt.sub) nugget_name = '%s_%s_%s_%s' % \ (rule_enz_str, mod_condition_name, rule_sub_str, mod_site) action_name = nugget_name + '_act' kf_mod = 1e-6 nugget = Nugget(nugget_name, nugget_name, kf_mod) enz_id = nugget.add_agent(stmt.enz) sub_id = nugget.add_agent(stmt.sub) st = states[mod_condition_name] from_state, to_state = (st[0], st[1]) if is_mod else (st[1], st[0]) mod_site_id = nugget.add_node(mod_site, {'val': from_state}) action_id = nugget.add_node(action_name, {'val': to_state}) nugget.add_typing(mod_site_id, 'state') nugget.add_typing(action_id, 'mod') nugget.add_edge(mod_site_id, sub_id) nugget.add_edge(action_id, mod_site_id) nugget.add_edge(enz_id, action_id) # Typing dicts linking the nugget to the Action Graph and to the # Kami graph typing_dict_ag = { 'from': nugget_name, 'to': 'action_graph', 'mapping': {}, 'total': False, 'ignore_attrs': False } typing_dict_kami = { 'from': nugget_name, 'to': 'kami', 'mapping': nugget.get_typing_dict(), 'total': True, 'ignore_attrs': True } # Add the graphs for this nugget to the graphs and typing lists model['typing'] += [typing_dict_ag, typing_dict_kami] model['graphs'].append(nugget.get_nugget_dict())
def _mod_demod_assemble_one_step(stmt, model, is_mod): # Define some basic parameters for the modification mc = stmt._get_mod_condition() mod_condition_name = mc.mod_type mod_site = get_mod_site_name(mc) rule_enz_str = get_agent_rule_str(stmt.enz) rule_sub_str = get_agent_rule_str(stmt.sub) nugget_name = '%s_%s_%s_%s' % \ (rule_enz_str, mod_condition_name, rule_sub_str, mod_site) action_name = nugget_name + '_act' kf_mod = 1e-6 nugget = Nugget(nugget_name, nugget_name, kf_mod) enz_id = nugget.add_agent(stmt.enz) sub_id = nugget.add_agent(stmt.sub) st = states[mod_condition_name] from_state, to_state = (st[0], st[1]) if is_mod else (st[1], st[0]) mod_site_id = nugget.add_node(mod_site, {'val': from_state}) action_id = nugget.add_node(action_name, {'val': to_state}) nugget.add_typing(mod_site_id, 'state') nugget.add_typing(action_id, 'mod') nugget.add_edge(mod_site_id, sub_id) nugget.add_edge(action_id, mod_site_id) nugget.add_edge(enz_id, action_id) # Typing dicts linking the nugget to the Action Graph and to the # Kami graph typing_dict_ag = {'from': nugget_name, 'to': 'action_graph', 'mapping': {}, 'total': False, 'ignore_attrs': False} typing_dict_kami = {'from': nugget_name, 'to': 'kami', 'mapping': nugget.get_typing_dict(), 'total': True, 'ignore_attrs': True} # Add the graphs for this nugget to the graphs and typing lists model['typing'] += [typing_dict_ag, typing_dict_kami] model['graphs'].append(nugget.get_nugget_dict())
def get_create_observable(model, agent): site_pattern = pa.get_site_pattern(agent) obs_name = pa.get_agent_rule_str(agent) + '_obs' try: monomer = model.monomers[pa._n(agent.name)] except KeyError: raise MissingMonomerError('%s is not in the model ' % agent.name) try: monomer_state = monomer(site_pattern) except Exception as e: msg = 'Site pattern %s invalid for monomer %s' % \ (site_pattern, monomer.name) raise MissingMonomerSiteError(msg) obs = Observable(obs_name, monomer(site_pattern)) model.add_component(obs) return obs
def get_create_observable(model, agent): site_pattern = pa.get_site_pattern(agent) obs_name = pa.get_agent_rule_str(agent) + '_obs' try: monomer = model.monomers[pa._n(agent.name)] except KeyError: raise MissingMonomerError('%s is not in the model ' % agent.name, agent) try: monomer_state = monomer(site_pattern) except Exception as e: msg = 'Site pattern %s invalid for monomer %s' % \ (site_pattern, monomer.name) raise MissingMonomerSiteError(msg) obs = Observable(obs_name, monomer(site_pattern)) try: model.add_component(obs) except ComponentDuplicateNameError as e: pass return obs
def test_rule_name_str_5(): a = Agent('BRAF', mods=[ModCondition('phosphorylation', 'serine', '123')]) s = pa.get_agent_rule_str(a) assert s == 'BRAF_phosphoS123'
def test_rule_name_str_3(): a = Agent('GRB2', bound_conditions=[BoundCondition(Agent('EGFR'), False)]) s = pa.get_agent_rule_str(a) assert s == 'GRB2_nEGFR'
def test_rule_name_str_1(): s = pa.get_agent_rule_str(Agent('BRAF')) assert s == 'BRAF'
def complex_assemble_one_step(stmt, model): pairs = itertools.combinations(stmt.members, 2) for pair in pairs: # Make a rule name nugget_name = '_'.join([get_agent_rule_str(m) for m in pair]) nugget_name += '_bind' action_name = nugget_name + '_act' kf_bind = 1e-6 nugget = Nugget(nugget_name, nugget_name, kf_bind) action_id = nugget.add_node(action_name) # Initialize dicts/lists for this nugget nugget.add_typing(action_id, 'bnd') for agent in pair: agent_id = nugget.add_agent(agent) agent_bs = get_binding_site_name(agent) agent_bs_id = nugget.add_node(agent_bs) nugget.add_edge(agent_bs_id, agent_id) nugget.add_edge(agent_bs_id, action_id) # Add to the Kami typing dict nugget.add_typing(agent_bs_id, 'locus') # Typing dicts linking the nugget to the Action Graph and to the # Kami graph typing_dict_ag = { 'from': nugget_name, 'to': 'action_graph', 'mapping': {}, 'total': False, 'ignore_attrs': False } typing_dict_kami = { 'from': nugget_name, 'to': 'kami', 'mapping': nugget.get_typing_dict(), 'total': True, 'ignore_attrs': True } # Add the graphs for this nugget to the graphs and typing lists model['typing'] += [typing_dict_ag, typing_dict_kami] model['graphs'].append(nugget.get_nugget_dict()) # In reverse reaction, assume that dissocition is unconditional nugget_name = '_'.join([get_agent_rule_str(m) for m in pair]) nugget_name += '_dissociate' action_name = nugget_name + '_act' kr_bind = 1e-1 nugget = Nugget(nugget_name, nugget_name, kr_bind) action_id = nugget.add_node(action_name) nugget.add_typing(action_id, 'brk') for agent in pair: agent_bs = get_binding_site_name(agent) agent_id = nugget.add_node(agent.name) agent_bs_id = nugget.add_node(agent_bs) nugget.add_edge(agent_bs_id, agent_id) nugget.add_edge(agent_bs_id, action_id) nugget.add_typing(agent_id, 'agent') nugget.add_typing(agent_bs_id, 'locus') # Typing dicts linking the nugget to the Action Graph and to the # Kami graph typing_dict_ag = { 'from': nugget_name, 'to': 'action_graph', 'mapping': {}, 'total': False, 'ignore_attrs': False } typing_dict_kami = { 'from': nugget_name, 'to': 'kami', 'mapping': nugget.get_typing_dict(), 'total': True, 'ignore_attrs': True } # Add the graphs for this nugget to the graphs and typing lists model['typing'] += [typing_dict_ag, typing_dict_kami] model['graphs'].append(nugget.get_nugget_dict())