Exemple #1
0
def test_model_round():
    mr = ModelRound(previous_stmts, '2020-01-01-00-00-00')
    assert mr
    assert mr.get_total_statements() == 2
    assert len(mr.get_stmt_hashes()) == 2
    assert mr.get_statement_types() == [('Activation', 2)]
    assert all(agent_tuple in mr.get_agent_distribution()
               for agent_tuple in [('BRAF', 1), ('MAP2K1', 2), ('MAPK1', 1)])
    assert all((stmt_hash, 1) in mr.get_statements_by_evidence()
               for stmt_hash in mr.get_stmt_hashes())
    assert mr.get_sources_distribution() == [('assertion', 2)]
    mr2 = ModelRound(new_stmts, '2020-01-02-00-00-00')
    assert mr2
    assert mr2.get_total_statements() == 4
    assert len(mr2.get_stmt_hashes()) == 4
    assert mr2.get_statement_types() == [('Activation', 4)]
    assert all(agent_tuple in mr2.get_agent_distribution()
               for agent_tuple in [('BRAF', 2), ('MAP2K1',
                                                 2), ('MAPK1',
                                                      1), ('MTOR',
                                                           1), ('AKT', 2)])
    assert len(mr2.find_delta_hashes(mr, 'statements')['added']) == 2
    assert all(source_tuple in mr2.get_sources_distribution()
               for source_tuple in [('assertion', 2), ('test_source1',
                                                       1), ('test_source2',
                                                            1)])
Exemple #2
0
def test_model_stats_generator():
    latest_round = ModelRound(new_stmts, '2020-01-02-00-00-00')
    previous_round = ModelRound(previous_stmts, '2020-01-01-00-00-00')
    sg = ModelStatsGenerator('test',
                             latest_round=latest_round,
                             previous_round=previous_round,
                             previous_json_stats=previous_model_stats)
    sg.make_stats()
    assert sg.json_stats
    model_summary = sg.json_stats['model_summary']
    assert model_summary['model_name'] == 'test'
    assert model_summary['number_of_statements'] == 4
    assert model_summary['stmts_type_distr'] == [('Activation', 4)]
    assert all(agent_tuple in model_summary['agent_distr']
               for agent_tuple in [('AKT', 2), ('BRAF',
                                                2), ('MAP2K1',
                                                     2), ('MTOR',
                                                          1), ('MAPK1', 1)])
    assert all(source_tuple in model_summary['sources']
               for source_tuple in [('assertion', 2), ('test_source1',
                                                       1), ('test_source2',
                                                            1)])
    assert len(model_summary['stmts_by_evidence']) == 4
    assert len(model_summary['all_stmts']) == 4
    model_delta = sg.json_stats['model_delta']
    assert len(model_delta['statements_hashes_delta']['added']) == 2
    changes = sg.json_stats['changes_over_time']
    assert changes['number_of_statements'] == [2, 4]
    assert len(changes['dates']) == 2
Exemple #3
0
def test_model_round():
    mr = ModelRound(previous_stmts, '2020-01-01-00-00-00', previous_papers)
    assert mr
    assert mr.get_total_statements() == 2
    assert len(mr.get_stmt_hashes()) == 2
    assert mr.get_statement_types() == [('Activation', 2)]
    assert all(agent_tuple in mr.get_agent_distribution() for agent_tuple in
               [('BRAF', 1), ('MAP2K1', 2), ('MAPK1', 1)])
    assert all((stmt_hash, 1) in mr.get_statements_by_evidence() for stmt_hash
               in mr.get_stmt_hashes())
    assert mr.get_sources_distribution() == [('assertion', 2)]
    assert mr.get_number_raw_papers() == 1, mr.get_number_raw_papers()
    assert mr.get_number_assembled_papers() == 1
    mr2 = ModelRound(new_stmts, '2020-01-02-00-00-00', new_papers)
    assert mr2
    assert mr2.get_total_statements() == 4
    assert len(mr2.get_stmt_hashes()) == 4
    assert mr2.get_statement_types() == [('Activation', 4)]
    assert all(agent_tuple in mr2.get_agent_distribution() for agent_tuple in
               [('BRAF', 2), ('MAP2K1', 2), ('MAPK1', 1), ('MTOR', 1),
                ('AKT', 2)])
    assert len(mr2.find_delta_hashes(mr, 'statements')['added']) == 2
    assert all(source_tuple in mr2.get_sources_distribution() for source_tuple
               in [('assertion', 2), ('test_source1', 1), ('test_source2', 1)])
    assert mr2.get_number_raw_papers() == 3
    assert set(mr2.find_delta_hashes(mr, 'raw_papers')['added']) == {
        '2345', '3456'}
    assert mr2.get_number_assembled_papers() == 2, mr2.stmts_by_papers
    assert set(mr2.find_delta_hashes(mr, 'assembled_papers')['added']) == {
        '2345'}
