Example #1
0
def phenotypes_actions(institute_id, case_name):
    """Perform actions on multiple phenotypes."""
    institute_obj, case_obj = institute_and_case(store, institute_id,
                                                 case_name)
    case_url = url_for(".case", institute_id=institute_id, case_name=case_name)
    action = request.form["action"]
    hpo_ids = request.form.getlist("hpo_id")
    user_obj = store.user(current_user.email)

    if action == "PHENOMIZER":
        if len(hpo_ids) == 0:
            hpo_ids = [
                term["phenotype_id"]
                for term in case_obj.get("phenotype_terms", [])
            ]

        username = current_app.config["PHENOMIZER_USERNAME"]
        password = current_app.config["PHENOMIZER_PASSWORD"]
        diseases = controllers.hpo_diseases(username, password, hpo_ids)
        if diseases:
            return render_template(
                "cases/diseases.html",
                diseases=diseases,
                institute=institute_obj,
                case=case_obj,
            )

    if action == "DELETE":
        for hpo_id in hpo_ids:
            # DELETE a phenotype from the list
            store.remove_phenotype(institute_obj, case_obj, user_obj, case_url,
                                   hpo_id)

    if action == "ADDGENE":
        hgnc_ids = parse_raw_gene_ids(request.form.getlist("genes"))
        store.update_dynamic_gene_list(case_obj,
                                       hgnc_ids=list(hgnc_ids),
                                       add_only=True)

    if action == "GENES":
        hgnc_symbols = parse_raw_gene_symbols(request.form.getlist("genes"))
        store.update_dynamic_gene_list(case_obj,
                                       hgnc_symbols=list(hgnc_symbols))

    if action == "GENERATE":
        if len(hpo_ids) == 0:
            hpo_ids = [
                term["phenotype_id"]
                for term in case_obj.get("phenotype_terms", [])
            ]
        results = store.generate_hpo_gene_list(*hpo_ids)
        # determine how many HPO terms each gene must match
        hpo_count = int(request.form.get("min_match") or 1)
        hgnc_ids = [result[0] for result in results if result[1] >= hpo_count]
        store.update_dynamic_gene_list(case_obj,
                                       hgnc_ids=hgnc_ids,
                                       phenotype_ids=hpo_ids)

    return redirect("#".join([case_url, "phenotypes_panel"]))
Example #2
0
def phenotypes_actions(institute_id, case_name):
    """Perform actions on multiple phenotypes."""
    institute_obj, case_obj = institute_and_case(store, institute_id,
                                                 case_name)
    case_url = url_for('.case', institute_id=institute_id, case_name=case_name)
    action = request.form['action']
    hpo_ids = request.form.getlist('hpo_id')
    user_obj = store.user(current_user.email)

    if action == 'DELETE':
        for hpo_id in hpo_ids:
            # DELETE a phenotype from the list
            store.remove_phenotype(institute_obj, case_obj, user_obj, case_url,
                                   hpo_id)
    elif action == 'PHENOMIZER':
        if len(hpo_ids) == 0:
            hpo_ids = [
                term['phenotype_id']
                for term in case_obj.get('phenotype_terms', [])
            ]

        username = current_app.config['PHENOMIZER_USERNAME']
        password = current_app.config['PHENOMIZER_PASSWORD']
        diseases = controllers.hpo_diseases(username, password, hpo_ids)
        return render_template('cases/diseases.html',
                               diseases=diseases,
                               institute=institute_obj,
                               case=case_obj)

    elif action == 'GENES':
        hgnc_symbols = set()
        for raw_symbols in request.form.getlist('genes'):
            # avoid empty lists
            if raw_symbols:
                hgnc_symbols.update(
                    raw_symbol.split(' ', 1)[0]
                    for raw_symbol in raw_symbols.split('|'))
        store.update_dynamic_gene_list(case_obj, hgnc_symbols=hgnc_symbols)

    elif action == 'GENERATE':
        if len(hpo_ids) == 0:
            hpo_ids = [
                term['phenotype_id']
                for term in case_obj.get('phenotype_terms', [])
            ]
        results = store.generate_hpo_gene_list(*hpo_ids)
        # determine how many HPO terms each gene must match
        hpo_count = int(request.form.get('min_match') or 1)
        hgnc_ids = [result[0] for result in results if result[1] >= hpo_count]
        store.update_dynamic_gene_list(case_obj,
                                       hgnc_ids=hgnc_ids,
                                       phenotype_ids=hpo_ids)

    return redirect(case_url)
