def test_host_comparison(self): """instances with same host, account, database, port are equal""" h1 = HostAccount("ensembldb.ensembl.org", "anonymous", "", port=5306) h2 = HostAccount("ensembldb.ensembl.org", "anonymous", "", port=5306) self.assertNotEqual(id(h1), id(h2)) self.assertEqual(h1, h2) # hashes are also equal self.assertEqual(hash(h1), hash(h2)) h3 = HostAccount("ensembldb.ensembl.org", "anonymous", "", port=5300) self.assertNotEqual(h1, h3) self.assertNotEqual(hash(h1), hash(h3))
def drop(configpath, mysqlcfg, verbose, debug): """drop databases from a MySQL server""" mysql_info = read_mysql_config(mysqlcfg, "mysql") account = HostAccount( mysql_info["host"], mysql_info["user"], mysql_info["passwd"], port=mysql_info["port"], ) server = DbConnection(account, db_name="PARENT", pool_recycle=36000) cursor = server.cursor() release, remote_path, local_path, species_dbs = read_config(configpath) content = get_db_name(account=account, release=str(release)) content = [str(n) for n in content] dbnames = reduce_dirnames(content, species_dbs) click.echo("The following databases will be deleted:") click.echo("\n".join(" %s" % d for d in dbnames)) try: click.confirm("Confirm you want to delete the databases", abort=True) except click.exceptions.Abort: click.echo("EXITING") exit(0) for dbname in dbnames: click.echo(f"Dropping {dbname}") _drop_db(cursor, dbname) if verbose: display_dbs(cursor, release) cursor.close()
def install(configpath, mysqlcfg, force_overwrite, verbose, debug): """install ensembl databases into a MySQL server""" mysql_info = read_mysql_config(mysqlcfg, "mysql") account = HostAccount( mysql_info["host"], mysql_info["user"], mysql_info["passwd"], port=mysql_info["port"], ) server = DbConnection(account, db_name="PARENT", pool_recycle=36000) release, remote_path, local_path, species_dbs = read_config(configpath) content = os.listdir(local_path) cursor = server.cursor() sql_for_speed = ["SET FOREIGN_KEY_CHECKS=0;", "SET UNIQUE_CHECKS=0;"] cursor.execute("\n".join(sql_for_speed)) dbnames = reduce_dirnames(content, species_dbs) dbnames = sorted_by_size(local_path, dbnames, debug=debug) for dbname in dbnames: chk = get_installed_checkpoint_path(local_path, dbname.name) server.ping(reconnect=True) # reconnect if server not alive if force_overwrite: _drop_db(cursor, dbname.name) if chk.exists(): chk.unlink() if verbose: click.echo(f"Creating database {dbname.name}") # now create dbname sql = f"CREATE DATABASE IF NOT EXISTS {dbname}" r = cursor.execute(sql) install_one_db( mysqlcfg, server, account, dbname.name, local_path, force_overwrite=force_overwrite, verbose=verbose, debug=debug, ) if debug: display_dbs(cursor, release) click.echo(server) undo_sql_for_speed = ["SET FOREIGN_KEY_CHECKS=1;", "SET UNIQUE_CHECKS=1;"] server.ping(reconnect=True) cursor.execute("\n".join(undo_sql_for_speed)) cursor.close()
def test_account_str(self): """str""" h1 = HostAccount("ensembldb.ensembl.org", "anonymous", "", port=5306) self.assertEqual(str(h1), "user:[email protected]:5306") self.assertEqual(h1.formatted(), "anonymous:@ensembldb.ensembl.org:5306") # default port, actual password h2 = HostAccount("mysql.host.org", "me", "tricky") self.assertEqual(str(h2), "user:[email protected]:3306") self.assertEqual(h2.formatted(), "me:[email protected]:3306")
def show(release, mysqlcfg): """shows databases corresponding to release""" if mysqlcfg.name == _mycfg: click.secho(f"{show.help}\n") click.secho("use --help for more options") exit() mysql_info = read_mysql_config(mysqlcfg, "mysql") account = HostAccount( mysql_info["host"], mysql_info["user"], mysql_info["passwd"], port=mysql_info["port"], ) names = get_db_name(account=account, release=str(release)) click.echo(f"Databases at host='{account.host}' for release={release}") if names: click.echo("\n".join(" %s" % n for n in names)) else: click.echo(" None")
__author__ = "Gavin Huttley, Hua Ying" __copyright__ = "Copyright 2016-, The EnsemblDb Project" __credits__ = ["Gavin Huttley", "hua Ying"] __license__ = "BSD" __version__ = "3.0a1" __maintainer__ = "Gavin Huttley" __email__ = "*****@*****.**" __status__ = "alpha" if "ENSEMBL_ACCOUNT" in os.environ: args = os.environ["ENSEMBL_ACCOUNT"].split() host, username, password = args[0:3] kwargs = {} if len(args) > 3: kwargs["port"] = int(args[3]) account = HostAccount(host, username, password, **kwargs) else: account = get_ensembl_account(release=ENSEMBL_RELEASE) class TestFeatureCoordLevels(TestCase): def setUp(self): self.chicken = Genome(species="chicken", release=ENSEMBL_RELEASE, account=account) def test_feature_levels(self): ChickenFeatureLevels = FeatureCoordLevels("chicken") chicken_feature_levels = ChickenFeatureLevels( feature_types=["gene", "cpg", "est"], core_db=self.chicken.CoreDb,
from ensembldb3.compara import Compara, Genome from ensembldb3.host import HostAccount, get_ensembl_account from . import ENSEMBL_GENOMES_RELEASE __author__ = "Jason Merkin" __copyright__ = "Copyright 2016-, The EnsemblDb Project" __credits__ = ["Jason Merkin", "Gavin Huttley", "Hua Ying"] __license__ = "BSD" __version__ = "3.0a1" __maintainer__ = "Gavin Huttley" __email__ = "*****@*****.**" __status__ = "alpha" account = HostAccount("mysql-eg-publicsql.ebi.ac.uk", "anonymous", "", port=4157) class MZ_ComparaTestBase(TestCase): comp = Compara( ["D.grimshawi", "D.melanogaster"], release=ENSEMBL_GENOMES_RELEASE, account=account, division="metazoa", ) class MZ_TestCompara(MZ_ComparaTestBase): def test_query_genome(self): """compara should attach valid genome attributes by common name"""