Exemplo n.º 1
0
def link(context, bed_stream):
    """Link related genomic elements."""
    chanjo_db = ChanjoDB(uri=context.obj['database'])
    result = link_elements(bed_stream)
    with click.progressbar(result.models, length=result.count,
                           label='adding transcripts') as bar:
        for tx_model in bar:
            chanjo_db.add(tx_model)
    try:
        chanjo_db.save()
    except IntegrityError:
        LOG.exception('elements already linked?')
        chanjo_db.session.rollback()
        click.echo("use 'chanjo db setup --reset' to re-build")
        context.abort()
Exemplo n.º 2
0
def init(context, force, demo, auto, root_dir):
    """Bootstrap a new chanjo setup."""
    root_path = path(root_dir).abspath()
    log.info("setting up chanjo under: %s", root_path)
    db_uri = context.obj.get('database')
    abs_db_path = root_path.joinpath(DB_NAME)
    db_uri = db_uri or "sqlite:///{}".format(abs_db_path)
    # test setup of sambamba
    sambamba_bin = find_executable('sambamba')
    if sambamba_bin is None:  # pragma: no cover
        log.warn("'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)
    elif auto or click.confirm('Bootstrap CCDS transcript BED?'):
        # ensure root dir exists
        root_path.makedirs_p()
        pull(root_dir, force=force)

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

    # setup config file
    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 = yaml.dump(data, default_flow_style=False)
        log.info("writing config file: %s", conf_path)
        conf_handle.write(data_str)

    click.echo('Chanjo bootstrap successful! Now run: ')
    bed_path = root_path.joinpath(BED_NAME)
    click.echo("chanjo --config {} link {}".format(conf_path, bed_path))
Exemplo n.º 3
0
def link(context, bed_stream):
    """Link related genomic elements."""
    chanjo_db = ChanjoDB(uri=context.obj['database'])
    result = link_elements(bed_stream)
    with click.progressbar(result.models, length=result.count,
                           label='adding transcripts') as bar:
        for tx_model in bar:
            chanjo_db.add(tx_model)
    try:
        chanjo_db.save()
    except IntegrityError:
        log.exception('elements already linked?')
        chanjo_db.session.rollback()
        click.echo("use 'chanjo db setup --reset' to re-build")
        context.abort()
Exemplo n.º 4
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))
Exemplo n.º 5
0
def load(context, sample, group, name, group_name, threshold, bed_stream):
    """Load Sambamba output into the database for a sample."""
    chanjo_db = ChanjoDB(uri=context.obj['database'])
    source = os.path.abspath(bed_stream.name)

    result = load_transcripts(bed_stream, sample_id=sample, group_id=group,
                              source=source, threshold=threshold)

    result.sample.name = name
    result.sample.group_name = group_name
    try:
        chanjo_db.add(result.sample)
        with click.progressbar(result.models, length=result.count,
                               label='loading transcripts') as bar:
            for tx_model in bar:
                chanjo_db.add(tx_model)
        chanjo_db.save()
    except IntegrityError as error:
        LOG.error('sample already loaded, rolling back')
        LOG.debug(error.args[0])
        chanjo_db.session.rollback()
        context.abort()
Exemplo n.º 6
0
def existing_db(tmpdir):
    db_path = tmpdir.join("coverage.sqlite3")
    chanjo_db = ChanjoDB(str(db_path))
    chanjo_db.set_up()
    yield chanjo_db
    chanjo_db.tear_down()
Exemplo n.º 7
0
def chanjo_db():
    _chanjo_db = ChanjoDB("sqlite://")
    _chanjo_db.set_up()
    yield _chanjo_db
    _chanjo_db.tear_down()
Exemplo n.º 8
0
def test_no_dialect():
    # GIVEN not explicity specifying SQLite dialect
    # WHEN setting up the API
    chanjo_db = ChanjoDB(':memory:')
    # THEN chanjo should guess it
    assert chanjo_db.dialect == 'sqlite'