示例#1
0
def test_model_check_data():
    # Create a set of statements
    a = Agent('A', db_refs={'HGNC': '1'})
    b = Agent('B', db_refs={'HGNC': '2'})
    b_phos = Agent('B',
                   mods=[ModCondition('phosphorylation')],
                   db_refs={'HGNC': '2'})
    c = Agent('C', db_refs={'HGNC': '3'})
    c_phos = Agent('C',
                   mods=[ModCondition('phosphorylation')],
                   db_refs={'HGNC': '3'})
    d = Agent('D', db_refs={'HGNC': '4'})
    d_phos = Agent('D',
                   mods=[ModCondition('phosphorylation')],
                   db_refs={'HGNC': '4'})

    # Two paths from A to D: One going through B and another through C
    st1 = Phosphorylation(a, b)
    st2 = Phosphorylation(b_phos, d)
    st3 = Phosphorylation(a, c)
    st4 = Phosphorylation(c_phos, d)
    # Statements/Data agents for checking
    stmt_to_check = Phosphorylation(a, d)
    agent_obs = [b_phos, c_phos, d_phos]
    # Make model
    pa = PysbAssembler()
    pa.add_statements([st1, st2, st3, st4])
    pa.make_model(policies='one_step')
    mc = ModelChecker(pa.model, [stmt_to_check], agent_obs)
    results = mc.check_model(max_paths=5)
    mc.get_im().draw('im.pdf', prog='dot')
    # Create observable
    assert len(results) == 1
    pr = results[0][1]
    res = pr.paths[0:2]
    assert len(res) == 2
    p1 = [('A_phosphorylation_B_phospho', 1),
          ('B_phospho_phosphorylation_D_phospho', 1), ('D_phospho_p_obs', 1)]
    assert p1 in res
    p2 = [('A_phosphorylation_C_phospho', 1),
          ('C_phospho_phosphorylation_D_phospho', 1), ('D_phospho_p_obs', 1)]
    assert p2 in res
    # Now, a vector linking agents with values, expressed at first as
    # +/- 1
    # This data should ensure that the path through B should be more highly
    # ranked than the path through C
    data = {b_phos: 1, c_phos: -1, d_phos: 1}
    paths = results[0][1].paths
    scored_paths = mc.score_paths(paths, data)
    assert scored_paths[0][0] == p1
    assert scored_paths[0][1] == 0
    assert scored_paths[1][0] == p2
示例#2
0
                paths = []
                for stmt in stmt_list:
                    print("Checking: %s" % stmt)
                    result = mc.check_statement(stmt, max_paths=5,
                                                max_path_length=6)
                    print(result)
                    if result.path_found:
                        path_found = 1
                        if result.paths:
                            paths += result.paths
                    else:
                        print("No path found")
                if paths:
                    print('===========================')
                    print('Scoring a total of %d paths' % len(paths))
                    scored_result = mc.score_paths(paths, agent_values,
                                                   loss_of_function=True)
                    for res in scored_result:
                        print(res[1])
                        for link in res[0]:
                            print('--->', link[0], link[1])
                    paths = [s[0] for s in scored_result]
                    print('===========================')
                results.append((drug_name, ab, relation, value, path_found,
                                paths))
        with open('pathfinding_results.pkl', 'wb') as fh:
            pickle.dump(results, fh)
    else:
        with open('pathfinding_results.pkl', 'rb') as fh:
            results = pickle.load(fh)

    #write_unicode_csv('model_check_results.csv', results)