def setup_database(request): """Setup the mongo adapter""" print('') logger.info("Setting up database") host = 'localhost' port = 27017 db_name = 'testdatabase' client = MongoClient( host=host, port=port, ) #Initialize an adapter adapter = MongoAdapter() #Connect to the test database adapter.connect_to_database( database=db_name, host=host, port=port ) logger.info("Database setup") def teardown(): print('\n') logger.info('Teardown database') client.drop_database(db_name) logger.info('Teardown done') request.addfinalizer(teardown) return adapter
def scout(context): """Update sample information for samples from Scout.""" db = context.obj["db"] mongo_auth = context.obj["SCOUT_AUTH"] mongo_adapter = MongoAdapter() mongo_adapter.connect_to_database(**mongo_auth) process_scout(db, mongo_adapter)
def archive(context): """Update sample information for samples from Scout.""" db = context.obj["db"] mip_root = context.obj["MIP_ANALYSIS_ROOT"] mongo_auth = context.obj["SCOUT_AUTH"] mongo_adapter = MongoAdapter() mongo_adapter.connect_to_database(**mongo_auth) process_archive(db, mongo_adapter, mip_root)
def queue(context): """Add stuff to the queue.""" db = context.obj['db'] mongo_auth = context.obj['SCOUT_AUTH'] mongo_adapter = MongoAdapter() mongo_adapter.connect_to_database(**mongo_auth) analyze.trigger(db, context.obj['MIP_CUST_ROOTS']) visualize.trigger(db, mongo_adapter)
def cli(ctx, mongodb, username, password, host, port, logfile, loglevel, config): """Manage Scout interactions.""" init_log(logger, logfile, loglevel) mongo_configs = {} configs = {} if config: logger.info("Use config file {0}".format(config)) configs = ConfigObj(config) if mongodb: mongo_configs['mongodb'] = mongodb else: mongo_configs['mongodb'] = configs.get('mongodb', 'variantDatabase') logger.info("Setting mongodb to {0}".format(mongo_configs['mongodb'])) if host: mongo_configs['host'] = host else: mongo_configs['host'] = configs.get('host', 'localhost') logger.info("Setting host to {0}".format(mongo_configs['host'])) if port: mongo_configs['port'] = port else: mongo_configs['port'] = int(configs.get('port', 27017)) logger.info("Setting port to {0}".format(mongo_configs['port'])) if username: mongo_configs['username'] = username else: mongo_configs['username'] = configs.get('username') if password: mongo_configs['password'] = password else: mongo_configs['password'] = configs.get('password') logger.info("Setting up a mongo adapter") mongo_adapter = MongoAdapter() logger.info("Connecting to database") mongo_adapter.connect_to_database( database=mongo_configs['mongodb'], host=mongo_configs['host'], port=mongo_configs['port'], username=mongo_configs['username'], password=mongo_configs['password'] ) mongo_configs['adapter'] = mongo_adapter ctx.obj = mongo_configs
def setup_loaded_database(request): """Setup a mongo databse with loaded variants""" print('') logger.info("Setting up database and populate it") host = 'localhost' port = 27017 db_name = 'testdatabase' client = MongoClient( host=host, port=port, ) #Initialize an adapter adapter = MongoAdapter() #Connect to the test database adapter.connect_to_database( database=db_name, host=host, port=port ) scout_configs = ConfigObj(scout_config) case = adapter.add_case( case_lines=open(scout_configs['ped'], 'r'), case_type='ped', owner=scout_configs['owner'], scout_configs=scout_configs ) adapter.add_variants( vcf_file=scout_configs['load_vcf'], variant_type='clinical', case=case, ) logger.info("Database setup") def teardown(): print('\n') logger.info('Teardown database') client.drop_database(db_name) logger.info('Teardown done') request.addfinalizer(teardown) return adapter