def __init__(self, sm_config, analysis_version, database): reports_path = Path(proj_root()) / 'tests/reports' timestamp = datetime.now().replace(microsecond=0).isoformat().replace( ':', '-') suffix = f'{database}-v{analysis_version}' self.sm_config = sm_config self.db = DB() self.ds_id = '2000-01-01_00h00m01s' self.ref_results_path = reports_path / f'spheroid-{suffix}.csv' self.output_results_path = reports_path / f'test-{suffix}-{timestamp}.csv' self.ds_name = 'sci_test_spheroid_untreated' self.ds_data_path = join(self.sm_config['fs']['spark_data_path'], self.ds_name) self.moldb = MOL_DBS[database] self.analysis_version = analysis_version self.input_path = join(proj_root(), 'tests/data/untreated') self.ds_config_path = join(self.input_path, 'config.json') self.metrics = [ 'chaos', 'spatial', 'spectral', 'mz_err_abs', 'mz_err_rel', 'msm', 'fdr' ] self.comparison_df = None
def test_lcms_geometry_factory(): lcms_file_path = join( proj_root(), 'tests/data/lcms_acq_geometry_example/apple_surface_swab.mzML') geometry = make_acq_geometry('lcms', lcms_file_path, {}, (0, 0)) assert geometry['length_unit'] == 's' assert not geometry['acquisition_grid']['regular_grid'] assert len(geometry['acquisition_grid']['coord_list']) == 285 assert geometry['pixel_size'] == { 'regular_size': True, 'size_x': 1, 'size_y': 1 }
def sm_config(): SMConfig.set_path(Path(proj_root()) / TEST_CONFIG_PATH) SMConfig.get_conf( update=True) # Force reload in case previous tests modified it worker_id = os.environ.get('PYTEST_XDIST_WORKER', 'gw0') test_id = f'sm_test_{worker_id}' # Update the internal cached copy of the config, so independent calls to SMConfig.get_conf() # also get the updated config SMConfig._config_dict['db']['database'] = test_id SMConfig._config_dict['elasticsearch']['index'] = test_id SMConfig._config_dict['rabbitmq']['prefix'] = f'test_{worker_id}__' for path in SMConfig._config_dict['lithops']['sm_storage'].values(): # prefix keys with test ID so they can be cleaned up later path[1] = f'{test_id}/{path[1]}' # __LITHOPS_SESSION_ID determines the prefix to use for anonymous cloudobjects os.environ['__LITHOPS_SESSION_ID'] = f'{test_id}/cloudobjects' return SMConfig.get_conf()
def ensure_db_populated(sm_config, analysis_version, database): db = DB() # Install DB schema if needed query = "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'dataset'" tables_exist = db.select_one(query)[0] >= 1 if not tables_exist: print('Installing DB schema') db.alter(DB_SQL_SCHEMA) # Import HMDB if needed moldb = MOL_DBS[database] try: molecular_db.find_by_name_version(moldb['name'], moldb['version']) except SMError: print(f'Importing {database}') with TemporaryDirectory() as tmp: urlretrieve(moldb['url'], f'{tmp}/moldb.tsv') molecular_db.create(moldb['name'], moldb['version'], f'{tmp}/moldb.tsv') if analysis_version > 1: if len( db.select( "SELECT name FROM scoring_model WHERE name = 'v3_default'") ) == 0: print("Importing v3_default scoring model") params = upload_catboost_scoring_model( model=Path(proj_root()) / '../scoring-models/v3_default/model-2022-01-05T13-45-26.947188-416b1311.cbm', bucket=sm_config['lithops']['lithops']['storage_bucket'], prefix=f'test_scoring_models/v3_default', is_public=False, ) save_scoring_model_to_db(name='v3_default', type_='catboost', params=params)
if __name__ == '__main__': parser = argparse.ArgumentParser( description='Scientific tests runner\n' 'Example: python tests/sci_test/spheroid.py' 'or: python tests/sci_test/spheroid.py --lithops --analysis-version 3') parser.add_argument('--save', action='store_true', help='save comparison report even on success') parser.add_argument('--save-ref', action='store_true', help='update reference results') parser.add_argument( '--config', dest='sm_config_path', default=join(proj_root(), 'conf/scitest_config.json'), help='path to sm config file', ) parser.add_argument( '--store-images', action='store_true', help='whether to store ion images. (Default: don\'t store)', ) parser.add_argument( '--lithops', action='store_true', help= 'whether to use the Lithops executor. (Default: use Spark executor)', ) parser.add_argument('--analysis-version', type=int,