Ejemplo n.º 1
0
def extend(context, no_link, date, category, sample, archive_type, case_name,
           asset_path):
    """Add an additional asset to a run."""
    manager = api.manager(context.obj['database'])
    run_obj = run_orabort(context, case_name, date)
    if sample:
        sample_map = {smpl.name: smpl for smpl in run_obj.samples}
        sample_obj = sample_map[sample]
    else:
        sample_obj = None
    new_asset = api.add_asset(run_obj, asset_path, category, archive_type,
                              sample=sample_obj)

    root_path = context.obj['root']
    run_root = get_rundir(root_path, run_obj.case.name, run_obj)
    filename = new_asset.basename()
    if no_link:
        new_path = asset_path
    else:
        new_path = run_root.joinpath(filename)
        log.debug("link asset: %s -> %s", new_asset.original_path, new_path)
        path(new_asset.original_path).link(new_path)

    new_asset.path = new_path
    run_obj.assets.append(new_asset)
    log.info("add asset: %s", new_asset.path)
    manager.commit()
Ejemplo n.º 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)
Ejemplo n.º 3
0
def restore_run(root_path, run_obj, tar_path, archive_type):
    """Restore files from a tar archive."""
    # confirm the checksum
    sha1 = getattr(run_obj, "{}_checksum".format(archive_type))
    assert checksum(tar_path) == sha1

    # unpack the files
    run_dir = get_rundir(root_path, run_obj.case.name, run_obj)
    untar_files(run_dir, tar_path)

    # update the "local" status of all files blindly
    for asset in run_obj.assets:
        if path(asset.path).exists():
            asset.is_local = True