def test_build_interval_data():
    # setup
    chanjo_db = Store(':memory:')
    chanjo_db.set_up()

    sample_id = 'rokinerl'
    group_id = 'group1'
    interval_data = []
Beispiel #2
0
def load(context, sample, group, bed_stream):
    """Load Sambamba output into the database for a sample."""
    chanjo_db = Store(uri=context.obj['database'])
    try:
        load_sambamba(chanjo_db, bed_stream, sample_id=sample, group_id=group)
    except IntegrityError:
        logger.error('sample already loaded, rolling back')
        chanjo_db.session.rollback()
        context.abort()
def test_lazy_load():
  """Test connection after post-init."""
  store = Store()

  # now we shouldn't have access to aliases
  assert hasattr(store, 'query') == False

  store.connect(':memory:')

  # ... but now we do!
  assert hasattr(store, 'query')
  assert store.dialect == 'sqlite'
Beispiel #4
0
    def setup(self):
        self.store = Store(':memory:')
        self.store.set_up()

        self.interval = BaseInterval('1',
                                     10,
                                     100,
                                     name='int1',
                                     block_ids=['block1', 'block2'],
                                     superblock_ids=['sblock1', 'sblock1'])

        self.db_interval = StoreInterval(interval_id=self.interval.name,
                                         contig=self.interval.contig,
                                         start=self.interval.start,
                                         end=self.interval.end,
                                         strand=self.interval.strand)
        self.interval_group = [('block2', self.db_interval, 'sblock1')]
def test_fetch_records():
    # set up
    chanjo_db = Store(':memory:')
    chanjo_db.set_up()
    chanjo_db.add(
        chanjo_db.create('interval',
                         interval_id='interval1',
                         contig='chr1',
                         start=10,
                         end=100,
                         strand='+'))
    chanjo_db.save()

    columns = (Interval.contig, Interval.start, Interval.end)
    intervals = list(fetch_records(chanjo_db, columns))
    assert len(intervals) == 1
    assert intervals[0] == ('chr1', 10, 100)
def test_exporter_pipeline():
    # set up
    chanjo_db = Store(':memory:')
    chanjo_db.set_up()
    chanjo_db.add(
        chanjo_db.create('interval',
                         interval_id='intervalY',
                         contig='Y',
                         start=123,
                         end=501,
                         strand='-'))
    chanjo_db.save()

    bed_lines = list(export_intervals(chanjo_db))

    assert bed_lines[0] == '#chrom\tchromStart\tchromEnd\tname\tscore\tstrand'
    assert bed_lines[1:] == ['Y\t122\t501\tintervalY\t0\t-']
def link(context, transcripts, bed_stream):
    """Link related genomic elements."""
    only_tx = transcripts or context.obj.get('transcripts') or False
    base = TXBASE if only_tx else BASE
    chanjo_db = Store(uri=context.obj['database'], base=base)
    try:
        if only_tx:
            result = load.link_transcripts(bed_stream)
            with click.progressbar(result.models,
                                   length=result.count,
                                   label='adding transcripts') as bar:
                for tx_model in bar:
                    chanjo_db.session.add(tx_model)
            chanjo_db.save()
        else:
            link_elements(chanjo_db, bed_stream)
    except IntegrityError:
        click.echo("elements already linked, use 'chanjo db setup --reset' "
                   "to re-build")
Beispiel #8
0
def init(context, setup, reset, automate):
    """Walk user through setting up a new config file."""
    # print a nice welcome message
    click.echo(chanjo.__banner__)

    if not automate:
        questions = [('sambamba.cov_treshold', 'sufficient coverage',
                      context.obj.get('sambamba', {}).get('cov_treshold',
                                                          [10, 20])),
                     ('database', 'central database path/URI',
                      context.obj['database'])]
        # launch init pipeline
        init_pipeline('chanjo', context.obj, questions)

    if setup:
        chanjo_db = Store(uri=context.obj.user_data['database'])
        if reset:
            chanjo_db.tear_down()
        chanjo_db.set_up()
