def test_missing_activity2(): stmts = [Inhibition(drug, raf), Activation(raf, mek)] md = ModelDiagnoser(stmts) suggs = md.get_missing_activities() assert len(suggs) == 1 assert suggs[0].subj.name == 'RAF' assert suggs[0].subj.activity assert suggs[0].subj.activity.activity_type == 'activity'
def test_missing_activity1(): stmts = [Activation(raf, mek), Phosphorylation(mek, erk)] md = ModelDiagnoser(stmts) suggs = md.get_missing_activities() assert len(suggs) == 1 assert suggs[0].enz.name == 'MEK' assert suggs[0].enz.activity assert suggs[0].enz.activity.activity_type == 'activity'
def test_check_model(): explain = Activation(raf, erk) mek_active = Agent('MEK', db_refs={'FPLX': 'MEK'}, activity=ActivityCondition('activity', True)) model_stmts = [Activation(raf, mek), Activation(mek_active, erk)] # Build the pysb model pa = PysbAssembler() pa.add_statements(model_stmts) pa.make_model(policies='one_step') md = ModelDiagnoser(model_stmts, pa.model, explain) result = md.check_explanation() assert result['has_explanation'] is True path = result['explanation_path'] assert len(path) == 2 assert path[0] == model_stmts[0] assert path[1] == model_stmts[1]
def run_diagnoser(self, res, model_stmts, model_exec): # Use a model diagnoser to identify explanations given the executable # model, the current statements, and the explanation goal if self.explain: md = ModelDiagnoser(model_stmts, model=model_exec, explain=self.explain) md_result = md.check_explanation() res.update(md_result) # If we got a proposal for a statement, get a specific # recommendation connect_stmts = res.get('connect_stmts') if connect_stmts: u_stmt, v_stmt = connect_stmts stmt_suggestions, sugg_subj, sugg_obj = \ md.suggest_statements(u_stmt, v_stmt) if stmt_suggestions: agents = [a.name for a in stmt_suggestions[0].agent_list() if a is not None] if len(set(agents)) > 1: res['stmt_suggestions'] = stmt_suggestions res['stmt_suggestions_subj'] = sugg_subj res['stmt_suggestions_obj'] = sugg_obj md = ModelDiagnoser(model_stmts) acts = md.get_missing_activities() if acts: logger.info('Missing activities found: %s' % acts) res['stmt_corrections'] = acts
def test_propose_statement(): jun = Agent('JUN', db_refs={'HGNC':'6204', 'UP': 'P05412'}) explain = Activation(raf, jun) erk_active = Agent('ERK', db_refs={'FPLX': 'ERK'}, activity=ActivityCondition('activity', True)) # Leave out MEK activates ERK model_stmts = [Activation(raf, mek), Activation(erk_active, jun)] # Build the pysb model pa = PysbAssembler() pa.add_statements(model_stmts) pa.make_model(policies='one_step') md = ModelDiagnoser(model_stmts, pa.model, explain) result = md.check_explanation() assert result['has_explanation'] is False assert result.get('explanation_path') is None inf_prop = result.get('connect_rules') assert inf_prop == ('RAF_activates_MEK_activity', 'ERK_act_activates_JUN_activity'), inf_prop stmt_prop = result.get('connect_stmts') assert stmt_prop == (model_stmts[0], model_stmts[1]) stmt_suggestions = md.suggest_statements(*stmt_prop)
def test_propose_statement(): jun = Agent('JUN', db_refs={'HGNC': '6204', 'UP': 'P05412'}) explain = Activation(raf, jun) erk_active = Agent('ERK', db_refs={'FPLX': 'ERK'}, activity=ActivityCondition('activity', True)) # Leave out MEK activates ERK model_stmts = [Activation(raf, mek), Activation(erk_active, jun)] # Build the pysb model pa = PysbAssembler() pa.add_statements(model_stmts) pa.make_model(policies='one_step') md = ModelDiagnoser(model_stmts, pa.model, explain) result = md.check_explanation() assert result['has_explanation'] is False assert result.get('explanation_path') is None inf_prop = result.get('connect_rules') assert inf_prop == ('RAF_activates_MEK_activity', 'ERK_act_activates_JUN_activity'), inf_prop stmt_prop = result.get('connect_stmts') assert stmt_prop == (model_stmts[0], model_stmts[1]) stmt_suggestions = md.suggest_statements(*stmt_prop)
def run_diagnoser(self, res, model_stmts, model_exec): # Use a model diagnoser to identify explanations given the executable # model, the current statements, and the explanation goal if self.explain: md = ModelDiagnoser(model_stmts, model=model_exec, explain=self.explain) md_result = md.check_explanation() res.update(md_result) # If we got a proposal for a statement, get a specific # recommendation connect_stmts = res.get('connect_stmts') if connect_stmts: u_stmt, v_stmt = connect_stmts stmt_suggestions = md.suggest_statements(u_stmt, v_stmt) if stmt_suggestions: agents = [a.name for a in stmt_suggestions[0].agent_list() if a is not None] if len(set(agents)) > 1: res['stmt_suggestions'] = stmt_suggestions md = ModelDiagnoser(model_stmts) acts = md.get_missing_activities() if acts: res['stmt_corrections'] = acts
def test_missing_activity3(): stmts = [Activation(raf, mek), Activation(raf, erk)] md = ModelDiagnoser(stmts) suggs = md.get_missing_activities() assert len(suggs) == 0