def test_get_mp_with_grounding_2(): a1 = Agent('A', mods=[ModCondition('phosphorylation', None, None)], db_refs={'HGNC': '6840'}) a2 = Agent('A', mods=[ModCondition('phosphorylation', 'Y', '187')], db_refs={'HGNC': '6840'}) Monomer('A_monomer', ['phospho', 'T185', 'Y187'], { 'phospho': 'y', 'T185': ['u', 'p'], 'Y187': ['u', 'p'] }) Annotation(A_monomer, 'http://identifiers.org/hgnc/HGNC:6840') A_monomer.site_annotations = [ Annotation(('phospho', 'y'), 'phosphorylation', 'is_modification'), Annotation(('T185', 'p'), 'phosphorylation', 'is_modification'), Annotation(('Y187', 'p'), 'phosphorylation', 'is_modification'), Annotation('T185', 'T', 'is_residue'), Annotation('T185', '185', 'is_position'), Annotation('Y187', 'Y', 'is_residue'), Annotation('Y187', '187', 'is_position') ] mps_1 = list(pa.grounded_monomer_patterns(model, a1)) assert len(mps_1) == 3 mps_2 = list(pa.grounded_monomer_patterns(model, a2)) assert len(mps_2) == 1 mp = mps_2[0] assert mp.monomer == A_monomer assert mp.site_conditions == {'Y187': ('p', WILD)}
def test_phospho_mod_grounding(): a = Agent('MEK1', mods=[ ModCondition('phosphorylation', 'S', '218'), ModCondition('phosphorylation', 'S', '222') ], db_refs={'HGNC': '6840'}) b = Agent('ERK2', db_refs={'HGNC': '6871'}) a_phos = Agent('Foo', mods=[ModCondition('phosphorylation', None, None)], db_refs={'HGNC': '6840'}) st1 = Phosphorylation(a, b, 'T', '185') pysb_asmb = pa.PysbAssembler(policies='one_step') pysb_asmb.add_statements([st1]) model = pysb_asmb.make_model() mps = list(pa.grounded_monomer_patterns(model, a_phos)) assert len(mps) == 2 assert mps[0].monomer.name == 'MEK1' assert mps[1].monomer.name == 'MEK1' sc = [mp.site_conditions for mp in mps] assert {'S218': ('p', WILD)} in sc assert {'S222': ('p', WILD)} in sc # Check if we get the doubly phosphorylated MonomerPattern mps = list(pa.grounded_monomer_patterns(model, a)) assert len(mps) == 1 assert mps[0].monomer.name == 'MEK1' assert mps[0].site_conditions == {'S218': ('p', WILD), 'S222': ('p', WILD)}
def test_get_mp_with_grounding(): foo = Agent('Foo', db_refs={'HGNC': 'foo'}) a = Agent('A', db_refs={'HGNC': '6840'}) b = Agent('B', db_refs={'HGNC': '6871'}) Monomer('A_monomer') Monomer('B_monomer') Annotation(A_monomer, 'http://identifiers.org/hgnc/HGNC:6840') Annotation(B_monomer, 'http://identifiers.org/hgnc/HGNC:6871') mps = list(pa.grounded_monomer_patterns(model, foo)) assert len(mps) == 0 mps = list(pa.grounded_monomer_patterns(model, a)) assert len(mps) == 1 assert mps[0].monomer == A_monomer mps = list(pa.grounded_monomer_patterns(model, b)) assert len(mps) == 1 assert mps[0].monomer == B_monomer
def _check_modification(self, stmt, max_paths, max_path_length): """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.debug('No monomers found corresponding to agent %s' % stmt.enz) return PathResult(False, 'SUBJECT_MONOMERS_NOT_FOUND', max_paths, max_path_length) else: enz_mps = [None] # Get target polarity target_polarity = -1 if isinstance(stmt, RemoveModification) else 1 obs_names = self.stmt_to_obs[stmt] if not obs_names: logger.debug("No observables for stmt %s, returning False" % stmt) return PathResult(False, 'OBSERVABLES_NOT_FOUND', max_paths, max_path_length) for enz_mp, obs_name in itertools.product(enz_mps, obs_names): # FIXME Returns on the path found for the first enz_mp/obs combo result = self._find_im_paths(enz_mp, obs_name, target_polarity, max_paths, max_path_length) # If result for this observable is not False, then we return it; # otherwise, that means there was no path for this observable, so # we have to try the next one if result.path_found: return result # If we got here, then there was no path for any observable return PathResult(False, 'NO_PATHS_FOUND', max_paths, max_path_length)
def test_get_mp_with_grounding(): foo = Agent('Foo', db_refs={'HGNC': 'foo'}) a = Agent('A', db_refs={'HGNC': '6840'}) b = Agent('B', db_refs={'HGNC': '6871'}) Monomer('A_monomer') Monomer('B_monomer') Annotation(A_monomer, 'http://identifiers.org/hgnc/HGNC:6840') Annotation(B_monomer, 'http://identifiers.org/hgnc/HGNC:6871') mps = list(pa.grounded_monomer_patterns(model, foo)) assert len(mps) == 0 mps = list(pa.grounded_monomer_patterns(model, a)) assert len(mps) == 1 assert mps[0].monomer == A_monomer mps = list(pa.grounded_monomer_patterns(model, b)) assert len(mps) == 1 assert mps[0].monomer == B_monomer
def check_policy(policy): pysb_asmb = pa.PysbAssembler(policies=policy) pysb_asmb.add_statements([st1]) model = pysb_asmb.make_model() mps = list(pa.grounded_monomer_patterns(model, b_phos)) assert len(mps) == 1 assert mps[0].monomer.name == 'ERK2' assert mps[0].site_conditions == {'T185': ('p', WILD)}
def check_policy(policy): pysb_asmb = pa.PysbAssembler(policies=policy) pysb_asmb.add_statements([st1]) model = pysb_asmb.make_model() mps = list(pa.grounded_monomer_patterns(model, b_phos)) assert len(mps) == 1 assert mps[0].monomer.name == 'ERK2' assert mps[0].site_conditions == {'T185': ('p', WILD)}
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 _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_grounded_active_pattern(): a = Agent('A', db_refs={'HGNC': '1234'}) b = Agent('B', db_refs={'HGNC': '5678'}) b_phos = Agent('B', mods=[ModCondition('phosphorylation', 'S', '100')], db_refs={'HGNC': '5678'}) b_act = Agent('B', activity=ActivityCondition('activity', True), db_refs={'HGNC': '5678'}) st1 = Phosphorylation(a, b, 'S', '100') st2 = ActiveForm(b_phos, 'activity', True) pysba = PysbAssembler(policies='one_step') pysba.add_statements([st1, st2]) model = pysba.make_model() mps = list(pa.grounded_monomer_patterns(model, b_act))
def test_get_mp_with_grounding_2(): a1 = Agent('A', mods=[ModCondition('phosphorylation', None, None)], db_refs={'HGNC': '6840'}) a2 = Agent('A', mods=[ModCondition('phosphorylation', 'Y', '187')], db_refs={'HGNC': '6840'}) Monomer('A_monomer', ['phospho', 'T185', 'Y187'], {'phospho': 'y', 'T185':['u', 'p'], 'Y187':['u','p']}) Annotation(A_monomer, 'http://identifiers.org/hgnc/HGNC:6840') A_monomer.site_annotations = [ Annotation(('phospho', 'y'), 'phosphorylation', 'is_modification'), Annotation(('T185', 'p'), 'phosphorylation', 'is_modification'), Annotation(('Y187', 'p'), 'phosphorylation', 'is_modification'), Annotation('T185', 'T', 'is_residue'), Annotation('T185', '185', 'is_position'), Annotation('Y187', 'Y', 'is_residue'), Annotation('Y187', '187', 'is_position') ] mps_1 = list(pa.grounded_monomer_patterns(model, a1)) assert len(mps_1) == 3 mps_2 = list(pa.grounded_monomer_patterns(model, a2)) assert len(mps_2) == 1 mp = mps_2[0] assert mp.monomer == A_monomer assert mp.site_conditions == {'Y187': ('p', WILD)}
def add_obs_for_agent(agent): obj_mps = list(pa.grounded_monomer_patterns(self.model, agent)) if not obj_mps: logger.debug('No monomer patterns found in model for agent %s, ' 'skipping' % agent) return obs_list = [] for obj_mp in obj_mps: obs_name = _monomer_pattern_label(obj_mp) + '_obs' # Add the observable obj_obs = Observable(obs_name, obj_mp, _export=False) obs_list.append(obs_name) try: self.model.add_component(obj_obs) except ComponentDuplicateNameError as e: pass return obs_list
def test_phospho_mod_grounding(): a = Agent('MEK1', mods=[ModCondition('phosphorylation', 'S', '218'), ModCondition('phosphorylation', 'S', '222')], db_refs={'HGNC': '6840'}) b = Agent('ERK2', db_refs={'HGNC': '6871'}) a_phos = Agent('Foo', mods=[ModCondition('phosphorylation', None, None)], db_refs={'HGNC': '6840'}) st1 = Phosphorylation(a, b, 'T', '185') pysb_asmb = pa.PysbAssembler(policies='one_step') pysb_asmb.add_statements([st1]) model = pysb_asmb.make_model() mps = list(pa.grounded_monomer_patterns(model, a_phos)) assert len(mps) == 2 assert mps[0].monomer.name == 'MEK1' assert mps[1].monomer.name == 'MEK1' sc = [mp.site_conditions for mp in mps] assert {'S218': ('p', WILD)} in sc assert {'S222': ('p', WILD)} in sc
def test_multiple_grounding_mods(): mek = Agent('MEK1', db_refs={'HGNC': '6840'}) erk = Agent('ERK2', db_refs={'HGNC': '6871'}) cbl = Agent('CBL', db_refs={'HGNC': '1541'}) ub_phos_erk = Agent('ERK2', mods=[ModCondition('phosphorylation', None, None), ModCondition('ubiquitination', None, None)], db_refs={'HGNC': '6871'}) st1 = Phosphorylation(mek, erk, 'T', '185') st2 = Phosphorylation(mek, erk, 'Y', '187') st3 = Ubiquitination(cbl, erk, 'K', '40') st4 = Ubiquitination(cbl, erk, 'K', '50') pysb_asmb = pa.PysbAssembler(policies='one_step') pysb_asmb.add_statements([st1, st2, st3, st4]) model = pysb_asmb.make_model() mps = list(pa.grounded_monomer_patterns(model, ub_phos_erk)) assert len(mps) == 4 assert mps[0].monomer.name == 'ERK2' assert mps[1].monomer.name == 'ERK2' assert mps[2].monomer.name == 'ERK2' assert mps[3].monomer.name == 'ERK2'