def _mod_demod_assemble_one_step(stmt, model, is_mod): # Define some basic parameters for the modification mod_condition_name = stmt.__class__.__name__.lower() if not is_mod: mod_condition_name = ist.modtype_to_inverse[mod_condition_name] mod_site = get_mod_site_name(mod_condition_name, stmt.residue, stmt.position) 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' monomer = model.monomers[pa._n(agent.name)] obs = Observable(obs_name.encode('utf-8'), monomer(site_pattern)) model.add_component(obs) return obs
def _check_regulate_activity(self, stmt): """Check a RegulateActivity statement.""" logger.info('Checking stmt: %s' % stmt) # FIXME Currently this will match rules with the corresponding monomer # pattern from the Activation/Inhibition statement, which will nearly # always have no state conditions on it. In future, this statement foo # should also match rules in which 1) the agent is in its active form, # or 2) the agent is tagged as the enzyme in a rule of the appropriate # activity (e.g., a phosphorylation rule) FIXME subj_mp = pa.get_monomer_pattern(self.model, stmt.subj) target_polarity = 1 if stmt.is_activation else -1 # This may fail, since there may be no rule in the model activating the # object, and the object may not have an "active" site of the # appropriate type obj_obs_name = pa.get_agent_rule_str(stmt.obj) + '_obs' try: obj_site_pattern = pa.get_site_pattern(stmt.obj) obj_site_pattern.update({stmt.obj_activity: 'active'}) obj_monomer = self.model.monomers[stmt.obj.name] obj_mp = obj_monomer(**obj_site_pattern) except Exception as e: logger.info("Could not create obj monomer pattern: %s" % e) return False obj_obs = Observable(obj_obs_name, obj_mp, _export=False) return self._find_im_paths(subj_mp, obj_obs, target_polarity)
def get_create_observable(model, agent): site_pattern = pa.get_site_pattern(agent) obs_name = pa.get_agent_rule_str(agent) + '_obs' monomer = model.monomers[agent.name] 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) 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 _check_modification(self, stmt): """Check a Modification statement.""" # Identify the observable we're looking for in the model, which # may not exist! # The observable is the modified form of the substrate logger.info('Checking stmt: %s' % stmt) # Look for an agent with the appropriate grounding in the model if stmt.enz is not None: enz_mps = list(pa.grounded_monomer_patterns(self.model, stmt.enz)) if not enz_mps: logger.info('No monomers found corresponding to agent %s' % stmt.enz) return False else: enz_mps = [None] # Get target polarity demodify_list = (Dephosphorylation, Dehydroxylation, Desumoylation, Deacetylation, Deglycosylation, Deribosylation, Deubiquitination, Defarnesylation) target_polarity = -1 if type(stmt) in demodify_list else 1 # Add modification to substrate agent # TODO TODO TODO: Should be updated to get a valid mod condition name mod_condition_name = stmt.__class__.__name__.lower() if mod_condition_name.startswith('de'): mod_condition_name = mod_condition_name[2:] # TODO TODO TODO modified_sub = _add_modification_to_agent(stmt.sub, mod_condition_name, stmt.residue, stmt.position) obs_name = pa.get_agent_rule_str(modified_sub) + '_obs' obj_mps = list(pa.grounded_monomer_patterns(self.model, modified_sub)) if not obj_mps: logger.info('Failed to create observable; returning False') return False # Try to find paths between pairs of matching subj and object monomer # patterns for enz_mp, obj_mp in itertools.product(enz_mps, obj_mps): obj_obs = Observable(obs_name, obj_mp, _export=False) # Return True for the first valid path we find if self._find_im_paths(enz_mp, obj_obs, target_polarity): return True # If we got here, then there was no path for any observable return False
def test_rule_name_str_1(): s = pa.get_agent_rule_str(Agent('BRAF')) assert(s == 'BRAF')
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_5(): a = Agent("BRAF", mods=[ModCondition("phosphorylation", "serine", "123")]) s = get_agent_rule_str(a) print s assert s == "BRAF_phosphoS123"
def test_rule_name_str_3(): a = Agent("GRB2", bound_conditions=[BoundCondition(Agent("EGFR"), False)]) s = get_agent_rule_str(a) print s assert s == "GRB2_nEGFR"
def test_rule_name_str_1(): s = 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())