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()
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()
def setup_tmp(tmpdir): tmp_path = Path(tmpdir).joinpath('analyses') tmp_path.makedirs_p() db_path = tmp_path.joinpath('store.sqlite3') uri = "sqlite:///{}".format(db_path) manager = api.manager(uri) manager.create_all() data = dict(uri=uri, root=tmp_path, path=str(db_path), manager=manager) yield data manager.drop_all()
def setup_db(db_uri, reset=False): """Setup database with tables and store config. Args: root_path (path): root to store analyses db_uri (str): connection string to database reset (Optional[bool]): whether to reset an existing database """ log.info("setup a new database: %s", db_uri) db = api.manager(db_uri) if reset: db.drop_all() db.create_all()
def archive(context, date, force, case_name): """Archive compiled assets to PDC.""" manager = api.manager(context.obj['database']) run_obj = run_orabort(context, case_name, date) if not run_obj.compiled_at: log.warn("run not compiled yet: %s", case_name) if force or click.confirm("do you want to compile the run?"): date_str = run_obj.analyzed_at.date().isoformat() context.invoke(compile_cmd, date=date_str, force=True, case_name=case_name) # refresh the run object run_obj = AnalysisRun.query.get(run_obj.id) else: context.abort() if force or click.confirm("are you sure you want to archive the run?"): archive_run(run_obj, force=force) manager.commit()
def add(context, force, yes, replace, references, pipeline, config): """Add analyses from different pipelines.""" manager = api.manager(context.obj['database']) config_data = yaml.load(config) if not references: default_ref = "pipelines/references/{}.yaml".format(pipeline) references = pkg_resources.resource_string("housekeeper", default_ref) reference_data = yaml.load(references) loader = LOADERS[pipeline] try: data = loader(config_data, reference_data, force=force) except exc.MalformattedPedigreeError as error: log.error("bad PED formatting: %s", error.message) context.abort() except exc.AnalysisNotFinishedError as error: log.error("analysis not finished: %s", error.message) context.abort() except exc.UnsupportedVersionError as error: new_or_old = 'old' if pipeline == 'mip' else 'new' log.error("pipeline too %s: %s", new_or_old, error.message) context.abort() records = link_records(data) case_name = records['case'].name old_run = check_existing(case_name, records['run']) if old_run: message = "identical run detected: {}".format(case_name) if force or replace: log.warn(message) api.delete(context.obj['root'], old_run) manager.commit() else: log.error(message) context.abort() try: commit_analysis(manager, context.obj['root'], records['case'], records['run']) click.echo("added new analysis: {}".format(case_name)) sample_ids = ', '.join(sample.lims_id for sample in records['run'].samples) click.echo("including samples: {}".format(sample_ids)) except exc.AnalysisConflictError: click.echo("analysis output not removed: {}".format(case_name))