Ejemplo n.º 1
0
def phenotypes(institute_id, case_name, phenotype_id=None):
    """Handle 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)
    is_group = request.args.get('is_group') == 'yes'
    user_obj = store.user(current_user.email)

    if phenotype_id:
        # DELETE a phenotype item/group from case
        store.remove_phenotype(institute_obj, case_obj, user_obj, case_url,
                               phenotype_id, is_group=is_group)
    else:
        try:
            # add a new phenotype item/group to the case
            phenotype_term = request.form['hpo_term']
            if phenotype_term.startswith('HP:') or len(phenotype_term) == 7:
                hpo_term = phenotype_term.split(' | ', 1)[0]
                store.add_phenotype(institute_obj, case_obj, user_obj, case_url,
                                    hpo_term=hpo_term, is_group=is_group)
            else:
                # assume omim id
                store.add_phenotype(institute_obj, case_obj, user_obj, case_url,
                                    omim_term=phenotype_term)
        except ValueError:
            return abort(400, ("unable to add phenotype: {}".format(phenotype_term)))
    return redirect(case_url)
Ejemplo n.º 2
0
def phenotypes(institute_id, case_name, phenotype_id=None):
    """Handle 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)
    is_group = request.args.get('is_group') == 'yes'
    user_obj = store.user(current_user.email)

    if phenotype_id:
        # DELETE a phenotype item/group from case
        store.remove_phenotype(institute_obj, case_obj, user_obj, case_url,
                               phenotype_id, is_group=is_group)
    else:
        try:
            # add a new phenotype item/group to the case
            phenotype_term = request.form['hpo_term']
            if phenotype_term.startswith('HP:') or len(phenotype_term) == 7:
                hpo_term = phenotype_term.split(' | ', 1)[0]
                store.add_phenotype(institute_obj, case_obj, user_obj, case_url,
                                    hpo_term=hpo_term, is_group=is_group)
            else:
                # assume omim id
                store.add_phenotype(institute_obj, case_obj, user_obj, case_url,
                                    omim_term=phenotype_term)
        except ValueError:
            return abort(400, ("unable to add phenotype: {}".format(phenotype_term)))
    return redirect(case_url)
Ejemplo n.º 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 == "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"]))
Ejemplo n.º 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 == '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)
Ejemplo n.º 5
0
def phenotypes(institute_id, case_name, phenotype_id=None):
    """Handle 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)
    is_group = request.args.get("is_group") == "yes"
    user_obj = store.user(current_user.email)

    if phenotype_id:
        # DELETE a phenotype item/group from case
        store.remove_phenotype(institute_obj,
                               case_obj,
                               user_obj,
                               case_url,
                               phenotype_id,
                               is_group=is_group)
    else:
        try:
            # add a new phenotype item/group to the case
            hpo_term = None
            omim_term = None

            phenotype_term = request.form["hpo_term"]
            phenotype_inds = request.form.getlist(
                "phenotype_inds")  # Individual-level phenotypes

            if phenotype_term.startswith("HP:") or len(phenotype_term) == 7:
                hpo_term = phenotype_term.split(" | ", 1)[0]
            else:
                omim_term = phenotype_term

            store.add_phenotype(
                institute=institute_obj,
                case=case_obj,
                user=user_obj,
                link=case_url,
                hpo_term=hpo_term,
                omim_term=omim_term,
                is_group=is_group,
                phenotype_inds=phenotype_inds,
            )
        except ValueError:
            flash(
                f"Unable to add phenotype for the given terms:{phenotype_term}",
                "warning",
            )
            return redirect(case_url)

    return redirect("#".join([case_url, "phenotypes_panel"]))
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)