def populate_institute_form(form, institute_obj): """Populate institute settings form Args: form(scout.server.blueprints.institutes.models.InstituteForm) institute_obj(dict) An institute object """ # get all other institutes to populate the select of the possible collaborators institutes_tuples = [] for inst in store.institutes(): if not inst["_id"] == institute_obj["_id"]: institutes_tuples.append(((inst["_id"], inst["display_name"]))) form.display_name.default = institute_obj.get("display_name") form.institutes.choices = institutes_tuples form.coverage_cutoff.default = institute_obj.get("coverage_cutoff") form.frequency_cutoff.default = institute_obj.get("frequency_cutoff") # collect all available default HPO terms and populate the pheno_groups form select with these values default_phenotypes = [ choice[0].split(" ")[0] for choice in form.pheno_groups.choices ] if institute_obj.get("phenotype_groups"): for key, value in institute_obj["phenotype_groups"].items(): if not key in default_phenotypes: custom_group = " ".join([ key, ",", value.get("name"), "( {} )".format(value.get("abbr")) ]) form.pheno_groups.choices.append((custom_group, custom_group)) # populate gene panels multiselect with panels from institute available_panels = list(store.latest_panels(institute_obj["_id"])) # And from institute's collaborators for collaborator in institute_obj.get("collaborators", []): available_panels += list(store.latest_panels(collaborator)) panel_set = set() for panel in available_panels: panel_set.add((panel["panel_name"], panel["display_name"])) form.gene_panels.choices = sorted(panel_set, key=lambda tup: tup[1]) return default_phenotypes
def panels(): """Show all panels for a case.""" if request.method == 'POST': # update an existing panel csv_file = request.files['csv_file'] content = csv_file.stream.read() if b'\n' in content: lines = content.decode().split('\n') else: lines = content.decode('windows-1252').split('\r') new_panel_name = request.form.get('new_panel_name') if new_panel_name: panel_obj = controllers.new_panel( store=store, institute_id=request.form['institute'], panel_name=new_panel_name, display_name=request.form['display_name'], csv_lines=lines, ) if panel_obj is None: return redirect(request.referrer) flash("new gene panel added: {}!".format(panel_obj['panel_name'])) else: panel_obj = controllers.update_panel(store, request.form['panel_name'], lines) if panel_obj is None: return abort( 404, "gene panel not found: {}".format( request.form['panel_name'])) return redirect(url_for('panels.panel', panel_id=panel_obj['_id'])) institutes = list(user_institutes(store, current_user)) panel_names = [ name for institute in institutes for name in store.gene_panels( institute_id=institute['_id']).distinct('panel_name') ] panel_versions = {} for name in panel_names: panel_versions[name] = store.gene_panels(panel_id=name) panel_groups = [] for institute_obj in institutes: institute_panels = store.latest_panels(institute_obj['_id']) panel_groups.append((institute_obj, institute_panels)) return dict(panel_groups=panel_groups, panel_names=panel_names, panel_versions=panel_versions, institutes=institutes)
def panels(): """Show all panels for a user""" if request.method == "POST": # Edit/create a new panel and redirect to its page redirect_panel_id = controllers.panel_create_or_update(store, request) if redirect_panel_id: return redirect(url_for("panels.panel", panel_id=redirect_panel_id)) return redirect(url_for("panels.panels")) institutes = list(user_institutes(store, current_user)) panel_names = [ name for institute in institutes for name in store.gene_panels(institute_id=institute["_id"], include_hidden=True).distinct("panel_name") ] panel_versions = {} for name in panel_names: panels = store.gene_panels(panel_id=name, include_hidden=True) panel_versions[name] = [ panel_obj for panel_obj in panels if controllers.shall_display_panel(panel_obj, current_user) ] panel_groups = [] for institute_obj in institutes: institute_panels = ( panel_obj for panel_obj in store.latest_panels(institute_obj["_id"], include_hidden=True) if controllers.shall_display_panel(panel_obj, current_user)) panel_groups.append((institute_obj, institute_panels)) return dict( panel_groups=panel_groups, panel_names=panel_names, panel_versions=panel_versions, institutes=institutes, )
def panels(): """Show all panels for a case.""" if request.method == "POST": # update an existing panel csv_file = request.files["csv_file"] content = csv_file.stream.read() lines = None try: if b"\n" in content: lines = content.decode("utf-8-sig", "ignore").split("\n") else: lines = content.decode("windows-1252").split("\r") except Exception as err: flash( "Something went wrong while parsing the panel CSV file! ({})". format(err), "danger", ) return redirect(request.referrer) new_panel_name = request.form.get("new_panel_name") if new_panel_name: # create a new panel new_panel_id = controllers.new_panel( store=store, institute_id=request.form["institute"], panel_name=new_panel_name, display_name=request.form["display_name"], description=request.form["description"], csv_lines=lines, ) if new_panel_id is None: flash( "Something went wrong and the panel list was not updated!", "warning", ) return redirect(request.referrer) else: flash("new gene panel added, {}!".format(new_panel_name), "success") return redirect(url_for("panels.panel", panel_id=new_panel_id)) else: # modify an existing panel update_option = request.form["modify_option"] panel_obj = controllers.update_panel( store=store, panel_name=request.form["panel_name"], csv_lines=lines, option=update_option, ) if panel_obj is None: return abort( 404, "gene panel not found: {}".format( request.form["panel_name"])) else: return redirect( url_for("panels.panel", panel_id=panel_obj["_id"])) institutes = list(user_institutes(store, current_user)) panel_names = [ name for institute in institutes for name in store.gene_panels( institute_id=institute["_id"]).distinct("panel_name") ] panel_versions = {} for name in panel_names: panel_versions[name] = store.gene_panels(panel_id=name) panel_groups = [] for institute_obj in institutes: institute_panels = store.latest_panels(institute_obj["_id"]) panel_groups.append((institute_obj, institute_panels)) return dict( panel_groups=panel_groups, panel_names=panel_names, panel_versions=panel_versions, institutes=institutes, )
def panels(): """Show all panels for a case.""" if request.method == 'POST': # update an existing panel csv_file = request.files['csv_file'] content = csv_file.stream.read() lines = None try: if b'\n' in content: lines = content.decode('utf-8', 'ignore').split('\n') else: lines = content.decode('windows-1252').split('\r') except Exception as err: flash('Something went wrong while parsing the panel CSV file! ({})'.format(err), 'danger') return redirect(request.referrer) new_panel_name = request.form.get('new_panel_name') if new_panel_name: #create a new panel new_panel_id = controllers.new_panel( store=store, institute_id=request.form['institute'], panel_name=new_panel_name, display_name=request.form['display_name'], description=request.form['description'], csv_lines=lines, ) if new_panel_id is None: flash('Something went wrong and the panel list was not updated!','warning') return redirect(request.referrer) else: flash("new gene panel added, {}!".format(new_panel_name),'success') return redirect(url_for('panels.panel', panel_id=new_panel_id)) else: # modify an existing panel update_option = request.form['modify_option'] panel_obj= controllers.update_panel( store=store, panel_name=request.form['panel_name'], csv_lines=lines, option=update_option ) if panel_obj is None: return abort(404, "gene panel not found: {}".format(request.form['panel_name'])) else: return redirect(url_for('panels.panel', panel_id=panel_obj['_id'])) institutes = list(user_institutes(store, current_user)) panel_names = [name for institute in institutes for name in store.gene_panels(institute_id=institute['_id']).distinct('panel_name')] panel_versions = {} for name in panel_names: panel_versions[name]=store.gene_panels(panel_id=name) panel_groups = [] for institute_obj in institutes: institute_panels = store.latest_panels(institute_obj['_id']) panel_groups.append((institute_obj, institute_panels)) return dict(panel_groups=panel_groups, panel_names=panel_names, panel_versions=panel_versions, institutes=institutes)
def panels(): """Show all panels for a case.""" if request.method == 'POST': # update an existing panel csv_file = request.files['csv_file'] content = csv_file.stream.read() lines = None try: if b'\n' in content: lines = content.decode('utf-8', 'ignore').split('\n') else: lines = content.decode('windows-1252').split('\r') except Exception as err: flash('Something went wrong while parsing the panel CSV file! ({})'.format(err), 'danger') return redirect(request.referrer) new_panel_name = request.form.get('new_panel_name') if new_panel_name: #create a new panel new_panel_id = controllers.new_panel( store=store, institute_id=request.form['institute'], panel_name=new_panel_name, display_name=request.form['display_name'], csv_lines=lines, ) if new_panel_id is None: flash('Something went wrong and the panel list was not updated!','warning') return redirect(request.referrer) else: flash("new gene panel added, {}!".format(new_panel_name),'success') return redirect(url_for('panels.panel', panel_id=new_panel_id)) else: # modify an existing panel update_option = request.form['modify_option'] panel_obj= controllers.update_panel( store=store, panel_name=request.form['panel_name'], csv_lines=lines, option=update_option ) if panel_obj is None: return abort(404, "gene panel not found: {}".format(request.form['panel_name'])) else: return redirect(url_for('panels.panel', panel_id=panel_obj['_id'])) institutes = list(user_institutes(store, current_user)) panel_names = [name for institute in institutes for name in store.gene_panels(institute_id=institute['_id']).distinct('panel_name')] panel_versions = {} for name in panel_names: panel_versions[name]=store.gene_panels(panel_id=name) panel_groups = [] for institute_obj in institutes: institute_panels = store.latest_panels(institute_obj['_id']) panel_groups.append((institute_obj, institute_panels)) return dict(panel_groups=panel_groups, panel_names=panel_names, panel_versions=panel_versions, institutes=institutes)