Beispiel #9
0
def test_builder_pipeline():
  """Test the entire builder pipeline."""
  chanjo_db = Store(':memory:')
  chanjo_db.set_up()

  # test with minimal BED "file"
  bed_stream = io.open('tests/fixtures/CCDS.mini.bed', 'r', encoding='utf-8')
  init_db(chanjo_db, bed_stream)

  block = chanjo_db.get('block', 'CCDS2.2')
  assert block.start == 12
  assert block.end == 35

  superblock = chanjo_db.get('superblock', 'RFPL2')
  assert superblock.start == 32586759
  assert superblock.end == 32589260

  block_ids = [block_.id for block_ in superblock.blocks]
  assert set(block_ids) == set(['CCDS46694.1', 'CCDS54521.1'])

  assert len(chanjo_db.find('block')) == 5
  assert len(chanjo_db.find('superblock')) == 4
Beispiel #10
0
def init(context, setup, reset, automate, transcripts):
    """Walk user through setting up a new config file."""
    # print a nice welcome message
    click.echo(chanjo.__banner__)

    cov_tresholds = (context.obj.get('sambamba',
                                     {}).get('cov_treshold', [10, 20]))
    defaults = {
        'sambamba.cov_treshold': {
            'value': cov_tresholds,
            'prompt': 'sufficient coverage'
        },
        'database': {
            'value': str(context.obj['database']),
            'prompt': 'central database path/URI'
        }
    }

    if not automate:
        questions = [(key, value['prompt'], value['value'])
                     for key, value in iteritems(defaults)]
        # launch init pipeline
        init_pipeline('chanjo', context.obj, questions)
    else:
        logger.info('setting default config values')
        for key, value in iteritems(defaults):
            context.obj.set(key, value['value'], scope=context.obj.user_data)

    # write to the config file
    context.obj.save(default_flow_style=False)

    if setup:
        only_tx = transcripts or context.obj.get('transcripts') or False
        base = TXBASE if only_tx else BASE
        chanjo_db = Store(uri=context.obj['database'], base=base)
        if reset:
            chanjo_db.tear_down()
        chanjo_db.set_up()
Beispiel #11
0
def load(context, sample, group, transcripts, threshold, bed_stream):
    """Load Sambamba output into the database for a sample."""
    only_tx = transcripts or context.obj.get('transcripts') or False
    base = TXBASE if only_tx else BASE
    chanjo_db = Store(uri=context.obj['database'], base=base)
    try:
        if only_tx:
            source = os.path.abspath(bed_stream.name)
            load_transcripts(chanjo_db,
                             bed_stream,
                             sample=sample,
                             group=group,
                             source=source,
                             threshold=threshold)
        else:
            load_sambamba(chanjo_db,
                          bed_stream,
                          sample_id=sample,
                          group_id=group)
    except IntegrityError as error:
        logger.error('sample already loaded, rolling back')
        logger.debug(error.message)
        chanjo_db.session.rollback()
        context.abort()
Beispiel #12
0
def db(context):
    """Interact with the database for maintainance tasks."""
    context.db = Store(uri=context.obj['database'])
Beispiel #13
0
def db(context, transcripts):
    """Interact with the database for maintainance tasks."""
    only_tx = transcripts or context.obj.get('transcripts') or False
    base = TXBASE if only_tx else BASE
    context.db = Store(uri=context.obj['database'], base=base)
 def setup(self):
   self.store = Store(':memory:')
   self.store.set_up()
Beispiel #15
0
 def setup(self):
     self.store = Store('sqlite://')
     self.store.set_up()
Beispiel #16
0
 def setup(self):
     self.store = Store('sqlite://')
     self.store.set_up()
     self.row_data = parse_sambamba.depth_output(bed_lines)
Beispiel #17
0
def link(context, bed_stream):
    """Load Sambamba output into the database for a sample."""
    chanjo_db = Store(uri=context.obj['database'])
    link_elements(chanjo_db, bed_stream)