def global_setup(sm_config): init_loggers(sm_config['logs']) if 'aws' in sm_config: populate_aws_env_vars(sm_config['aws']) image_storage.init(sm_config) image_storage.configure_bucket(sm_config)
def on_startup(config_path: str) -> Dict: from sm.engine import image_storage # pylint: disable=import-outside-toplevel,cyclic-import SMConfig.set_path(config_path) sm_config = SMConfig.get_conf() init_loggers(sm_config['logs']) if 'aws' in sm_config: populate_aws_env_vars(sm_config['aws']) image_storage.init(sm_config) return sm_config
def main(): parser = argparse.ArgumentParser( description='Merge mol_dbs and adducts into config') parser.add_argument('--config', default='conf/config.json', help='SM config path') args = parser.parse_args() SMConfig.set_path(args.config) init_loggers(SMConfig.get_conf()['logs']) conf = SMConfig.get_conf() with ConnectionPool(conf['db']): db = DB() populate_ion_formula(db) populate_ions(db) populate_ion_id(db)
def main(): parser = argparse.ArgumentParser( description='Migrate MolDB data from service to database') parser.add_argument('--config', default='conf/config.json', help='SM config path') args = parser.parse_args() SMConfig.set_path(args.config) config = SMConfig.get_conf() init_loggers(config['logs']) moldb_db_config = { 'host': 'localhost', 'database': 'mol_db', 'user': '******' } dump_moldb_tables(moldb_db_config) import_moldb_tables(config['db']) os.remove('/tmp/molecule.csv') os.remove('/tmp/molecular_db.csv')
create_subparser = subparsers.add_parser('create') create_subparser.add_argument('--drop', action='store_true', help='Delete existing index if exists') swap_subparser = subparsers.add_parser( 'swap', help='Swap the active and inactive indexes') drop_subparser = subparsers.add_parser( 'drop', help='Drop the index. Can only be used on the inactive index') status_subparser = subparsers.add_parser('status', help='Show current index mapping') args = parser.parse_args() SMConfig.set_path(args.config_path) init_loggers(SMConfig.get_conf()['logs']) es_config = SMConfig.get_conf()['elasticsearch'] es_man = ESIndexManager(es_config) alias = es_config['index'] active_index = es_man.internal_index_name(alias) inactive_index = es_man.another_index_name(active_index) index = inactive_index if args.inactive else active_index if args.action == 'create': if args.drop: es_man.delete_index(index) es_man.create_index(index) if not args.inactive: es_man.remap_alias(index, alias) elif args.action == 'swap':
import logging import pandas as pd from sm.engine.db import DB, ConnectionPool from sm.engine.config import init_loggers if __name__ == '__main__': parser = argparse.ArgumentParser( description='Update molecular database molecule names') parser.add_argument('--config', default='conf/config.json', help='SM config path') parser.add_argument('file_path', help='Path to file with new names') args = parser.parse_args() init_loggers() logger = logging.getLogger('engine') logger.info(f'Importing new names from {args.file_path}') db_config = {"host": "localhost", "database": "mol_db", "user": "******"} with ConnectionPool(db_config): db = DB() names_df = pd.read_csv(args.file_path, sep='\t')[['id', 'name']] sql = ( 'WITH molecule_name AS (SELECT UNNEST(%s::text[]) as id_, UNNEST(%s::text[]) as name_) ' 'UPDATE molecule SET mol_name = molecule_name.name_ ' 'FROM molecule_name WHERE molecule.mol_id = molecule_name.id_') db.alter(sql, [names_df.id.values.tolist(),