Exemple #4
0
def test_agent_stats_generator():
    # First generate model and test stats
    latest_round = ModelRound(new_stmts, '2020-01-02-00-00-00', new_papers)
    previous_round = ModelRound(previous_stmts, '2020-01-01-00-00-00',
                                previous_papers)
    msg = ModelStatsGenerator('test', latest_round=latest_round,
                              previous_round=previous_round,
                              previous_json_stats=previous_model_stats)
    msg.make_stats()
    model_stats = msg.json_stats
    latest_round = TestRound(new_results, '2020-01-02-00-00-00')
    previous_round = TestRound(previous_results, '2020-01-01-00-00-00')
    tsg = TestStatsGenerator('test', latest_round=latest_round,
                             previous_round=previous_round,
                             previous_json_stats=previous_test_stats)
    tsg.make_stats()
    test_stats = tsg.json_stats

    # Generate Agent stats using model and test stats and statements
    asg = AgentStatsGenerator('test', 'BRAF', new_stmts, model_stats,
                              test_stats)
    asg.make_stats()
    assert asg.json_stats

    # Agent stats has fewer stats fields
    model_summary = asg.json_stats['model_summary']
    model_delta = asg.json_stats['model_delta']
    paper_summary = asg.json_stats['paper_summary']
    test_summary = asg.json_stats['test_round_summary']
    assert model_summary['model_name'] == 'test'
    assert model_summary['stmts_type_distr'] == [['Activation', 2]]
    assert all(agent_tuple in model_summary['agent_distr'] for
               agent_tuple in [['AKT', 1], ['MAP2K1', 1]])
    assert all(source_tuple in model_summary['sources'] for source_tuple
               in [['assertion', 1], ['test_source1', 1]])
    assert len(model_summary['stmts_by_evidence']) == 2
    assert len(model_delta['statements_hashes_delta']['added']) == 1
    assert all(paper_tuple in paper_summary['paper_distr'] for
               paper_tuple in [['1234', 1], ['2345', 1]])
    assert paper_summary['stmts_by_paper']['1234'][0] == -20714390795236750
    assert paper_summary['stmts_by_paper']['2345'][0] == -13855132444206450
    assert len(paper_summary['paper_links']) == 2
    assert len(paper_summary['paper_titles']) == 2
    assert len(test_summary['agent_tests']) == 2
    assert len(test_summary['agent_paths']['pysb']) == 2
    assert len(test_summary['agent_paths']['pybel']) == 2
    assert len(test_summary['agent_paths']['signed_graph']) == 2
    assert len(test_summary['agent_paths']['unsigned_graph']) == 2
Exemple #5
0
def test_model_stats_generator():
    latest_round = ModelRound(new_stmts, '2020-01-02-00-00-00', new_papers)
    previous_round = ModelRound(previous_stmts, '2020-01-01-00-00-00',
                                previous_papers)
    sg = ModelStatsGenerator('test',
                             latest_round=latest_round,
                             previous_round=previous_round,
                             previous_json_stats=previous_model_stats)
    sg.make_stats()
    assert sg.json_stats
    model_summary = sg.json_stats['model_summary']
    assert model_summary['model_name'] == 'test'
    assert model_summary['number_of_statements'] == 4
    assert model_summary['stmts_type_distr'] == [('Activation', 4)]
    assert all(agent_tuple in model_summary['agent_distr']
               for agent_tuple in [('AKT', 2), ('BRAF',
                                                2), ('MAP2K1',
                                                     2), ('MTOR',
                                                          1), ('MAPK1', 1)])
    assert all(source_tuple in model_summary['sources']
               for source_tuple in [('assertion', 2), ('test_source1',
                                                       1), ('test_source2',
                                                            1)])
    assert len(model_summary['stmts_by_evidence']) == 4
    assert len(model_summary['all_stmts']) == 4
    model_delta = sg.json_stats['model_delta']
    assert len(model_delta['statements_hashes_delta']['added']) == 2
    paper_summary = sg.json_stats['paper_summary']
    assert set(paper_summary['raw_paper_ids']) == {'1234', '2345', '3456'}
    assert paper_summary['number_of_raw_papers'] == 3
    assert set(paper_summary['assembled_paper_ids']) == {'1234', '2345'}
    assert paper_summary['number_of_assembled_papers'] == 2
    assert all(paper_tuple in paper_summary['paper_distr']
               for paper_tuple in [('1234', 2), ('2345', 2)])
    assert set(paper_summary['stmts_by_paper']['1234']) == {
        29000400098290256, -20714390795236750
    }
    assert set(paper_summary['stmts_by_paper']['2345']) == {
        2874381165909177, -13855132444206450
    }
    paper_delta = sg.json_stats['paper_delta']
    assert len(paper_delta['raw_paper_ids_delta']['added']) == 2
    assert len(paper_delta['assembled_paper_ids_delta']['added']) == 1
    changes = sg.json_stats['changes_over_time']
    assert changes['number_of_statements'] == [2, 4]
    assert changes['number_of_raw_papers'] == [1, 3]
    assert changes['number_of_assembled_papers'] == [1, 2]
    assert len(changes['dates']) == 2