def __load_case_info(case, except_enabled=False, quality_enabled=False): wok = current_app.wok case_info = dict( id=case.id, name=case.name, state=case.state.title if case.state is not None else None,created=case.created, started=case.started, finished=case.finished, removed=case.removed) if case.state is not None: case_info["state"] = case.state.title if case.properties is not None: conf = get_project_conf() results_path = get_results_path(conf) project_path = os.path.join(results_path, case.properties["path"]) quality = None if quality_enabled: project_results = ProjectResults(path=project_path) quality = project_results.load_quality_control() zip_path = os.path.join(project_path, "results.zip") website_path = os.path.join(project_path, "website", "results", "project.tsv") case_info.update( analysis_type=case.properties["analysis_type"], results_available=os.path.exists(zip_path), website_available=os.path.exists(website_path), quality=quality if quality is not None and len(quality) > 0 else None) engine_case = wok.engine.case(case.engine_name) if engine_case is not None: exceptions = None if except_enabled: exceptions = __engine_case_exceptions(engine_case) case_info.update( state=engine_case.state.title, started=engine_case.started, finished=engine_case.finished, elapsed=engine_case.elapsed, progress=__engine_case_progress(engine_case), exceptions=exceptions) return case_info
def download(case_id): case = current_app.wok.case_by_id(case_id, current_user) if case is None: flash("Case does not exist, there is nothing to download", "error") return redirect(url_for(".index")) current_app.logger.info("[{}] Downloading case results {} ({})...".format(current_user.nick, case.name, case.engine_name)) conf = get_project_conf() results_path = get_results_path(conf) project_path = os.path.join(results_path, case.properties["path"]) dest_path = os.path.join(project_path, "results.zip") if not os.path.exists(dest_path): flash("Sorry, there were an internal error and the results are not available", "error") app.logger.error("[{}] results.zip not available for case {} at {}".format(current_user.nick, case.id, project_path)) return redirect(url_for(".index")) return send_file( dest_path, mimetype="application/x-gzip", as_attachment=True, attachment_filename="IntOGen-Mutations-{}.zip".format(case.name))
def run(type): if type not in [COHORT_ANALYSIS, SINGLE_TUMOR_ANALYSIS]: abort(400) if current_app.wok.cases_count(current_user) >= current_app.config.get("LIMIT_NUM_CASES", 100): flash("""There is a limit on the number of simultaneous analysis that can be managed. You must remove finished analysis before running new ones.""", "error") return redirect(url_for("cases.index")) cb = ConfigBuilder() cb.add_value("user_id", current_user.nick) cb.add_value("workspace", DEFAULT_WORKSPACE) if not current_user.is_anonymous(): cb.add_value("website.user_id", current_user.nick) conf = get_project_conf() if type == COHORT_ANALYSIS: project_id = "cohort-example" mutations_path = get_examples_path(conf, "meduloblastoma_cohort_tier1.muts") elif type == SINGLE_TUMOR_ANALYSIS: project_id = "single-tumor-example" mutations_path = get_examples_path(conf, "pat4_crc.muts") cb.add_value("variants_only", True) cb.add_value("skip_oncodrivefm", True) cb.add_value("skip_oncodriveclust", True) project_id = unique_project_id(project_id) cb.add_value("project.id", project_id) results_path, project_path, project_temp_path = get_paths(project_id, conf=conf) assembly = "hg19" project = dict( id=project_id, assembly=assembly, files=[mutations_path]) projects = [init_project_files(project)] cb.add_value("projects", projects) properties = dict( analysis_type=type, path=os.path.relpath(project_path, results_path), data_file=mutations_path) current_app.logger.info("[{}] Starting example {} ...".format(current_user.nick, project_id)) case = current_app.wok.create_case(current_user, project_id, cb, PROJECT_NAME, MUTATIONS_FLOW_NAME, properties=properties, start=False) engine_case = current_app.wok.engine.case(case.engine_name) #TODO use a background thread upload_files(current_app.logger, case.engine_name, engine_case.storages, projects) current_app.logger.info("[{}] Example {} started on case {}...".format( current_user.nick, project_id, case.engine_name)) engine_case.start() return redirect(url_for("cases.index", highlight=case.id))