Example #3
0
def phenotypes_actions(institute_id, case_name):
    """Perform actions on multiple phenotypes."""
    institute_obj, case_obj = institute_and_case(store, institute_id, case_name)
    case_url = url_for('.case', institute_id=institute_id, case_name=case_name)
    action = request.form['action']
    hpo_ids = request.form.getlist('hpo_id')
    user_obj = store.user(current_user.email)

    if action == 'DELETE':
        for hpo_id in hpo_ids:
            # DELETE a phenotype from the list
            store.remove_phenotype(institute_obj, case_obj, user_obj, case_url, hpo_id)
    elif action == 'PHENOMIZER':
        if len(hpo_ids) == 0:
            hpo_ids = [term['phenotype_id'] for term in case_obj.get('phenotype_terms', [])]

        username = current_app.config['PHENOMIZER_USERNAME']
        password = current_app.config['PHENOMIZER_PASSWORD']
        diseases = controllers.hpo_diseases(username, password, hpo_ids)
        return render_template('cases/diseases.html', diseases=diseases,
                               institute=institute_obj, case=case_obj)

    elif action == 'GENES':
        hgnc_symbols = set()
        for raw_symbols in request.form.getlist('genes'):
            # avoid empty lists
            if raw_symbols:
                hgnc_symbols.update(raw_symbol.split(' ', 1)[0] for raw_symbol in
                                    raw_symbols.split('|'))
        store.update_dynamic_gene_list(case_obj, hgnc_symbols=hgnc_symbols)

    elif action == 'GENERATE':
        if len(hpo_ids) == 0:
            hpo_ids = [term['phenotype_id'] for term in case_obj.get('phenotype_terms', [])]
        results = store.generate_hpo_gene_list(*hpo_ids)
        # determine how many HPO terms each gene must match
        hpo_count = int(request.form.get('min_match') or 1)
        hgnc_ids = [result[0] for result in results if result[1] >= hpo_count]
        store.update_dynamic_gene_list(case_obj, hgnc_ids=hgnc_ids, phenotype_ids=hpo_ids)

    return redirect(case_url)
Example #4
0
def phenotypes_actions(institute_id, case_name):
    """Perform actions on multiple phenotypes."""
    institute_obj, case_obj = institute_and_case(store, institute_id,
                                                 case_name)
    case_url = url_for(".case", institute_id=institute_id, case_name=case_name)
    action = request.form["action"]
    hpo_ids = request.form.getlist("hpo_id")
    user_obj = store.user(current_user.email)

    if action == "DELETE":
        for hpo_id in hpo_ids:
            # DELETE a phenotype from the list
            store.remove_phenotype(institute_obj, case_obj, user_obj, case_url,
                                   hpo_id)
    elif action == "PHENOMIZER":
        if len(hpo_ids) == 0:
            hpo_ids = [
                term["phenotype_id"]
                for term in case_obj.get("phenotype_terms", [])
            ]

        username = current_app.config["PHENOMIZER_USERNAME"]
        password = current_app.config["PHENOMIZER_PASSWORD"]
        diseases = controllers.hpo_diseases(username, password, hpo_ids)
        return render_template(
            "cases/diseases.html",
            diseases=diseases,
            institute=institute_obj,
            case=case_obj,
        )

    elif action == "ADDGENE":
        hgnc_symbol = None
        for raw_symbol in request.form.getlist("genes"):
            LOG.debug("raw gene: {}".format(raw_symbol))
            # avoid empty lists
            if raw_symbol:
                # take the first nubmer before |, and remove any space.
                try:
                    hgnc_symbol_split = raw_symbol.split("|", 1)[0]
                    hgnc_symbol = int(hgnc_symbol_split.replace(" ", ""))
                except ValueError:
                    flash(
                        "Provided gene info could not be parsed! "
                        "Please allow autocompletion to finish.",
                        "warning",
                    )
            LOG.debug("Parsed HGNC symbol {}".format(hgnc_symbol))
            store.update_dynamic_gene_list(case_obj,
                                           hgnc_ids=[hgnc_symbol],
                                           add_only=True)

    elif action == "GENES":
        hgnc_symbols = set()
        for raw_symbols in request.form.getlist("genes"):
            LOG.debug("raw gene list: {}".format(raw_symbols))
            # avoid empty lists
            if raw_symbols:
                try:
                    hgnc_symbols.update(
                        raw_symbol.split(" ", 1)[0]
                        for raw_symbol in raw_symbols.split("|"))
                except ValueError:
                    flash(
                        "Provided gene info could not be parsed! "
                        "Please allow autocompletion to finish.",
                        "warning",
                    )
            LOG.debug("HGNC symbols {}".format(hgnc_symbols))
        store.update_dynamic_gene_list(case_obj, hgnc_symbols=hgnc_symbols)

    elif action == "GENERATE":
        if len(hpo_ids) == 0:
            hpo_ids = [
                term["phenotype_id"]
                for term in case_obj.get("phenotype_terms", [])
            ]
        results = store.generate_hpo_gene_list(*hpo_ids)
        # determine how many HPO terms each gene must match
        hpo_count = int(request.form.get("min_match") or 1)
        hgnc_ids = [result[0] for result in results if result[1] >= hpo_count]
        store.update_dynamic_gene_list(case_obj,
                                       hgnc_ids=hgnc_ids,
                                       phenotype_ids=hpo_ids)

    return redirect(case_url)