Пример #1
0
def test_app_paths():
    # test with default root
    paths = constants.app_paths()
    root = os.path.expanduser('~/.mip2scout')
    assert paths.app == root
    assert paths.config == os.path.join(root, 'config.yaml')

    # test with custom app root
    paths = constants.app_paths('/tmp/mip2scout')
    assert paths.out == '/tmp/mip2scout/static'
    assert paths.log == '/tmp/mip2scout/logs/main.log'
Пример #2
0
def root(context, config, log, level, root_dir):
    """Process MIP output to prepare upload to Scout."""
    if config and os.path.exists(config.name):
        context.obj = yaml.load(config)
        context.default_map = context.obj
    else:
        context.obj = {}

    app_rootdir = root_dir or context.obj.get('root_dir') or APP_ROOT
    paths = context.obj['paths'] = app_paths(app_rootdir)
    build_folders(paths.app)
    log_path = log or paths.log
    # setup logging
    init_log(log_path, email_auth=context.obj.get('email'), level=level)
Пример #3
0
def all_cmd(context, root_dir, vtype, force, no_upload):
    """Do all the preprocessing for an analysis."""
    paths = app_paths(root_dir or context.obj["root_dir"] or APP_ROOT)
    mip_case = context.obj["case"]
    owner = mip_case.instance_tags[0]
    case_root = build_case_root(paths.out, cust_id=owner, case_id=mip_case.family_id)
    config_path = case_root.joinpath("{}.conf.ini".format(vtype))
    madeline_path = case_root.joinpath("madeline.xml")

    scout_db = scout_tools.ScoutDatabase(context.obj["mongodb"])
    logger.debug("checking if case is loaded in Scout")
    case_loaded = scout_db.case_is_loaded(owner, mip_case.family_id, mip_case.analyzed_at, vtype=vtype)

    if not force and case_loaded:
        logger.debug("case (%s) already uploaded", vtype)

    elif (mip_case.is_old and not case_loaded) and not force:
        logger.info("%s is from old analysis, use force", mip_case.family_id)

    else:
        if vtype == "clinical":
            logger.info("generating madeline SVG file")
            try:
                context.invoke(svg, out=madeline_path.open("w"))
            except SinglePedigreeError:
                logger.debug("skipping pedigree generation, single sample")
            except MadelineIncompatibleError:
                logger.debug("skipping pedigree generation, no connections")

            case_obj = scout_db.case(owner, mip_case.family_id)
            if case_obj and not case_loaded:
                logger.info("removing coverage from old analysis (%s)", case_obj.analysis_date)
                context.invoke(coverage_cmd, remove=True)

                logger.info("remove variants from frequency database")
                context.invoke(frequency, remove=True)

            logger.info("uploading coverage to chanjo database")
            context.invoke(coverage_cmd)

            logger.info("uploading variants to frequency database")
            context.invoke(frequency)

            logger.info("uploading genotypes to taboo database")
            context.invoke(genotype, force=force)

        logger.info("generating '%s' config file", vtype)
        context.invoke(config, out=config_path.open("w"), vtype=vtype, madeline_path=madeline_path)

        if not no_upload:
            logger.info("uploading case and variants to scout")
            context.invoke(upload, config=config_path, force=force)

            # also upload research variants if the case is_research
            if vtype == "clinical" and case_obj and case_obj.is_research:
                logger.info("old case marked as research")
                logger.info("generating research config file")
                config_path = case_root.joinpath("research.conf.ini")
                context.invoke(config, out=config_path, vtype="research")
                logger.info("uploading research variants to scout")
                context.invoke(upload, config=config_path, force=force)