Пример #1
0
def _load_tests_from_cache(test_corpus):
    tests, file_key = tests_cache.get(test_corpus, (None, None))
    latest_on_s3 = find_latest_s3_file(EMMAA_BUCKET_NAME,
                                       f'tests/{test_corpus}', '.pkl')
    if file_key != latest_on_s3:
        tests, file_key = load_tests_from_s3(test_corpus, EMMAA_BUCKET_NAME)
        if isinstance(tests, dict):
            tests = tests['tests']
        tests_cache[test_corpus] = (tests, file_key)
    else:
        logger.info(f'Loaded {test_corpus} from cache.')
    return tests
Пример #2
0
def test_load_tests_from_s3():
    # Local imports are recommended when using moto
    from emmaa.model_tests import load_tests_from_s3, StatementCheckingTest
    client = setup_bucket(add_tests=True)
    test_dict, _ = load_tests_from_s3('simple_tests', bucket=TEST_BUCKET_NAME)
    assert isinstance(test_dict, dict)
    tests = test_dict['tests']
    assert isinstance(tests, list)
    assert len(tests) == 1
    test = tests[0]
    assert isinstance(test, StatementCheckingTest)
    assert isinstance(test_dict['test_data'], dict)
    assert isinstance(test_dict['test_data']['description'], str)
Пример #3
0
def test_model_to_tests():
    # Local imports are recommended when using moto
    from emmaa.model_tests import model_to_tests, load_tests_from_s3, \
        StatementCheckingTest
    client = setup_bucket(add_model=True)
    test_dict = model_to_tests('test', bucket=TEST_BUCKET_NAME)
    assert isinstance(test_dict, dict)
    assert 'test_data' in test_dict
    assert 'tests' in test_dict
    tests = test_dict['tests']
    assert len(tests) == 2
    assert isinstance(tests[0], StatementCheckingTest)
    loaded_tests, _ = load_tests_from_s3('test_tests', bucket=TEST_BUCKET_NAME)
    assert loaded_tests
    assert isinstance(loaded_tests, dict)
    assert 'test_data' in loaded_tests
    assert 'tests' in loaded_tests
Пример #4
0
def test_model_to_tests():
    # Local imports are recommended when using moto
    from emmaa.model_tests import model_to_tests, load_tests_from_s3, \
        StatementCheckingTest
    from emmaa.model import save_config_to_s3, load_config_from_s3
    client = setup_bucket(add_model=True, add_mm=True)
    test_dict = model_to_tests('test', bucket=TEST_BUCKET_NAME)
    assert isinstance(test_dict, dict)
    assert 'test_data' in test_dict
    assert 'tests' in test_dict
    tests = test_dict['tests']
    # With default config get tests for each statement
    assert len(tests) == 2
    # Modify config to filter
    config = load_config_from_s3('test', bucket=TEST_BUCKET_NAME)
    config['make_tests'] = {
        'filter': {
            'conditions': {
                'curated': False
            },
            'evid_policy': 'any'
        }
    }
    save_config_to_s3('test', config, bucket=TEST_BUCKET_NAME)
    test_dict = model_to_tests('test', bucket=TEST_BUCKET_NAME)
    assert isinstance(test_dict, dict)
    assert 'test_data' in test_dict
    assert 'tests' in test_dict
    tests = test_dict['tests']
    # With modified config statements are filtered
    assert len(tests) == 1
    assert isinstance(tests[0], StatementCheckingTest)
    loaded_tests, _ = load_tests_from_s3('test_tests', bucket=TEST_BUCKET_NAME)
    assert loaded_tests
    assert isinstance(loaded_tests, dict)
    assert 'test_data' in loaded_tests
    assert 'tests' in loaded_tests
Пример #5
0
def test_load_tests_from_s3():
    tests = load_tests_from_s3('simple_model_test.pkl')
    assert isinstance(tests, list)
    assert len(tests) == 1
    test = tests[0]
    assert isinstance(test, StatementCheckingTest)
Пример #6
0
                        '--chemical_disease',
                        help='Path to ctd chemical disease statements pkl',
                        required=True)
    parser.add_argument('-cg',
                        '--chemical_gene',
                        help='Path to ctd chemical gene statements pkl',
                        required=True)
    parser.add_argument('-gd',
                        '--gene_disease',
                        help='Path to ctd gene disease statements pkl',
                        required=True)
    args = parser.parse_args()

    # Load model statements and tests
    model_stmts, _ = get_assembled_statements('covid19')
    curated_tests, _ = load_tests_from_s3('covid19_curated_tests')
    if isinstance(curated_tests, dict):  # if descriptions were added
        curated_tests = curated_tests['tests']
    mitre_tests, _ = load_tests_from_s3('covid19_mitre_tests')
    if isinstance(mitre_tests, dict):  # if descriptions were added
        mitre_tests = mitre_tests['tests']
    all_test_stmts = [test.stmt for test in curated_tests] + \
        [test.stmt for test in mitre_tests]

    # Load CTD statements
    chem_dis_stmts = ac.load_statements(args.chemical_disease)
    chem_gene_stmts = ac.load_statements(args.chemical_gene)
    gene_dis_stmts = ac.load_statements(args.gene_disease)
    all_ctd_stmts = chem_dis_stmts + chem_gene_stmts + gene_dis_stmts

    # Collect most frequents gene groundings for model statements and