예제 #1
0
def scout(context, madeline_exe, date, replace, case_name):
    """Prepare a config and files for Scout."""
    madeline_exe = madeline_exe or context.obj['madeline_exe']
    manager = api.manager(context.obj['database'])
    root_path = context.obj['root']
    run_obj = run_orabort(context, case_name, date)
    if not run_obj.pipeline_version.startswith('v4'):
        log.error("unsupported pipeline version: %s", run_obj.pipeline_version)
        context.abort()

    existing_conf = (api.assets(category='scout-config', run_id=run_obj.id)
                        .first())
    if existing_conf:
        if replace:
            log.info("deleting existing scout config: %s", existing_conf.path)
            api.delete_asset(existing_conf)
            existing_mad = (api.assets(category='madeline', run_id=run_obj.id)
                               .first())
            if existing_mad:
                log.info("deleting existing madeline: %s", existing_mad.path)
                api.delete_asset(existing_mad)
            manager.commit()
        else:
            log.error("scout config already generated")
            context.abort()

    prepare_scout(run_obj, root_path, madeline_exe)
    manager.commit()
예제 #2
0
def prepare_scout(run_obj, root_path, madeline_exe):
    """Prepare files for Scout upload."""
    run_root = Path(get_rundir(root_path, run_obj.case.name, run=run_obj))
    config_data = build_config(run_obj)

    pedigree = api.assets(category='pedigree', run_id=run_obj.id).one()
    # extract external sample ids
    ped_yaml = api.assets(category='pedigree-yaml', run_id=run_obj.id).one()
    with Path(ped_yaml.path).open() as in_handle:
        ped_data = yaml.load(in_handle)
    sample_map = {sample['sample_id']: sample['sample_name']
                  for sample in ped_data['samples']}
    madeline_path = build_madeline(pedigree.path, run_root, madeline_exe,
                                   sample_map)
    if madeline_path:
        mad_asset = api.add_asset(run_obj, madeline_path, 'madeline')
        mad_asset.path = str(madeline_path)
        log.info("add madeline asset: %s", mad_asset.path)
        run_obj.assets.append(mad_asset)
        config_data['madeline'] = mad_asset.path

    # save the new scout config
    config_path = Path(run_root).joinpath('scout.conf.yaml')
    with open(config_path, 'w') as out_handle:
        yaml.safe_dump(config_data, out_handle, indent=4,
                       default_flow_style=False)

    scout_asset = api.add_asset(run_obj, config_path, 'scout-config')
    scout_asset.path = config_path
    log.info("add scout config asset: %s", scout_asset.path)
    run_obj.assets.append(scout_asset)
예제 #3
0
def replace_paths(old_root, new_root):
    """Replace root paths for assets."""
    all_assets = api.assets()
    with click.progressbar(all_assets,
                           label='updating asset paths',
                           length=all_assets.count()) as bar:
        for asset in bar:
            new_path = asset.path.replace(old_root, new_root)
            log.debug("replacing path: %s -> %s", asset.path, new_path)
            assert Path(new_path).exists(), "can't find asset: {}".format(new_path)
            asset.path = new_path
예제 #4
0
def mip_sex(context, sample, case_id):
    """Parse out analysis determined sex of sample."""
    if sample and case_id is None:
        sample_obj = api.sample(sample)
        if sample_obj is None:
            log.warn('sorry, sample not found')
            context.abort()
        case_id = sample_obj.case_id

    qc_metrics = api.assets(case_id, category='qc').first()
    qcm_data = yaml.load(qc_metrics.path)
    sample_sexes = parse_mipsex(qcm_data)
    if sample:
        click.echo(sample_sexes[sample])
    else:
        for sample_id, sex in sample_sexes.items():
            click.echo("{}: {}".format(sample_id, sex))