Beispiel #1
0
def cli(ctx, conn_host, database, username, password, port, host, verbose, 
        logfile, backend):
    """loqusdb: manage a local variant count database."""
    # configure root logger to print to STDERR
    loglevel = LEVELS.get(min(verbose,1), "INFO")
    init_log(
        logger = logger, 
        filename = logfile, 
        loglevel = loglevel
    )
    
    # mongo uri looks like:
    #mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
    uri = None
    if username and password:
        uri = "{0}{1}:{2}@{3}:{4}/{5}".format(
              conn_host, username, password, host, port, database
              )
        logger.info('uri={0}'.format(uri))
    
    adapter = MongoAdapter()
    adapter.connect(
        host=host, 
        port=port, 
        database=database,
        uri=uri
    )
    
    ctx.obj = {}
    ctx.obj['db'] = database
    ctx.obj['user'] = username
    ctx.obj['password'] = password
    ctx.obj['port'] = port
    ctx.obj['host'] = host
    ctx.obj['adapter'] = adapter
Beispiel #2
0
def cli(ctx, conn_host, database, username, password, port, host, verbose,
        logfile, backend):
    """loqusdb: manage a local variant count database."""
    # configure root logger to print to STDERR
    loglevel = LEVELS.get(max(verbose, 1), "INFO")
    init_log(logger=logger, filename=logfile, loglevel=loglevel)

    # mongo uri looks like:
    #mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
    uri = None
    if username and password:
        uri = "{0}{1}:{2}@{3}:{4}/{5}".format(conn_host, username, password,
                                              host, port, database)
        logger.info('uri={0}'.format(uri))

    adapter = MongoAdapter()
    adapter.connect(host=host, port=port, database=database, uri=uri)

    ctx.obj = {}
    ctx.obj['db'] = database
    ctx.obj['user'] = username
    ctx.obj['password'] = password
    ctx.obj['port'] = port
    ctx.obj['host'] = host
    ctx.obj['adapter'] = adapter
Beispiel #3
0
import logging
import pytest
from mongomock import MongoClient
from pymongo import MongoClient as RealMongoClient

from loqusdb.plugins import MongoAdapter
from loqusdb.log import init_log

logger = logging.getLogger('.')

init_log(logger, loglevel='DEBUG')

@pytest.fixture(scope='function')
def mongo_client(request):
    """Return a mongomock client"""
    client = MongoClient()
    return client

# @pytest.fixture(scope='function')
# def real_mongo_client(request):
#     """Return a mongo client"""
#     client = RealMongoClient()
#
#     def teardown():
#         client.drop_database('test')
#
#     request.addfinalizer(teardown)
#     return client

@pytest.fixture(scope='function')
def mongo_adapter(request, mongo_client):
Beispiel #4
0
import logging
import pytest
from mongomock import MongoClient
from pymongo import MongoClient as RealMongoClient

from ped_parser import FamilyParser

from loqusdb.plugins import MongoAdapter
from loqusdb.log import init_log

logger = logging.getLogger('.')

init_log(logger, loglevel='DEBUG')


class Variant(object):
    """Mock a cyvcf variant
    
    Default is to return a variant with three individuals high genotype 
    quality.
    """
    def __init__(self,
                 chrom='1',
                 pos=80000,
                 ref='A',
                 alt='C',
                 end=None,
                 gt_quals=[60, 60, 60],
                 gt_types=[1, 1, 0]):
        super(Variant, self).__init__()
        self.CHROM = chrom
Beispiel #5
0
import cyvcf2
import pytest

from loqusdb.build_models.case import build_case
from loqusdb.build_models.variant import build_variant
from loqusdb.log import init_log
from loqusdb.models import Case
from loqusdb.plugins.mongo.adapter import MongoAdapter
from loqusdb.utils.load import update_case
from mongomock import MongoClient as MockClient
from ped_parser import FamilyParser
from pymongo import MongoClient

logger = logging.getLogger(".")

init_log(logger, loglevel="DEBUG")

REAL_DATABASE = "loqus-test"
TEST_DATABASE = "test"


class CyvcfVariant(object):
    """Mock a cyvcf variant

    Default is to return a variant with three individuals high genotype
    quality.
    """
    def __init__(
        self,
        chrom="1",
        pos=80000,