Example #1
0
def test_setup_demo(tmpdir):
    # GIVEN a non-existing target directory
    target_dir = tmpdir.join('chanjo-demo')
    target_path = str(target_dir)
    demo.setup_demo(target_path)
    files = os.listdir(target_path)
    expected_files = os.listdir('chanjo/init/demo-files')
    assert files == expected_files

    # GIVEN the files are already in place
    with pytest.raises(OSError):
        demo.setup_demo(target_path)
Example #2
0
def init(context, force, demo, auto, root_dir):
    """Bootstrap a new chanjo setup."""
    is_bootstrapped = False
    root_path = Path(root_dir)

    LOG.info("setting up chanjo under: %s", root_path)
    db_uri = context.obj.get('database')
    db_uri = db_uri or "sqlite:///{}".format(
        root_path.joinpath(DB_NAME).abspath())

    # test setup of sambamba
    sambamba_bin = find_executable('sambamba')
    if sambamba_bin is None:  # pragma: no cover
        LOG.warning("'sambamba' command not found")
    else:
        LOG.debug("'sambamba' found: %s", sambamba_bin)

    if demo:
        LOG.info("copying demo files: %s", root_dir)
        setup_demo(root_dir, force=force)

        LOG.info("configure new chanjo database: %s", db_uri)
        chanjo_db = ChanjoDB(db_uri)
        chanjo_db.set_up()
        is_bootstrapped = True
    elif auto or click.confirm('Bootstrap HGNC transcript BED?'):
        pull(root_dir, force=force)

        LOG.info("configure new chanjo database: %s", db_uri)
        chanjo_db = ChanjoDB(db_uri)
        chanjo_db.set_up()
        is_bootstrapped = True

    # setup config file
    root_path.makedirs_p()
    conf_path = root_path.joinpath('chanjo.yaml')
    with codecs.open(conf_path, 'w', encoding='utf-8') as conf_handle:
        data = {'database': db_uri}
        data_str = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper)
        LOG.info("writing config file: %s", conf_path)
        conf_handle.write(data_str)

    if is_bootstrapped:
        click.echo('Chanjo bootstrap successful! Now run: ')
        bed_path = root_path.joinpath(DEMO_BED_NAME if demo else BED_NAME)
        click.echo("chanjo --config {} link {}".format(conf_path, bed_path))
Example #3
0
def init(context, force, demo, auto, root_dir):
    """Bootstrap a new chanjo setup."""
    is_bootstrapped = False
    root_path = Path(root_dir)

    LOG.info("setting up chanjo under: %s", root_path)
    db_uri = context.obj.get('database')
    db_uri = db_uri or "sqlite:///{}".format(root_path.joinpath(DB_NAME).abspath())

    # test setup of sambamba
    sambamba_bin = find_executable('sambamba')
    if sambamba_bin is None:  # pragma: no cover
        LOG.warning("'sambamba' command not found")
    else:
        LOG.debug("'sambamba' found: %s", sambamba_bin)

    if demo:
        LOG.info("copying demo files: %s", root_dir)
        setup_demo(root_dir, force=force)

        LOG.info("configure new chanjo database: %s", db_uri)
        chanjo_db = ChanjoDB(db_uri)
        chanjo_db.set_up()
        is_bootstrapped = True
    elif auto or click.confirm('Bootstrap HGNC transcript BED?'):
        pull(root_dir, force=force)

        LOG.info("configure new chanjo database: %s", db_uri)
        chanjo_db = ChanjoDB(db_uri)
        chanjo_db.set_up()
        is_bootstrapped = True

    # setup config file
    root_path.makedirs_p()
    conf_path = root_path.joinpath('chanjo.yaml')
    with codecs.open(conf_path, 'w', encoding='utf-8') as conf_handle:
        data = {'database': db_uri}
        data_str = ruamel.yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper)
        LOG.info("writing config file: %s", conf_path)
        conf_handle.write(data_str)

    if is_bootstrapped:
        click.echo('Chanjo bootstrap successful! Now run: ')
        bed_path = root_path.joinpath(DEMO_BED_NAME if demo else BED_NAME)
        click.echo("chanjo --config {} link {}".format(conf_path, bed_path))
Example #4
0
def test_setup_demo_existing_dir(tmpdir):
    with pytest.raises(OSError):
        demo.setup_demo(str(tmpdir))